summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/font-col.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-col.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/font-col.lua86
1 files changed, 46 insertions, 40 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-col.lua b/Master/texmf-dist/tex/context/base/font-col.lua
index d313357a2e0..e0d2fed112d 100644
--- a/Master/texmf-dist/tex/context/base/font-col.lua
+++ b/Master/texmf-dist/tex/context/base/font-col.lua
@@ -8,27 +8,29 @@ if not modules then modules = { } end modules ['font-col'] = {
-- possible optimization: delayed initialization of vectors
-local format, gmatch, texsprint, type = string.format, string.gmatch, tex.sprint, type
-local traverse_id, first_character = node.traverse_id, node.first_character
+local gmatch, type = string.gmatch, type
+local traverse_id = node.traverse_id
local lpegmatch = lpeg.match
-
-local ctxcatcodes = tex.ctxcatcodes
+local settings_to_hash = utilities.parsers.settings_to_hash
local trace_collecting = false trackers.register("fonts.collecting", function(v) trace_collecting = v end)
-local fontdata = fonts.ids
+local report_fonts = logs.reporter("fonts","collections")
-local glyph = node.id('glyph')
+local fonts, context = fonts, context
-fonts.normalizers = fonts.normalizers or { }
+fonts.collections = fonts.collections or { }
+local collections = fonts.collections
-fonts.collections = fonts.collections or { }
-fonts.collections.definitions = fonts.collections.definitions or { }
-fonts.collections.vectors = fonts.collections.vectors or { }
+collections.definitions = collections.definitions or { }
+local definitions = collections.definitions
-local collections = fonts.collections
-local definitions = fonts.collections.definitions
-local vectors = fonts.collections.vectors
+collections.vectors = collections.vectors or { }
+local vectors = collections.vectors
+
+local fontdata = fonts.hashes.identifiers
+
+local glyph = node.id('glyph')
local list, current, active = { }, 0, false
@@ -54,28 +56,28 @@ function collections.define(name,font,ranges,details)
local d = definitions[name]
if d then
if name and trace_collecting then
- logs.report("fonts","def: extending set %s using %s",name, font)
+ report_fonts("def: extending set %s using %s",name, font)
end
else
if name and trace_collecting then
- logs.report("fonts","def: defining set %s using %s",name, font)
+ report_fonts("def: defining set %s using %s",name, font)
end
d = { }
definitions[name] = d
end
- details = aux.settings_to_hash(details)
+ details = settings_to_hash(details)
-- todo, combine per font start/stop as arrays
- for s in gmatch(ranges,"([^, ]+)") do
+ for s in gmatch(ranges,"[^, ]+") do
local start, stop, description = characters.getrange(s)
if start and stop then
if trace_collecting then
if description then
- logs.report("fonts","def: using range %s (U+%04x-U+%04X, %s)",s,start,stop,description)
+ report_fonts("def: using range %s (U+%05x-U+%05X, %s)",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
- logs.report("fonts","def: overlapping ranges U+%04x-U+%04X and U+%04x-U+%04X",start,stop,di.start,di.stop)
+ report_fonts("def: overlapping ranges U+%05x-U+%05X and U+%05x-U+%05X",start,stop,di.start,di.stop)
end
end
end
@@ -85,27 +87,27 @@ function collections.define(name,font,ranges,details)
end
end
-function collections.stage_1(name)
+function collections.stage_one(name)
local last = font.current()
if trace_collecting then
- logs.report("fonts","def: registering font %s with name %s",last,name)
+ report_fonts("def: registering font %s with name %s",last,name)
end
list[#list+1] = last
end
-function collections.stage_2(name)
+function collections.stage_two(name)
statistics.starttiming(fonts)
local d = definitions[name]
local t = { }
if trace_collecting then
- logs.report("fonts","def: process collection %s",name)
+ report_fonts("def: process collection %s",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
- logs.report("fonts","def: remapping font %s to %s for range U+%04X - U+%04X",current,id,start,stop)
+ report_fonts("def: remapping font %s to %s for range U+%05X - U+%05X",current,id,start,stop)
end
local check = toboolean(f.check or "false",true)
local force = toboolean(f.force or "true",true)
@@ -138,12 +140,14 @@ function collections.stage_2(name)
end
vectors[current] = t
if trace_collecting then
- logs.report("fonts","def: activating collection %s for font %s",name,current)
+ report_fonts("def: activating collection %s for font %s",name,current)
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)
@@ -158,37 +162,37 @@ function collections.prepare(name)
local d = definitions[name]
if d then
if trace_collecting then
- local filename = file.basename(fontdata[current].filename or "?")
- logs.report("fonts","def: applying collection %s to %s (file: %s)",name,current,filename)
+ local filename = file.basename(fontdata[current].properties.filename or "?")
+ report_fonts("def: applying collection %s to %s (file: %s)",name,current,filename)
end
list = { }
- texsprint(ctxcatcodes,"\\dostartcloningfonts") -- move this to tex \dostart...
+ context.dostartcloningfonts() -- move this to tex \dostart...
for i=1,#d do
local f = d[i]
local name = f.font
local scale = f.rscale or 1
if lpegmatch(okay,name) then
- texsprint(ctxcatcodes,format("\\doclonefonta{%s}{%s}",name,scale)) -- define with unique specs
+ context.doclonefonta(name,scale) -- define with unique specs
else
- texsprint(ctxcatcodes,format("\\doclonefontb{%s}{%s}",name,scale)) -- define with inherited specs
+ context.doclonefontb(name,scale) -- define with inherited specs
end
- texsprint(ctxcatcodes,format("\\ctxlua{fonts.collections.stage_1('%s')}",name)) -- registering main font
+ context.doclonefontstageone(name) -- registering main font
end
- texsprint(ctxcatcodes,format("\\ctxlua{fonts.collections.stage_2('%s')}",name)) -- preparing clone vectors
- texsprint(ctxcatcodes,"\\dostopcloningfonts")
+ context.doclonefontstagetwo(name) -- preparing clone vectors
+ context.dostopcloningfonts()
elseif trace_collecting then
- local filename = file.basename(fontdata[current].filename or "?")
- logs.report("fonts","def: error in applying collection %s to %s (file: %s)",name,current,filename)
+ local filename = file.basename(fontdata[current].properties.filename or "?")
+ report_fonts("def: error in applying collection %s to %s (file: %s)",name,current,filename)
end
end
function collections.message(message)
if trace_collecting then
- logs.report("fonts","tex: %s",message)
+ report_fonts("tex: %s",message)
end
end
-function collections.process(head)
+function collections.process(head) -- this way we keep feature processing
if active then
local done = false
for n in traverse_id(glyph,head) do
@@ -199,18 +203,20 @@ function collections.process(head)
if type(id) == "table" then
local newid, newchar = id[1], id[2]
if trace_collecting then
- logs.report("fonts","lst: remapping character %s in font %s to character %s in font %s",n.char,n.font,newchar,newid)
+ 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
- logs.report("fonts","lst: remapping font %s to %s for character %s",n.font,id,n.char)
+ report_fonts("lst: remapping font %s to %s for character %s",n.font,id,n.char)
end
n.font = id
end
end
end
end
+ return head, done
+ else
+ return head, false
end
- return head, done
end