diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/font-nod.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/font-nod.lua | 187 |
1 files changed, 103 insertions, 84 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/font-nod.lua b/Master/texmf-dist/tex/context/base/mkiv/font-nod.lua index a0eb88a252c..2670a924bbf 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/font-nod.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/font-nod.lua @@ -32,10 +32,6 @@ nodes.tasks = tasks local handlers = nodes.handlers or { } nodes.handlers = handlers -local nuts = nodes.nuts -local tonut = nuts.tonut -local tonode = nuts.tonode - local injections = nodes.injections or { } nodes.injections = injections @@ -56,17 +52,23 @@ local kern_code = nodecodes.kern local dir_code = nodecodes.dir local localpar_code = nodecodes.localpar +local nuts = nodes.nuts +local tonut = nuts.tonut +local tonode = nuts.tonode + local getfield = nuts.getfield local getnext = nuts.getnext local getprev = nuts.getprev local getid = nuts.getid local getfont = nuts.getfont local getsubtype = nuts.getsubtype +local getchar = nuts.getchar local getlist = nuts.getlist local getdisc = nuts.getdisc +local getcomponents = nuts.getcomponents local isglyph = nuts.isglyph local getkern = nuts.getkern -local getdirection = nuts.getdirection +local getdir = nuts.getdir local getwidth = nuts.getwidth local setbox = nuts.setbox @@ -76,11 +78,10 @@ local setsubtype = nuts.setsubtype local copy_node_list = nuts.copy_list local hpack_node_list = nuts.hpack local flush_node_list = nuts.flush_list +local traverse_nodes = nuts.traverse +----- traverse_id = nuts.traverse_id local protect_glyphs = nuts.protect_glyphs -local nextnode = nuts.traversers.node -local nextglyph = nuts.traversers.glyph - local nodepool = nuts.pool local new_glyph = nodepool.glyph @@ -97,8 +98,11 @@ local fontparameters = hashes.parameters local properties = nodes.properties.data +-- direct.set_properties_mode(true,false) +-- direct.set_properties_mode(true,true) -- default + local function freeze(h,where) - for n in nextnode, h do -- todo: disc but not traced anyway + for n in traverse_nodes(tonut(h)) do -- todo: disc but not traced anyway local p = properties[n] if p then local i = p.injections if i then p.injections = fastcopy(i) end @@ -111,15 +115,15 @@ local function freeze(h,where) end function char_tracers.collect(head,list,tag,n) + head = tonut(head) n = n or 0 - local ok = false - local fn = nil + local ok, fn = false, nil while head do - local char, id = isglyph(head) - if char then - local font = id - if font ~= fn then - ok, fn = false, font + local c, id = isglyph(head) + if c then + local f = getfont(head) + if f ~= fn then + ok, fn = false, f end if not ok then ok = true @@ -128,23 +132,23 @@ function char_tracers.collect(head,list,tag,n) list[n][tag] = { } end local l = list[n][tag] - -- l[#l+1] = { char, font, i } - l[#l+1] = { char, font } + -- l[#l+1] = { c, f, i } + l[#l+1] = { c, f } elseif id == disc_code then -- skip -- local pre, post, replace = getdisc(head) -- if replace then - -- for n in nextglyph, replace do + -- for n in traverse_id(glyph_code,replace) do -- l[#l+1] = { c, f } -- end -- end -- if pre then - -- for n in nextglyph, pre do + -- for n in traverse_id(glyph_code,pre) do -- l[#l+1] = { c, f } -- end -- end -- if post then - -- for n in nextglyph, post do + -- for n in traverse_id(glyph_code,post) do -- l[#l+1] = { c, f } -- end -- end @@ -160,8 +164,7 @@ function char_tracers.equal(ta, tb) return false else for i=1,#ta do - local a = ta[i] - local b = tb[i] + local a, b = ta[i], tb[i] -- if a[1] ~= b[1] or a[2] ~= b[2] or a[3] ~= b[3] then if a[1] ~= b[1] or a[2] ~= b[2] then return false @@ -218,12 +221,12 @@ function char_tracers.start() function handlers.characters(head) local n = #list char_tracers.collect(head,list,'before',n) - head = npc(head) -- for the moment tonode + local h, d = npc(tonode(head)) -- for the moment tonode char_tracers.collect(head,list,'after',n) if #list > n then list[#list+1] = { } end - return head + return h, d end function char_tracers.stop() tracers.list['characters'] = list @@ -294,44 +297,47 @@ end function step_tracers.features() -- we cannot use first_glyph here as it only finds characters with subtype < 256 local f = collection[1] - for n, char, font in nextglyph, f do - local tfmdata = fontidentifiers[font] - local features = tfmdata.resources.features - local result_1 = { } - local result_2 = { } - local gpos = features and features.gpos or { } - local gsub = features and features.gsub or { } - for feature, value in table.sortedhash(tfmdata.shared.features) do - if feature == "number" or feature == "features" then - value = false - elseif type(value) == "boolean" then - if value then - value = "yes" - else + while f do + if getid(f) == glyph_code then + local tfmdata = fontidentifiers[getfont(f)] + local features = tfmdata.resources.features + local result_1 = { } + local result_2 = { } + local gpos = features and features.gpos or { } + local gsub = features and features.gsub or { } + for feature, value in table.sortedhash(tfmdata.shared.features) do + if feature == "number" or feature == "features" then value = false + elseif type(value) == "boolean" then + if value then + value = "yes" + else + value = false + end + else + -- use value end + if value then + if gpos[feature] or gsub[feature] or feature == "language" or feature == "script" then + result_1[#result_1+1] = formatters["%s=%s"](feature,value) + else + result_2[#result_2+1] = formatters["%s=%s"](feature,value) + end + end + end + if #result_1 > 0 then + context("{\\bf[basic:} %, t{\\bf]} ",result_1) else - -- use value + context("{\\bf[}no basic features{\\bf]} ") end - if value then - if gpos[feature] or gsub[feature] or feature == "language" or feature == "script" then - result_1[#result_1+1] = formatters["%s=%s"](feature,value) - else - result_2[#result_2+1] = formatters["%s=%s"](feature,value) - end + if #result_2 > 0 then + context("{\\bf[extra:} %, t{\\bf]}",result_2) + else + context("{\\bf[}no extra features{\\bf]}") end + return end - if #result_1 > 0 then - context("{\\bf[basic:} %, t{\\bf]} ",result_1) - else - context("{\\bf[}no basic features{\\bf]} ") - end - if #result_2 > 0 then - context("{\\bf[extra:} %, t{\\bf]}",result_2) - else - context("{\\bf[}no extra features{\\bf]}") - end - return + f = getnext(f) end end @@ -343,15 +349,21 @@ end function step_tracers.font(command) local c = collection[1] - for n, char, font in nextglyph, c do - local name = file.basename(fontproperties[font].filename or "unknown") - local size = fontparameters[font].size or 0 - if command then - context[command](font,name,size) -- size in sp + while c do + local id = getid(c) + if id == glyph_code then + local font = getfont(c) + local name = file.basename(fontproperties[font].filename or "unknown") + local size = fontparameters[font].size or 0 + if command then + context[command](font,name,size) -- size in sp + else + context("[%s: %s @ %p]",font,name,size) + end + return else - context("[%s: %s @ %p]",font,name,size) + c = getnext(c) end - return end end @@ -364,7 +376,9 @@ local colors = { function step_tracers.codes(i,command,space) local c = collection[i] - local function showchar(c,f) + local function showchar(c) + local f = getfont(c) + local c = getchar(c) if command then local d = fontdescriptions[f] local d = d and d[c] @@ -378,10 +392,10 @@ function step_tracers.codes(i,command,space) if w then context.startcolor(colors[what]) context("%s:",what) - for c, id in nextnode, w do + for c in traverse_nodes(w) do + local id = getid(c) if id == glyph_code then - local c, f = isglyph(c) - showchar(c,f) + showchar(c) else context("[%s]",nodecodes[id]) end @@ -392,11 +406,11 @@ function step_tracers.codes(i,command,space) end while c do - local char, id = isglyph(c) - if char then - showchar(char,id) - elseif id == dir_code or (id == localpar_code and getsubtype(c) == 0) then - context("[%s]",getdirection(c) or "?") + local id = getid(c) + if id == glyph_code then + showchar(c) + elseif id == dir_code or id == localpar_code then + context("[%s]",getdir(c)) elseif id == disc_code then local pre, post, replace = getdisc(c) if pre or post or replace then @@ -439,12 +453,13 @@ end function step_tracers.check(head) if collecting then step_tracers.reset() - local n = copy_node_list(head) + local h = tonut(head) + local n = copy_node_list(h) freeze(n,"check") - injections.keepcounts() -- one-time + injections.keepcounts(n) -- one-time local l = injections.handler(n,"trace") if l then -- hm, can be false - n = l + n = tonut(l) end protect_glyphs(n) collection[1] = n @@ -455,12 +470,13 @@ function step_tracers.register(head) if collecting then local nc = #collection+1 if messages[nc] then - local n = copy_node_list(head) + local h = tonut(head) + local n = copy_node_list(h) freeze(n,"register") - injections.keepcounts() -- one-time + injections.keepcounts(n) -- one-time local l = injections.handler(n,"trace") if l then -- hm, can be false - n = l + n = tonut(l) end protect_glyphs(n) collection[nc] = n @@ -485,11 +501,14 @@ local threshold = 65536 -- 1pt local function toutf(list,result,nofresult,stopcriterium,nostrip) if list then - for n, id in nextnode, tonut(list) do - if id == glyph_code then - local c, f = isglyph(n) - if c > 0 then - local fc = fontcharacters[f] + for n in traverse_nodes(tonut(list)) do + local c, id = isglyph(n) + if c then + local components = getcomponents(n) + if components then + result, nofresult = toutf(components,result,nofresult,false,true) + elseif c > 0 then + local fc = fontcharacters[getfont(n)] if fc then local fcc = fc[c] if fcc then |