summaryrefslogtreecommitdiff
path: root/tex/context/base/font-col.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-10-20 01:21:09 +0300
committerMarius <mariausol@gmail.com>2013-10-20 01:21:09 +0300
commitb8ac6d7b7fdb16293c28034c349efd5b0b7b20b3 (patch)
tree0e9051dbe21b4e9cfc72fe594df5b0fe7bc511f3 /tex/context/base/font-col.lua
parent965214d981e6129b782c67adcaf3a81aedcb0bac (diff)
downloadcontext-b8ac6d7b7fdb16293c28034c349efd5b0b7b20b3.tar.gz
beta 2013.10.20 07:09
Diffstat (limited to 'tex/context/base/font-col.lua')
-rw-r--r--tex/context/base/font-col.lua113
1 files changed, 76 insertions, 37 deletions
diff --git a/tex/context/base/font-col.lua b/tex/context/base/font-col.lua
index 20c99c9b4..b15997cba 100644
--- a/tex/context/base/font-col.lua
+++ b/tex/context/base/font-col.lua
@@ -7,6 +7,7 @@ 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
@@ -15,12 +16,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 = node.traverse_id
+local traverse_id = nodes.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")
@@ -43,7 +44,22 @@ local list = { }
local current = 0
local enabled = false
--- maybe also a copy
+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
function collections.reset(name,font)
if font and font ~= "" then
@@ -86,8 +102,22 @@ function collections.define(name,font,ranges,details)
end
end
end
- details.font, details.start, details.stop = font, start, stop
- d[#d+1] = fastcopy(details)
+ 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),
+ }
end
end
end
@@ -102,57 +132,62 @@ 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
- for i=1,#d do
- local f = d[i]
- local id = list[i]
- local start, stop = f.start, f.stop
+ 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
if trace_collecting then
- report_fonts("remapping font %a to %a for range %U - %U",current,id,start,stop)
+ report_fonts("remapping font %a to %a for range %U - %U",current,cloneid,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 i=start,stop do
- if newchars[i] and (force or (not t[i] and not oldchars[i])) 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
if remap then
- t[i] = { id, remap[i] }
+ vector[unic] = { cloneid, remap[unicode] }
else
- t[i] = id
+ vector[unic] = cloneid
end
end
end
else
- for i=start,stop do
- if force or (not t[i] and not oldchars[i]) then
+ for unicode = start, stop do
+ local unic = unicode + offset - start
+ if force or (not vector[unic] and not oldchars[unic]) then
if remap then
- t[i] = { id, remap[i] }
+ vector[unic] = { cloneid, remap[unicode] }
else
- t[i] = id
+ vector[unic] = cloneid
end
end
end
end
end
- vectors[current] = t
if trace_collecting then
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
+ checkenabled()
statistics.stoptiming(fonts)
end
@@ -163,11 +198,14 @@ end
--
-- if lpegmatch(okay,name) then
-function collections.prepare(name)
+function collections.prepare(name) -- we can do this in lua now
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
@@ -213,12 +251,13 @@ 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 %a in font %a to character %a in font %a",n.char,n.font,newchar,newid)
+ report_fonts("remapping character %C in font %a to character %C in font %a",getchar(n),getfont(n),newchar,newid)
end
- n.font, n.char = newid, newchar
+ n.font = newid
+ n.char = newchar
else
if trace_collecting then
- report_fonts("remapping font %a to %a for character %a",n.font,id,n.char)
+ report_fonts("remapping font %a to %a for character %C",getfont(n),id,getchar(n))
end
n.font = id
end