diff options
author | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
commit | 824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch) | |
tree | abfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/font-col.lua | |
parent | 689aefb0727676ed3cddf331337b4be226495e72 (diff) |
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-col.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-col.lua | 128 |
1 files changed, 65 insertions, 63 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-col.lua b/Master/texmf-dist/tex/context/base/font-col.lua index f8add1e4e1d..20c99c9b4a3 100644 --- a/Master/texmf-dist/tex/context/base/font-col.lua +++ b/Master/texmf-dist/tex/context/base/font-col.lua @@ -8,32 +8,40 @@ if not modules then modules = { } end modules ['font-col'] = { -- possible optimization: delayed initialization of vectors -local gmatch, type = string.gmatch, type -local traverse_id = node.traverse_id -local lpegmatch = lpeg.match +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 fastcopy = table.fastcopy -local settings_to_hash = utilities.parsers.settings_to_hash +----- P, Cc, lpegmatch = lpeg.P, lpeg.Cc, lpeg.match -local trace_collecting = false trackers.register("fonts.collecting", function(v) trace_collecting = v end) +local traverse_id = node.traverse_id +local settings_to_hash = utilities.parsers.settings_to_hash -local report_fonts = logs.reporter("fonts","collections") +local trace_collecting = false trackers.register("fonts.collecting", function(v) trace_collecting = v end) -local fonts, context = fonts, context +local report_fonts = logs.reporter("fonts","collections") -fonts.collections = fonts.collections or { } -local collections = fonts.collections +local collections = fonts.collections or { } +fonts.collections = collections -collections.definitions = collections.definitions or { } -local definitions = collections.definitions +local definitions = collections.definitions or { } +collections.definitions = definitions -collections.vectors = collections.vectors or { } -local vectors = collections.vectors +local vectors = collections.vectors or { } +collections.vectors = vectors -local fontdata = fonts.hashes.identifiers +local fontdata = fonts.hashes.identifiers +local glyph_code = nodes.nodecodes.glyph +local currentfont = font.current -local glyph = node.id('glyph') +local fontpatternhassize = fonts.helpers.fontpatternhassize -local list, current, active = { }, 0, false +local list = { } +local current = 0 +local enabled = false -- maybe also a copy @@ -55,17 +63,13 @@ function collections.define(name,font,ranges,details) -- todo: details -> method=force|conditional rscale= -- todo: remap=name local d = definitions[name] - if d then - if name and trace_collecting then - report_fonts("def: extending set %s using %s",name, font) - end - else - if name and trace_collecting then - report_fonts("def: defining set %s using %s",name, font) - end + if not d then d = { } definitions[name] = d end + if name and trace_collecting then + report_fonts("extending collection %a using %a",name,font) + end details = settings_to_hash(details) -- todo, combine per font start/stop as arrays for s in gmatch(ranges,"[^, ]+") do @@ -73,12 +77,12 @@ function collections.define(name,font,ranges,details) if start and stop then if trace_collecting then if description then - report_fonts("def: using range %s (U+%05x-U+%05X, %s)",s,start,stop,description) + report_fonts("using range %a, slots %U - %U, description %a)",s,start,stop,description) end for i=1,#d do local di = d[i] if (start >= di.start and start <= di.stop) or (stop >= di.start and stop <= di.stop) then - report_fonts("def: overlapping ranges U+%05x-U+%05X and U+%05x-U+%05X",start,stop,di.start,di.stop) + report_fonts("overlapping ranges %U - %U and %U - %U",start,stop,di.start,di.stop) end end end @@ -91,9 +95,9 @@ end -- todo: provide a lua variant (like with definefont) function collections.registermain(name) - local last = font.current() + local last = currentfont() if trace_collecting then - report_fonts("def: registering font %s with name %s",last,name) + report_fonts("registering font %a with name %a",last,name) end list[#list+1] = last end @@ -103,14 +107,14 @@ function collections.clonevector(name) local d = definitions[name] local t = { } if trace_collecting then - report_fonts("def: process collection %s",name) + report_fonts("processing collection %a",name) end for i=1,#d do local f = d[i] local id = list[i] local start, stop = f.start, f.stop if trace_collecting then - report_fonts("def: remapping font %s to %s for range U+%05X - U+%05X",current,id,start,stop) + report_fonts("remapping font %a to %a for range %U - %U",current,id,start,stop) end local check = toboolean(f.check or "false",true) local force = toboolean(f.force or "true",true) @@ -143,22 +147,24 @@ function collections.clonevector(name) end vectors[current] = t if trace_collecting then - report_fonts("def: activating collection %s for font %s",name,current) + report_fonts("activating collection %a for font %a",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 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 +-- +-- 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 function collections.prepare(name) - current = font.current() + current = currentfont() if vectors[current] then return end @@ -166,7 +172,7 @@ function collections.prepare(name) if d then if trace_collecting then local filename = file.basename(fontdata[current].properties.filename or "?") - report_fonts("def: applying collection %s to %s (file: %s)",name,current,filename) + report_fonts("applying collection %a to %a, file %a",name,current,filename) end list = { } context.pushcatcodes("prt") -- context.unprotect() @@ -175,7 +181,7 @@ function collections.prepare(name) local f = d[i] local name = f.font local scale = f.rscale or 1 - if lpegmatch(okay,name) then + if fontpatternhassize(name) then context.font_fallbacks_clone_unique(name,scale) else context.font_fallbacks_clone_inherited(name,scale) @@ -187,7 +193,7 @@ function collections.prepare(name) context.popcatcodes() -- context.protect() elseif trace_collecting then local filename = file.basename(fontdata[current].properties.filename or "?") - report_fonts("def: error in applying collection %s to %s (file: %s)",name,current,filename) + report_fonts("error while applying collection %a to %a, file %a",name,current,filename) end end @@ -198,32 +204,28 @@ function collections.report(message) end function collections.process(head) -- this way we keep feature processing - 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 + 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("remapping character %a in font %a to character %a in font %a",n.char,n.font,newchar,newid) + end + n.font, n.char = newid, newchar + else + if trace_collecting then + report_fonts("remapping font %a to %a for character %a",n.font,id,n.char) end + n.font = id end end end - return head, done - else - return head, false end + return head, done end -- interface |