diff options
Diffstat (limited to 'tex/context/base/font-fbk.lua')
-rw-r--r-- | tex/context/base/font-fbk.lua | 139 |
1 files changed, 94 insertions, 45 deletions
diff --git a/tex/context/base/font-fbk.lua b/tex/context/base/font-fbk.lua index 6712fbe88..fc12ea2b1 100644 --- a/tex/context/base/font-fbk.lua +++ b/tex/context/base/font-fbk.lua @@ -10,11 +10,13 @@ local cos, tan, rad, format = math.cos, math.tan, math.rad, string.format local utfbyte, utfchar = utf.byte, utf.char local trace_combining = false trackers.register("fonts.combining", function(v) trace_combining = v end) -local trace_combining_all = false trackers.register("fonts.combining.all", function(v) trace_combining_all = v end) +local trace_combining_all = false trackers.register("fonts.combining.all", function(v) trace_combining = v + trace_combining_all = v end) local force_combining = false -- just for demo purposes (see mk) -trackers.register("fonts.composing", "fonts.combining") +trackers.register("fonts.composing", "fonts.combining") +trackers.register("fonts.composing.all", "fonts.combining.all") local report_combining = logs.reporter("fonts","combining") @@ -71,7 +73,7 @@ local function composecharacters(tfmdata) 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 + for i, c in next, unicodecharacters do -- loop over all characters ... not that efficient but a specials hash takes memory if force_combining or not characters[i] then local s = c.specials if s and s[1] == 'char' then @@ -118,57 +120,104 @@ local function composecharacters(tfmdata) local ab = descriptions[acc].boundingbox -- todo: adapt height if cb and ab then - -- can be sped up for scale == 1 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 dx = (c_urx - a_urx - a_llx + c_llx)/2 - local dd = (c_urx - c_llx)*italicfactor - if a_ury < 0 then - if trace_combining then - t.commands = { push, {"right", dx-dd}, red, acc_t, black, pop, chr_t } - else - t.commands = { push, {"right", dx-dd}, acc_t, pop, chr_t } - end - elseif c_ury > a_lly then -- messy test - local dy - if compose then - -- experimental: we could use sx but all that testing - -- takes time and code - dy = compose[i] - if dy then - dy = dy.DY +local done = false +if compose then + local i_compose = compose[i] + local i_anchored = i_compose and i_compose.anchored + if i_anchored then + local c_compose = compose[chr] + local a_compose = compose[acc] + local c_anchors = c_compose and c_compose.anchors + local a_anchors = a_compose and a_compose.anchors + if c_anchors and a_anchors then + local c_anchor = c_anchors[i_anchored] + local a_anchor = a_anchors[i_anchored] + if c_anchor and a_anchor then + local cx = c_anchor.x or 0 + local cy = c_anchor.y or 0 + local ax = a_anchor.x or 0 + local ay = a_anchor.y or 0 + local dx = cx - ax + local dy = cy - ay + if trace_combining_all then + report_combining("building U+%05X (%s) from U+%05X (%s) and U+%05X (%s)",i,utfchar(i),chr,utfchar(chr),acc,utfchar(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 + if trace_combining 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", scale*dx}, {"down",-scale*dy}, acc_t, pop, chr_t } + end + done = true + end + end + end +end + if not done then + -- can be sped up for scale == 1 + local dx = (c_urx - a_urx - a_llx + c_llx)/2 + local dd = (c_urx - c_llx)*italicfactor + if a_ury < 0 then + if trace_combining then + t.commands = { push, {"right", dx-dd}, red, acc_t, black, pop, chr_t } + else + t.commands = { push, {"right", dx-dd}, acc_t, pop, chr_t } end - if not dy then - dy = compose[acc] + elseif c_ury > a_lly then -- messy test + local dy + if compose then + -- experimental: we could use sx but all that testing + -- takes time and code + dy = compose[i] if dy then - dy = dy and dy.DY + dy = dy.DY end - end - if not dy then - dy = compose.DY - end - if not dy then + if not dy then + dy = compose[acc] + if dy then + dy = dy and dy.DY + end + end + if not dy then + dy = compose.DY + end + if not dy then + dy = - deltaxheight + extraxheight + elseif dy > -1.5 and dy < 1.5 then + -- we assume a fraction of (percentage) + dy = - dy * deltaxheight + else + -- we assume fontunits (value smaller than 2 make no sense) + dy = - dy * scale + end + else dy = - deltaxheight + extraxheight - elseif dy > -1.5 and dy < 1.5 then - -- we assume a fraction of (percentage) - dy = - dy * deltaxheight + end + if trace_combining then + t.commands = { push, {"right", dx+dd}, {"down", dy}, green, acc_t, black, pop, chr_t } else - -- we assume fontunits (value smaller than 2 make no sense) - dy = - dy * scale + t.commands = { push, {"right", dx+dd}, {"down", dy}, acc_t, pop, chr_t } end else - dy = - deltaxheight + extraxheight - end - if trace_combining then - t.commands = { push, {"right", dx+dd}, {"down", dy}, green, acc_t, black, pop, chr_t } - else - t.commands = { push, {"right", dx+dd}, {"down", dy}, acc_t, pop, chr_t } - end - else - if trace_combining then - t.commands = { push, {"right", dx+dd}, blue, acc_t, black, pop, chr_t } - else - t.commands = { push, {"right", dx+dd}, acc_t, pop, chr_t } + if trace_combining then + t.commands = { push, {"right", dx+dd}, blue, acc_t, black, pop, chr_t } + else + t.commands = { push, {"right", dx+dd}, acc_t, pop, chr_t } + end end end else |