diff options
Diffstat (limited to 'tex/context/base/font-col.lua')
-rw-r--r-- | tex/context/base/font-col.lua | 96 |
1 files changed, 45 insertions, 51 deletions
diff --git a/tex/context/base/font-col.lua b/tex/context/base/font-col.lua index 4b96cca31..f8add1e4e 100644 --- a/tex/context/base/font-col.lua +++ b/tex/context/base/font-col.lua @@ -8,40 +8,32 @@ if not modules then modules = { } end modules ['font-col'] = { -- possible optimization: delayed initialization of vectors -local context, commands, trackers, logs = context, commands, trackers, logs -local node, nodes, fonts, characters = node, nodes, fonts, characters -local file, lpeg, table, string = file, lpeg, table, string - -local type, next, toboolean = type, next, toboolean -local gmatch = string.gmatch +local gmatch, type = string.gmatch, type +local traverse_id = node.traverse_id +local lpegmatch = lpeg.match local fastcopy = table.fastcopy ------ P, Cc, lpegmatch = lpeg.P, lpeg.Cc, lpeg.match - -local traverse_id = node.traverse_id -local settings_to_hash = utilities.parsers.settings_to_hash +local settings_to_hash = utilities.parsers.settings_to_hash -local trace_collecting = false trackers.register("fonts.collecting", function(v) trace_collecting = v end) +local trace_collecting = false trackers.register("fonts.collecting", function(v) trace_collecting = v end) -local report_fonts = logs.reporter("fonts","collections") +local report_fonts = logs.reporter("fonts","collections") -fonts.collections = fonts.collections or { } -local collections = fonts.collections +local fonts, context = fonts, context -collections.definitions = collections.definitions or { } -local definitions = collections.definitions +fonts.collections = fonts.collections or { } +local collections = fonts.collections -collections.vectors = collections.vectors or { } -local vectors = collections.vectors +collections.definitions = collections.definitions or { } +local definitions = collections.definitions -local fontdata = fonts.hashes.identifiers +collections.vectors = collections.vectors or { } +local vectors = collections.vectors -local glyph_code = nodes.nodecodes.glyph +local fontdata = fonts.hashes.identifiers -local fontpatternhassize = fonts.helpers.fontpatternhassize +local glyph = node.id('glyph') -local list = { } -local current = 0 -local enabled = false +local list, current, active = { }, 0, false -- maybe also a copy @@ -153,19 +145,17 @@ function collections.clonevector(name) if trace_collecting then report_fonts("def: activating collection %s for font %s",name,current) end - if not enabled then - nodes.tasks.enableaction("processors","fonts.collections.process") - enabled = true - end + active = true statistics.stoptiming(fonts) end -- we already have this parser --- --- local spec = (P("sa") + P("at") + P("scaled") + P("at") + P("mo")) * P(" ")^1 * (1-P(" "))^1 * P(" ")^0 * -1 --- local okay = ((1-spec)^1 * spec * Cc(true)) + Cc(false) --- --- if lpegmatch(okay,name) then + +local P, Cc = lpeg.P, lpeg.Cc +local spec = (P("sa") + P("at") + P("scaled") + P("at") + P("mo")) * P(" ")^1 * (1-P(" "))^1 * P(" ")^0 * -1 +local okay = ((1-spec)^1 * spec * Cc(true)) + Cc(false) + +-- todo: check for already done function collections.prepare(name) current = font.current() @@ -185,7 +175,7 @@ function collections.prepare(name) local f = d[i] local name = f.font local scale = f.rscale or 1 - if fontpatternhassize(name) then + if lpegmatch(okay,name) then context.font_fallbacks_clone_unique(name,scale) else context.font_fallbacks_clone_inherited(name,scale) @@ -208,28 +198,32 @@ function collections.report(message) end function collections.process(head) -- this way we keep feature processing - local done = false - for n in traverse_id(glyph_code,head) do - local v = vectors[n.font] - if v then - local id = v[n.char] - if id then - if type(id) == "table" then - local newid, newchar = id[1], id[2] - if trace_collecting then - report_fonts("lst: remapping character %s in font %s to character %s in font %s",n.char,n.font,newchar,newid) - end - n.font, n.char = newid, newchar - else - if trace_collecting then - report_fonts("lst: remapping font %s to %s for character %s",n.font,id,n.char) + if active then + local done = false + for n in traverse_id(glyph,head) do + local v = vectors[n.font] + if v then + local id = v[n.char] + if id then + if type(id) == "table" then + local newid, newchar = id[1], id[2] + if trace_collecting then + report_fonts("lst: remapping character %s in font %s to character %s in font %s",n.char,n.font,newchar,newid) + end + n.font, n.char = newid, newchar + else + if trace_collecting then + report_fonts("lst: remapping font %s to %s for character %s",n.font,id,n.char) + end + n.font = id end - n.font = id end end end + return head, done + else + return head, false end - return head, done end -- interface |