summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtx-server-ctx-fonttest.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-09-20 15:00:28 +0300
committerMarius <mariausol@gmail.com>2013-09-20 15:00:28 +0300
commitdf1ef72f7d17b4d6a0368ba1290e083b08280cc5 (patch)
treed78b63f738350b59fa7b0b792f6eccf19a8dd5e0 /scripts/context/lua/mtx-server-ctx-fonttest.lua
parent5be028e9e8cad8e72967191716ba3974bb7832db (diff)
downloadcontext-df1ef72f7d17b4d6a0368ba1290e083b08280cc5.tar.gz
beta 2013.09.20 14:01
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, 183 insertions, 111 deletions
diff --git a/scripts/context/lua/mtx-server-ctx-fonttest.lua b/scripts/context/lua/mtx-server-ctx-fonttest.lua
index a8d7edf41..da87fe9e8 100644
--- a/scripts/context/lua/mtx-server-ctx-fonttest.lua
+++ b/scripts/context/lua/mtx-server-ctx-fonttest.lua
@@ -20,44 +20,62 @@ dofile(resolvers.findfile("font-mis.lua","tex"))
local format, gsub, concat, match, find = string.format, string.gsub, table.concat, string.match, string.find
-local report = logs.reporter("ctx-fonttest")
+local formatters = string.formatters
-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 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 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 = { }
-process_templates.default = [[
+-- %\definedfont[name:%s*sample]
+
+process_templates.default = formatters [ [[
\starttext
- \setupdirections[bidi=global]
+ \setupdirections[bidi=one]
\definefontfeature[sample][analyze=yes,%s]
- \definedfont[name:%s*sample]
+ \definedfont[name:%s*none]
\startTEXpage[offset=3pt]
\detokenize{%s}
+ \blank
+ \definedfont[name:%s*sample]
+ \detokenize{%s}
\stopTEXpage
\stoptext
-]]
+]] ]
-process_templates.cache = [[
+process_templates.cache = formatters [ [[
\starttext
\definedfont[name:%s]
\startTEXpage[offset=3pt]
cached: \detokenize{%s}
\stopTEXpage
\stoptext
-]]
+]] ]
-process_templates.trace = [[
+process_templates.trace = formatters [ [[
\usemodule[fnt-20]
\definefontfeature[sample][%s]
@@ -73,9 +91,9 @@ process_templates.trace = [[
direction=0,
features=sample,
sample={‍\detokenize{%s}}]
-]]
+]] ]
-local javascripts = [[
+local javascripts = formatters [ [[
function selected_radio(name) {
var form = document.forms["main-form"] ;
var script = form.elements[name] ;
@@ -151,7 +169,28 @@ 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 = { }
@@ -163,8 +202,9 @@ local function showfeatures(f)
features = fonts.helpers.getfeatures(resolvers.findfile(f))
if not features then
report("building cache for '%s'",f)
- 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))
+ local usedname = file.addsuffix(tempname,"tex")
+ io.savedata(file.join(temppath,usedname),process_templates.cache(f,f))
+ runcontext(temppath,usedname)
features = fonts.helpers.getfeatures(f)
end
cache[f] = features or false
@@ -206,14 +246,15 @@ 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] = format("feature_hash['%s'] = new Array ;",s)
+ stupid[#stupid+1] = formatters["feature_hash['%s'] = new Array ;"](s)
for l, lr in next, sr do
- stupid[#stupid+1] = format("feature_hash['%s']['%s'] = new Array ;",s,l)
+ stupid[#stupid+1] = formatters["feature_hash['%s']['%s'] = new Array ;"](s,l)
for f, fr in next, lr do
- stupid[#stupid+1] = format("feature_hash['%s']['%s']['%s'] = true ;",s,l,f)
+ stupid[#stupid+1] = formatters["feature_hash['%s']['%s']['%s'] = true ;"](s,l,f)
end
end
end
@@ -228,7 +269,7 @@ local function showfeatures(f)
end
end
-local template_h = [[
+local template_h = formatters [ [[
<tr>
<th>safe name&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th>family name&nbsp;&nbsp;&nbsp;&nbsp;</th>
@@ -236,9 +277,9 @@ local template_h = [[
<th>font name&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th>weight&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th>filename</th>
-</tr>]]
+</tr>]] ]
-local template_d = [[
+local template_d = formatters [ [[
<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>
@@ -246,19 +287,22 @@ local template_d = [[
<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] = format(template_d, fontname, fontname,
+ listoffonts[#listoffonts+1] = template_d(
+ fontname,
+ fontname,
v.familyname or "",
t.variant or "normal",
t.weight or "normal",
@@ -276,25 +320,32 @@ local function select_font()
return "<b>no fonts</b>"
end
-local edit_template = [[
+local edit_template = formatters [ [[
<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 = [[
+local result_template = formatters [ [[
<br/> <br/>
<embed src="%s#view=Fit&amp;toolbar=0&amp;navpanes=0&amp;scrollbar=0" width="100%%"/>
- <br/> <br/> results:
- <a href='%s' target="source">tex file</a>
- <a href='%s' target="result">pdf file</a>
+ <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/>
-]]
+]] ]
+
+local main_template = formatters [ [[
+ <h1>Font: %s</h1><br/>
+ %s
+ %s
+]] ]
scripts.webserver.registerpath(temppath)
@@ -302,7 +353,7 @@ local function get_specification(name)
return fonts.names.resolvedspecification(name or "")
end
-local function edit_font(currentfont,detail,tempname)
+local function edit_font(currentfont,detail,tempname,runtime)
report("entering edit mode for '%s'",currentfont)
local specification = get_specification(currentfont)
if specification then
@@ -314,9 +365,9 @@ local function edit_font(currentfont,detail,tempname)
local v = sorted[k]
local s = fonts.handlers.otf.tables.scripts[v] or v
if detail and v == detail.script then
- 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)
+ 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)
else
- 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)
+ 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)
end
end
local sorted = table.sortedkeys(htmldata.languages)
@@ -324,9 +375,9 @@ local function edit_font(currentfont,detail,tempname)
local v = sorted[k]
local l = fonts.handlers.otf.tables.languages[v] or v
if detail and v == detail.language then
- 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)
+ 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)
else
- 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)
+ 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)
end
end
local sorted = table.sortedkeys(htmldata.features)
@@ -334,28 +385,34 @@ local function edit_font(currentfont,detail,tempname)
local v = sorted[k]
local f = fonts.handlers.otf.tables.features[v] or v
if detail and detail["f-"..v] then
- 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)
+ 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)
else
- 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)
+ 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)
end
end
for k=1,#what_options do
local v = what_options[k]
if detail and detail["o-"..v] then
- options[#options+1] = format("<input id='o-%s' type='checkbox' name='o-%s' checked='checked'/>&nbsp;%s",v,v,v)
+ options[#options+1] = formatters["<input id='o-%s' type='checkbox' name='o-%s' checked='checked'/>&nbsp;%s"](v,v,v)
else
- options[#options+1] = format("<input id='o-%s' type='checkbox' name='o-%s'/>&nbsp;%s",v,v,v)
+ options[#options+1] = formatters["<input id='o-%s' type='checkbox' name='o-%s'/>&nbsp;%s"](v,v,v)
end
end
- 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," "))
+ 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," ")
+ )
if tempname then
- 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 ""
+ 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 ""
else
- return e, htmldata.javascript or ""
+ return main_template(currentfont,e,""), htmldata.javascript or ""
end
else
return "error, nothing set up yet"
@@ -368,13 +425,13 @@ end
local function process_font(currentfont,detail) -- maybe just fontname
local features = {
"mode=node",
- format("language=%s",detail.language or "dflt"),
- format("script=%s",detail.script or "dflt"),
+ formatters["language=%s"](detail.language or "dflt"),
+ formatters["script=%s"](detail.script or "dflt"),
}
for k,v in next, detail do
local f = match(k,"^f%-(.*)$")
if f then
- features[#features+1] = format("%s=yes",f)
+ features[#features+1] = formatters["%s=yes"](f)
end
end
local variant = process_templates.default
@@ -385,69 +442,76 @@ 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 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)
+ 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)
io.savedata(fullname,data)
- os.execute(command)
- return edit_font(currentfont,detail,tempname)
+ io.flush()
+ local runtime = runcontext(temppath,usedname)
+ return edit_font(currentfont,detail,tempname,runtime)
end
-local tex_template = [[
+local tex_template = formatters [ [[
+<h1>Font: %s</h1><br/>
<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.addsuffix(tempname,"tex"))) or "no source yet"
- return format(tex_template,data)
+ local data = io.loaddata(file.join(temppath,file.replacesuffix(tempname,"tex"))) or "no source yet"
+ return tex_template(currentfont,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.addsuffix(tempname,'log'))) or "no log file yet"
+ local data = io.loaddata(file.join(temppath,file.replacesuffix(tempname,'log'))) or "no log file yet"
data = gsub(data,"[%s%%]*begin of optionfile.-end of optionfile[%s%%]*","\n")
- return format(tex_template,data)
+ return tex_template(currentfont,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] = format("<h1>names</h1>",what)
+ result[#result+1] = formatters["<h1>Font: %s</h1><br/>"](currentfont)
result[#result+1] = "<table>"
- 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] = 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] = "</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] = format("<h1>%s features</h1>",what)
+ result[#result+1] = formatters["<h1>%s features</h1><br/>"](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
@@ -461,7 +525,7 @@ local function show_font(currentfont,detail)
done = true
end
local title = fonts.handlers.otf.tables.features[f] or ""
- 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)," "))
+ 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)," "))
end
end
result[#result+1] = "</table>"
@@ -473,8 +537,7 @@ local function show_font(currentfont,detail)
return concat(result,"\n")
end
-
-local info_template = [[
+local info_template = formatters [ [[
<pre><tt>
version : %s
comment : %s
@@ -485,14 +548,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 format(info_template,m.version,m.comment,m.author,m.copyright)
+ return info_template(m.version,m.comment,m.author,m.copyright)
end
-local save_template = [[
+local save_template = formatters [ [[
the current setup has been saved:
<br/> <br/>
<table>
@@ -505,7 +568,7 @@ local save_template = [[
<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)
@@ -584,23 +647,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 format(save_template,name,title,currentfont,script,language,concat(table.sortedkeys(features)," "),concat(table.sortedkeys(options)," "),text)
+ return 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] = 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>")
+ 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>"
for k,v in table.sortedhash(storage) do
local fontname, fontfile = get_specification(v.font)
- 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>",
+ 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>"](
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 format("<table>%s</table>",concat(result,"\n"))
+ return formatters["<table>%s</table>"](concat(result,"\n"))
end
end
@@ -608,12 +671,12 @@ local function reset_font(currentfont)
return edit_font(currentfont)
end
-local extras_template = [[
+local extras_template = formatters [ [[
<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 = { }
@@ -625,16 +688,13 @@ local function do_extra(detail,currentfont,extra)
end
function extras.reload()
- local command = "mtxrun --script font --reload"
- report("run command: %s",command)
- os.execute(command)
+ identifyfonts()
return do_extras()
end
-
-local status_template = [[
+local status_template = formatters [ [[
<input type="hidden" name="currentfont" value="%s" />
-]]
+]] ]
local variables = {
['color-background-one'] = lmx.get('color-background-green'),
@@ -643,6 +703,8 @@ local variables = {
['formaction'] = "mtx-server-ctx-fonttest.lua",
}
+-- todo: use lmx file
+
function doit(configuration,filename,hashed)
local start = os.clock()
@@ -653,6 +715,12 @@ 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
@@ -673,30 +741,34 @@ function doit(configuration,filename,hashed)
local fontname, fontfile = get_specification(currentfont)
if fontfile then
- variables.title = format('ConTeXt Font Tester: %s (%s)',fontname,fontfile)
+ variables.title = formatters['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
- local buttons = { 'process', 'select', 'save', 'load', 'edit', 'reset', 'features', 'source', 'log', 'info', 'extras'}
+ 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 menu = { }
for i=1,#buttons do
local button = buttons[i]
- menu[#menu+1] = format("<button name='action' value='%s' type='submit'>%s</button>",button,button)
+ menu[#menu+1] = formatters["<button name='action' value='%s' type='submit'>%s</button>"](button,button)
end
variables.menu = concat(menu,"&nbsp;")
- variables.status = format(status_template,currentfont or "")
+ variables.status = 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