summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/math-act.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-04-27 01:41:25 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-04-27 01:41:25 +0200
commit762562da00d0ec1d50e6d3c2a701156ab42e6d71 (patch)
tree2dc664caa951963a393b0a2a9c9c85d1db6b8e10 /tex/context/base/mkiv/math-act.lua
parentf2a20e191bf71094aa21d37dee2ecd2f804dbc56 (diff)
downloadcontext-762562da00d0ec1d50e6d3c2a701156ab42e6d71.tar.gz
2017-04-27 01:06:00
Diffstat (limited to 'tex/context/base/mkiv/math-act.lua')
-rw-r--r--tex/context/base/mkiv/math-act.lua176
1 files changed, 154 insertions, 22 deletions
diff --git a/tex/context/base/mkiv/math-act.lua b/tex/context/base/mkiv/math-act.lua
index 602c3dc89..ee78b64f0 100644
--- a/tex/context/base/mkiv/math-act.lua
+++ b/tex/context/base/mkiv/math-act.lua
@@ -590,7 +590,134 @@ blocks["uppercasedoublestruck"].gaps = {
-- todo: tounicode
+-- function mathematics.injectfallbacks(target,original)
+-- local properties = original.properties
+-- if properties and properties.hasmath then
+-- local specification = target.specification
+-- if specification then
+-- local fallbacks = specification.fallbacks
+-- if fallbacks then
+-- local definitions = fonts.collections.definitions[fallbacks]
+-- if definitions then
+-- if trace_collecting then
+-- report_math("adding fallback characters to font %a",specification.hash)
+-- end
+-- local definedfont = fonts.definers.internal
+-- local copiedglyph = fonts.handlers.vf.math.copy_glyph
+-- local fonts = target.fonts
+-- local size = specification.size -- target.size
+-- local characters = target.characters
+-- if not fonts then
+-- fonts = { }
+-- target.fonts = fonts
+-- target.type = "virtual"
+-- target.properties.virtualized = true
+-- end
+-- if #fonts == 0 then
+-- fonts[1] = { id = 0, size = size } -- sel, will be resolved later
+-- end
+-- local done = { }
+-- for i=1,#definitions do
+-- local definition = definitions[i]
+-- local name = definition.font
+-- local start = definition.start
+-- local stop = definition.stop
+-- local gaps = definition.gaps
+-- local check = definition.check
+-- local force = definition.force
+-- local rscale = definition.rscale or 1
+-- local offset = definition.offset or start
+-- local id = definedfont { name = name, size = size * rscale }
+-- local index = #fonts + 1
+-- fonts[index] = { id = id, size = size }
+-- local chars = fontchars[id]
+-- local function remap(unic,unicode,gap)
+-- local unic = unicode + offset - start
+-- if check and not chars[unicode] then
+-- -- not in font
+-- elseif force or (not done[unic] and not characters[unic]) then
+-- if trace_collecting then
+-- report_math("remapping math character, vector %a, font %a, character %C%s%s",
+-- fallbacks,name,unic,check and ", checked",gap and ", gap plugged")
+-- end
+-- characters[unic] = copiedglyph(target,characters,chars,unicode,index)
+-- done[unic] = true
+-- end
+-- end
+-- for unicode = start, stop do
+-- local unic = unicode + offset - start
+-- remap(unic,unicode,false)
+-- end
+-- if gaps then
+-- for unic, unicode in next, gaps do
+-- remap(unic,unicode,true)
+-- end
+-- end
+-- end
+-- end
+-- end
+-- end
+-- end
+-- end
+
+local stack = { }
+
+function mathematics.registerfallbackid(n,id)
+ local top = stack[#stack]
+ if top then
+ top.list[n] = id
+ else
+ report_math("stack underrun in math fallbacks")
+ end
+end
+
function mathematics.injectfallbacks(target,original)
+ if #stack > 0 then
+ -- for now
+ return
+ end
+ local properties = original.properties
+ if properties and properties.hasmath then
+ local specification = target.specification
+ if specification then
+ local fallbacks = specification.fallbacks
+ if fallbacks then
+ local definitions = fonts.collections.definitions[fallbacks]
+ if definitions then
+ table.insert(stack, {
+ target = target,
+ original = original,
+ list = { },
+ })
+ if trace_collecting then
+ report_math("adding fallback characters to font %a",specification.hash)
+ end
+ local size = specification.size -- target.size
+ context.pushcatcodes("prt") -- context.unprotect()
+ for i=1,#definitions do
+ local definition = definitions[i]
+ local name = definition.font
+ local features = definition.features or ""
+ local size = size * (definition.rscale or 1)
+ context.font_fallbacks_register_math(i,name,features,size)
+ end
+ context.font_fallbacks_finish_math()
+ context.popcatcodes()
+ end
+ end
+ end
+ end
+end
+
+function mathematics.finishfallbacks()
+ local top = table.remove(stack)
+ if not top then
+ report_math("finish error in math fallbacks")
+ return
+ end
+ local target = top.target
+ local original = top.original
+ local list = top.list
local properties = original.properties
if properties and properties.hasmath then
local specification = target.specification
@@ -627,33 +754,38 @@ function mathematics.injectfallbacks(target,original)
local force = definition.force
local rscale = definition.rscale or 1
local offset = definition.offset or start
- local id = definedfont { name = name, size = size * rscale }
- local index = #fonts + 1
- fonts[index] = { id = id, size = size }
- local chars = fontchars[id]
- local function remap(unic,unicode,gap)
- local unic = unicode + offset - start
- if check and not chars[unicode] then
- -- not in font
- elseif force or (not done[unic] and not characters[unic]) then
- if trace_collecting then
- report_math("remapping math character, vector %a, font %a, character %C%s%s",
- fallbacks,name,unic,check and ", checked",gap and ", gap plugged")
+ local id = list[i]
+ if id then
+ local index = #fonts + 1
+ fonts[index] = { id = id, size = size }
+ local chars = fontchars[id]
+ local function remap(unic,unicode,gap)
+ local unic = unicode + offset - start
+ if check and not chars[unicode] then
+ -- not in font
+ elseif force or (not done[unic] and not characters[unic]) then
+ if trace_collecting then
+ report_math("remapping math character, vector %a, font %a, character %C%s%s",
+ fallbacks,name,unic,check and ", checked",gap and ", gap plugged")
+ end
+ characters[unic] = copiedglyph(target,characters,chars,unicode,index)
+ done[unic] = true
end
- characters[unic] = copiedglyph(target,characters,chars,unicode,index)
- done[unic] = true
end
- end
- for unicode = start, stop do
- local unic = unicode + offset - start
- remap(unic,unicode,false)
- end
- if gaps then
- for unic, unicode in next, gaps do
- remap(unic,unicode,true)
+ for unicode = start, stop do
+ local unic = unicode + offset - start
+ remap(unic,unicode,false)
+ end
+ if gaps then
+ for unic, unicode in next, gaps do
+ remap(unic,unicode,true)
+ end
end
end
end
+ xlist = nil
+ xtarget = nil
+ xoriginal = nil
end
end
end