diff options
Diffstat (limited to 'tex/context/base/mkiv/font-col.lua')
-rw-r--r-- | tex/context/base/mkiv/font-col.lua | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/tex/context/base/mkiv/font-col.lua b/tex/context/base/mkiv/font-col.lua index bce16fae7..8d3152df4 100644 --- a/tex/context/base/mkiv/font-col.lua +++ b/tex/context/base/mkiv/font-col.lua @@ -13,9 +13,10 @@ 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 type, next, tonumber, toboolean = type, next, tonumber, toboolean local gmatch = string.gmatch local fastcopy = table.fastcopy +local formatters = string.formatters local nuts = nodes.nuts local tonut = nuts.tonut @@ -23,7 +24,6 @@ local tonut = nuts.tonut local getfont = nuts.getfont local getchar = nuts.getchar -local setfield = nuts.setfield local setfont = nuts.setfont local traverse_id = nuts.traverse_id @@ -47,9 +47,19 @@ collections.definitions = definitions local vectors = collections.vectors or { } collections.vectors = vectors -local fontdata = fonts.hashes.identifiers -local chardata = fonts.hashes.characters +local fonthashes = fonts.hashes +local fonthelpers = fonts.helpers + +local fontdata = fonthashes.identifiers +local fontquads = fonthashes.quads +local chardata = fonthashes.characters +local propdata = fonthashes.properties + +local addprivate = fonthelpers.addprivate +local hasprivate = fonthelpers.hasprivate + local currentfont = font.current +local addcharacters = font.addcharacters local fontpatternhassize = fonts.helpers.fontpatternhassize @@ -133,6 +143,7 @@ function collections.define(name,font,ranges,details) rscale = tonumber (details.rscale) or 1, force = toboolean(details.force,true), check = toboolean(details.check,true), + factor = tonumber(details.factor), features = details.features, } end @@ -172,6 +183,10 @@ function collections.clonevector(name) local cloneid = list[i] local oldchars = fontdata[current].characters local newchars = fontdata[cloneid].characters + local factor = definition.factor + if factor then + vector.factor = factor + end if trace_collecting then report_fonts("remapping font %a to %a for range %U - %U",current,cloneid,start,stop) end @@ -220,13 +235,15 @@ function collections.prepare(name) -- we can do this in lua now .. todo if vectors[current] then return end - if fontdata[current].mathparameters then + local properties = propdata[current] + local mathsize = properties.mathsize + if mathsize == 1 or mathsize == 2 or mathsize == 3 then return end local d = definitions[name] if d then if trace_collecting then - local filename = file.basename(fontdata[current].properties.filename or "?") + local filename = file.basename(properties.filename or "?") report_fonts("applying collection %a to %a, file %a",name,current,filename) end list = { } @@ -246,9 +263,6 @@ function collections.prepare(name) -- we can do this in lua now .. todo context.font_fallbacks_prepare_clone_vectors(name) context.font_fallbacks_stop_cloning() context.popcatcodes() -- context.protect() - elseif trace_collecting then - local filename = file.basename(fontdata[current].properties.filename or "?") - report_fonts("error while applying collection %a to %a, file %a",name,current,filename) end end @@ -258,6 +272,41 @@ function collections.report(message) end end +local function monoslot(font,char,parent,factor) + local tfmdata = fontdata[font] + local privatename = formatters["faked mono %s"](char) + local privateslot = hasprivate(tfmdata,privatename) + if privateslot then + return privateslot + else + local characters = tfmdata.characters + local properties = tfmdata.properties + local width = factor * fontquads[parent] + local character = characters[char] + if character then + local data = { + width = width, + height = character.height, + depth = character.depth, + commands = { + { "right", (width - character.width or 0)/2 }, + { "slot", 0, char } + } + } + local u = addprivate(tfmdata, privatename, data) + addcharacters(properties.id, { + type = "real", + characters = { + [u] = data + }, + } ) + return u + else + return char + end + end +end + function collections.process(head) -- this way we keep feature processing local done = false for n in traverse_char(tonut(head)) do @@ -279,12 +328,17 @@ function collections.process(head) -- this way we keep feature processing setfont(n,newfont,newchar) done = true else + local fakemono = vector.factor if trace_collecting then report_fonts("remapping font %a to %a for character %C%s", font,vect,char,not chardata[vect][char] and " (missing)" or "" ) end - setfont(n,vect) + if fakemono then + setfont(n,vect,monoslot(vect,char,font,fakemono)) + else + setfont(n,vect) + end done = true end end |