summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtx-server-ctx-fonttest.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-10-20 01:20:14 +0300
committerMarius <mariausol@gmail.com>2013-10-20 01:20:14 +0300
commit965214d981e6129b782c67adcaf3a81aedcb0bac (patch)
tree84f5945aae8efc9b6eb1898b873be5453cafe43d /scripts/context/lua/mtx-server-ctx-fonttest.lua
parente7d0d90a434e5452ff9e86c8abab5a4cac35e2f1 (diff)
downloadcontext-965214d981e6129b782c67adcaf3a81aedcb0bac.tar.gz
stable 2013.05.28 00:36
Diffstat (limited to 'scripts/context/lua/mtx-server-ctx-fonttest.lua')
-rw-r--r--scripts/context/lua/mtx-server-ctx-fonttest.lua294
1 files changed, 111 insertions, 183 deletions
diff --git a/scripts/context/lua/mtx-server-ctx-fonttest.lua b/scripts/context/lua/mtx-server-ctx-fonttest.lua
index da87fe9e8..a8d7edf41 100644
--- a/scripts/context/lua/mtx-server-ctx-fonttest.lua
+++ b/scripts/context/lua/mtx-server-ctx-fonttest.lua
@@ -20,62 +20,44 @@ dofile(resolvers.findfile("font-mis.lua","tex"))
local format, gsub, concat, match, find = string.format, string.gsub, table.concat, string.match, string.find
-local formatters = string.formatters
+local report = logs.reporter("ctx-fonttest")
-local report = logs.reporter("ctx-fonttest")
-
-local sample_line = "This is a sample line!"
-local tempname = "mtx-server-ctx-fonttest-temp"
-local temppath = caches.setfirstwritablefile("temp","mtx-server-ctx-fonttest")
-local basename = "mtx-server-ctx-fonttest-data.lua"
-local basepath = temppath
+local sample_line = "This is a sample line!"
+local tempname = "mtx-server-ctx-fonttest-temp"
+local temppath = caches.setfirstwritablefile("temp","mtx-server-ctx-fonttest")
+local basename = "mtx-server-ctx-fonttest-data.lua"
+local basepath = temppath
local remove_suffixes = { "tex", "pdf", "log" }
-local what_options = { "trace", "basemode" }
+local what_options = { "trace", "basemode" }
for i=1,#remove_suffixes do
os.remove(file.join(temppath,file.addsuffix(tempname,remove_suffixes[i])))
end
-local foolcache = 0
-
-local function makename(name,new)
- if new then
- foolcache = foolcache > 25 and 1 or foolcache + 1
- end
- return formatters["%s-%02i"](name,foolcache)
-end
-
--- nowadays i would use the more advanced template mechanism with named variables
-
local process_templates = { }
--- %\definedfont[name:%s*sample]
-
-process_templates.default = formatters [ [[
+process_templates.default = [[
\starttext
- \setupdirections[bidi=one]
+ \setupdirections[bidi=global]
\definefontfeature[sample][analyze=yes,%s]
- \definedfont[name:%s*none]
+ \definedfont[name:%s*sample]
\startTEXpage[offset=3pt]
\detokenize{%s}
- \blank
- \definedfont[name:%s*sample]
- \detokenize{%s}
\stopTEXpage
\stoptext
-]] ]
+]]
-process_templates.cache = formatters [ [[
+process_templates.cache = [[
\starttext
\definedfont[name:%s]
\startTEXpage[offset=3pt]
cached: \detokenize{%s}
\stopTEXpage
\stoptext
-]] ]
+]]
-process_templates.trace = formatters [ [[
+process_templates.trace = [[
\usemodule[fnt-20]
\definefontfeature[sample][%s]
@@ -91,9 +73,9 @@ process_templates.trace = formatters [ [[
direction=0,
features=sample,
sample={‍\detokenize{%s}}]
-]] ]
+]]
-local javascripts = formatters [ [[
+local javascripts = [[
function selected_radio(name) {
var form = document.forms["main-form"] ;
var script = form.elements[name] ;
@@ -169,28 +151,7 @@ function check_language() {
function check_feature() {
// not needed
}
-]] ]
-
-local jitmode = false -- assumes local use (one user as shared)
-
-local run_context_normal = formatters["mtxrun --path=%q --script context --once --batchmode %q"]
-local run_context_jitted = formatters["mtxrun --path=%q --script context --once --batchmode --jit %q"]
-
-local function runcontext(temppath,filename)
- local start = os.clock()
- local command = (jitmode and run_context_jitted or run_context_normal)(temppath,filename)
- report("temppath: %s",temppath)
- report("filename: %s",filename)
- report("command: %s",command)
- os.execute(command)
- return os.clock() - start
-end
-
-local function identifyfonts()
- local command = "mtxrun --script font --reload"
- report("command: %s",command)
- os.execute(command)
-end
+]]
local cache = { }
@@ -202,9 +163,8 @@ local function showfeatures(f)
features = fonts.helpers.getfeatures(resolvers.findfile(f))
if not features then
report("building cache for '%s'",f)
- local usedname = file.addsuffix(tempname,"tex")
- io.savedata(file.join(temppath,usedname),process_templates.cache(f,f))
- runcontext(temppath,usedname)
+ io.savedata(file.join(temppath,file.addsuffix(tempname,"tex")),format(process_templates.cache,f,f))
+ os.execute(format("mtxrun --path=%s --script context --once --batchmode %s",temppath,tempname))
features = fonts.helpers.getfeatures(f)
end
cache[f] = features or false
@@ -246,15 +206,14 @@ local function showfeatures(f)
for what, v in table.sortedhash(features) do
show(what)
end
- -- we could json this
local stupid = { }
stupid[#stupid+1] = "var feature_hash = new Array ;"
for s, sr in next, rev do
- stupid[#stupid+1] = formatters["feature_hash['%s'] = new Array ;"](s)
+ stupid[#stupid+1] = format("feature_hash['%s'] = new Array ;",s)
for l, lr in next, sr do
- stupid[#stupid+1] = formatters["feature_hash['%s']['%s'] = new Array ;"](s,l)
+ stupid[#stupid+1] = format("feature_hash['%s']['%s'] = new Array ;",s,l)
for f, fr in next, lr do
- stupid[#stupid+1] = formatters["feature_hash['%s']['%s']['%s'] = true ;"](s,l,f)
+ stupid[#stupid+1] = format("feature_hash['%s']['%s']['%s'] = true ;",s,l,f)
end
end
end
@@ -269,7 +228,7 @@ local function showfeatures(f)
end
end
-local template_h = formatters [ [[
+local template_h = [[
<tr>
<th>safe name&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th>family name&nbsp;&nbsp;&nbsp;&nbsp;</th>
@@ -277,9 +236,9 @@ local template_h = formatters [ [[
<th>font name&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th>weight&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th>filename</th>
-</tr>]] ]
+</tr>]]
-local template_d = formatters [ [[
+local template_d = [[
<tr>
<td><a href='mtx-server-ctx-fonttest.lua?selection=%s'>%s</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>%s&nbsp;&nbsp;&nbsp;&nbsp;</td>
@@ -287,22 +246,19 @@ local template_d = formatters [ [[
<td>%s&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>%s&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>%s</td>
-</tr>]] ]
+</tr>]]
local function select_font()
local t = fonts.names.list(".*",false,true)
if t then
local listoffonts = { }
- listoffonts[#listoffonts+1] = "<h1>Fonts</h1><br/>"
listoffonts[#listoffonts+1] = "<table>"
- listoffonts[#listoffonts+1] = template_h()
+ listoffonts[#listoffonts+1] = template_h
for k, v in table.sortedhash(t) do
local kind = v.format
if kind == "otf" or kind == "ttf" or kind == "ttc" then
local fontname = v.fontname
- listoffonts[#listoffonts+1] = template_d(
- fontname,
- fontname,
+ listoffonts[#listoffonts+1] = format(template_d, fontname, fontname,
v.familyname or "",
t.variant or "normal",
t.weight or "normal",
@@ -320,32 +276,25 @@ local function select_font()
return "<b>no fonts</b>"
end
-local edit_template = formatters [ [[
+local edit_template = [[
<textarea name='sampletext' rows='5' cols='100'>%s</textarea>
<br/> <br/>name:&nbsp;<input type='text' name='name' size='20' value=%q/>&nbsp;&nbsp; title:&nbsp;<input type='text' name='title' size='40' value=%q/>
<br/> <br/>scripts:&nbsp;%s
<br/> <br/>languages:&nbsp;%s
<br/> <br/>features:&nbsp;%s
<br/> <br/>options:&nbsp;%s
-]] ]
+]]
-- <embed src="%s#toolbar=0&amp;navpanes=0&amp;scrollbar=0" width="100%%"/>
-local result_template = formatters [ [[
+local result_template = [[
<br/> <br/>
<embed src="%s#view=Fit&amp;toolbar=0&amp;navpanes=0&amp;scrollbar=0" width="100%%"/>
- <br/> <br/> results:&nbsp;
- <a href='%s' target="source">tex file</a>&nbsp;&nbsp;
- <a href='%s' target="result">pdf file</a>&nbsp;&nbsp;
- (runtime: %s)
+ <br/> <br/> results:
+ <a href='%s' target="source">tex file</a>
+ <a href='%s' target="result">pdf file</a>
<br/> <br/>
-]] ]
-
-local main_template = formatters [ [[
- <h1>Font: %s</h1><br/>
- %s
- %s
-]] ]
+]]
scripts.webserver.registerpath(temppath)
@@ -353,7 +302,7 @@ local function get_specification(name)
return fonts.names.resolvedspecification(name or "")
end
-local function edit_font(currentfont,detail,tempname,runtime)
+local function edit_font(currentfont,detail,tempname)
report("entering edit mode for '%s'",currentfont)
local specification = get_specification(currentfont)
if specification then
@@ -365,9 +314,9 @@ local function edit_font(currentfont,detail,tempname,runtime)
local v = sorted[k]
local s = fonts.handlers.otf.tables.scripts[v] or v
if detail and v == detail.script then
- scripts[#scripts+1] = formatters["<input title='%s' id='s-%s' type='radio' name='script' value='%s' onclick='check_script()' checked='checked'/>&nbsp;<span id='t-s-%s'>%s</span>"](s,v,v,v,v)
+ scripts[#scripts+1] = format("<input title='%s' id='s-%s' type='radio' name='script' value='%s' onclick='check_script()' checked='checked'/>&nbsp;<span id='t-s-%s'>%s</span>",s,v,v,v,v)
else
- scripts[#scripts+1] = formatters["<input title='%s' id='s-%s' type='radio' name='script' value='%s' onclick='check_script()' />&nbsp;<span id='t-s-%s'>%s</span>"](s,v,v,v,v)
+ scripts[#scripts+1] = format("<input title='%s' id='s-%s' type='radio' name='script' value='%s' onclick='check_script()' />&nbsp;<span id='t-s-%s'>%s</span>",s,v,v,v,v)
end
end
local sorted = table.sortedkeys(htmldata.languages)
@@ -375,9 +324,9 @@ local function edit_font(currentfont,detail,tempname,runtime)
local v = sorted[k]
local l = fonts.handlers.otf.tables.languages[v] or v
if detail and v == detail.language then
- languages[#languages+1] = formatters["<input title='%s' id='l-%s' type='radio' name='language' value='%s' onclick='check_language()' checked='checked'/>&nbsp;<span id='t-l-%s'>%s</span>"](l,v,v,v,v)
+ languages[#languages+1] = format("<input title='%s' id='l-%s' type='radio' name='language' value='%s' onclick='check_language()' checked='checked'/>&nbsp;<span id='t-l-%s'>%s</span>",l,v,v,v,v)
else
- languages[#languages+1] = formatters["<input title='%s' id='l-%s' type='radio' name='language' value='%s' onclick='check_language()' />&nbsp;<span id='t-l-%s'>%s</span>"](l,v,v,v,v)
+ languages[#languages+1] = format("<input title='%s' id='l-%s' type='radio' name='language' value='%s' onclick='check_language()' />&nbsp;<span id='t-l-%s'>%s</span>",l,v,v,v,v)
end
end
local sorted = table.sortedkeys(htmldata.features)
@@ -385,34 +334,28 @@ local function edit_font(currentfont,detail,tempname,runtime)
local v = sorted[k]
local f = fonts.handlers.otf.tables.features[v] or v
if detail and detail["f-"..v] then
- features[#features+1] = formatters["<input title='%s' id='f-%s' type='checkbox' name='f-%s' onclick='check_feature()' checked='checked'/>&nbsp;<span id='t-f-%s'>%s</span>"](f,v,v,v,v)
+ features[#features+1] = format("<input title='%s' id='f-%s' type='checkbox' name='f-%s' onclick='check_feature()' checked='checked'/>&nbsp;<span id='t-f-%s'>%s</span>",f,v,v,v,v)
else
- features[#features+1] = formatters["<input title='%s' id='f-%s' type='checkbox' name='f-%s' onclick='check_feature()' />&nbsp;<span id='t-f-%s'>%s</span>"](f,v,v,v,v)
+ features[#features+1] = format("<input title='%s' id='f-%s' type='checkbox' name='f-%s' onclick='check_feature()' />&nbsp;<span id='t-f-%s'>%s</span>",f,v,v,v,v)
end
end
for k=1,#what_options do
local v = what_options[k]
if detail and detail["o-"..v] then
- options[#options+1] = formatters["<input id='o-%s' type='checkbox' name='o-%s' checked='checked'/>&nbsp;%s"](v,v,v)
+ options[#options+1] = format("<input id='o-%s' type='checkbox' name='o-%s' checked='checked'/>&nbsp;%s",v,v,v)
else
- options[#options+1] = formatters["<input id='o-%s' type='checkbox' name='o-%s'/>&nbsp;%s"](v,v,v)
+ options[#options+1] = format("<input id='o-%s' type='checkbox' name='o-%s'/>&nbsp;%s",v,v,v)
end
end
- local e = edit_template(
- detail and detail.sampletext or sample_line,
- detail and detail.name or "no name",
- detail and detail.title or "",
- concat(scripts," "),
- concat(languages," "),
- concat(features," "),
- concat(options," ")
- )
+ local e = format(edit_template,
+ (detail and detail.sampletext) or sample_line,(detail and detail.name) or "no name",(detail and detail.title) or "",
+ concat(scripts," "),concat(languages," "),concat(features," "),concat(options," "))
if tempname then
- local pdffile, texfile = file.replacesuffix(tempname,"pdf"), file.replacesuffix(tempname,"tex")
- local r = result_template(pdffile,texfile,pdffile,runtime and formatters["%0.3f"](runtime) or "-")
- return main_template(currentfont,e,r), htmldata.javascript or ""
+ local pdffile, texfile = file.addsuffix(tempname,"pdf"), file.addsuffix(tempname,"tex")
+ local r = format(result_template,pdffile,texfile,pdffile)
+ return e .. r, htmldata.javascript or ""
else
- return main_template(currentfont,e,""), htmldata.javascript or ""
+ return e, htmldata.javascript or ""
end
else
return "error, nothing set up yet"
@@ -425,13 +368,13 @@ end
local function process_font(currentfont,detail) -- maybe just fontname
local features = {
"mode=node",
- formatters["language=%s"](detail.language or "dflt"),
- formatters["script=%s"](detail.script or "dflt"),
+ format("language=%s",detail.language or "dflt"),
+ format("script=%s",detail.script or "dflt"),
}
for k,v in next, detail do
local f = match(k,"^f%-(.*)$")
if f then
- features[#features+1] = formatters["%s=yes"](f)
+ features[#features+1] = format("%s=yes",f)
end
end
local variant = process_templates.default
@@ -442,76 +385,69 @@ local function process_font(currentfont,detail) -- maybe just fontname
if sample == "" then sample = sample_line end
report("sample text: %s",sample)
dir.mkdirs(temppath)
- local tempname = makename(tempname,true)
- local usedname = file.addsuffix(tempname,"tex")
- local fullname = file.join(temppath,usedname)
- local data = variant(concat(features,","),currentfont,sample,currentfont,sample)
+ local fullname = file.join(temppath,file.addsuffix(tempname,"tex"))
+ local data = format(variant,concat(features,","),currentfont,sample)
+ local command = format("mtxrun --path=%q --script context --once --batchmode %q",temppath,tempname)
+ report("filename: %s",fullname)
+ report("command: %s",command)
io.savedata(fullname,data)
- io.flush()
- local runtime = runcontext(temppath,usedname)
- return edit_font(currentfont,detail,tempname,runtime)
+ os.execute(command)
+ return edit_font(currentfont,detail,tempname)
end
-local tex_template = formatters [ [[
-<h1>Font: %s</h1><br/>
+local tex_template = [[
<pre><tt>
%s
</tt></pre>
-]] ]
+]]
local function show_source(currentfont,detail)
- local tempname = makename(tempname)
if tempname and tempname ~= "" then
- local data = io.loaddata(file.join(temppath,file.replacesuffix(tempname,"tex"))) or "no source yet"
- return tex_template(currentfont,data)
+ local data = io.loaddata(file.join(temppath,file.addsuffix(tempname,"tex"))) or "no source yet"
+ return format(tex_template,data)
else
return "no source file"
end
end
local function show_log(currentfont,detail)
- local tempname = makename(tempname)
if tempname and tempname ~= "" then
- local data = io.loaddata(file.join(temppath,file.replacesuffix(tempname,'log'))) or "no log file yet"
+ local data = io.loaddata(file.join(temppath,file.addsuffix(tempname,'log'))) or "no log file yet"
data = gsub(data,"[%s%%]*begin of optionfile.-end of optionfile[%s%%]*","\n")
- return tex_template(currentfont,data)
+ return format(tex_template,data)
else
return "no log file"
end
end
--- much nicer would be an lmx template
-
local function show_font(currentfont,detail)
local specification = get_specification(currentfont)
local features = fonts.helpers.getfeatures(specification.filename)
local result = { }
- result[#result+1] = formatters["<h1>Font: %s</h1><br/>"](currentfont)
+ result[#result+1] = format("<h1>names</h1>",what)
result[#result+1] = "<table>"
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>fontname </td><td style='width:20em'>%s</td>"] (specification.fontname or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>designsize </td><td style='width:20em'>%s</td></tr>"](specification.designsize or "-")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>fullname </td><td style='width:20em'>%s</td>"] (specification.fullname or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>minimumsize</td><td style='width:20em'>%s</td></tr>"](specification.minsize or "-")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>filename </td><td style='width:20em'>%s</td>"] (specification.fontfile or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>maximumsize</td><td style='width:20em'>%s</td></tr>"](specification.maxsize or "-")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>rawname </td><td style='width:20em'>%s</td>"] (specification.rawname or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>fontweight </td><td style='width:20em'>%s</td></tr>"](specification.fontweight or "-")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>familyname </td><td style='width:20em'>%s</td>"] (specification.familyname or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>angle </td><td style='width:20em'>%s</td></tr>"](specification.angle or "-")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>subfamily </td><td style='width:20em'>%s</td>"] (specification.subfamily or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>variant </td><td style='width:20em'>%s</td></tr>"](specification.variant ~= "" and specification.variant or "normal")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>format </td><td style='width:20em'>%s</td>"] (specification.format or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>style </td><td style='width:20em'>%s</td></tr>"](specification.style ~= "" and specification.style or "normal")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>pfmwidth </td><td style='width:20em'>%s</td>"] (specification.pfmwidth ~= "" and specification.pfmwidth or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>weight </td><td style='width:20em'>%s</td></tr>"](specification.weight ~= "" and specification.weight or "normal")
- result[#result+1] = formatters["<tr><td class='tc' style='width:10em'>pfmheight </td><td style='width:20em'>%s</td>"] (specification.pfmweight ~= "" and specification.pfmweight or "-")
- result[#result+1] = formatters[" <td class='tc' style='width:10em'>width </td><td style='width:20em'>%s</td></tr>"](specification.width ~= "" and specification.width or "normal")
+ result[#result+1] = format("<tr><td class='tc'>fontname: </td><td>%s</td></tr>",currentfont)
+ result[#result+1] = format("<tr><td class='tc'>fullname: </td><td>%s</td></tr>",specification.fontname or "-")
+ result[#result+1] = format("<tr><td class='tc'>filename: </td><td>%s</td></tr>",specification.fontfile or "-")
+ result[#result+1] = format("<tr><td class='tc'>familyname: </td><td>%s</td></tr>",specification.familyname or "-")
+ result[#result+1] = format("<tr><td class='tc'>fontweight: </td><td>%s</td></tr>",specification.fontweight or "-")
+ result[#result+1] = format("<tr><td class='tc'>format: </td><td>%s</td></tr>",specification.format or "-")
+ result[#result+1] = format("<tr><td class='tc'>fullname: </td><td>%s</td></tr>",specification.fullname or "-")
+ result[#result+1] = format("<tr><td class='tc'>subfamily: </td><td>%s</td></tr>",specification.subfamily or "-")
+ result[#result+1] = format("<tr><td class='tc'>rawname: </td><td>%s</td></tr>",specification.rawname or "-")
+ result[#result+1] = format("<tr><td class='tc'>designsize: </td><td>%s</td></tr>",specification.designsize or "-")
+ result[#result+1] = format("<tr><td class='tc'>minimumsize:</td><td>%s</td></tr>",specification.minsize or "-")
+ result[#result+1] = format("<tr><td class='tc'>maximumsize:</td><td>%s</td></tr>",specification.maxsize or "-")
+ result[#result+1] = format("<tr><td class='tc'>style: </td><td>%s</td></tr>",specification.style ~= "" and specification.style or "normal")
+ result[#result+1] = format("<tr><td class='tc'>variant: </td><td>%s</td></tr>",specification.variant ~= "" and specification.variant or "normal")
+ result[#result+1] = format("<tr><td class='tc'>weight: </td><td>%s</td></tr>",specification.weight ~= "" and specification.weight or "normal")
+ result[#result+1] = format("<tr><td class='tc'>width: </td><td>%s</td></tr>",specification.width ~= "" and specification.width or "normal")
result[#result+1] = "</table>"
if features then
for what, v in table.sortedhash(features) do
local data = features[what]
if data and next(data) then
- result[#result+1] = formatters["<h1>%s features</h1><br/>"](what)
+ result[#result+1] = format("<h1>%s features</h1>",what)
result[#result+1] = "<table>"
result[#result+1] = "<tr><th>feature</th><th>tag&nbsp;</th><th>script&nbsp;</th><th>languages&nbsp;</th></tr>"
for f,ff in table.sortedhash(data) do
@@ -525,7 +461,7 @@ local function show_font(currentfont,detail)
done = true
end
local title = fonts.handlers.otf.tables.features[f] or ""
- result[#result+1] = formatters["<tr><td width='50%%'>%s&nbsp;&nbsp;</td><td><tt>%s&nbsp;&nbsp;</tt></td><td><tt>%s&nbsp;&nbsp;</tt></td><td><tt>%s&nbsp;&nbsp;</tt></td></tr>"](title,f,s,concat(table.sortedkeys(ss)," "))
+ result[#result+1] = format("<tr><td width='50%%'>%s&nbsp;&nbsp;</td><td><tt>%s&nbsp;&nbsp;</tt></td><td><tt>%s&nbsp;&nbsp;</tt></td><td><tt>%s&nbsp;&nbsp;</tt></td></tr>",title,f,s,concat(table.sortedkeys(ss)," "))
end
end
result[#result+1] = "</table>"
@@ -537,7 +473,8 @@ local function show_font(currentfont,detail)
return concat(result,"\n")
end
-local info_template = formatters [ [[
+
+local info_template = [[
<pre><tt>
version : %s
comment : %s
@@ -548,14 +485,14 @@ maillist : ntg-context at ntg.nl
webpage : www.pragma-ade.nl
wiki : contextgarden.net
</tt></pre>
-]] ]
+]]
local function info_about()
local m = modules ['mtx-server-ctx-fonttest']
- return info_template(m.version,m.comment,m.author,m.copyright)
+ return format(info_template,m.version,m.comment,m.author,m.copyright)
end
-local save_template = formatters [ [[
+local save_template = [[
the current setup has been saved:
<br/> <br/>
<table>
@@ -568,7 +505,7 @@ local save_template = formatters [ [[
<tr><td class='tc'>options&nbsp; </td><td>%s</td></tr>
<tr><td class='tc'>sampletext&nbsp;</td><td>%s</td></tr>
</table>
-]] ]
+]]
local function loadbase()
local datafile = file.join(basepath,basename)
@@ -647,23 +584,23 @@ local function save_font(currentfont,detail)
font = currentfont, title = title, script = script, language = language, features = features, options = options, text = text,
}
savebase(storage,name)
- return save_template(name,title,currentfont,script,language,concat(table.sortedkeys(features)," "),concat(table.sortedkeys(options)," "),text)
+ return format(save_template,name,title,currentfont,script,language,concat(table.sortedkeys(features)," "),concat(table.sortedkeys(options)," "),text)
end
local function load_font(currentfont)
local datafile = file.join(basepath,basename)
local storage = loadbase(datafile)
local result = {}
- result[#result+1] = "<tr><th>del&nbsp;</th><th>name&nbsp;</th><th>font&nbsp;</th><th>fontname&nbsp;</th><th>script&nbsp;</th><th>language&nbsp;</th><th>features&nbsp;</th><th>title&nbsp;</th><th>sampletext&nbsp;</th></tr>"
+ result[#result+1] = format("<tr><th>del&nbsp;</th><th>name&nbsp;</th><th>font&nbsp;</th><th>fontname&nbsp;</th><th>script&nbsp;</th><th>language&nbsp;</th><th>features&nbsp;</th><th>title&nbsp;</th><th>sampletext&nbsp;</th></tr>")
for k,v in table.sortedhash(storage) do
local fontname, fontfile = get_specification(v.font)
- result[#result+1] = formatters["<tr><td><a href='mtx-server-ctx-fonttest.lua?deletename=%s'>x</a>&nbsp;</td><td><a href='mtx-server-ctx-fonttest.lua?loadname=%s'>%s</a>&nbsp;</td><td>%s&nbsp;</td<td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td></tr>"](
+ result[#result+1] = format("<tr><td><a href='mtx-server-ctx-fonttest.lua?deletename=%s'>x</a>&nbsp;</td><td><a href='mtx-server-ctx-fonttest.lua?loadname=%s'>%s</a>&nbsp;</td><td>%s&nbsp;</td<td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s&nbsp;</td></tr>",
k,k,k,v.font,fontname,v.script,v.language,concat(table.sortedkeys(v.features)," "),v.title or "no title",v.text or "")
end
if #result == 1 then
return "nothing saved yet"
else
- return formatters["<table>%s</table>"](concat(result,"\n"))
+ return format("<table>%s</table>",concat(result,"\n"))
end
end
@@ -671,12 +608,12 @@ local function reset_font(currentfont)
return edit_font(currentfont)
end
-local extras_template = formatters [ [[
+local extras_template = [[
<a href='mtx-server-ctx-fonttest.lua?extra=reload'>remake font database</a> (take some time)<br/><br/>
-]] ]
+]]
local function do_extras(detail,currentfont,extra)
- return extras_template()
+ return extras_template
end
local extras = { }
@@ -688,13 +625,16 @@ local function do_extra(detail,currentfont,extra)
end
function extras.reload()
- identifyfonts()
+ local command = "mtxrun --script font --reload"
+ report("run command: %s",command)
+ os.execute(command)
return do_extras()
end
-local status_template = formatters [ [[
+
+local status_template = [[
<input type="hidden" name="currentfont" value="%s" />
-]] ]
+]]
local variables = {
['color-background-one'] = lmx.get('color-background-green'),
@@ -703,8 +643,6 @@ local variables = {
['formaction'] = "mtx-server-ctx-fonttest.lua",
}
--- todo: use lmx file
-
function doit(configuration,filename,hashed)
local start = os.clock()
@@ -715,12 +653,6 @@ function doit(configuration,filename,hashed)
local action = detail.action
local selection = detail.selection
- if action == "luajittex" then
- jitmode = true
- elseif action == "luatex" then
- jitmode = false
- end
-
local loadname = detail.loadname
local deletename = detail.deletename
local extra = detail.extra
@@ -741,34 +673,30 @@ function doit(configuration,filename,hashed)
local fontname, fontfile = get_specification(currentfont)
if fontfile then
- variables.title = formatters['ConTeXt Font Tester: %s (%s)'](fontname,fontfile)
+ variables.title = format('ConTeXt Font Tester: %s (%s)',fontname,fontfile)
else
variables.title = 'ConTeXt Font Tester'
end
- if jitmode then
- variables.title = variables.title .. " (using LuaJit vm)"
- end
-
-- lua table and adapt
- report("action: %s",action or "no action")
-
- local buttons = { 'process', 'select', 'save', 'load', 'edit', 'reset', 'features', 'source', 'log', 'info', 'extras', jitmode and "luatex" or "luajittex" }
+ local buttons = { 'process', 'select', 'save', 'load', 'edit', 'reset', 'features', 'source', 'log', 'info', 'extras'}
local menu = { }
for i=1,#buttons do
local button = buttons[i]
- menu[#menu+1] = formatters["<button name='action' value='%s' type='submit'>%s</button>"](button,button)
+ menu[#menu+1] = format("<button name='action' value='%s' type='submit'>%s</button>",button,button)
end
variables.menu = concat(menu,"&nbsp;")
- variables.status = status_template(currentfont or "")
+ variables.status = format(status_template,currentfont or "")
variables.maintext = ""
variables.javascriptdata = ""
variables.javascripts = ""
variables.javascriptinit = ""
+ report("action: %s",action or "no action")
+
local result
if action == "select" then