diff options
Diffstat (limited to 'tex')
51 files changed, 1425 insertions, 885 deletions
diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index ba09a88df..bcbde1da7 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2018.05.24 15:49} +\newcontextversion{2018.06.02 22:34} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii index 3ba85bde6..d060c0332 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2018.05.24 15:49} +\edef\contextversion{2018.06.02 22:34} %D For those who want to use this: diff --git a/tex/context/base/mkii/mult-cs.mkii b/tex/context/base/mkii/mult-cs.mkii index 9a4cc112b..ce6d82a5b 100644 --- a/tex/context/base/mkii/mult-cs.mkii +++ b/tex/context/base/mkii/mult-cs.mkii @@ -853,7 +853,7 @@ \setinterfaceconstant{headseparator}{headseparator} \setinterfaceconstant{headstyle}{stylhlavicky} \setinterfaceconstant{height}{vyska} -\setinterfaceconstant{hfactor}{vfaktor} +\setinterfaceconstant{hfactor}{hfaktor} \setinterfaceconstant{hfil}{hfil} \setinterfaceconstant{hidenumber}{hidenumber} \setinterfaceconstant{hoffset}{hoffset} @@ -1274,6 +1274,7 @@ \setinterfaceconstant{vcompact}{vcompact} \setinterfaceconstant{vector}{vector} \setinterfaceconstant{veroffset}{offsethlavicky} +\setinterfaceconstant{vfactor}{vfaktor} \setinterfaceconstant{vfil}{vfil} \setinterfaceconstant{viewerprefix}{viewerprefix} \setinterfaceconstant{voffset}{voffset} diff --git a/tex/context/base/mkii/mult-it.mkii b/tex/context/base/mkii/mult-it.mkii index 38fb2de40..6716084c0 100644 --- a/tex/context/base/mkii/mult-it.mkii +++ b/tex/context/base/mkii/mult-it.mkii @@ -1274,6 +1274,7 @@ \setinterfaceconstant{vcompact}{vcompact} \setinterfaceconstant{vector}{vector} \setinterfaceconstant{veroffset}{veroffset} +\setinterfaceconstant{vfactor}{vfactor} \setinterfaceconstant{vfil}{vfil} \setinterfaceconstant{viewerprefix}{viewerprefix} \setinterfaceconstant{voffset}{voffset} diff --git a/tex/context/base/mkiv/attr-ini.mkiv b/tex/context/base/mkiv/attr-ini.mkiv index 451ab9dfa..e3d328e3d 100644 --- a/tex/context/base/mkiv/attr-ini.mkiv +++ b/tex/context/base/mkiv/attr-ini.mkiv @@ -84,8 +84,8 @@ \let\dompattribute\gobbletwoarguments -\unexpanded\def\resetglobalattributes{\the\t_attr_list_global} -\unexpanded\def\resetlocalattributes {\the\t_attr_list_local } +\unexpanded\def\resetglobalattributes{\the\t_attr_list_global\attribute\zerocount\zerocount} +\unexpanded\def\resetlocalattributes {\the\t_attr_list_local \attribute\zerocount\zerocount} \let\resetallattributes\resetlocalattributes diff --git a/tex/context/base/mkiv/buff-ver.lua b/tex/context/base/mkiv/buff-ver.lua index d9178b1df..2e9489e61 100644 --- a/tex/context/base/mkiv/buff-ver.lua +++ b/tex/context/base/mkiv/buff-ver.lua @@ -445,7 +445,7 @@ function visualizers.registerescapecommand(name,token,normalmethod,escapecommand end token = P(token) local notoken = hack((1 - token)^1) - local cstoken = name_pattern * space_pattern + local cstoken = Cs(name_pattern * (space_pattern/"")) escapepattern = ( (token / "") * (cstoken / (escapecommand or texcommand)) diff --git a/tex/context/base/mkiv/char-ini.mkiv b/tex/context/base/mkiv/char-ini.mkiv index 9c41df673..229e07633 100644 --- a/tex/context/base/mkiv/char-ini.mkiv +++ b/tex/context/base/mkiv/char-ini.mkiv @@ -42,8 +42,8 @@ % use \normalUchar when possible .. the next one is nice for documents and it also accepts % 0x prefixed numbers -\def\utfchar #1{\clf_utfchar \numexpr#1\relax} -\def\safechar#1{\clf_safechar\numexpr#1\relax} +\def\utfchar #1{\clf_utfchar {#1}} +\def\safechar#1{\clf_safechar{#1}} \unexpanded\def\Ux #1{\Uchar\numexpr"#1\relax} % used in xml \def\eUx#1{\Uchar\numexpr"#1\relax} % used in xml diff --git a/tex/context/base/mkiv/char-tex.lua b/tex/context/base/mkiv/char-tex.lua index 065152881..66997a647 100644 --- a/tex/context/base/mkiv/char-tex.lua +++ b/tex/context/base/mkiv/char-tex.lua @@ -8,7 +8,7 @@ if not modules then modules = { } end modules ['char-tex'] = { local lpeg = lpeg local tonumber, next, type = tonumber, next, type -local format, find, gmatch = string.format, string.find, string.gmatch +local format, find, gmatch, match = string.format, string.find, string.gmatch, string.match local utfchar, utfbyte = utf.char, utf.byte local concat, tohash = table.concat, table.tohash local P, C, R, S, V, Cs, Cc = lpeg.P, lpeg.C, lpeg.R, lpeg.S, lpeg.V, lpeg.Cs, lpeg.Cc @@ -462,16 +462,24 @@ function commands.makeactive(n,name) -- not used -- context("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name) end +local function to_number(s) + local n = tonumber(s) + if n then + return n + end + return tonumber(match(s,'^"(.*)$'),16) or 0 +end + implement { name = "utfchar", - actions = { utfchar, contextsprint }, - arguments = "integer" + actions = { to_number, utfchar, contextsprint }, + arguments = "string" } implement { name = "safechar", - actions = { texcharacters.safechar, contextsprint }, - arguments = "integer" + actions = { to_number, texcharacters.safechar, contextsprint }, + arguments = "string" } implement { diff --git a/tex/context/base/mkiv/cldf-bas.lua b/tex/context/base/mkiv/cldf-bas.lua index 070546637..15e941db2 100644 --- a/tex/context/base/mkiv/cldf-bas.lua +++ b/tex/context/base/mkiv/cldf-bas.lua @@ -89,11 +89,15 @@ function context.glyph(id,k) local glyph = new_glyph(id,k) glyph.attr = current_attr() context(glyph) + -- context.node(glyph) end end -local function ctx_par () context("\\par") end -local function ctx_space() context("\\space") end +-- local function ctx_par () context("\\par") end +-- local function ctx_space() context("\\space") end + +local ctx_par = context.cs.par +local ctx_space = context.cs.space context.par = ctx_par context.space = ctx_space @@ -101,8 +105,11 @@ context.space = ctx_space ctxcore.par = ctx_par ctxcore.space = ctx_space -local function ctx_bgroup() context("{") end -local function ctx_egroup() context("}") end +-- local function ctx_bgroup() context("{") end +-- local function ctx_egroup() context("}") end + +local ctx_bgroup = context.cs.bgroup +local ctx_egroup = context.cs.egroup context.bgroup = ctx_bgroup context.egroup = ctx_egroup diff --git a/tex/context/base/mkiv/cldf-ini.lua b/tex/context/base/mkiv/cldf-ini.lua index f3bd0f563..71529f96c 100644 --- a/tex/context/base/mkiv/cldf-ini.lua +++ b/tex/context/base/mkiv/cldf-ini.lua @@ -52,6 +52,11 @@ if not modules then modules = { } end modules ['cldf-ini'] = { -- watching Trio Hiromi Uehara, Anthony Jackson & Simon Phillips (discovered via the -- later on YT). Hopefully the video breaks made the following better in the end. +-- This module is also a test bed for experimental features so the content changes over +-- time (for the better or worse). There have been no fundamental changes for many years +-- and performance has not changed much either. + + local format, stripstring = string.format, string.strip local next, type, tostring, tonumber, unpack, select, rawset = next, type, tostring, tonumber, unpack, select, rawset local insert, remove, concat = table.insert, table.remove, table.concat @@ -84,6 +89,12 @@ local texgetcount = tex.getcount local isnode = node.is_node local writenode = node.write local copynodelist = node.copy_list +local tonut = node.direct.todirect + +local istoken = token.is_token +local newtoken = token.new +local createtoken = token.create +local setluatoken = token.set_lua local catcodenumbers = catcodes.numbers @@ -104,16 +115,46 @@ local report_cld = logs.reporter("cld","stack") local processlines = true -- experiments.register("context.processlines", function(v) processlines = v end) +local tokenflushmode = false +local nodeflushmode = false +local scannerdefmode = false +local maxflushnodeindex = 0x10FFFF - 1 + +if LUATEXFUNCTIONALITY and LUATEXFUNCTIONALITY > 6780 then + + -- The gain in performasnce is neglectable. + + tokenflushmode = true + nodeflushmode = true + scannerdefmode = true + maxflushnodeindex = token.biggest_char() - 1 + +end + +-- tokenflushmode = false +-- scannerdefmode = false +-- nodeflushmode = false + -- In earlier experiments a function tables was referred to as lua.calls and the -- primitive \luafunctions was \luacall and we used our own implementation of -- a function table (more indirectness). +local trialtypesettingstate = 0 + +function context.trialtypesetting() + return texgetcount(trialtypesettingstate) ~= 0 +end + +function context.registertrialtypesetting(name) + trialtypesettingstate = createtoken(name).index +end + local knownfunctions = lua.get_functions_table() local showstackusage = false trackers.register("context.stack",function(v) showstackusage = v end) -local freed, nofused, noffreed = { }, 0, 0 -- maybe use the number of @@trialtypesetting +local freed, nofused, noffreed = { }, 0, 0 local usedstack = function() return nofused, noffreed @@ -122,7 +163,7 @@ end local flushfunction = function(slot,arg) if arg() then -- keep - elseif texgetcount("@@trialtypesetting") == 0 then -- @@trialtypesetting is private! + elseif texgetcount(trialtypesettingstate) == 0 then noffreed = noffreed + 1 freed[noffreed] = slot knownfunctions[slot] = false @@ -147,7 +188,7 @@ local storefunction = function(arg) end local flushnode = function(slot,arg) - if texgetcount("@@trialtypesetting") == 0 then -- @@trialtypesetting is private! + if texgetcount(trialtypesettingstate) == 0 then writenode(arg) noffreed = noffreed + 1 freed[noffreed] = slot @@ -182,9 +223,13 @@ local f_resolve = nil local p_resolve = ((1-lpegP("."))^1 / function(s) f_resolve = f_resolve[s] end * lpegP(".")^0)^1 local function resolvestoredfunction(str) - f_resolve = global - lpegmatch(p_resolve,str) - return f_resolve + if type(str) == "string" then + f_resolve = global + lpegmatch(p_resolve,str) + return f_resolve + else + return str + end end local function expose(slot,f,...) -- so we can register yet undefined functions @@ -246,17 +291,17 @@ local registerfunction = function(f,direct) -- either f=code or f=namespace,dire func = resolvestoredfunction(f) end if type(func) ~= "function" then - func = function() report_cld("invalid resolve %A",f) end + func = function() report_cld("invalid resolve %A, case %s",f,1) end end elseif type(f) == "string" then func = loadstring(f) if type(func) ~= "function" then - func = function() report_cld("invalid code %A",f) end + func = function() report_cld("invalid code %A, case %s",f,2) end end elseif type(f) == "function" then func = f else - func = function() report_cld("invalid function %A",f) end + func = function() report_cld("invalid function %A, case %s",f,3) end end knownfunctions[slot] = func return slot @@ -305,53 +350,52 @@ local storedscanners = interfaces.storedscanners storage.register("interfaces/storedscanners", storedscanners, "interfaces.storedscanners") local interfacescanners = setmetatablenewindex(function(t,k,v) + rawset(t,k,v) if storedscanners[k] then - -- report_cld("warning: scanner %a is already set",k) + -- report_cld("warning: scanner %a is already set (mode 1a)",k) -- os.exit() -- \scan_<k> is already in the format -- report_cld("using interface scanner: %s",k) + elseif scannerdefmode then + -- report_cld("installing interface scanner: %s (mode 1b)",k) + -- local n = registerfunction(interfaces.scanners[k],true) + local n = registerfunction("interfaces.scanners."..k,true) + storedscanners[k] = n + local name = "clf_" .. k + setluatoken(name,n,"global") -- todo : protected and "protected" or "" else - -- todo: allocate slot here and pass it + -- report_cld("installing interface scanner: %s (mode 1c)",k) storedscanners[k] = true - -- report_cld("installing interface scanner: %s",k) context("\\installctxscanner{clf_%s}{interfaces.scanners.%s}",k,k) end - rawset(t,k,v) + -- rawset(t,k,v) end) function interfaces.registerscanner(name,action,protected,public,call) + rawset(interfacescanners,name,action) if storedscanners[name] then - -- report_cld("warning: scanner %a is already set",k) + -- report_cld("warning: scanner %a is already set (mode 2a)",name) -- os.exit() -- \scan_<k> is already in the format -- report_cld("using interface scanner: %s",k) + elseif scannerdefmode then + -- report_cld("installing interface scanner: %s (mode 2b)",name) + -- local n = registerfunction(action,true) -- todo + local n = registerfunction("interfaces.scanners."..name,true) + storedscanners[name] = n + local name = public and name or ("clf_" .. name) + setluatoken(name,n,"global",protected and "protected" or "") else storedscanners[name] = true --- if protected then --- -- report_cld("installing expandable interface scanner: %s",k) --- if public then --- context("\\installprotectedctxscanner{%s}{interfaces.scanners.%s}",name,name) --- else --- context("\\installprotectedctxscanner{clf_%s}{interfaces.scanners.%s}",name,name) --- end --- else --- -- report_cld("installing protected interface scanner: %s",k) --- if public then --- context("\\installctxscanner{%s}{interfaces.scanners.%s}",name,name) --- else --- context("\\installctxscanner{clf_%s}{interfaces.scanners.%s}",name,name) --- end --- end - -- report_cld("installing interface scanner: %s",k) - context("\\install%sctxscanner%s{%s%s}{interfaces.scanners.%s}", - protected and "protected" or "", - call and "call" or "", - public and "" or "clf_", - name, - name - ) - end - rawset(interfacescanners,name,action) + -- report_cld("installing interface scanner: %s (mode 2c)",name) + context("\\install%sctxscanner{%s%s}{interfaces.scanners.%s}", + protected and "protected" or "", + public and "" or "clf_", + name, + name + ) + end + -- rawset(interfacescanners,name,action) end interfaces.scanners = storage.mark(interfacescanners) @@ -379,7 +423,7 @@ end local function dummy() end -function commands.ctxresetter(name) +function commands.ctxresetter(name) -- to be checked return function() if storedscanners[name] then rawset(interfacescanners,name,dummy) @@ -388,10 +432,6 @@ function commands.ctxresetter(name) end end -function context.trialtypesetting() - return texgetcount("@@trialtypesetting") ~= 0 -end - -- Should we keep the catcodes with the function? local catcodestack = { } @@ -683,8 +723,17 @@ local s_cldl_argument_e = "}" -- local s_cldl_argument_b = "{" -- local s_cldl_argument_f = "{ " +local t_cldl_luafunction = createtoken("luafunctioncall") +local lua_expandable_call_code = token.command_id and token.command_id("lua_expandable_call") + local function writer(parent,command,...) -- already optimized before call - flush(currentcatcodes,command) -- todo: ctx|prt|texcatcodes + + if type(command) == "string" then -- for now + flush(currentcatcodes,command) -- todo: ctx|prt|texcatcodes + else + flush(command) -- todo: ctx|prt|texcatcodes + end + local direct = false -- local t = { ... } -- for i=1,#t do @@ -751,7 +800,16 @@ local function writer(parent,command,...) -- already optimized before call elseif tn == 1 then -- some 20% faster than the next loop local tj = ti[1] if type(tj) == "function" then - flush(currentcatcodes,s_cldl_option_b,storefunction(tj),s_cldl_option_e) + tj = storefunction(tj) + if tokenflushmode then + if newtoken then + flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_code),"]") + else + flush(currentcatcodes,"[",t_cldl_luafunction,tj,"]") + end + else + flush(currentcatcodes,s_cldl_option_b,tj,s_cldl_option_e) + end else flush(currentcatcodes,"[",tj,"]") end @@ -760,10 +818,15 @@ local function writer(parent,command,...) -- already optimized before call for j=1,tn do local tj = ti[j] if type(tj) == "function" then - if j == tn then - flush(currentcatcodes,s_cldl_option_s,storefunction(tj),"]") + tj = storefunction(tj) + if tokenflushmode then + if newtoken then + flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_code),j == tn and "]" or ",") + else + flush(currentcatcodes,"[",t_cldl_luafunction,tj,j == tn and "]" or ",") + end else - flush(currentcatcodes,s_cldl_option_s,storefunction(tj),",") + flush(currentcatcodes,s_cldl_option_s,tj,j == tn and "]" or ",") end else if j == tn then @@ -776,7 +839,16 @@ local function writer(parent,command,...) -- already optimized before call end elseif typ == "function" then -- todo: ctx|prt|texcatcodes - flush(currentcatcodes,s_cldl_argument_f,storefunction(ti),s_cldl_argument_e) + ti = storefunction(ti) + if tokenflushmode then + if newtoken then + flush(currentcatcodes,"{",newtoken(ti,lua_expandable_call_code),"}") + else + flush(currentcatcodes,"{",t_cldl_luafunction,ti,"}") + end + else + flush(currentcatcodes,s_cldl_argument_f,ti,s_cldl_argument_e) + end elseif typ == "boolean" then if ti then flushdirect(currentcatcodes,"\r") @@ -785,62 +857,99 @@ local function writer(parent,command,...) -- already optimized before call end elseif typ == "thread" then report_context("coroutines not supported as we cannot yield across boundaries") - elseif isnode(ti) then -- slow - flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) + elseif isnode(ti) then -- slow | why {} here ? + if nodeflushmode then + local n = tonut(ti) + if n <= maxflushnodeindex then + flush(currentcatcodes,"{",ti,"}") + else + flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) + end + else + flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) + end else report_context("error: %a gets a weird argument %a",command,ti) end +-- else +-- local n = isnode(ti) +-- if n then +-- if nodeflushmode and n <= maxflushnodeindex then +-- flush(ti) +-- else +-- flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) +-- end +-- else +-- report_context("error: %a gets a weird argument %a",command,ti) +-- end +-- end end end end --- if performance really matters we can consider a compiler but it will never --- pay off - --- local function prtwriter(command,...) -- already optimized before call --- flush(prtcatcodes,command) --- for i=1,select("#",...) do --- local ti = select(i,...) --- if ti == nil then --- -- nothing --- elseif ti == "" then --- flush(prtcatcodes,"{}") --- else --- local tp = type(ti) --- if tp == "string" or tp == "number"then --- flush(prtcatcodes,"{",ti,"}") --- elseif tp == "function" then --- flush(prtcatcodes,s_cldl_argument_f,storefunction(ti),s_cldl_argument_e) --- elseif isnode(ti) then --- flush(prtcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) --- else --- report_context("fatal error: prt %a gets a weird argument %a",command,ti) --- end --- end --- end --- end +local core + +if tokenflushmode then -- combine them + + local toks = tokens.cache + + context.tokenizedcs = toks -local core = setmetatableindex(function(parent,k) - local c = "\\" .. k -- tostring(k) - local f = function(first,...) - if first == nil then + core = setmetatableindex(function(parent,k) + local t + local f = function(first,...) + if not t then + t = toks[k] + end + if first == nil then + flush(t) + else + return writer(context,t,first,...) + end + end + parent[k] = f + return f + end) + + core.cs = setmetatableindex(function(parent,k) + local t + local f = function() + if not t then + t = toks[k] + end + flush(t) + end + parent[k] = f + return f + end) + +else + + context.tokenizedcs = false + + core = setmetatableindex(function(parent,k) + local c = "\\" .. k + local f = function(first,...) + if first == nil then + flush(currentcatcodes,c) + else + return writer(context,c,first,...) + end + end + parent[k] = f + return f + end) + + core.cs = setmetatableindex(function(parent,k) + local c = "\\" .. k -- tostring(k) + local f = function() flush(currentcatcodes,c) - else - return writer(context,c,first,...) end - end - parent[k] = f - return f -end) + parent[k] = f + return f + end) -core.cs = setmetatableindex(function(parent,k) - local c = "\\" .. k -- tostring(k) - local f = function() - flush(currentcatcodes,c) - end - parent[k] = f - return f -end) +end local indexer = function(parent,k) if type(k) == "string" then @@ -935,8 +1044,16 @@ local caller = function(parent,f,a,...) end elseif typ == "function" then -- ignored: a ... - flush(currentcatcodes,"{\\cldl",storefunction(f),"}") -- todo: ctx|prt|texcatcodes - -- flush(currentcatcodes,"{",storefunction(f),"}") -- todo: ctx|prt|texcatcodes + f = storefunction(f) + if tokenflushmode then + if newtoken then + flush(currentcatcodes,"{",newtoken(f,lua_expandable_call_code),"}") + else + flush(currentcatcodes,"{",t_cldl_luafunction,f,"}") + end + else + flush(currentcatcodes,s_cldl_argument_b,f,s_cldl_argument_e) -- todo: ctx|prt|texcatcodes + end elseif typ == "boolean" then if f then if a ~= nil then @@ -955,20 +1072,46 @@ local caller = function(parent,f,a,...) elseif typ == "thread" then report_context("coroutines not supported as we cannot yield across boundaries") elseif isnode(f) then -- slow - -- writenode(f) - flush(currentcatcodes,"\\cldl",storenode(f)," ") - -- flush(currentcatcodes,"",storenode(f)," ") + if nodeflushmode then + local n = tonut(f) + if n <= maxflushnodeindex then + flush(f) + else + flush(currentcatcodes,s_cldl_option_s,storenode(f)," ") + end + else + flush(currentcatcodes,s_cldl_option_s,storenode(f)," ") + end else report_context("error: %a gets a weird argument %a","context",f) end +-- else +-- local n = isnode(f) +-- if n then +-- if nodeflushmode and n <= maxflushnodeindex then +-- flush(f) +-- else +-- flush(currentcatcodes,s_cldl_option_s,storenode(f)," ") +-- end +-- else +-- report_context("error: %a gets a weird argument %a","context",f) +-- end +-- end end end -context.nodes = { +context.nodes = { -- todo store = storenode, flush = function(n) - flush(currentcatcodes,"\\cldl",storenode(n)," ") - -- flush(currentcatcodes,"",storenode(n)," ") + if nodeflushmode then + if tonut(n) <= maxflushnodeindex then + flush(n) + else + flush(currentcatcodes,s_cldl_option_s,storenode(n)," ") + end + else + flush(currentcatcodes,s_cldl_option_s,storenode(n)," ") + end end, } @@ -1014,8 +1157,8 @@ local nofflushes = 0 local tracingpermitted = true local visualizer = lpeg.replacer { - { "\n","<<newline>>" }, - { "\r","<<par>>" }, + { "\n", "<<newline>>" }, + { "\r", "<<par>>" }, } statistics.register("traced context", function() @@ -1028,13 +1171,47 @@ statistics.register("traced context", function() end end) +local function userdata(argument) + if isnode(argument) then + return formatters["<< %s node %i>>"](nodes.nodecodes[argument.id],tonut(argument)) + end + if istoken(argument) then + local csname = argument.csname + if csname then + -- return formatters["<<\\%s>>"](csname) + return formatters["\\%s"](csname) + end + local cmdname = argument.cmdname + if cmdname == "lua_expandable_call" or cmdname == "lua_call" then + return "<<function>>" -- argument.mode + end + return "<<token>>" + end + return "<<userdata>>" +end + + local tracedwriter = function(parent,...) -- also catcodes ? nofwriters = nofwriters + 1 local savedflush = flush local savedflushdirect = flushdirect -- unlikely to be used here local t, n = { "w : - : " }, 1 local traced = function(catcodes,...) -- todo: check for catcodes - local s = concat({...}) + local s = type(catcodes) == "number" and { ... } or { catcodes, ... } + for i=1,#s do + local argument = s[i] + local argtype = type(argument) + if argtype == "string" then + s[i] = lpegmatch(visualizer,argument) + elseif argtype == "number" then + s[i] = argument + elseif argtype == "userdata" then + s[i] = userdata(argument) + else + s[i] = formatters["<<%S>>"](argument) + end + end + s = concat(s) s = lpegmatch(visualizer,s) n = n + 1 t[n] = s @@ -1073,6 +1250,8 @@ local traced = function(one,two,...) collapsed[c] = lpegmatch(visualizer,argument) elseif argtype == "number" then collapsed[c] = argument + elseif argtype == "userdata" then + collapsed[c] = userdata(argument) else collapsed[c] = formatters["<<%S>>"](argument) end @@ -1085,6 +1264,8 @@ local traced = function(one,two,...) currenttrace(formatters["f : - : %s"](lpegmatch(visualizer,one))) elseif argtype == "number" then currenttrace(formatters["f : - : %s"](one)) + elseif argtype == "userdata" then + currenttrace(formatters["f : - : %s"](userdata(one))) else currenttrace(formatters["f : - : <<%S>>"](one)) end @@ -1367,14 +1548,22 @@ function context.newindexer(catcodes,cmdcodes) contentcatcodes = savedcatcodes end - handler.cs = setmetatableindex(function(parent,k) - local c = "\\" .. k -- tostring(k) - local f = function() - flush(cmdcodes,c) - end - parent[k] = f - return f - end) + if tokenflushmode then + + handler.cs = core.cs + + else + + handler.cs = setmetatableindex(function(parent,k) + local c = "\\" .. k -- tostring(k) + local f = function() + flush(cmdcodes,c) + end + parent[k] = f + return f + end) + + end setmetatableindex(handler,indexer) setmetatablecall (handler,caller) @@ -1427,21 +1616,51 @@ do end end - local function indexer(parent,k) - if type(k) == "string" then - local c = "\\" .. k - local f = function(first,...) - if first == nil then - flush(currentcatcodes,c) - else - return formattedflush(parent,c,first,...) + local indexer + + if tokenflushmode then -- combine them + + local toks = tokens.cache + + indexer = function(parent,k) + if type(k) == "string" then + local t + local f = function(first,...) + if not t then + t = toks[k] + end + if first == nil then + flush(t) + else + return formattedflush(parent,t,first,...) + end end + parent[k] = f + return f + else + return context -- catch end - parent[k] = f - return f - else - return context -- catch end + + else + + indexer = function(parent,k) + if type(k) == "string" then + local c = "\\" .. k + local f = function(first,...) + if first == nil then + flush(currentcatcodes,c) + else + return formattedflush(parent,c,first,...) + end + end + parent[k] = f + return f + else + return context -- catch + end + end + end -- formatted([catcodes,]format[,...]) diff --git a/tex/context/base/mkiv/cldf-scn.lua b/tex/context/base/mkiv/cldf-scn.lua index a8dddc6c8..d0b16e034 100644 --- a/tex/context/base/mkiv/cldf-scn.lua +++ b/tex/context/base/mkiv/cldf-scn.lua @@ -77,7 +77,7 @@ function interfaces.implement(specification) if scanners[name] and not specification.overload then report("warning: 'scanners.%s' is redefined",name) end --- scanners[name] = scanner + -- scanners[name] = scanner -- we now use: register(name,scanner,specification.protected,specification.public,specification.call) if private then return diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 2790235d5..c064cb4d5 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2018.05.24 15:49} +\newcontextversion{2018.06.02 22:34} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index f88d9bc4c..84cd66a3f 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -42,7 +42,7 @@ %D has to match \type {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2018.05.24 15:49} +\edef\contextversion{2018.06.02 22:34} \edef\contextkind {beta} %D For those who want to use this: @@ -106,6 +106,7 @@ \loadmarkfile{catc-ctx} \loadmarkfile{catc-sym} +\loadmarkfile{toks-ini} \loadmarkfile{cldf-ini} % \tracecatcodetables @@ -114,7 +115,7 @@ % \unexpanded long before etex came around. \loadmarkfile{luat-ini} -\loadmarkfile{toks-ini} +\loadmarkfile{toks-scn} \loadmarkfile{syst-aux} \loadmarkfile{syst-lua} diff --git a/tex/context/base/mkiv/core-env.lua b/tex/context/base/mkiv/core-env.lua index 0ef37a6d6..23f7ca178 100644 --- a/tex/context/base/mkiv/core-env.lua +++ b/tex/context/base/mkiv/core-env.lua @@ -42,11 +42,7 @@ local systemmodes = { } -- undefined: mode == 0 or cmdname = "undefined_cs" -local cache = setmetatableindex(function(t,k) - local v = createtoken(k) - t[k] = v - return v -end) +local cache = tokens.cache -- we can have a modes cache too diff --git a/tex/context/base/mkiv/core-env.mkiv b/tex/context/base/mkiv/core-env.mkiv index c93350db0..185df780f 100644 --- a/tex/context/base/mkiv/core-env.mkiv +++ b/tex/context/base/mkiv/core-env.mkiv @@ -87,18 +87,22 @@ % demo: trialtypesetting is a systemmode as well as an if -\newsystemmode{trialtypesetting} % the name of \@@trialtypesetting might change (also at the lua end) +\newsystemmode{trialtypesetting} -\expandafter\let\expandafter\@@trialtypesetting\csname\??mode\systemmodeprefix trialtypesetting\endcsname % private ! +\expandafter\let\expandafter\c_trial_typesetting\csname\??mode\systemmodeprefix trialtypesetting\endcsname % private ! \appendtoks - \@@trialtypesetting\enabledmode + \c_trial_typesetting\enabledmode + \luacopyinputnodes\plusone \to \everysettrialtypesetting \appendtoks - \@@trialtypesetting\disabledmode + \c_trial_typesetting\disabledmode + \luacopyinputnodes\zerocount \to \everyresettrialtypesetting +\ctxlua{context.registertrialtypesetting("c_trial_typesetting")} + % user ones \let\syst_mode_prefix\relax diff --git a/tex/context/base/mkiv/data-res.lua b/tex/context/base/mkiv/data-res.lua index 9f5e3a8ac..e3c5c32b9 100644 --- a/tex/context/base/mkiv/data-res.lua +++ b/tex/context/base/mkiv/data-res.lua @@ -1903,7 +1903,7 @@ function resolvers.dowithfilesintree(pattern,handle,before,after) -- will move, end end if after then - after(blobtype,blobpath,pattern,total,checked,done) + after(blobtype,blobpath,pattern,checked,done) end end end diff --git a/tex/context/base/mkiv/file-job.lua b/tex/context/base/mkiv/file-job.lua index dbf6da9b4..486aee63a 100644 --- a/tex/context/base/mkiv/file-job.lua +++ b/tex/context/base/mkiv/file-job.lua @@ -386,7 +386,6 @@ local function starttext() if trace_jobfiles then report_jobfiles("starting text") end - -- registerfileinfo[begin]jobfilename context.dostarttext() end textlevel = textlevel + 1 @@ -406,8 +405,6 @@ local function stoptext() report_jobfiles("stopping text") end context.dostoptext() - -- registerfileinfo[end]jobfilename - context.finalend() stopped = true end end diff --git a/tex/context/base/mkiv/font-dsp.lua b/tex/context/base/mkiv/font-dsp.lua index 6279dda89..e875991e1 100644 --- a/tex/context/base/mkiv/font-dsp.lua +++ b/tex/context/base/mkiv/font-dsp.lua @@ -51,6 +51,9 @@ if not modules then modules = { } end modules ['font-dsp'] = { -- All this packing in the otf format is somewhat obsessive as nowadays 4K resolution -- multi-gig videos pass through our networks and storage and memory is abundant. +-- Although we use a few table readers there i sno real gain in there (apart from having +-- less code. After all there are often not that many demanding features. + local next, type = next, type local band = bit32.band local extract = bit32.extract @@ -94,30 +97,38 @@ local readfixed = streamreader.readfixed4 local read2dot14 = streamreader.read2dot14 local skipshort = streamreader.skipshort local skipbytes = streamreader.skip -local readfword = readshort local readbytetable = streamreader.readbytetable local readbyte = streamreader.readbyte +local readcardinaltable = streamreader.readcardinaltable +local readintegertable = streamreader.readintegertable +local readfword = readshort + +local short = 2 +local ushort = 2 +local ulong = 4 directives.register("fonts.streamreader",function() - streamreader = utilities.streams - - setposition = streamreader.setposition - getposition = streamreader.getposition - readushort = streamreader.readcardinal2 - readulong = streamreader.readcardinal4 - readinteger = streamreader.readinteger1 - readshort = streamreader.readinteger2 - readstring = streamreader.readstring - readtag = streamreader.readtag - readbytes = streamreader.readbytes - readfixed = streamreader.readfixed4 - read2dot14 = streamreader.read2dot14 - skipshort = streamreader.skipshort - skipbytes = streamreader.skip - readfword = readshort - readbytetable = streamreader.readbytetable - readbyte = streamreader.readbyte + streamreader = utilities.streams + + setposition = streamreader.setposition + getposition = streamreader.getposition + readushort = streamreader.readcardinal2 + readulong = streamreader.readcardinal4 + readinteger = streamreader.readinteger1 + readshort = streamreader.readinteger2 + readstring = streamreader.readstring + readtag = streamreader.readtag + readbytes = streamreader.readbytes + readfixed = streamreader.readfixed4 + read2dot14 = streamreader.read2dot14 + skipshort = streamreader.skipshort + skipbytes = streamreader.skip + readbytetable = streamreader.readbytetable + readbyte = streamreader.readbyte + readcardinaltable = streamreader.readcardinaltable + readintegertable = streamreader.readintegertable + readfword = readshort end) @@ -220,39 +231,6 @@ local read_integer = { streamreader.readinteger4, } --- using helpers doesn't make much sense, subtle differences --- --- local function readushortarray(f,n) --- local t = { } --- for i=1,n do --- t[i] = readushort(f) --- end --- return t --- end --- --- local function readulongarray(f,n) --- local t = { } --- for i=1,n do --- t[i] = readulong(f) --- end --- return t --- end --- --- local function readushortarray(f,target,first,size) --- if not size then --- for i=1,size do --- target[i] = readushort(f) --- end --- else --- for i=1,size do --- target[first+i] = readushort(f) --- end --- end --- return target --- end --- --- so we get some half helper - half non helper mix then - -- Traditionally we use these unique names (so that we can flatten the lookup list -- (we create subsets runtime) but I will adapt the old code to newer names. @@ -504,10 +482,7 @@ local function readvariationdata(f,storeoffset,factors) -- store local format = readushort(f) local regionoffset = storeoffset + readulong(f) local nofdeltadata = readushort(f) - local deltadata = { } - for i=1,nofdeltadata do - deltadata[i] = readulong(f) - end + local deltadata = readcardinaltable(f,nofdeltadata,ulong) -- regions setposition(f,regionoffset) local nofaxis = readushort(f) @@ -538,10 +513,7 @@ local function readvariationdata(f,storeoffset,factors) -- store end -- we could test before and save a for for i=1,nofdeltasets do - local t = { } -- newtable - for i=1,nofshorts do - t[i] = readshort(f) - end + local t = readintegertable(f,nofshorts,short) for i=nofshorts+1,nofregions do t[i] = readinteger(f) end @@ -566,21 +538,32 @@ helpers.readvariationdata = readvariationdata local function readcoverage(f,offset,simple) setposition(f,offset) local coverageformat = readushort(f) - local coverage = { } if coverageformat == 1 then local nofcoverage = readushort(f) if simple then - for i=1,nofcoverage do - coverage[i] = readushort(f) + -- often 1 or 2 + if nofcoverage == 1 then + return { readushort(f) } + elseif nofcoverage == 2 then + return { readushort(f), readushort(f) } + else + return readcardinaltable(f,nofcoverage,ushort) end + elseif nofcoverage == 1 then + return { [readushort(f)] = 0 } + elseif nofcoverage == 2 then + return { [readushort(f)] = 0, [readushort(f)] = 1 } else + local coverage = { } for i=0,nofcoverage-1 do coverage[readushort(f)] = i -- index in record end + return coverage end elseif coverageformat == 2 then local nofranges = readushort(f) - local n = simple and 1 or 0 -- needs checking + local coverage = { } + local n = simple and 1 or 0 -- needs checking for i=1,nofranges do local firstindex = readushort(f) local lastindex = readushort(f) @@ -597,10 +580,11 @@ local function readcoverage(f,offset,simple) end end end + return coverage else report("unknown coverage format %a ",coverageformat) + return { } end - return coverage end local function readclassdef(f,offset,preset) @@ -834,23 +818,17 @@ local function readfirst(f,offset) return { readushort(f) } end -local function readarray(f,offset,first) +-- quite often 0, 1, 2 + +function readarray(f,offset) if offset then setposition(f,offset) end local n = readushort(f) - if first then - local t = { first } - for i=2,n do - t[i] = readushort(f) - end - return t, n + if n == 1 then + return { readushort(f) }, 1 elseif n > 0 then - local t = { } - for i=1,n do - t[i] = readushort(f) - end - return t, n + return readcardinaltable(f,n,ushort), n end end @@ -1251,10 +1229,7 @@ function gsubhandlers.single(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofg elseif subtype == 2 then -- in streamreader a seek and fetch is faster than a temp table local coverage = readushort(f) local nofreplacements = readushort(f) - local replacements = { } - for i=1,nofreplacements do - replacements[i] = readushort(f) - end + local replacements = readcardinaltable(f,nofreplacements,ushort) local coverage = readcoverage(f,tableoffset + coverage) -- not simple as we need to set key/value anyway for index, newindex in next, coverage do newindex = newindex + 1 @@ -1282,18 +1257,10 @@ local function sethandler(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyp if subtype == 1 then local coverage = readushort(f) local nofsequence = readushort(f) - local sequences = { } - for i=1,nofsequence do - sequences[i] = readushort(f) - end + local sequences = readcardinaltable(f,nofsequence,ushort) for i=1,nofsequence do setposition(f,tableoffset + sequences[i]) - local n = readushort(f) - local s = { } - for i=1,n do - s[i] = readushort(f) - end - sequences[i] = s + sequences[i] = readcardinaltable(f,readushort(f),ushort) end local coverage = readcoverage(f,tableoffset + coverage) for index, newindex in next, coverage do @@ -1328,19 +1295,20 @@ function gsubhandlers.ligature(f,fontdata,lookupid,lookupoffset,offset,glyphs,no if subtype == 1 then local coverage = readushort(f) local nofsets = readushort(f) - local ligatures = { } - for i=1,nofsets do - ligatures[i] = readushort(f) - end + local ligatures = readcardinaltable(f,nofsets,ushort) for i=1,nofsets do local offset = lookupoffset + offset + ligatures[i] setposition(f,offset) local n = readushort(f) - local l = { } - for i=1,n do - l[i] = offset + readushort(f) + if n == 1 then + ligatures[i] = { offset + readushort(f) } + else + local l = { } + for i=1,n do + l[i] = offset + readushort(f) + end + ligatures[i] = l end - ligatures[i] = l end local coverage = readcoverage(f,tableoffset + coverage) for index, newindex in next, coverage do @@ -1988,10 +1956,15 @@ do local parameters = readushort(f) -- feature.parameters local noflookups = readushort(f) if noflookups > 0 then - local lookups = { } +-- local lookups = { } +-- feature.lookups = lookups +-- for j=1,noflookups do +-- lookups[j] = readushort(f) + 1 +-- end + local lookups = readcardinaltable(f,noflookups,ushort) feature.lookups = lookups for j=1,noflookups do - lookups[j] = readushort(f) + 1 + lookups[j] = lookups[j] + 1 end end if parameters > 0 then @@ -2007,11 +1980,8 @@ do local function readlookups(f,lookupoffset,lookuptypes,featurehash,featureorder) setposition(f,lookupoffset) - local lookups = { } local noflookups = readushort(f) - for i=1,noflookups do - lookups[i] = readushort(f) - end + local lookups = readcardinaltable(f,noflookups,ushort) for lookupid=1,noflookups do local offset = lookups[lookupid] setposition(f,lookupoffset+offset) @@ -2302,9 +2272,7 @@ do end end end --- report("before : % t",rlookups[index]) rlookups[index] = noffound > 0 and found or false --- report("after : % t",rlookups[index]) else rlookups[index] = false end @@ -2344,11 +2312,12 @@ do record.condition = nil record.matchtype = "always" else - setposition(f,variationsoffset+offset) + local offset = variationsoffset+offset + setposition(f,offset) local nofconditions = readushort(f) local conditions = { } for i=1,nofconditions do - conditions[i] = variationsoffset+offset+readulong(f) + conditions[i] = offset + readulong(f) end record.conditions = conditions record.matchtype = "condition" @@ -2391,10 +2360,7 @@ do setposition(f,tableoffset) local parameters = readulong(f) -- feature parameters local noflookups = readushort(f) - local lookups = { } - for i=1,noflookups do - lookups[i] = readushort(f) -- not sure what to do with these - end + local lookups = readcardinaltable(f,noflookups,ushort) -- not sure what to do with these -- todo : resolve to proper lookups record.substitutions = lookups end @@ -2617,10 +2583,7 @@ function readers.gdef(f,fontdata,specification) local format = readushort(f) if format == 1 then local nofsets = readushort(f) - local sets = { } - for i=1,nofsets do - sets[i] = readulong(f) - end + local sets = readcardinal(f,nofsets,ulong) for i=1,nofsets do local offset = sets[i] if offset ~= 0 then @@ -2857,14 +2820,8 @@ local function readmathvariants(f,fontdata,offset) local hcoverage = readushort(f) local vnofglyphs = readushort(f) local hnofglyphs = readushort(f) - local vconstruction = { } - local hconstruction = { } - for i=1,vnofglyphs do - vconstruction[i] = readushort(f) - end - for i=1,hnofglyphs do - hconstruction[i] = readushort(f) - end + local vconstruction = readcardinaltable(f,vnofglyphs,ushort) + local hconstruction = readcardinaltable(f,hnofglyphs,ushort) fontdata.mathconstants.MinConnectorOverlap = minoverlap @@ -3039,10 +2996,7 @@ function readers.cpal(f,fontdata,specification) local nofcolorrecords = readushort(f) local firstcoloroffset = readulong(f) local colorrecords = { } - local palettes = { } - for i=1,nofpalettes do - palettes[i] = readushort(f) - end + local palettes = readcardinaltable(f,nofpalettes,ushort) if version == 1 then -- used for guis local palettettypesoffset = readulong(f) diff --git a/tex/context/base/mkiv/font-otr.lua b/tex/context/base/mkiv/font-otr.lua index 8b5c676c1..c7438dd43 100644 --- a/tex/context/base/mkiv/font-otr.lua +++ b/tex/context/base/mkiv/font-otr.lua @@ -121,32 +121,40 @@ local read2dot14 = streamreader.read2dot14 -- 16-bit signed fixed num local readfword = readshort -- 16-bit signed integer that describes a quantity in FUnits local readufword = readushort -- 16-bit unsigned integer that describes a quantity in FUnits local readoffset = readushort +local readcardinaltable = streamreader.readcardinaltable +local readintegertable = streamreader.readintegertable function streamreader.readtag(f) return lower(stripstring(readstring(f,4))) end +local short = 2 +local ushort = 2 +local ulong = 4 + directives.register("fonts.streamreader",function() - streamreader = utilities.streams - - openfile = streamreader.open - closefile = streamreader.close - setposition = streamreader.setposition - skipshort = streamreader.skipshort - readbytes = streamreader.readbytes - readstring = streamreader.readstring - readbyte = streamreader.readcardinal1 - readushort = streamreader.readcardinal2 - readuint = streamreader.readcardinal3 - readulong = streamreader.readcardinal4 - readshort = streamreader.readinteger2 - readlong = streamreader.readinteger4 - readfixed = streamreader.readfixed4 - read2dot14 = streamreader.read2dot14 - readfword = readshort - readufword = readushort - readoffset = readushort + streamreader = utilities.streams + + openfile = streamreader.open + closefile = streamreader.close + setposition = streamreader.setposition + skipshort = streamreader.skipshort + readbytes = streamreader.readbytes + readstring = streamreader.readstring + readbyte = streamreader.readcardinal1 + readushort = streamreader.readcardinal2 + readuint = streamreader.readcardinal3 + readulong = streamreader.readcardinal4 + readshort = streamreader.readinteger2 + readlong = streamreader.readinteger4 + readfixed = streamreader.readfixed4 + read2dot14 = streamreader.read2dot14 + readfword = readshort + readufword = readushort + readoffset = readushort + readcardinaltable = streamreader.readcardinaltable + readintegertable = streamreader.readintegertable function streamreader.readtag(f) return lower(stripstring(readstring(f,4))) @@ -1349,34 +1357,18 @@ formatreaders[4] = function(f,fontdata,offset) -- skipshort(f,3) -- searchrange entryselector rangeshift -- - local endchars = { } - local startchars = { } - local deltas = { } - local offsets = { } - local indices = { } local mapping = fontdata.mapping local glyphs = fontdata.glyphs local duplicates = fontdata.duplicates local nofdone = 0 - -- - for i=1,nofsegments do - endchars[i] = readushort(f) - end - local reserved = readushort(f) -- 0 - for i=1,nofsegments do - startchars[i] = readushort(f) - end - for i=1,nofsegments do - deltas[i] = readshort(f) - end - for i=1,nofsegments do - offsets[i] = readushort(f) - end + local endchars = readcardinaltable(f,nofsegments,ushort) + local reserved = readushort(f) -- 0 + local startchars = readcardinaltable(f,nofsegments,ushort) + local deltas = readcardinaltable(f,nofsegments,ushort) + local offsets = readcardinaltable(f,nofsegments,ushort) -- format length language nofsegments searchrange entryselector rangeshift 4-tables - local size = (length - 2 * 2 - 5 * 2 - 4 * 2 * nofsegments) / 2 - for i=1,size-1 do - indices[i] = readushort(f) - end + local size = (length - 2 * 2 - 5 * 2 - 4 * 2 * nofsegments) / 2 + local indices = readcardinaltable(f,size-1,ushort) -- for segment=1,nofsegments do local startchar = startchars[segment] @@ -2237,12 +2229,9 @@ local function loadfontdata(specification) fontdata = readdata(f,0,specification) elseif version == "ttcf" then local subfont = tonumber(specification.subfont) - local offsets = { } local ttcversion = readulong(f) local nofsubfonts = readulong(f) - for i=1,nofsubfonts do - offsets[i] = readulong(f) - end + local offsets = readcardinaltable(f,nofsubfonts,ulong) if subfont then -- a number of not if subfont >= 1 and subfont <= nofsubfonts then fontdata = readdata(f,offsets[subfont],specification) diff --git a/tex/context/base/mkiv/font-syn.lua b/tex/context/base/mkiv/font-syn.lua index 52f425db3..3951e8742 100644 --- a/tex/context/base/mkiv/font-syn.lua +++ b/tex/context/base/mkiv/font-syn.lua @@ -1172,7 +1172,7 @@ local function analyzefiles(olddata) report_names("scanning path %a for %s files",blobpath,suffix) end, function(blobtype,blobpath,pattern,total,checked,done) blobpath = resolveprefix(blobpath) -- no shortcut - report_names("%s entries found, %s %s files checked, %s okay",total,checked,suffix,done) + report_names("%s %s files checked, %s okay",checked,suffix,done) end) end diff --git a/tex/context/base/mkiv/font-ttf.lua b/tex/context/base/mkiv/font-ttf.lua index 181bfbcc6..1365b250d 100644 --- a/tex/context/base/mkiv/font-ttf.lua +++ b/tex/context/base/mkiv/font-ttf.lua @@ -38,41 +38,49 @@ local sqrt, round = math.sqrt, math.round local char = string.char local concat = table.concat -local report = logs.reporter("otf reader","ttf") +local report = logs.reporter("otf reader","ttf") -local trace_deltas = false +local trace_deltas = false -local readers = fonts.handlers.otf.readers -local streamreader = readers.streamreader +local readers = fonts.handlers.otf.readers +local streamreader = readers.streamreader -local setposition = streamreader.setposition -local getposition = streamreader.getposition -local skipbytes = streamreader.skip -local readbyte = streamreader.readcardinal1 -- 8-bit unsigned integer -local readushort = streamreader.readcardinal2 -- 16-bit unsigned integer -local readulong = streamreader.readcardinal4 -- 24-bit unsigned integer -local readchar = streamreader.readinteger1 -- 8-bit signed integer -local readshort = streamreader.readinteger2 -- 16-bit signed integer -local read2dot14 = streamreader.read2dot14 -- 16-bit signed fixed number with the low 14 bits of fraction (2.14) (F2DOT14) -local readinteger = streamreader.readinteger1 +local setposition = streamreader.setposition +local getposition = streamreader.getposition +local skipbytes = streamreader.skip +local readbyte = streamreader.readcardinal1 -- 8-bit unsigned integer +local readushort = streamreader.readcardinal2 -- 16-bit unsigned integer +local readulong = streamreader.readcardinal4 -- 24-bit unsigned integer +local readchar = streamreader.readinteger1 -- 8-bit signed integer +local readshort = streamreader.readinteger2 -- 16-bit signed integer +local read2dot14 = streamreader.read2dot14 -- 16-bit signed fixed number with the low 14 bits of fraction (2.14) (F2DOT14) +local readinteger = streamreader.readinteger1 +local readcardinaltable = streamreader.readcardinaltable +local readintegertable = streamreader.readintegertable directives.register("fonts.streamreader",function() - streamreader = utilities.streams + streamreader = utilities.streams - setposition = streamreader.setposition - getposition = streamreader.getposition - skipbytes = streamreader.skip - readbyte = streamreader.readcardinal1 - readushort = streamreader.readcardinal2 - readulong = streamreader.readcardinal4 - readchar = streamreader.readinteger1 - readshort = streamreader.readinteger2 - read2dot14 = streamreader.read2dot14 - readinteger = streamreader.readinteger1 + setposition = streamreader.setposition + getposition = streamreader.getposition + skipbytes = streamreader.skip + readbyte = streamreader.readcardinal1 + readushort = streamreader.readcardinal2 + readulong = streamreader.readcardinal4 + readchar = streamreader.readinteger1 + readshort = streamreader.readinteger2 + read2dot14 = streamreader.read2dot14 + readinteger = streamreader.readinteger1 + readcardinaltable = streamreader.readcardinaltable + readintegertable = streamreader.readintegertable end) +local short = 2 +local ushort = 2 +local ulong = 4 + local helpers = readers.helpers local gotodatatable = helpers.gotodatatable @@ -699,13 +707,10 @@ end -- end of converter local function readglyph(f,nofcontours) -- read deltas here, saves space - local points = { } - local contours = { } - local instructions = { } - local flags = { } - for i=1,nofcontours do - contours[i] = readshort(f) + 1 - end + local points = { } + local instructions = { } + local flags = { } + local contours = readintegertable(f,nofcontours,short) local nofpoints = contours[nofcontours] local nofinstructions = readushort(f) skipbytes(f,nofinstructions) diff --git a/tex/context/base/mkiv/l-dir.lua b/tex/context/base/mkiv/l-dir.lua index bc691d536..d13550643 100644 --- a/tex/context/base/mkiv/l-dir.lua +++ b/tex/context/base/mkiv/l-dir.lua @@ -75,7 +75,8 @@ function dir.current() return (gsub(currentdir(),"\\","/")) end --- somewhat optimized +-- The next one is somewhat optimized but still slow but it's a pitty that the iterator +-- doesn't return a mode too. local function glob_pattern_function(path,patt,recurse,action) if isdir(path) then @@ -89,6 +90,8 @@ local function glob_pattern_function(path,patt,recurse,action) usedpath = path end local dirs + local nofdirs = 0 + local noffiles = #result for name in walkdir(usedpath) do if name ~= "." and name ~= ".." then local full = path .. name @@ -98,16 +101,18 @@ local function glob_pattern_function(path,patt,recurse,action) action(full) end elseif recurse and mode == "directory" then - if not dirs then - dirs = { full } + if dirs then + nofdirs = nofdirs + 1 + dirs[nofdirs] = full else - dirs[#dirs+1] = full + nofdirs = 1 + dirs = { full } end end end end if dirs then - for i=1,#dirs do + for i=1,nofdirs do glob_pattern_function(dirs[i],patt,recurse,action) end end @@ -118,38 +123,41 @@ local function glob_pattern_table(path,patt,recurse,result) if not result then result = { } end - if isdir(path) then - local usedpath - if path == "/" then - usedpath = "/." - elseif not find(path,"/$") then - usedpath = path .. "/." - path = path .. "/" - else - usedpath = path - end - local dirs - for name in walkdir(usedpath) do - if name ~= "." and name ~= ".." then - local full = path .. name - local mode = attributes(full,'mode') - if mode == 'file' then - if not patt or find(full,patt) then - result[#result+1] = full - end - elseif recurse and mode == "directory" then - if not dirs then - dirs = { full } - else - dirs[#dirs+1] = full - end + local usedpath + if path == "/" then + usedpath = "/." + elseif not find(path,"/$") then + usedpath = path .. "/." + path = path .. "/" + else + usedpath = path + end + local dirs + local nofdirs = 0 + local noffiles = #result + for name, a in walkdir(usedpath) do + if name ~= "." and name ~= ".." then + local full = path .. name + local mode = attributes(full,'mode') + if mode == 'file' then + if not patt or find(full,patt) then + noffiles = noffiles + 1 + result[noffiles] = full + end + elseif recurse and mode == "directory" then + if dirs then + nofdirs = nofdirs + 1 + dirs[nofdirs] = full + else + nofdirs = 1 + dirs = { full } end end end - if dirs then - for i=1,#dirs do - glob_pattern_table(dirs[i],patt,recurse,result) - end + end + if dirs then + for i=1,nofdirs do + glob_pattern_table(dirs[i],patt,recurse,result) end end return result @@ -160,12 +168,13 @@ local function globpattern(path,patt,recurse,method) if patt and sub(patt,1,-3) == path then patt = false end + local okay = isdir(path) if kind == "function" then - return glob_pattern_function(path,patt,recurse,method) + return okay and glob_pattern_function(path,patt,recurse,method) or { } elseif kind == "table" then - return glob_pattern_table(path,patt,recurse,method) + return okay and glob_pattern_table(path,patt,recurse,method) or method else - return glob_pattern_table(path,patt,recurse,{ }) + return okay and glob_pattern_table(path,patt,recurse,{ }) or { } end end diff --git a/tex/context/base/mkiv/l-lpeg.lua b/tex/context/base/mkiv/l-lpeg.lua index e3d0ff9c3..5101a2e8d 100644 --- a/tex/context/base/mkiv/l-lpeg.lua +++ b/tex/context/base/mkiv/l-lpeg.lua @@ -291,8 +291,12 @@ patterns.beginline = #(1-newline) patterns.longtostring = Cs(whitespace^0/"" * ((patterns.quoted + nonwhitespace^1 + whitespace^1/"" * (P(-1) + Cc(" ")))^0)) -local function anywhere(pattern) --slightly adapted from website - return P { P(pattern) + 1 * V(1) } +-- local function anywhere(pattern) -- slightly adapted from website +-- return P { P(pattern) + 1 * V(1) } +-- end + +function anywhere(pattern) -- faster + return (1-P(pattern))^0 * P(pattern) end lpeg.anywhere = anywhere diff --git a/tex/context/base/mkiv/l-os.lua b/tex/context/base/mkiv/l-os.lua index b4b1a8645..b34c35edb 100644 --- a/tex/context/base/mkiv/l-os.lua +++ b/tex/context/base/mkiv/l-os.lua @@ -223,6 +223,13 @@ local name, platform = os.name or "linux", os.getenv("MTX_PLATFORM") or "" -- os.bits = 32 | 64 +-- os.uname() +-- sysname +-- machine +-- release +-- version +-- nodename + if platform ~= "" then os.platform = platform diff --git a/tex/context/base/mkiv/l-table.lua b/tex/context/base/mkiv/l-table.lua index 04c318792..69f45d9b4 100644 --- a/tex/context/base/mkiv/l-table.lua +++ b/tex/context/base/mkiv/l-table.lua @@ -1228,8 +1228,9 @@ end function table.reverse(t) -- check with 5.3 ? if t then local n = #t + local m = n + 1 for i=1,floor(n/2) do -- maybe just n//2 - local j = n - i + 1 + local j = m - i t[i], t[j] = t[j], t[i] end return t diff --git a/tex/context/base/mkiv/luat-ini.mkiv b/tex/context/base/mkiv/luat-ini.mkiv index 93f908a07..da5a3a310 100644 --- a/tex/context/base/mkiv/luat-ini.mkiv +++ b/tex/context/base/mkiv/luat-ini.mkiv @@ -265,55 +265,84 @@ % \def\syst_helpers_checked_stripped_csname#1% % {\if\noexpand#1\letterbackslash\else#1\fi} -\normalprotected\def\installctxfunction#1#2% expandable - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax - \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunction\csname\??luafunction\m_syst_name\endcsname}} - -\normalprotected\def\installctxscanner#1#2% expandable - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax - \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunction\csname\??luafunction\m_syst_name\endcsname}} - -\normalprotected\def\installprotectedctxfunction#1#2% protected - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax - \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunction\csname\??luafunction\m_syst_name\endcsname}} - -\normalprotected\def\installprotectedctxscanner#1#2% protected - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax - \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunction\csname\??luafunction\m_syst_name\endcsname}} - -% not yet used - -\ifdefined\luafunctioncall \else - \protected\def\luafunctioncall{\luafunctioncall} -\fi +\ifdefined\normalluadef + + \normalprotected\def\installctxfunction#1#2% expandable + {\edef\m_syst_name{\csstring#1}% + \global\expandafter\normalluadef\csname\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax} + + \normalprotected\def\installctxscanner#1#2% expandable + {\edef\m_syst_name{\csstring#1}% + \global\expandafter\normalluadef\csname\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax} + + \normalprotected\def\installprotectedctxfunction#1#2% protected + {\edef\m_syst_name{\csstring#1}% + \global\normalprotected\expandafter\normalluadef\csname\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax} + + \normalprotected\def\installprotectedctxscanner#1#2% protected + {\edef\m_syst_name{\csstring#1}% + \global\normalprotected\expandafter\normalluadef\csname\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax} + + \normalprotected\def\resetctxscanner#1% + {\edef\m_syst_name{\csstring#1}% + \expandafter\glet\csname\m_syst_name\endcsname\relax} + + % \let\installctxfunctioncall \installctxfunction + % \let\installctxscannercall \installctxscanner + % \let\installprotectedctxfunctioncall\installprotectedctxfunction + % \let\installprotectedctxscannercall \installprotectedctxscanner + +\else + + \ifdefined\luafunctioncall \else + \normalprotected\def\luafunctioncall{\luafunction} + \fi + + \normalprotected\def\installctxfunction#1#2% expandable + {\edef\m_syst_name{\csstring#1}% + \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax + \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunction\csname\??luafunction\m_syst_name\endcsname}} + + \normalprotected\def\installctxscanner#1#2% expandable + {\edef\m_syst_name{\csstring#1}% + \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax + \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunction\csname\??luafunction\m_syst_name\endcsname}} + + \normalprotected\def\installprotectedctxfunction#1#2% protected + {\edef\m_syst_name{\csstring#1}% + \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax + \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} + + \normalprotected\def\installprotectedctxscanner#1#2% protected + {\edef\m_syst_name{\csstring#1}% + \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax + \expandafter\xdef\csname\m_syst_name\endcsname{\noexpand\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} + + \normalprotected\def\resetctxscanner#1% + {\edef\m_syst_name{\csstring#1}% + \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\zerocount + \expandafter\glet\csname\m_syst_name\endcsname\relax} + + % \normalprotected\def\installctxfunctioncall#1#2% + % {\edef\m_syst_name{\csstring#1}% + % \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax + % \expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} + % + % \normalprotected\def\installctxscannercall#1#2% + % {\edef\m_syst_name{\csstring#1}% + % \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax + % \expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} + % + % \normalprotected\def\installprotectedctxfunctioncall#1#2% + % {\edef\m_syst_name{\csstring#1}% + % \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax + % \normalprotected\expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} + % + % \normalprotected\def\installprotectedctxscannercall#1#2% + % {\edef\m_syst_name{\csstring#1}% + % \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax + % \normalprotected\expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} -\normalprotected\def\installctxfunctioncall#1#2% - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax - \expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} - -\normalprotected\def\installctxscannercall#1#2% - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax - \expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} - -\normalprotected\def\installprotectedctxfunctioncall#1#2% - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxfunction("#2",true)}\relax - \normalprotected\expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} - -\normalprotected\def\installprotectedctxscannercall#1#2% - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\ctxcommand{ctxscanner("\m_syst_name","#2",true)}\relax - \normalprotected\expandafter\xdef\csname\m_syst_name\endcsname{\luafunctioncall\csname\??luafunction\m_syst_name\endcsname}} - -\normalprotected\def\resetctxscanner#1% - {\edef\m_syst_name{\csstring#1}% - \global\expandafter\chardef\csname\??luafunction\m_syst_name\endcsname\zerocount - \expandafter\glet\csname\m_syst_name\endcsname\relax} +\fi \protect \endinput diff --git a/tex/context/base/mkiv/lxml-ini.mkiv b/tex/context/base/mkiv/lxml-ini.mkiv index 7c97ffb2c..c4d6176ec 100644 --- a/tex/context/base/mkiv/lxml-ini.mkiv +++ b/tex/context/base/mkiv/lxml-ini.mkiv @@ -231,6 +231,7 @@ \unexpanded\def\xmlremovedocumentsetup #1#2{\clf_xmlremovesetup {#1}{#2}} \unexpanded\def\xmlresetdocumentsetups #1{\clf_xmlresetsetups {#1}} +\unexpanded\def\xmlflushsetups #1{\clf_xmlflushsetups {#1}{*}{}} % #1 == id where to apply * \unexpanded\def\xmlflushdocumentsetups #1#2{\clf_xmlflushsetups {#1}{*}{#2}} % #1 == id where to apply * and #2 \let\xmlregistersetup \xmlappendsetup @@ -240,7 +241,7 @@ \unexpanded\def\xmlregisteredsetups {\xmlstarttiming - \xmlflushsetups + \xmlflushsetups\xmldocument \xmldefaulttotext\xmldocument % after include \xmlstoptiming} diff --git a/tex/context/base/mkiv/lxml-lpt.lua b/tex/context/base/mkiv/lxml-lpt.lua index 9cccac120..a80a33f42 100644 --- a/tex/context/base/mkiv/lxml-lpt.lua +++ b/tex/context/base/mkiv/lxml-lpt.lua @@ -157,11 +157,11 @@ apply_axis['root'] = function(list) end apply_axis['self'] = function(list) ---~ local collected = { } ---~ for l=1,#list do ---~ collected[l] = list[l] ---~ end ---~ return collected + -- local collected = { } + -- for l=1,#list do + -- collected[l] = list[l] + -- end + -- return collected return list end @@ -171,18 +171,32 @@ apply_axis['child'] = function(list) local ll = list[l] local dt = ll.dt if dt then -- weird that this is needed - local en = 0 - for k=1,#dt do - local dk = dt[k] + local n = #dt + if n == 0 then + ll.en = 0 + elseif n == 1 then + local dk = dt[1] if dk.tg then c = c + 1 collected[c] = dk - dk.ni = k -- refresh - en = en + 1 - dk.ei = en + dk.ni = 1 -- refresh + dk.ei = 1 + ll.en = 1 + end + else + local en = 0 + for k=1,#dt do + local dk = dt[k] + if dk.tg then + c = c + 1 + en = en + 1 + collected[c] = dk + dk.ni = k -- refresh + dk.ei = en + end end + ll.en = en end - ll.en = en end end return collected @@ -191,19 +205,36 @@ end local function collect(list,collected,c) local dt = list.dt if dt then - local en = 0 - for k=1,#dt do - local dk = dt[k] + local n = #dt + if n == 0 then + list.en = 0 + elseif n == 1 then + local dk = dt[1] if dk.tg then c = c + 1 collected[c] = dk - dk.ni = k -- refresh - en = en + 1 - dk.ei = en + dk.ni = 1 -- refresh + dk.ei = 1 c = collect(dk,collected,c) + list.en = 1 + else + list.en = 0 end + else + local en = 0 + for k=1,n do + local dk = dt[k] + if dk.tg then + c = c + 1 + en = en + 1 + collected[c] = dk + dk.ni = k -- refresh + dk.ei = en + c = collect(dk,collected,c) + end + end + list.en = en end - list.en = en end return c end @@ -219,22 +250,38 @@ end local function collect(list,collected,c) local dt = list.dt if dt then - local en = 0 - for k=1,#dt do - local dk = dt[k] + local n = #dt + if n == 0 then + list.en = 0 + elseif n == 1 then + local dk = dt[1] if dk.tg then c = c + 1 collected[c] = dk - dk.ni = k -- refresh - en = en + 1 - dk.ei = en + dk.ni = 1 -- refresh + dk.ei = 1 c = collect(dk,collected,c) + list.en = 1 + end + else + local en = 0 + for k=1,#dt do + local dk = dt[k] + if dk.tg then + c = c + 1 + en = en + 1 + collected[c] = dk + dk.ni = k -- refresh + dk.ei = en + c = collect(dk,collected,c) + end end + list.en = en end - list.en = en end return c end + apply_axis['descendant-or-self'] = function(list) local collected, c = { }, 0 for l=1,#list do @@ -301,40 +348,40 @@ apply_axis['namespace'] = function(list) end apply_axis['following'] = function(list) -- incomplete ---~ local collected, c = { }, 0 ---~ for l=1,#list do ---~ local ll = list[l] ---~ local p = ll.__p__ ---~ local d = p.dt ---~ for i=ll.ni+1,#d do ---~ local di = d[i] ---~ if type(di) == "table" then ---~ c = c + 1 ---~ collected[c] = di ---~ break ---~ end ---~ end ---~ end ---~ return collected + -- local collected, c = { }, 0 + -- for l=1,#list do + -- local ll = list[l] + -- local p = ll.__p__ + -- local d = p.dt + -- for i=ll.ni+1,#d do + -- local di = d[i] + -- if type(di) == "table" then + -- c = c + 1 + -- collected[c] = di + -- break + -- end + -- end + -- end + -- return collected return { } end apply_axis['preceding'] = function(list) -- incomplete ---~ local collected, c = { }, 0 ---~ for l=1,#list do ---~ local ll = list[l] ---~ local p = ll.__p__ ---~ local d = p.dt ---~ for i=ll.ni-1,1,-1 do ---~ local di = d[i] ---~ if type(di) == "table" then ---~ c = c + 1 ---~ collected[c] = di ---~ break ---~ end ---~ end ---~ end ---~ return collected + -- local collected, c = { }, 0 + -- for l=1,#list do + -- local ll = list[l] + -- local p = ll.__p__ + -- local d = p.dt + -- for i=ll.ni-1,1,-1 do + -- local di = d[i] + -- if type(di) == "table" then + -- c = c + 1 + -- collected[c] = di + -- break + -- end + -- end + -- end + -- return collected return { } end diff --git a/tex/context/base/mkiv/lxml-tex.lua b/tex/context/base/mkiv/lxml-tex.lua index eed3b123a..0e8f2541c 100644 --- a/tex/context/base/mkiv/lxml-tex.lua +++ b/tex/context/base/mkiv/lxml-tex.lua @@ -92,6 +92,8 @@ local forceraw = false local p_texescape = patterns.texescape +local tokenizedcs = context.tokenizedcs + directives.enable("xml.path.keeplastmatch") -- tex entities @@ -499,13 +501,30 @@ function lxml.checkindex(name) return root and root.index or 0 end -function lxml.withindex(name,n,command) -- will change as name is always there now - local i, p = lpegmatch(splitter,n) - if p then - contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",n,"}") - else - contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",name,"::",n,"}") +if tokenizedcs then + + function lxml.withindex(name,n,command) -- will change as name is always there now + local i, p = lpegmatch(splitter,n) + local w = tokenizedcs.xmlw + if p then + contextsprint(ctxcatcodes,w,"{",command,"}{",n,"}") + else + contextsprint(ctxcatcodes,w,"{",command,"}{",name,"::",n,"}") + end end + +else + + function lxml.withindex(name,n,command) -- will change as name is always there now + local i, p = lpegmatch(splitter,n) + + if p then + contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",n,"}") + else + contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",name,"::",n,"}") + end + end + end function lxml.getindex(name,n) -- will change as name is always there now @@ -728,21 +747,6 @@ end local default_element_handler = xml.gethandlers("verbose").functions["@el@"] --- local xmlw = setmetatableindex(function(t,k) --- local v = setmetatableindex(function(t,kk) --- local v --- if kk == false then --- v = "\\xmlw{" .. k .. "}{" --- else --- v = "\\xmlw{" .. k .. "}{" .. kk .. "::" --- end --- t[kk] = v --- return v --- end) --- t[k]= v --- return v --- end) - local setfilename = false local trace_name = false local report_name = logs.reporter("lxml") @@ -765,39 +769,80 @@ trackers.register("system.synctex.xml",function(v) trace_name = v end) -local function tex_element(e,handlers) - if setfilename then - syncfilename(e,"element") - end - local command = e.command - if command == nil then - default_element_handler(e,handlers) - elseif command == true then - -- text (no <self></self>) / so, no mkii fallback then - handlers.serialize(e.dt,handlers) - elseif command == false then - -- ignore - else - local tc = type(command) - if tc == "string" then - local rootname, ix = e.name, e.ix - if rootname then - if not ix then - addindex(rootname,false,true) - ix = e.ix +local tex_element + +if tokenizedcs then + + tex_element = function(e,handlers) + if setfilename then + syncfilename(e,"element") + end + local command = e.command + if command == nil then + default_element_handler(e,handlers) + elseif command == true then + -- text (no <self></self>) / so, no mkii fallback then + handlers.serialize(e.dt,handlers) + elseif command == false then + -- ignore + else + local tc = type(command) + if tc == "string" then + local rootname, ix = e.name, e.ix + local w = tokenizedcs.xmlw + if rootname then + if not ix then + addindex(rootname,false,true) + ix = e.ix + end + contextsprint(ctxcatcodes,w,"{",command,"}{",rootname,"::",ix,"}") + else + report_lxml("fatal error: no index for %a",command) + contextsprint(ctxcatcodes,w,"{",command,"}{",ix or 0,"}") end - -- faster than context.xmlw - contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",rootname,"::",ix,"}") - -- contextsprint(ctxcatcodes,xmlw[command][rootname],ix,"}") - else - report_lxml("fatal error: no index for %a",command) - contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",ix or 0,"}") - -- contextsprint(ctxcatcodes,xmlw[command][false],ix or 0,"}") + elseif tc == "function" then + command(e) + end + end + end + +else + + tex_element = function(e,handlers) + if setfilename then + syncfilename(e,"element") + end + local command = e.command + if command == nil then + default_element_handler(e,handlers) + elseif command == true then + -- text (no <self></self>) / so, no mkii fallback then + handlers.serialize(e.dt,handlers) + elseif command == false then + -- ignore + else + local tc = type(command) + if tc == "string" then + local rootname, ix = e.name, e.ix + if rootname then + if not ix then + addindex(rootname,false,true) + ix = e.ix + end + -- faster than context.xmlw + contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",rootname,"::",ix,"}") + -- contextsprint(ctxcatcodes,xmlw[command][rootname],ix,"}") + else + report_lxml("fatal error: no index for %a",command) + contextsprint(ctxcatcodes,"\\xmlw{",command,"}{",ix or 0,"}") + -- contextsprint(ctxcatcodes,xmlw[command][false],ix or 0,"}") + end + elseif tc == "function" then + command(e) end - elseif tc == "function" then - command(e) end end + end -- <?context-directive foo ... ?> @@ -1180,7 +1225,7 @@ function lxml.flushsetups(id,...) local sd = setups[document] if sd then for k=1,#sd do - local v= sd[k] + local v = sd[k] if not done[v] then if trace_loading then report_lxml("applying setup %02i : %a to %a",k,v,document) @@ -1442,29 +1487,63 @@ end -- the number of commands is often relative small but there can be many calls -- to this finalizer -local function command(collected,cmd,otherwise) - local n = collected and #collected - if n and n > 0 then - local wildcard = find(cmd,"*",1,true) - for c=1,n do -- maybe optimize for n=1 - local e = collected[c] - local ix = e.ix - local name = e.name - if name and not ix then - addindex(name,false,true) - ix = e.ix - end - if not ix or not name then - report_lxml("no valid node index for element %a using command %s",name or "?",cmd) - elseif wildcard then - contextsprint(ctxcatcodes,"\\xmlw{",(gsub(cmd,"%*",e.tg)),"}{",name,"::",ix,"}") - else - contextsprint(ctxcatcodes,"\\xmlw{",cmd,"}{",name,"::",ix,"}") +local command + +if tokenizedcs then + + command = function(collected,cmd,otherwise) + local n = collected and #collected + local w = tokenizedcs.xmlw + if n and n > 0 then + local wildcard = find(cmd,"*",1,true) + for c=1,n do -- maybe optimize for n=1 + local e = collected[c] + local ix = e.ix + local name = e.name + if name and not ix then + addindex(name,false,true) + ix = e.ix + end + if not ix or not name then + report_lxml("no valid node index for element %a using command %s",name or "?",cmd) + elseif wildcard then + contextsprint(ctxcatcodes,w,"{",(gsub(cmd,"%*",e.tg)),"}{",name,"::",ix,"}") + else + contextsprint(ctxcatcodes,w,"{",cmd,"}{",name,"::",ix,"}") + end + end + elseif otherwise then + contextsprint(ctxcatcodes,w,"{",otherwise,"}{#1}") + end + end + +else + + command = function(collected,cmd,otherwise) + local n = collected and #collected + if n and n > 0 then + local wildcard = find(cmd,"*",1,true) + for c=1,n do -- maybe optimize for n=1 + local e = collected[c] + local ix = e.ix + local name = e.name + if name and not ix then + addindex(name,false,true) + ix = e.ix + end + if not ix or not name then + report_lxml("no valid node index for element %a using command %s",name or "?",cmd) + elseif wildcard then + contextsprint(ctxcatcodes,"\\xmlw{",(gsub(cmd,"%*",e.tg)),"}{",name,"::",ix,"}") + else + contextsprint(ctxcatcodes,"\\xmlw{",cmd,"}{",name,"::",ix,"}") + end end + elseif otherwise then + contextsprint(ctxcatcodes,"\\xmlw{",otherwise,"}{#1}") end - elseif otherwise then - contextsprint(ctxcatcodes,"\\xmlw{",otherwise,"}{#1}") end + end -- local wildcards = setmetatableindex(function(t,k) @@ -1675,7 +1754,7 @@ local function concatrange(collected,start,stop,separator,lastseparator,textonly end end -local function concat(collected,separator,lastseparator,textonly) -- test this on mml +local function concatlist(collected,separator,lastseparator,textonly) -- test this on mml concatrange(collected,false,false,separator,lastseparator,textonly) end @@ -1697,14 +1776,12 @@ texfinalizers.context = ctxtext texfinalizers.position = position texfinalizers.match = match texfinalizers.index = index -texfinalizers.concat = concat +texfinalizers.concat = concatlist texfinalizers.concatrange = concatrange texfinalizers.chainattribute = chainattribute texfinalizers.chainpath = chainpath texfinalizers.default = all -- !! -local concat = table.concat - function texfinalizers.tag(collected,n) if collected then local nc = #collected @@ -2139,24 +2216,51 @@ function lxml.direct(id) end end -function lxml.command(id,pattern,cmd) - local i, p = getid(id,true) - local collected = xmlapplylpath(getid(i),pattern) - if collected then - local nc = #collected - if nc > 0 then - local rootname = p or i.name - for c=1,nc do - local e = collected[c] - local ix = e.ix - if not ix then - addindex(rootname,false,true) - ix = e.ix +if tokenizedcs then + + function lxml.command(id,pattern,cmd) + local i, p = getid(id,true) + local collected = xmlapplylpath(getid(i),pattern) + if collected then + local nc = #collected + if nc > 0 then + local rootname = p or i.name + local w = tokenizedcs.xmlw + for c=1,nc do + local e = collected[c] + local ix = e.ix + if not ix then + addindex(rootname,false,true) + ix = e.ix + end + contextsprint(ctxcatcodes,w,"{",cmd,"}{",rootname,"::",ix,"}") + end + end + end + end + +else + + function lxml.command(id,pattern,cmd) + local i, p = getid(id,true) + local collected = xmlapplylpath(getid(i),pattern) + if collected then + local nc = #collected + if nc > 0 then + local rootname = p or i.name + for c=1,nc do + local e = collected[c] + local ix = e.ix + if not ix then + addindex(rootname,false,true) + ix = e.ix + end + contextsprint(ctxcatcodes,"\\xmlw{",cmd,"}{",rootname,"::",ix,"}") end - contextsprint(ctxcatcodes,"\\xmlw{",cmd,"}{",rootname,"::",ix,"}") end end end + end -- loops @@ -2292,13 +2396,13 @@ function texfinalizers.lettered(collected) end end ---~ function texfinalizers.apply(collected,what) -- to be tested ---~ if collected then ---~ for c=1,#collected do ---~ contextsprint(ctxcatcodes,what(collected[c].dt[1])) ---~ end ---~ end ---~ end +-- function texfinalizers.apply(collected,what) -- to be tested +-- if collected then +-- for c=1,#collected do +-- contextsprint(ctxcatcodes,what(collected[c].dt[1])) +-- end +-- end +-- end function lxml.toparameters(id) local e = getid(id) diff --git a/tex/context/base/mkiv/math-ini.mkiv b/tex/context/base/mkiv/math-ini.mkiv index dc88f82aa..4115a13c4 100644 --- a/tex/context/base/mkiv/math-ini.mkiv +++ b/tex/context/base/mkiv/math-ini.mkiv @@ -739,20 +739,20 @@ % this one too: \letvalue{\??mathcodecommand op}\mathop ? \unexpanded\def\normalmbox - {\hbox\bgroup + {\normalhbox\bgroup \usemathematicsstyleandcolor\c!textstyle\c!textcolor % new - \dowithnextboxcs\math_mbox_finish\hbox} + \dowithnextboxcs\math_mbox_finish\normalhbox} \def\math_mbox_finish {\flushnextbox \egroup} \unexpanded\def\mbox % we cannot add \dontleavehmode ... else no \setbox0\mbox possible - {\ifmmode\normalmbox\else\hbox\fi} + {\ifmmode\normalmbox\else\normalhbox\fi} \unexpanded\def\enablembox - {\appendtoks\math_enable_mbox\to \everymathematics} - {\everymathematics\expandafter{\the\everymathematics\math_enable_mbox}} + %{\appendtoks\math_enable_mbox\to \everymathematics} + {\toksapp\everymathematics{\math_enable_mbox}} \def\math_enable_mbox {\let\hbox\mbox} @@ -760,7 +760,7 @@ \unexpanded\def\snappedmath#1% sort of \struttedbox {\dontleavehmode \begingroup - \setbox\scratchbox\hbox\bgroup + \setbox\scratchbox\normalhbox\bgroup \startimath#1\stopimath \egroup \ht\scratchbox\strutht @@ -2817,6 +2817,56 @@ \mathrulesfam\zerocount \to \everymathematics +%D Maybe: + +% \starttabulate[|||c|c|] +% \BC positive \BC negative \BC text \BC math \NC \NR +% \NC \tex {f1} \tex {hairspace} \tex{,} \NC \tex {b1} \tex {neghairspace} \NC {\darkred\vl}\f1{\darkblue\vl} \NC ${\darkred\vl}\f1{\darkblue\vl}$ \NC \NR +% \NC \tex {f2} \tex {thinspace} \tex{:} \NC \tex {b2} \tex {negthinspace} \tex{!} \NC {\darkred\vl}\f2{\darkblue\vl} \NC ${\darkred\vl}\f2{\darkblue\vl}$ \NC \NR +% \NC \tex {f3} \tex {medspace} \tex{;} \NC \tex {b3} \tex {negmedspace} \NC {\darkred\vl}\f3{\darkblue\vl} \NC ${\darkred\vl}\f3{\darkblue\vl}$ \NC \NR +% \NC \tex {f4} \tex {thickspace} \NC \tex {b4} \tex {negthickspace} \NC {\darkred\vl}\f4{\darkblue\vl} \NC ${\darkred\vl}\f4{\darkblue\vl}$ \NC \NR +% \NC \tex {f5} \tex {enspace} \NC \tex {b5} \NC {\darkred\vl}\f5{\darkblue\vl} \NC ${\darkred\vl}\f5{\darkblue\vl}$ \NC \NR +% \NC \tex {f6} \tex {emspace} \NC \tex {b6} \NC {\darkred\vl}\f6{\darkblue\vl} \NC ${\darkred\vl}\f6{\darkblue\vl}$ \NC \NR +% \stoptabulate + +% \unexpanded\def\negenspace{\kern-.5\emwidth} +% \unexpanded\def\negemspace{\kern- \emwidth} +% +% \unexpanded\def\math_f#1% +% {\ifcase#1\or +% \hairspace +% \or +% \thinspace +% \or +% \medspace +% \or +% \thickspace +% \or +% \enspace +% \or +% \emspace +% \fi} +% +% \unexpanded\def\math_b#1% +% {\ifcase#1\or +% \neghairspace +% \or +% \negthinspace +% \or +% \negmedspace +% \or +% \negthickspace +% \or +% \negenspace +% \or +% \negemspace +% \fi} +% +% \appendtoks +% \let\f\math_f +% \let\b\math_b +% \to \everymathematics + \protect \endinput % % not used (yet) diff --git a/tex/context/base/mkiv/mult-low.lua b/tex/context/base/mkiv/mult-low.lua index 1b794ef73..3d733aa2e 100644 --- a/tex/context/base/mkiv/mult-low.lua +++ b/tex/context/base/mkiv/mult-low.lua @@ -414,11 +414,7 @@ return { "startluacode", "stopluacode", "startlua", "stoplua", "startctxfunction","stopctxfunction","ctxfunction", "startctxfunctiondefinition","stopctxfunctiondefinition", - "installctxfunction", "installctxfunctioncall", - "installprotectedctxfunction", "installprotectedctxfunctioncall", - "installctxscanner", "installctxscannercall", - "resetctxscanner", - "installprotectedctxscanner", "installprotectedctxscannercall", + "installctxfunction", "installprotectedctxfunction", "installprotectedctxscanner", "installctxscanner", "resetctxscanner", "cldprocessfile", "cldloadfile", "cldloadviafile", "cldcontext", "cldcommand", -- "carryoverpar", diff --git a/tex/context/base/mkiv/mult-prm.lua b/tex/context/base/mkiv/mult-prm.lua index edb66b991..3aa265b8d 100644 --- a/tex/context/base/mkiv/mult-prm.lua +++ b/tex/context/base/mkiv/mult-prm.lua @@ -237,6 +237,7 @@ return { "crampedscriptscriptstyle", "crampedscriptstyle", "crampedtextstyle", + "csstring", "draftmode", "dviextension", "dvifeedback", @@ -244,8 +245,6 @@ return { "efcode", "etoksapp", "etokspre", - "xtoksapp", - "xtokspre", "exceptionpenalty", "expanded", "expandglyphsinfont", @@ -254,18 +253,20 @@ return { "fontid", "formatname", "gleaders", - "glet", + "gtoksapp", + "gtokspre", "hjcode", "hyphenationbounds", "hyphenationmin", "hyphenpenaltymode", "ifabsdim", "ifabsnum", + "ifcondition", "ifincsname", "ifprimitive", "ignoreligaturesinfont", - "immediateassignment", "immediateassigned", + "immediateassignment", "initcatcodetable", "insertht", "lastnamedcs", @@ -286,6 +287,10 @@ return { "localleftbox", "localrightbox", "lpcode", + "luabytecode", + "luabytecodecall", + "luacopyinputnodes", + "luadef", "luaescapestring", "luafunction", "luafunctioncall", @@ -367,12 +372,12 @@ return { "textdirection", "toksapp", "tokspre", - "gtoksapp", - "gtokspre", "tracingfonts", "uniformdeviate", "useboxresource", "useimageresource", + "xtoksapp", + "xtokspre", }, ["omega"]={ "Omegaminorversion", @@ -533,7 +538,6 @@ return { "cr", "crcr", "csname", - "csstring", "day", "deadcycles", "def", @@ -591,6 +595,7 @@ return { "fontname", "futurelet", "gdef", + "glet", "global", "globaldefs", "halign", @@ -834,4 +839,4 @@ return { ["xetex"]={ "XeTeXversion", }, -} +}
\ No newline at end of file diff --git a/tex/context/base/mkiv/spac-ver.mkiv b/tex/context/base/mkiv/spac-ver.mkiv index 70f79bdad..4c78dfd69 100644 --- a/tex/context/base/mkiv/spac-ver.mkiv +++ b/tex/context/base/mkiv/spac-ver.mkiv @@ -2016,7 +2016,7 @@ \expandafter\nostartblankhandling \fi} -\def\nostartblankhandling#1\stopblankhandling +\unexpanded\def\nostartblankhandling#1\stopblankhandling {} \def\dostartblankhandling @@ -2044,7 +2044,7 @@ \setfalse\c_space_vspacing_done \the\everybeforeblankhandling} -\def\addpredefinedblankskip#1#2% +\unexpanded\def\addpredefinedblankskip#1#2% {\settrue\c_space_vspacing_done \advance\s_spac_vspacing_temp#1\dimexpr\csname\??vspacingamount#2\endcsname\relax} @@ -2091,7 +2091,7 @@ \def\spac_vspacing_nop_ignore {\ifmmode\else\par\fi} -\def\directvspacing#1% +\unexpanded\def\directvspacing#1% {\par\clf_vspacing{#1}} \def\directcheckedvspacing diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex f177ab844..ce9997904 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex 102f1ce2d..4df2c4555 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/strc-mar.lua b/tex/context/base/mkiv/strc-mar.lua index bb79ac7a9..51f896aa7 100644 --- a/tex/context/base/mkiv/strc-mar.lua +++ b/tex/context/base/mkiv/strc-mar.lua @@ -650,28 +650,49 @@ end -- pushing to context: -local separator = context.nested.markingseparator -local command = context.nested.markingcommand -local ctxconcat = context.concat - -local function fetchonemark(name,range,method) - context(command(name,fetched(name,range,method))) -end +-- local separator = context.nested.markingseparator +-- local command = context.nested.markingcommand +-- local ctxconcat = context.concat + +-- local function fetchonemark(name,range,method) +-- context(command(name,fetched(name,range,method))) +-- end + +-- local function fetchtwomarks(name,range) +-- ctxconcat( { +-- command(name,fetched(name,range,v_first)), +-- command(name,fetched(name,range,v_last)), +-- }, separator(name)) +-- end + +-- local function fetchallmarks(name,range) +-- ctxconcat( { +-- command(name,fetched(name,range,v_previous)), +-- command(name,fetched(name,range,v_first)), +-- command(name,fetched(name,range,v_last)), +-- }, separator(name)) +-- end + + local ctx_separator = context.markingseparator + local ctx_command = context.markingcommand + + local function fetchonemark(name,range,method) + ctx_command(name,fetched(name,range,method)) + end -local function fetchtwomarks(name,range) - ctxconcat( { - command(name,fetched(name,range,v_first)), - command(name,fetched(name,range,v_last)), - }, separator(name)) -end + local function fetchtwomarks(name,range) + ctx_command(name,fetched(name,range,v_first)) + ctx_separator(name) + ctx_command(name,fetched(name,range,v_last)) + end -local function fetchallmarks(name,range) - ctxconcat( { - command(name,fetched(name,range,v_previous)), - command(name,fetched(name,range,v_first)), - command(name,fetched(name,range,v_last)), - }, separator(name)) -end + local function fetchallmarks(name,range) + ctx_command(name,fetched(name,range,v_previous)) + ctx_separator(name) + ctx_command(name,fetched(name,range,v_first)) + ctx_separator(name) + ctx_command(name,fetched(name,range,v_last)) + end function marks.fetch(name,range,method) -- chapter page first | chapter column:1 first if trace_marks_get then diff --git a/tex/context/base/mkiv/syst-aux.lua b/tex/context/base/mkiv/syst-aux.lua index f9d8505f1..27f194b0a 100644 --- a/tex/context/base/mkiv/syst-aux.lua +++ b/tex/context/base/mkiv/syst-aux.lua @@ -373,10 +373,17 @@ implement { -- not faster but just less tracing: -local firstoftwoarguments = context.firstoftwoarguments -local secondoftwoarguments = context.secondoftwoarguments -local firstofoneargument = context.firstofoneargument -local gobbleoneargument = context.gobbleoneargument +local ctx_protected_cs = context.protected.cs -- more efficient + +local ctx_firstoftwoarguments = ctx_protected_cs.firstoftwoarguments +local ctx_secondoftwoarguments = ctx_protected_cs.secondoftwoarguments +local ctx_firstofoneargument = ctx_protected_cs.firstofoneargument +local ctx_gobbleoneargument = ctx_protected_cs.gobbleoneargument + +context.firstoftwoarguments = ctx_firstoftwoarguments +context.secondoftwoarguments = ctx_secondoftwoarguments +context.firstofoneargument = ctx_firstofoneargument +context.gobbleoneargument = ctx_gobbleoneargument local hash = utilities.parsers.hashes.settings_to_set @@ -384,9 +391,9 @@ local function doifelsecommon(a,b) if a == b then setmacro("commalistelement",a) if a == "" then - secondoftwoarguments() + ctx_secondoftwoarguments() else - firstoftwoarguments() + ctx_firstoftwoarguments() end return end @@ -400,7 +407,7 @@ local function doifelsecommon(a,b) for k in next, ha do if hb[k] then setmacro("commalistelement",k) - firstoftwoarguments() + ctx_firstoftwoarguments() return end end @@ -408,28 +415,28 @@ local function doifelsecommon(a,b) if hash[a][b] then -- if settings_to_set(a)[b] then setmacro("commalistelement",b) - firstoftwoarguments() + ctx_firstoftwoarguments() return end elseif bb then if hash[b][a] then -- if settings_to_set(b)[a] then setmacro("commalistelement",a) - firstoftwoarguments() + ctx_firstoftwoarguments() return end end setmacro("commalistelement","") - secondoftwoarguments() + ctx_secondoftwoarguments() end local function doifcommon(a,b) if a == b then setmacro("commalistelement",a) if a == "" then - gobbleoneargument() + ctx_gobbleoneargument() else - firstofoneargument() + ctx_firstofoneargument() end return end @@ -443,7 +450,7 @@ local function doifcommon(a,b) for k in next, ha do if hb[k] then setmacro("commalistelement",k) - firstofoneargument() + ctx_firstofoneargument() return end end @@ -451,28 +458,28 @@ local function doifcommon(a,b) if hash[a][b] then -- if settings_to_set(a)[b] then setmacro("commalistelement",b) - firstofoneargument() + ctx_firstofoneargument() return end elseif bb then if hash[b][a] then -- if settings_to_set(b)[a] then setmacro("commalistelement",a) - firstofoneargument() + ctx_firstofoneargument() return end end setmacro("commalistelement","") - gobbleoneargument() + ctx_gobbleoneargument() end local function doifnotcommon(a,b) if a == b then setmacro("commalistelement",a) if a == "" then - firstofoneargument() + ctx_firstofoneargument() else - gobbleoneargument() + ctx_gobbleoneargument() end return end @@ -486,7 +493,7 @@ local function doifnotcommon(a,b) for k in next, ha do if hb[k] then setmacro("commalistelement",k) - gobbleoneargument() + ctx_gobbleoneargument() return end end @@ -494,28 +501,28 @@ local function doifnotcommon(a,b) if hash[a][b] then -- if settings_to_set(a)[b] then setmacro("commalistelement",b) - gobbleoneargument() + ctx_gobbleoneargument() return end elseif bb then if hash[b][a] then -- if settings_to_set(b)[a] then setmacro("commalistelement",a) - gobbleoneargument() + ctx_gobbleoneargument() return end end setmacro("commalistelement","") - firstofoneargument() + ctx_firstofoneargument() end local function doifelseinset(a,b) if a == b then setmacro("commalistelement",a) if a == "" then - secondoftwoarguments() + ctx_secondoftwoarguments() else - firstoftwoarguments() + ctx_firstoftwoarguments() end return end @@ -524,21 +531,21 @@ local function doifelseinset(a,b) if hash[b][a] then -- if settings_to_set(b)[a] then setmacro("commalistelement",a) - firstoftwoarguments() + ctx_firstoftwoarguments() return end end setmacro("commalistelement","") - secondoftwoarguments() + ctx_secondoftwoarguments() end local function doifinset(a,b) if a == b then setmacro("commalistelement",a) if a == "" then - gobbleoneargument() + ctx_gobbleoneargument() else - firstofoneargument() + ctx_firstofoneargument() end return end @@ -547,21 +554,21 @@ local function doifinset(a,b) if hash[b][a] then -- if settings_to_set(b)[a] then setmacro("commalistelement",a) - firstofoneargument() + ctx_firstofoneargument() return end end setmacro("commalistelement","") - gobbleoneargument() + ctx_gobbleoneargument() end local function doifnotinset(a,b) if a == b then setmacro("commalistelement",a) if a == "" then - firstofoneargument() + ctx_firstofoneargument() else - gobbleoneargument() + ctx_gobbleoneargument() end return end @@ -570,12 +577,12 @@ local function doifnotinset(a,b) if hash[b][a] then -- if settings_to_set(b)[a] then setmacro("commalistelement",a) - gobbleoneargument() + ctx_gobbleoneargument() return end end setmacro("commalistelement","") - firstofoneargument() + ctx_firstofoneargument() end implement { diff --git a/tex/context/base/mkiv/syst-ini.mkiv b/tex/context/base/mkiv/syst-ini.mkiv index dcf7810b7..485a87ecb 100644 --- a/tex/context/base/mkiv/syst-ini.mkiv +++ b/tex/context/base/mkiv/syst-ini.mkiv @@ -1265,7 +1265,7 @@ \ifdefined\prerelpenalty \else \newcount\prerelpenalty \fi \ifdefined\breakafterdirmode \else \newcount\breakafterdirmode \fi - -\ifdefined\exceptionpenalty \else \newcount\exceptionpenalty \fi +\ifdefined\exceptionpenalty \else \newcount\exceptionpenalty \fi +\ifdefined\luacopyinputnodes \else \newcount\luacopyinputnodes \fi \protect \endinput diff --git a/tex/context/base/mkiv/syst-lua.lua b/tex/context/base/mkiv/syst-lua.lua index 35cd22123..a8e9e1b01 100644 --- a/tex/context/base/mkiv/syst-lua.lua +++ b/tex/context/base/mkiv/syst-lua.lua @@ -15,10 +15,10 @@ local context = context local implement = interfaces.implement local ctx_protected_cs = context.protected.cs -- more efficient -local ctx_firstoftwoarguments = ctx_protected_cs.firstoftwoarguments -local ctx_secondoftwoarguments = ctx_protected_cs.secondoftwoarguments -local ctx_firstofoneargument = ctx_protected_cs.firstofoneargument -local ctx_gobbleoneargument = ctx_protected_cs.gobbleoneargument +local ctx_firstoftwoarguments = context.firstoftwoarguments +local ctx_secondoftwoarguments = context.secondoftwoarguments +local ctx_firstofoneargument = context.firstofoneargument +local ctx_gobbleoneargument = context.gobbleoneargument local two_strings = interfaces.strings[2] diff --git a/tex/context/base/mkiv/task-ini.lua b/tex/context/base/mkiv/task-ini.lua index 29ae69eb1..49f85f01d 100644 --- a/tex/context/base/mkiv/task-ini.lua +++ b/tex/context/base/mkiv/task-ini.lua @@ -94,7 +94,6 @@ appendaction("shipouts", "finishers", "attributes.viewerlayers.handler", appendaction("shipouts", "wrapup", "nodes.handlers.export", nil, "nut", "disabled" ) -- always last appendaction("shipouts", "wrapup", "luatex.synctex.collect", nil, "nut", "disabled" ) - appendaction("math", "normalizers", "noads.handlers.showtree", nil, "nonut", "disabled" ) appendaction("math", "normalizers", "noads.handlers.unscript", nil, "nonut", "enabled" ) appendaction("math", "normalizers", "noads.handlers.variants", nil, "nonut", "enabled" ) diff --git a/tex/context/base/mkiv/toks-ini.lua b/tex/context/base/mkiv/toks-ini.lua index 481858971..dfdf854d0 100644 --- a/tex/context/base/mkiv/toks-ini.lua +++ b/tex/context/base/mkiv/toks-ini.lua @@ -18,41 +18,15 @@ local printtable = table.print local concat = table.concat local format = string.format -if setinspector then +if token.commands then - local istoken = token.is_token - local simple = { letter = "letter", other_char = "other" } + local commands = token.commands() - local function astable(t) - if t and istoken(t) then - local cmdname = t.cmdname - local simple = simple[cmdname] - if simple then - return { - category = simple, - character = utfchar(t.mode) or nil, - } - else - return { - command = t.command, - id = t.id, - tok = t.tok, - csname = t.csname, - active = t.active, - expandable = t.expandable, - protected = t.protected, - mode = t.mode, - index = t.index, - cmdname = cmdname, - } - end - end - end + tokens.commands = utilities.storage.allocate(table.swapped(commands,commands)) - tokens.istoken = istoken - tokens.astable = astable +else - setinspector("token",function(v) if istoken(v) then printtable(astable(v),tostring(v)) return true end end) + tokens.commands = { } end @@ -79,25 +53,26 @@ local get_macro = token.get_macro local get_meaning = token.get_meaning local get_cmdname = token.get_cmdname local set_char = token.set_char +local set_lua = token.set_lua + local create_token = token.create +local new_token = token.new +local is_defined = token.is_defined +local is_token = token.is_token -if not set_char then -- for a while - local contextsprint = context.sprint - local ctxcatcodes = catcodes.numbers.ctxcatcodes - set_char = function(n,u) contextsprint(ctxcatcodes,format("\\chardef\\%s=%s",n,u)) end -end +if not is_defined then + + is_defined = function(name) + return get_cmdname(create_token(name)) ~= "undefined_cs" + end -function tokens.defined(name) - return get_cmdname(create_token(name)) ~= "undefined_cs" end --- set_macro = function(k,v,g) --- if g == "global" then --- context.setgvalue(k,v or '') --- else --- context.setvalue(k,v or '') --- end --- end +tokens.new = new_token +tokens.create = create_token +tokens.istoken = is_token +tokens.isdefined = is_defined +tokens.defined = is_defined local bits = { escape = 0x00000001, -- 2^00 @@ -272,6 +247,7 @@ tokens.getters = { -- these don't expand tokens.setters = { macro = set_macro, char = set_char, + lua = set_lua, count = tex.setcount, dimen = tex.setdimen, skip = tex.setglue, @@ -301,3 +277,45 @@ tokens.setters = { -- /* unsave_tex_scanner(texstate); */ -- return 1; -- } + +if setinspector then + + local simple = { letter = "letter", other_char = "other" } + + local function astable(t) + if t and is_token(t) then + local cmdname = t.cmdname + local simple = simple[cmdname] + if simple then + return { + category = simple, + character = utfchar(t.mode) or nil, + } + else + return { + command = t.command, + id = t.id, + tok = t.tok, + csname = t.csname, + active = t.active, + expandable = t.expandable, + protected = t.protected, + mode = t.mode, + index = t.index, + cmdname = cmdname, + } + end + end + end + + tokens.astable = astable + + setinspector("token",function(v) local t = astable(v) if t then printtable(t,tostring(v)) return true end end) + +end + +tokens.cache = table.setmetatableindex(function(t,k) + local v = create_token(k) + t[k] = v + return v +end) diff --git a/tex/context/base/mkiv/toks-ini.mkiv b/tex/context/base/mkiv/toks-ini.mkiv index 9d3375432..af22d5393 100644 --- a/tex/context/base/mkiv/toks-ini.mkiv +++ b/tex/context/base/mkiv/toks-ini.mkiv @@ -15,11 +15,6 @@ \unprotect -\newtoks\t_get_macro % will go away - \registerctxluafile{toks-ini}{} -\registerctxluafile{toks-scn}{} -\registerctxluafile{cldf-scn}{} -\registerctxluafile{cldf-stp}{} \protect \endinput diff --git a/tex/context/base/mkiv/toks-scn.mkiv b/tex/context/base/mkiv/toks-scn.mkiv new file mode 100644 index 000000000..49edf0c24 --- /dev/null +++ b/tex/context/base/mkiv/toks-scn.mkiv @@ -0,0 +1,22 @@ +%D \module +%D [ file=toks-ini, +%D version=2007.03.03, +%D title=\CONTEXT\ Token Support, +%D subtitle=Initialization, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt Token Support / Scanners} + +\unprotect + +\registerctxluafile{toks-scn}{} +\registerctxluafile{cldf-scn}{} +\registerctxluafile{cldf-stp}{} + +\protect \endinput diff --git a/tex/context/base/mkiv/util-fil.lua b/tex/context/base/mkiv/util-fil.lua index 0e8ed4e57..d568a2e1f 100644 --- a/tex/context/base/mkiv/util-fil.lua +++ b/tex/context/base/mkiv/util-fil.lua @@ -343,3 +343,40 @@ if fio and fio.readcardinal1 then end end + +if fio and fio.readcardinaltable then + + files.readcardinaltable = fio.readcardinaltable + files.readintegertable = fio.readintegertable + +else + + local readcardinal1 = files.readcardinal1 + local readcardinal2 = files.readcardinal2 + local readcardinal3 = files.readcardinal3 + local readcardinal4 = files.readcardinal4 + + function files.readcardinaltable(f,n,b) + local t = { } + if b == 1 then for i=1,n do t[i] = readcardinal1(f) end + elseif b == 2 then for i=1,n do t[i] = readcardinal2(f) end + elseif b == 3 then for i=1,n do t[i] = readcardinal3(f) end + elseif b == 4 then for i=1,n do t[i] = readcardinal4(f) end end + return t + end + + local readinteger1 = files.readinteger1 + local readinteger2 = files.readinteger2 + local readinteger3 = files.readinteger3 + local readinteger4 = files.readinteger4 + + function files.readintegertable(f,n,b) + local t = { } + if b == 1 then for i=1,n do t[i] = readinteger1(f) end + elseif b == 2 then for i=1,n do t[i] = readinteger2(f) end + elseif b == 3 then for i=1,n do t[i] = readinteger3(f) end + elseif b == 4 then for i=1,n do t[i] = readinteger4(f) end end + return t + end + +end diff --git a/tex/context/base/mkiv/util-sac.lua b/tex/context/base/mkiv/util-sac.lua index b509d9a9b..09c3819c5 100644 --- a/tex/context/base/mkiv/util-sac.lua +++ b/tex/context/base/mkiv/util-sac.lua @@ -386,3 +386,40 @@ if sio and sio.readcardinal2 then streams.readinteger = streams.readinteger1 end + +if sio and sio.readcardinaltable then + + streams.readcardinaltable = sio.readcardinaltable + streams.readintegertable = sio.readintegertable + +else + + local readcardinal1 = streams.readcardinal1 + local readcardinal2 = streams.readcardinal2 + local readcardinal3 = streams.readcardinal3 + local readcardinal4 = streams.readcardinal4 + + function streams.readcardinaltable(f,n,b) + local t = { } + if b == 1 then for i=1,n do t[i] = readcardinal1(f) end + elseif b == 2 then for i=1,n do t[i] = readcardinal2(f) end + elseif b == 3 then for i=1,n do t[i] = readcardinal3(f) end + elseif b == 4 then for i=1,n do t[i] = readcardinal4(f) end end + return t + end + + local readinteger1 = streams.readinteger1 + local readinteger2 = streams.readinteger2 + local readinteger3 = streams.readinteger3 + local readinteger4 = streams.readinteger4 + + function streams.readintegertable(f,n,b) + local t = { } + if b == 1 then for i=1,n do t[i] = readinteger1(f) end + elseif b == 2 then for i=1,n do t[i] = readinteger2(f) end + elseif b == 3 then for i=1,n do t[i] = readinteger3(f) end + elseif b == 4 then for i=1,n do t[i] = readinteger4(f) end end + return t + end + +end diff --git a/tex/context/interface/mkii/keys-cs.xml b/tex/context/interface/mkii/keys-cs.xml index 521393c17..7c70baad8 100644 --- a/tex/context/interface/mkii/keys-cs.xml +++ b/tex/context/interface/mkii/keys-cs.xml @@ -859,7 +859,7 @@ <cd:constant name='headseparator' value='headseparator'/> <cd:constant name='headstyle' value='stylhlavicky'/> <cd:constant name='height' value='vyska'/> - <cd:constant name='hfactor' value='vfaktor'/> + <cd:constant name='hfactor' value='hfaktor'/> <cd:constant name='hfil' value='hfil'/> <cd:constant name='hidenumber' value='hidenumber'/> <cd:constant name='hoffset' value='hoffset'/> @@ -1280,6 +1280,7 @@ <cd:constant name='vcompact' value='vcompact'/> <cd:constant name='vector' value='vector'/> <cd:constant name='veroffset' value='offsethlavicky'/> + <cd:constant name='vfactor' value='vfaktor'/> <cd:constant name='vfil' value='vfil'/> <cd:constant name='viewerprefix' value='viewerprefix'/> <cd:constant name='voffset' value='voffset'/> diff --git a/tex/context/interface/mkii/keys-it.xml b/tex/context/interface/mkii/keys-it.xml index da7970619..809790fea 100644 --- a/tex/context/interface/mkii/keys-it.xml +++ b/tex/context/interface/mkii/keys-it.xml @@ -1280,6 +1280,7 @@ <cd:constant name='vcompact' value='vcompact'/> <cd:constant name='vector' value='vector'/> <cd:constant name='veroffset' value='veroffset'/> + <cd:constant name='vfactor' value='vfactor'/> <cd:constant name='vfil' value='vfil'/> <cd:constant name='viewerprefix' value='viewerprefix'/> <cd:constant name='voffset' value='voffset'/> diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf Binary files differindex 77855e8c0..43387f6a1 100644 --- a/tex/context/interface/mkiv/i-context.pdf +++ b/tex/context/interface/mkiv/i-context.pdf diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf Binary files differindex 903c92bb2..1cb15e8b2 100644 --- a/tex/context/interface/mkiv/i-readme.pdf +++ b/tex/context/interface/mkiv/i-readme.pdf diff --git a/tex/context/modules/mkiv/s-fonts-shapes.lua b/tex/context/modules/mkiv/s-fonts-shapes.lua index 2c4cd445f..4fc810a92 100644 --- a/tex/context/modules/mkiv/s-fonts-shapes.lua +++ b/tex/context/modules/mkiv/s-fonts-shapes.lua @@ -58,39 +58,6 @@ function moduledata.fonts.shapes.showlist(specification) -- todo: ranges for k, v in next, characters.data do if chrs[k] then NC() context("0x%05X",k) - NC() char(id,k) -- getvalue(cs) context.char(k) - NC() char(id,v.shcode) - NC() char(id,v.lccode or k) - NC() char(id,v.uccode or k) - NC() special(id,v.specials) - NC() context.tx(v.description) - NC() NR() - end - end - context.stoptabulate() - context.endgroup() -end - -function moduledata.fonts.shapes.showlist(specification) -- todo: ranges - specification = interfaces.checkedspecification(specification) - local id, cs = fonts.definers.internal(specification,"<module:fonts:shapes:font>") - local chrs = fontdata[id].characters - context.begingroup() - context.tt() - context.starttabulate { "|l|c|c|c|c|l|l|" } - context.FL() - NC() context.bold("unicode") - NC() context.bold("glyph") - NC() context.bold("shape") - NC() context.bold("lower") - NC() context.bold("upper") - NC() context.bold("specials") - NC() context.bold("description") - NC() NR() - context.TL() - for k, v in next, characters.data do - if chrs[k] then - NC() context("0x%05X",k) NC() char(id,k) NC() char(id,v.shcode) NC() char(id,v.lccode or k) diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 54e95b3af..f65ca966e 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 05/24/18 15:49:05 +-- merge date : 06/02/18 22:34:21 do -- begin closure to overcome local limits and interference @@ -305,8 +305,8 @@ patterns.propername=(uppercase+lowercase+underscore)*(uppercase+lowercase+unders patterns.somecontent=(anything-newline-space)^1 patterns.beginline=#(1-newline) patterns.longtostring=Cs(whitespace^0/""*((patterns.quoted+nonwhitespace^1+whitespace^1/""*(P(-1)+Cc(" ")))^0)) -local function anywhere(pattern) - return P { P(pattern)+1*V(1) } +function anywhere(pattern) + return (1-P(pattern))^0*P(pattern) end lpeg.anywhere=anywhere function lpeg.instringchecker(p) @@ -2001,8 +2001,9 @@ end function table.reverse(t) if t then local n=#t + local m=n+1 for i=1,floor(n/2) do - local j=n-i+1 + local j=m-i t[i],t[j]=t[j],t[i] end return t @@ -4868,6 +4869,35 @@ if fio and fio.readcardinal1 then skipposition(f,4*(n or 1)) end end +if fio and fio.readcardinaltable then + files.readcardinaltable=fio.readcardinaltable + files.readintegertable=fio.readintegertable +else + local readcardinal1=files.readcardinal1 + local readcardinal2=files.readcardinal2 + local readcardinal3=files.readcardinal3 + local readcardinal4=files.readcardinal4 + function files.readcardinaltable(f,n,b) + local t={} + if b==1 then for i=1,n do t[i]=readcardinal1(f) end + elseif b==2 then for i=1,n do t[i]=readcardinal2(f) end + elseif b==3 then for i=1,n do t[i]=readcardinal3(f) end + elseif b==4 then for i=1,n do t[i]=readcardinal4(f) end end + return t + end + local readinteger1=files.readinteger1 + local readinteger2=files.readinteger2 + local readinteger3=files.readinteger3 + local readinteger4=files.readinteger4 + function files.readintegertable(f,n,b) + local t={} + if b==1 then for i=1,n do t[i]=readinteger1(f) end + elseif b==2 then for i=1,n do t[i]=readinteger2(f) end + elseif b==3 then for i=1,n do t[i]=readinteger3(f) end + elseif b==4 then for i=1,n do t[i]=readinteger4(f) end end + return t + end +end end -- closure @@ -11325,9 +11355,14 @@ local read2dot14=streamreader.read2dot14 local readfword=readshort local readufword=readushort local readoffset=readushort +local readcardinaltable=streamreader.readcardinaltable +local readintegertable=streamreader.readintegertable function streamreader.readtag(f) return lower(stripstring(readstring(f,4))) end +local short=2 +local ushort=2 +local ulong=4 directives.register("fonts.streamreader",function() streamreader=utilities.streams openfile=streamreader.open @@ -11347,6 +11382,8 @@ directives.register("fonts.streamreader",function() readfword=readshort readufword=readushort readoffset=readushort + readcardinaltable=streamreader.readcardinaltable + readintegertable=streamreader.readintegertable function streamreader.readtag(f) return lower(stripstring(readstring(f,4))) end @@ -12049,32 +12086,17 @@ formatreaders[4]=function(f,fontdata,offset) local language=readushort(f) local nofsegments=readushort(f)/2 skipshort(f,3) - local endchars={} - local startchars={} - local deltas={} - local offsets={} - local indices={} local mapping=fontdata.mapping local glyphs=fontdata.glyphs local duplicates=fontdata.duplicates local nofdone=0 - for i=1,nofsegments do - endchars[i]=readushort(f) - end + local endchars=readcardinaltable(f,nofsegments,ushort) local reserved=readushort(f) - for i=1,nofsegments do - startchars[i]=readushort(f) - end - for i=1,nofsegments do - deltas[i]=readshort(f) - end - for i=1,nofsegments do - offsets[i]=readushort(f) - end + local startchars=readcardinaltable(f,nofsegments,ushort) + local deltas=readcardinaltable(f,nofsegments,ushort) + local offsets=readcardinaltable(f,nofsegments,ushort) local size=(length-2*2-5*2-4*2*nofsegments)/2 - for i=1,size-1 do - indices[i]=readushort(f) - end + local indices=readcardinaltable(f,size-1,ushort) for segment=1,nofsegments do local startchar=startchars[segment] local endchar=endchars[segment] @@ -12816,12 +12838,9 @@ local function loadfontdata(specification) fontdata=readdata(f,0,specification) elseif version=="ttcf" then local subfont=tonumber(specification.subfont) - local offsets={} local ttcversion=readulong(f) local nofsubfonts=readulong(f) - for i=1,nofsubfonts do - offsets[i]=readulong(f) - end + local offsets=readcardinaltable(f,nofsubfonts,ulong) if subfont then if subfont>=1 and subfont<=nofsubfonts then fontdata=readdata(f,offsets[subfont],specification) @@ -14957,6 +14976,8 @@ local readchar=streamreader.readinteger1 local readshort=streamreader.readinteger2 local read2dot14=streamreader.read2dot14 local readinteger=streamreader.readinteger1 +local readcardinaltable=streamreader.readcardinaltable +local readintegertable=streamreader.readintegertable directives.register("fonts.streamreader",function() streamreader=utilities.streams setposition=streamreader.setposition @@ -14969,7 +14990,12 @@ directives.register("fonts.streamreader",function() readshort=streamreader.readinteger2 read2dot14=streamreader.read2dot14 readinteger=streamreader.readinteger1 + readcardinaltable=streamreader.readcardinaltable + readintegertable=streamreader.readintegertable end) +local short=2 +local ushort=2 +local ulong=4 local helpers=readers.helpers local gotodatatable=helpers.gotodatatable local function mergecomposites(glyphs,shapes) @@ -15531,12 +15557,9 @@ local function repackpoints(glyphs,shapes) end local function readglyph(f,nofcontours) local points={} - local contours={} local instructions={} local flags={} - for i=1,nofcontours do - contours[i]=readshort(f)+1 - end + local contours=readintegertable(f,nofcontours,short) local nofpoints=contours[nofcontours] local nofinstructions=readushort(f) skipbytes(f,nofinstructions) @@ -16063,9 +16086,14 @@ local readfixed=streamreader.readfixed4 local read2dot14=streamreader.read2dot14 local skipshort=streamreader.skipshort local skipbytes=streamreader.skip -local readfword=readshort local readbytetable=streamreader.readbytetable local readbyte=streamreader.readbyte +local readcardinaltable=streamreader.readcardinaltable +local readintegertable=streamreader.readintegertable +local readfword=readshort +local short=2 +local ushort=2 +local ulong=4 directives.register("fonts.streamreader",function() streamreader=utilities.streams setposition=streamreader.setposition @@ -16081,9 +16109,11 @@ directives.register("fonts.streamreader",function() read2dot14=streamreader.read2dot14 skipshort=streamreader.skipshort skipbytes=streamreader.skip - readfword=readshort readbytetable=streamreader.readbytetable readbyte=streamreader.readbyte + readcardinaltable=streamreader.readcardinaltable + readintegertable=streamreader.readintegertable + readfword=readshort end) local gsubhandlers={} local gposhandlers={} @@ -16351,10 +16381,7 @@ local function readvariationdata(f,storeoffset,factors) local format=readushort(f) local regionoffset=storeoffset+readulong(f) local nofdeltadata=readushort(f) - local deltadata={} - for i=1,nofdeltadata do - deltadata[i]=readulong(f) - end + local deltadata=readcardinaltable(f,nofdeltadata,ulong) setposition(f,regionoffset) local nofaxis=readushort(f) local nofregions=readushort(f) @@ -16382,10 +16409,7 @@ local function readvariationdata(f,storeoffset,factors) usedregions[i]=regions[readushort(f)+1] end for i=1,nofdeltasets do - local t={} - for i=1,nofshorts do - t[i]=readshort(f) - end + local t=readintegertable(f,nofshorts,short) for i=nofshorts+1,nofregions do t[i]=readinteger(f) end @@ -16405,20 +16429,30 @@ helpers.readvariationdata=readvariationdata local function readcoverage(f,offset,simple) setposition(f,offset) local coverageformat=readushort(f) - local coverage={} if coverageformat==1 then local nofcoverage=readushort(f) if simple then - for i=1,nofcoverage do - coverage[i]=readushort(f) + if nofcoverage==1 then + return { readushort(f) } + elseif nofcoverage==2 then + return { readushort(f),readushort(f) } + else + return readcardinaltable(f,nofcoverage,ushort) end + elseif nofcoverage==1 then + return { [readushort(f)]=0 } + elseif nofcoverage==2 then + return { [readushort(f)]=0,[readushort(f)]=1 } else + local coverage={} for i=0,nofcoverage-1 do coverage[readushort(f)]=i end + return coverage end elseif coverageformat==2 then local nofranges=readushort(f) + local coverage={} local n=simple and 1 or 0 for i=1,nofranges do local firstindex=readushort(f) @@ -16436,10 +16470,11 @@ local function readcoverage(f,offset,simple) end end end + return coverage else report("unknown coverage format %a ",coverageformat) + return {} end - return coverage end local function readclassdef(f,offset,preset) setposition(f,offset) @@ -16645,23 +16680,15 @@ local function readfirst(f,offset) end return { readushort(f) } end -local function readarray(f,offset,first) +function readarray(f,offset) if offset then setposition(f,offset) end local n=readushort(f) - if first then - local t={ first } - for i=2,n do - t[i]=readushort(f) - end - return t,n + if n==1 then + return { readushort(f) },1 elseif n>0 then - local t={} - for i=1,n do - t[i]=readushort(f) - end - return t,n + return readcardinaltable(f,n,ushort),n end end local function readcoveragearray(f,offset,t,simple) @@ -17014,10 +17041,7 @@ function gsubhandlers.single(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofg elseif subtype==2 then local coverage=readushort(f) local nofreplacements=readushort(f) - local replacements={} - for i=1,nofreplacements do - replacements[i]=readushort(f) - end + local replacements=readcardinaltable(f,nofreplacements,ushort) local coverage=readcoverage(f,tableoffset+coverage) for index,newindex in next,coverage do newindex=newindex+1 @@ -17042,18 +17066,10 @@ local function sethandler(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyp if subtype==1 then local coverage=readushort(f) local nofsequence=readushort(f) - local sequences={} - for i=1,nofsequence do - sequences[i]=readushort(f) - end + local sequences=readcardinaltable(f,nofsequence,ushort) for i=1,nofsequence do setposition(f,tableoffset+sequences[i]) - local n=readushort(f) - local s={} - for i=1,n do - s[i]=readushort(f) - end - sequences[i]=s + sequences[i]=readcardinaltable(f,readushort(f),ushort) end local coverage=readcoverage(f,tableoffset+coverage) for index,newindex in next,coverage do @@ -17085,19 +17101,20 @@ function gsubhandlers.ligature(f,fontdata,lookupid,lookupoffset,offset,glyphs,no if subtype==1 then local coverage=readushort(f) local nofsets=readushort(f) - local ligatures={} - for i=1,nofsets do - ligatures[i]=readushort(f) - end + local ligatures=readcardinaltable(f,nofsets,ushort) for i=1,nofsets do local offset=lookupoffset+offset+ligatures[i] setposition(f,offset) local n=readushort(f) - local l={} - for i=1,n do - l[i]=offset+readushort(f) + if n==1 then + ligatures[i]={ offset+readushort(f) } + else + local l={} + for i=1,n do + l[i]=offset+readushort(f) + end + ligatures[i]=l end - ligatures[i]=l end local coverage=readcoverage(f,tableoffset+coverage) for index,newindex in next,coverage do @@ -17674,10 +17691,10 @@ do local parameters=readushort(f) local noflookups=readushort(f) if noflookups>0 then - local lookups={} + local lookups=readcardinaltable(f,noflookups,ushort) feature.lookups=lookups for j=1,noflookups do - lookups[j]=readushort(f)+1 + lookups[j]=lookups[j]+1 end end if parameters>0 then @@ -17692,11 +17709,8 @@ do end local function readlookups(f,lookupoffset,lookuptypes,featurehash,featureorder) setposition(f,lookupoffset) - local lookups={} local noflookups=readushort(f) - for i=1,noflookups do - lookups[i]=readushort(f) - end + local lookups=readcardinaltable(f,noflookups,ushort) for lookupid=1,noflookups do local offset=lookups[lookupid] setposition(f,lookupoffset+offset) @@ -17989,11 +18003,12 @@ do record.condition=nil record.matchtype="always" else - setposition(f,variationsoffset+offset) + local offset=variationsoffset+offset + setposition(f,offset) local nofconditions=readushort(f) local conditions={} for i=1,nofconditions do - conditions[i]=variationsoffset+offset+readulong(f) + conditions[i]=offset+readulong(f) end record.conditions=conditions record.matchtype="condition" @@ -18035,10 +18050,7 @@ do setposition(f,tableoffset) local parameters=readulong(f) local noflookups=readushort(f) - local lookups={} - for i=1,noflookups do - lookups[i]=readushort(f) - end + local lookups=readcardinaltable(f,noflookups,ushort) record.substitutions=lookups end end @@ -18242,10 +18254,7 @@ function readers.gdef(f,fontdata,specification) local format=readushort(f) if format==1 then local nofsets=readushort(f) - local sets={} - for i=1,nofsets do - sets[i]=readulong(f) - end + local sets=readcardinal(f,nofsets,ulong) for i=1,nofsets do local offset=sets[i] if offset~=0 then @@ -18467,14 +18476,8 @@ local function readmathvariants(f,fontdata,offset) local hcoverage=readushort(f) local vnofglyphs=readushort(f) local hnofglyphs=readushort(f) - local vconstruction={} - local hconstruction={} - for i=1,vnofglyphs do - vconstruction[i]=readushort(f) - end - for i=1,hnofglyphs do - hconstruction[i]=readushort(f) - end + local vconstruction=readcardinaltable(f,vnofglyphs,ushort) + local hconstruction=readcardinaltable(f,hnofglyphs,ushort) fontdata.mathconstants.MinConnectorOverlap=minoverlap local function get(offset,coverage,nofglyphs,construction,kvariants,kparts,kitalic) if coverage~=0 and nofglyphs>0 then @@ -18625,10 +18628,7 @@ function readers.cpal(f,fontdata,specification) local nofcolorrecords=readushort(f) local firstcoloroffset=readulong(f) local colorrecords={} - local palettes={} - for i=1,nofpalettes do - palettes[i]=readushort(f) - end + local palettes=readcardinaltable(f,nofpalettes,ushort) if version==1 then local palettettypesoffset=readulong(f) local palettelabelsoffset=readulong(f) |