summaryrefslogtreecommitdiff
path: root/tex/context/base/font-col.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/font-col.lua')
-rw-r--r--tex/context/base/font-col.lua113
1 files changed, 37 insertions, 76 deletions
diff --git a/tex/context/base/font-col.lua b/tex/context/base/font-col.lua
index b15997cba..20c99c9b4 100644
--- a/tex/context/base/font-col.lua
+++ b/tex/context/base/font-col.lua
@@ -7,7 +7,6 @@ if not modules then modules = { } end modules ['font-col'] = {
}
-- possible optimization: delayed initialization of vectors
--- we should also share equal vectors (math)
local context, commands, trackers, logs = context, commands, trackers, logs
local node, nodes, fonts, characters = node, nodes, fonts, characters
@@ -16,12 +15,12 @@ local file, lpeg, table, string = file, lpeg, table, string
local type, next, toboolean = type, next, toboolean
local gmatch = string.gmatch
local fastcopy = table.fastcopy
+----- P, Cc, lpegmatch = lpeg.P, lpeg.Cc, lpeg.match
-local traverse_id = nodes.traverse_id
-
+local traverse_id = node.traverse_id
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")
@@ -44,22 +43,7 @@ local list = { }
local current = 0
local enabled = false
-local function checkenabled()
- -- a bit ugly but nicer than a fuzzy state while defining math
- if next(vectors) then
- if not enabled then
- nodes.tasks.enableaction("processors","fonts.collections.process")
- enabled = true
- end
- else
- if enabled then
- nodes.tasks.disableaction("processors","fonts.collections.process")
- enabled = false
- end
- end
-end
-
-collections.checkenabled = checkenabled
+-- maybe also a copy
function collections.reset(name,font)
if font and font ~= "" then
@@ -102,22 +86,8 @@ function collections.define(name,font,ranges,details)
end
end
end
- local offset = details.offset
- if type(offset) == "string" then
- local start = characters.getrange(offset)
- offset = start or false
- else
- offset = tonumber(offset) or false
- end
- d[#d+1] = {
- font = font,
- start = start,
- stop = stop,
- offset = offset,
- rscale = tonumber (details.rscale) or 1,
- force = toboolean(details.force,true),
- check = toboolean(details.check,true),
- }
+ details.font, details.start, details.stop = font, start, stop
+ d[#d+1] = fastcopy(details)
end
end
end
@@ -132,62 +102,57 @@ function collections.registermain(name)
list[#list+1] = last
end
--- check: when true, only set when present in font
--- force: when false, then not set when already set
-
function collections.clonevector(name)
statistics.starttiming(fonts)
+ local d = definitions[name]
+ local t = { }
if trace_collecting then
report_fonts("processing collection %a",name)
end
- local definitions = definitions[name]
- local vector = { }
- vectors[current] = vector
- for i=1,#definitions do
- local definition = definitions[i]
- local name = definition.font
- local start = definition.start
- local stop = definition.stop
- local check = definition.check
- local force = definition.force
- local offset = definition.offset or start
- local remap = definition.remap
- local cloneid = list[i]
- local oldchars = fontdata[current].characters
- local newchars = fontdata[cloneid].characters
+ 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("remapping font %a to %a for range %U - %U",current,cloneid,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)
+ local remap = f.remap or nil
+ -- check: when true, only set when present in font
+ -- force: when false, then not set when already set
+ local oldchars = fontdata[current].characters
+ local newchars = fontdata[id].characters
if check then
- for unicode = start, stop do
- local unic = unicode + offset - start
- if not newchars[unicode] then
- -- not in font
- elseif force or (not vector[unic] and not oldchars[unic]) then
+ for i=start,stop do
+ if newchars[i] and (force or (not t[i] and not oldchars[i])) then
if remap then
- vector[unic] = { cloneid, remap[unicode] }
+ t[i] = { id, remap[i] }
else
- vector[unic] = cloneid
+ t[i] = id
end
end
end
else
- for unicode = start, stop do
- local unic = unicode + offset - start
- if force or (not vector[unic] and not oldchars[unic]) then
+ for i=start,stop do
+ if force or (not t[i] and not oldchars[i]) then
if remap then
- vector[unic] = { cloneid, remap[unicode] }
+ t[i] = { id, remap[i] }
else
- vector[unic] = cloneid
+ t[i] = id
end
end
end
end
end
+ vectors[current] = t
if trace_collecting then
report_fonts("activating collection %a for font %a",name,current)
end
- checkenabled()
+ if not enabled then
+ nodes.tasks.enableaction("processors","fonts.collections.process")
+ enabled = true
+ end
statistics.stoptiming(fonts)
end
@@ -198,14 +163,11 @@ end
--
-- if lpegmatch(okay,name) then
-function collections.prepare(name) -- we can do this in lua now
+function collections.prepare(name)
current = currentfont()
if vectors[current] then
return
end
- if fontdata[current].mathparameters then
- return
- end
local d = definitions[name]
if d then
if trace_collecting then
@@ -251,13 +213,12 @@ function collections.process(head) -- this way we keep feature processing
if type(id) == "table" then
local newid, newchar = id[1], id[2]
if trace_collecting then
- report_fonts("remapping character %C in font %a to character %C in font %a",getchar(n),getfont(n),newchar,newid)
+ report_fonts("remapping character %a in font %a to character %a in font %a",n.char,n.font,newchar,newid)
end
- n.font = newid
- n.char = newchar
+ n.font, n.char = newid, newchar
else
if trace_collecting then
- report_fonts("remapping font %a to %a for character %C",getfont(n),id,getchar(n))
+ report_fonts("remapping font %a to %a for character %a",n.font,id,n.char)
end
n.font = id
end