diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/font-fbk.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/font-fbk.lua | 272 |
1 files changed, 126 insertions, 146 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/font-fbk.lua b/Master/texmf-dist/tex/context/base/mkiv/font-fbk.lua index 122e43ddc71..79ebc3f2557 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/font-fbk.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/font-fbk.lua @@ -14,38 +14,38 @@ local next = next <p>This is very experimental code!</p> --ldx]]-- -local trace_visualize = false trackers.register("fonts.composing.visualize", function(v) trace_visualize = v end) -local trace_define = false trackers.register("fonts.composing.define", function(v) trace_define = v end) +local trace_combining_visualize = false trackers.register("fonts.composing.visualize", function(v) trace_combining_visualize = v end) +local trace_combining_define = false trackers.register("fonts.composing.define", function(v) trace_combining_define = v end) -local report = logs.reporter("fonts","combining") +trackers.register("fonts.combining", "fonts.composing.define") -- for old times sake (and manuals) +trackers.register("fonts.combining.all", "fonts.composing.*") -- for old times sake (and manuals) + +local report_combining = logs.reporter("fonts","combining") + +local force_combining = false -- just for demo purposes (see mk) local allocate = utilities.storage.allocate local fonts = fonts local handlers = fonts.handlers local constructors = fonts.constructors -local helpers = fonts.helpers local otf = handlers.otf local afm = handlers.afm local registerotffeature = otf.features.register local registerafmfeature = afm.features.register -local addotffeature = otf.addfeature - local unicodecharacters = characters.data local unicodefallbacks = characters.fallbacks -local vfcommands = helpers.commands -local charcommand = vfcommands.char -local rightcommand = vfcommands.right -local downcommand = vfcommands.down -local upcommand = vfcommands.up -local push = vfcommands.push -local pop = vfcommands.pop +local vf = handlers.vf +local commands = vf.combiner.commands +local push = vf.predefined.push +local pop = vf.predefined.pop -local force_combining = false -- just for demo purposes (see mk) -local fraction = 0.15 -- 30 units for lucida +local force_composed = false +local cache = { } -- we could make these weak +local fraction = 0.15 -- 30 units for lucida -- todo: we also need to update the feature hashes ... i'll do that when i'm in the mood -- and/or when i need it @@ -65,15 +65,15 @@ local function composecharacters(tfmdata) local italicfactor = parameters.italicfactor or 0 local vfspecials = backends.tables.vfspecials --brr local red, green, blue, black - if trace_visualize then + if trace_combining_visualize then red = vfspecials.startcolor("red") green = vfspecials.startcolor("green") blue = vfspecials.startcolor("blue") black = vfspecials.stopcolor end local compose = fonts.goodies.getcompositions(tfmdata) - if compose and trace_visualize then - report("using compose information from goodies file") + if compose and trace_combining_visualize then + report_combining("using compose information from goodies file") end local done = false for i, c in next, unicodecharacters do -- loop over all characters ... not that efficient but a specials hash takes memory @@ -105,25 +105,31 @@ local function composecharacters(tfmdata) acc = unicodefallbacks[acc] charsacc = acc and characters[acc] end - local chr_t = charcommand[chr] + local chr_t = cache[chr] + if not chr_t then + -- chr_t = { "slot", 1, chr } + -- chr_t = { "slot", 0, chr } + chr_t = { "char", chr } + cache[chr] = chr_t + end if charsacc then - if trace_define then - report("composed %C, base %C, accent %C",i,chr,acc) + if trace_combining_define then + report_combining("composed %C, base %C, accent %C",i,chr,acc) + end + local acc_t = cache[acc] + if not acc_t then + -- acc_t = { "slot", 1, acc } + -- acc_t = { "slot", 0, acc } + acc_t = { "char", acc } + cache[acc] = acc_t end - local acc_t = charcommand[acc] local cb = descriptions[chr].boundingbox local ab = descriptions[acc].boundingbox -- todo: adapt height if cb and ab then - local c_llx = scale*cb[1] - local c_lly = scale*cb[2] - local c_urx = scale*cb[3] - local c_ury = scale*cb[4] - local a_llx = scale*ab[1] - local a_lly = scale*ab[2] - local a_urx = scale*ab[3] - local a_ury = scale*ab[4] - local done = false + local c_llx, c_lly, c_urx, c_ury = scale*cb[1], scale*cb[2], scale*cb[3], scale*cb[4] + local a_llx, a_lly, a_urx, a_ury = scale*ab[1], scale*ab[2], scale*ab[3], scale*ab[4] + local done = false if compose then local i_compose = compose[i] local i_anchored = i_compose and i_compose.anchored @@ -142,30 +148,26 @@ local function composecharacters(tfmdata) local ay = a_anchor.y or 0 local dx = cx - ax local dy = cy - ay - if trace_define then - report("building %C from %C and %C",i,chr,acc) - report(" boundingbox:") - report(" chr: %3i %3i %3i %3i",unpack(cb)) - report(" acc: %3i %3i %3i %3i",unpack(ab)) - report(" anchors:") - report(" chr: %3i %3i",cx,cy) - report(" acc: %3i %3i",ax,ay) - report(" delta:") - report(" %s: %3i %3i",i_anchored,dx,dy) + if trace_combining_define then + report_combining("building %C from %C and %C",i,chr,acc) + report_combining(" boundingbox:") + report_combining(" chr: %3i %3i %3i %3i",unpack(cb)) + report_combining(" acc: %3i %3i %3i %3i",unpack(ab)) + report_combining(" anchors:") + report_combining(" chr: %3i %3i",cx,cy) + report_combining(" acc: %3i %3i",ax,ay) + report_combining(" delta:") + report_combining(" %s: %3i %3i",i_anchored,dx,dy) end - local right = rightcommand[scale*dx] - local down = upcommand[scale*dy] - if trace_visualize then - t.commands = { - push, right, down, - green, acc_t, black, - pop, chr_t, - } + if trace_combining_visualize then + t.commands = { push, {"right", scale*dx}, {"down",-scale*dy}, green, acc_t, black, pop, chr_t } + -- t.commands = { + -- push, {"right", scale*cx}, {"down", -scale*cy}, red, {"rule",10000,10000,10000}, pop, + -- push, {"right", scale*ax}, {"down", -scale*ay}, blue, {"rule",10000,10000,10000}, pop, + -- push, {"right", scale*dx}, {"down", -scale*dy}, green, acc_t, black, pop, chr_t + -- } else - t.commands = { - push, right, down, - acc_t, pop, chr_t, - } + t.commands = { push, {"right", scale*dx}, {"down",-scale*dy}, acc_t, pop, chr_t } end done = true end @@ -177,17 +179,10 @@ local function composecharacters(tfmdata) local dx = (c_urx - a_urx - a_llx + c_llx)/2 local dd = (c_urx - c_llx)*italicfactor if a_ury < 0 then - local right = rightcommand[dx-dd] - if trace_visualize then - t.commands = { - push, right, red, acc_t, - black, pop, chr_t, - } + if trace_combining_visualize then + t.commands = { push, {"right", dx-dd}, red, acc_t, black, pop, chr_t } else - t.commands = { - push, right, acc_t, pop, - chr_t, - } + t.commands = { push, {"right", dx-dd}, acc_t, pop, chr_t } end elseif c_ury > a_lly then -- messy test local dy @@ -219,46 +214,27 @@ local function composecharacters(tfmdata) else dy = - deltaxheight + extraxheight end - local right = rightcommand[dx+dd] - local down = downcommand[dy] - if trace_visualize then - t.commands = { - push, right, down, green, - acc_t, black, pop, chr_t, - } + if trace_combining_visualize then + t.commands = { push, { "right", dx+dd }, { "down", dy }, green, acc_t, black, pop, chr_t } else - t.commands = { - push, right, down, acc_t, - pop, chr_t, - } + t.commands = { push, { "right", dx+dd }, { "down", dy }, acc_t, pop, chr_t } end else - local right = rightcommand[dx+dd] - if trace_visualize then - t.commands = { - push, right, blue, acc_t, - black, pop, chr_t, - } + if trace_combining_visualize then + t.commands = { push, { "right", dx+dd }, blue, acc_t, black, pop, chr_t } else - t.commands = { - push, right, acc_t, pop, - chr_t, - } + t.commands = { push, { "right", dx+dd }, acc_t, pop, chr_t } end end end else - t.commands = { - chr_t, -- else index mess - } + t.commands = { chr_t } -- else index mess end else - if trace_define then - report("%C becomes simplified %C",i,chr) + if trace_combining_define then + report_combining("%C becomes simplified %C",i,chr) end - t.commands = { - chr_t, -- else index mess - } + t.commands = { chr_t } -- else index mess end done = true characters[i] = t @@ -278,7 +254,7 @@ local function composecharacters(tfmdata) end end -local specification = { +local compose_specification = { name = "compose", description = "additional composed characters", manipulators = { @@ -287,71 +263,75 @@ local specification = { } } -registerotffeature(specification) -registerafmfeature(specification) +registerotffeature(compose_specification) +registerafmfeature(compose_specification) -addotffeature { - name = "char-ligatures", - type = "ligature", - data = characters.splits.char, - order = { "char-ligatures" }, - prepend = true, -} +vf.helpers.composecharacters = composecharacters -addotffeature { - name = "compat-ligatures", - type = "ligature", - data = characters.splits.compat, - order = { "compat-ligatures" }, - prepend = true, -} +-- This installs the builder into the regular virtual font builder, +-- which only makes sense as demo. -registerotffeature { - name = 'char-ligatures', - description = 'unicode char specials to ligatures', -} +commands["compose.trace.enable"] = function() + trace_combining_visualize = true +end -registerotffeature { - name = 'compat-ligatures', - description = 'unicode compat specials to ligatures', -} +commands["compose.trace.disable"] = function() + trace_combining_visualize = false +end -do +commands["compose.force.enable"] = function() + force_combining = true +end - -- This installs the builder into the regular virtual font builder, - -- which only makes sense as demo. +commands["compose.force.disable"] = function() + force_combining = false +end - local vf = handlers.vf - local commands = vf.combiner.commands +commands["compose.trace.set"] = function(g,v) + if v[2] == nil then + trace_combining_visualize = true + else + trace_combining_visualize = v[2] + end +end - vf.helpers.composecharacters = composecharacters +commands["compose.apply"] = function(g,v) + composecharacters(g) +end - commands["compose.trace.enable"] = function() - trace_visualize = true - end +-- vf builder - commands["compose.trace.disable"] = function() - trace_visualize = false - end +-- { "pdf", "origin", "q " .. s .. " 0 0 " .. s .. " 0 0 cm" }, +-- { "pdf", "origin", "q 1 0 0 1 " .. -w .. " " .. -h .. " cm" }, +-- { "pdf", "origin", "/Fm\XX\space Do" }, +-- { "pdf", "origin", "Q" }, +-- { "pdf", "origin", "Q" }, - commands["compose.force.enable"] = function() - force_combining = true - end +-- new and experimental - commands["compose.force.disable"] = function() - force_combining = false - end +local everywhere = { ["*"] = { ["*"] = true } } -- or: { ["*"] = { "*" } } +local noflags = { } - commands["compose.trace.set"] = function(g,v) - if v[2] == nil then - trace_visualize = true - else - trace_visualize = v[2] - end - end +local char_specification = { + type = "ligature", + features = everywhere, + data = characters.splits.char, + order = { "char-ligatures" }, + flags = noflags, + prepend = true, +} - commands["compose.apply"] = function(g,v) - composecharacters(g) - end +local compat_specification = { + type = "ligature", + features = everywhere, + data = characters.splits.compat, + order = { "compat-ligatures" }, + flags = noflags, + prepend = true, +} -end +otf.addfeature("char-ligatures", char_specification) -- xlig (extra) +otf.addfeature("compat-ligatures",compat_specification) -- plig (pseudo) + +registerotffeature { name = 'char-ligatures', description = 'unicode char specials to ligatures' } +registerotffeature { name = 'compat-ligatures', description = 'unicode compat specials to ligatures' } |