summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/font-fbk.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-fbk.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/font-fbk.lua260
1 files changed, 170 insertions, 90 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-fbk.lua b/Master/texmf-dist/tex/context/base/font-fbk.lua
index 0d1ae6218eb..6c4f78a3c54 100644
--- a/Master/texmf-dist/tex/context/base/font-fbk.lua
+++ b/Master/texmf-dist/tex/context/base/font-fbk.lua
@@ -6,72 +6,77 @@ if not modules then modules = { } end modules ['font-fbk'] = {
license = "see context related readme files"
}
+local cos, tan, rad, format = math.cos, math.tan, math.rad, string.format
+
+local trace_combining = false trackers.register("fonts.combining", function(v) trace_combining = v end)
+
--[[ldx--
<p>This is very experimental code!</p>
--ldx]]--
-fonts = fonts or { }
-fonts.fallbacks = fonts.fallbacks or { }
-fonts.vf.aux.combine.trace = false
+fonts.fallbacks = fonts.fallbacks or { }
-fonts.vf.aux.combine.commands["enable-tracing"] = function(g,v)
- fonts.vf.aux.combine.trace = true
+local vf = fonts.vf
+local tfm = fonts.tfm
+
+vf.aux.combine.commands["enable-tracing"] = function(g,v)
+ trace_combining = true
end
-fonts.vf.aux.combine.commands["disable-tracing"] = function(g,v)
- fonts.vf.aux.combine.trace = false
+vf.aux.combine.commands["disable-tracing"] = function(g,v)
+ trace_combining = false
end
-fonts.vf.aux.combine.commands["set-tracing"] = function(g,v)
+vf.aux.combine.commands["set-tracing"] = function(g,v)
if v[2] == nil then
- fonts.vf.aux.combine.trace = true
+ trace_combining = true
else
- fonts.vf.aux.combine.trace = v[2]
+ trace_combining = v[2]
end
end
-function fonts.vf.aux.combine.initialize_trace()
- if fonts.vf.aux.combine.trace then
+function vf.aux.combine.initialize_trace()
+ if trace_combining then
return "special", "pdf: .8 0 0 rg .8 0 0 RG", "pdf: 0 .8 0 rg 0 .8 0 RG", "pdf: 0 0 .8 rg 0 0 .8 RG", "pdf: 0 g 0 G"
else
return "comment", "", "", "", ""
end
end
-fonts.vf.aux.combine.force_fallback = false
+vf.aux.combine.force_fallback = false
-fonts.vf.aux.combine.commands["fake-character"] = function(g,v) -- g, nr, fallback_id
+vf.aux.combine.commands["fake-character"] = function(g,v) -- g, nr, fallback_id
local index, fallback = v[2], v[3]
- if fonts.vf.aux.combine.force_fallback or not g.characters[index] then
+ if vf.aux.combine.force_fallback or not g.characters[index] then
if fonts.fallbacks[fallback] then
- g.characters[index] = fonts.fallbacks[fallback](g)
+ g.characters[index], g.descriptions[index] = fonts.fallbacks[fallback](g)
end
end
end
fonts.fallbacks['textcent'] = function (g)
- local c = string.byte("c")
+ local c = ("c"):byte()
local t = table.fastcopy(g.characters[c])
- local s = fonts.tfm.scaled(g.specification.size or g.size)
- local a = - math.tan(math.rad(g.italicangle or 0))
- local special, red, green, blue, black = fonts.vf.aux.combine.initialize_trace()
+ local a = - tan(rad(g.italicangle or 0))
+ local special, red, green, blue, black = vf.aux.combine.initialize_trace()
+ local quad = g.parameters.quad
if a == 0 then
t.commands = {
{"push"}, {"slot", 1, c}, {"pop"},
{"right", .5*t.width},
{"down", .2*t.height},
{special, green},
- {"rule", 1.4*t.height, .02*s},
+ {"rule", 1.4*t.height, .02*quad},
{special, black},
}
else
t.commands = {
{"push"},
- {"right", .5*t.width-.025*s},
+ {"right", .5*t.width-.025*quad},
{"down", .2*t.height},
- {"special",string.format("pdf: q 1 0 %s 1 0 0 cm",a)},
+ {"special",format("pdf: q 1 0 %s 1 0 0 cm",a)},
{special, green},
- {"rule", 1.4*t.height, .025*s},
+ {"rule", 1.4*t.height, .025*quad},
{special, black},
{"special","pdf: Q"},
{"pop"},
@@ -82,15 +87,17 @@ fonts.fallbacks['textcent'] = function (g)
-- todo: set height
t.height = 1.2*t.height
t.depth = 0.2*t.height
- return t
+ g.virtualized = true
+ local d = g.descriptions
+ return t, d and d[c]
end
fonts.fallbacks['texteuro'] = function (g)
- local c = string.byte("C")
+ local c = ("C"):byte()
local t = table.fastcopy(g.characters[c])
- local s = fonts.tfm.scaled(g.specification.size or g.size)
- local d = math.cos(math.rad(90+(g.italicangle)))
- local special, red, green, blue, black = fonts.vf.aux.combine.initialize_trace()
+ local d = cos(rad(90+(g.italicangle)))
+ local special, red, green, blue, black = vf.aux.combine.initialize_trace()
+ local quad = g.parameters.quad
t.width = 1.05*t.width
t.commands = {
{"right", .05*t.width},
@@ -98,28 +105,40 @@ fonts.fallbacks['texteuro'] = function (g)
{"right", .5*t.width*d},
{"down", -.5*t.height},
{special, green},
- {"rule", .05*s, .4*s},
+ {"rule", .05*quad, .4*quad},
{special, black},
}
- return t
+ g.virtualized = true
+ return t, g.descriptions[c]
end
-- maybe store llx etc instead of bbox in tfm blob / more efficient
-fonts.vf.aux.combine.force_composed = false
+vf.aux.combine.force_composed = false
+
+local push, pop = { "push" }, { "pop" }
-function fonts.vf.aux.compose_characters(g) -- todo: scaling depends on call location
+local cache = { } -- we could make these weak
+
+function vf.aux.compose_characters(g) -- todo: scaling depends on call location
-- this assumes that slot 1 is self, there will be a proper self some day
- local chars = g.characters
- local fastcopy = table.fastcopy
- local xchar = chars[string.byte("X")]
- if xchar and xchar.description then
- local cap_lly = xchar.description.boundingbox[4]
- local ita_cor = math.cos(math.rad(90+(g.italicangle or 0)))
- local force = fonts.vf.aux.combine.force_composed
- local fallbacks = characters.context.fallbacks
- local special, red, green, blue, black = fonts.vf.aux.combine.initialize_trace()
- for i,c in pairs(characters.data) do
+ local chars, descs = g.characters, g.descriptions
+ local X = ("X"):byte()
+ local xchar = chars[X]
+ local xdesc = descs[X]
+ if xchar and xdesc then
+ local scale = g.factor or 1
+ local cap_lly = scale*xdesc.boundingbox[4]
+ local ita_cor = cos(rad(90+(g.italicangle or 0)))
+ local force = vf.aux.combine.force_composed
+ local fallbacks = characters.fallbacks
+ local special, red, green, blue, black
+ if trace_combining then
+ special, red, green, blue, black = vf.aux.combine.initialize_trace()
+ red, green, blue, black = { special, red }, { special, green }, { special, blue }, { special, black }
+ end
+ local done = false
+ for i,c in next, characters.data do
if force or not chars[i] then
local s = c.specials
if s and s[1] == 'char' then
@@ -129,71 +148,132 @@ function fonts.vf.aux.compose_characters(g) -- todo: scaling depends on call loc
local cc = c.category
if cc == 'll' or cc == 'lu' or cc == 'lt' then
local acc = s[3]
- local t = fastcopy(charschr)
- local d = t.description
- d.name = c.adobename or "unknown"
- d.unicode = i
+ local t = { }
+ for k, v in next, charschr do
+ if k ~= "commands" then
+ t[k] = v
+ end
+ end
local charsacc = chars[acc]
+--~ local ca = charsacc.category
+--~ if ca == "mn" then
+--~ -- mark nonspacing
+--~ elseif ca == "ms" then
+--~ -- mark spacing combining
+--~ elseif ca == "me" then
+--~ -- mark enclosing
+--~ else
if not charsacc then
acc = fallbacks[acc]
charsacc = acc and chars[acc]
end
if charsacc then
- local cb = charschr.description.boundingbox
- local ab = charsacc.description.boundingbox
+ local chr_t = cache[chr]
+ if not cht_t then
+ chr_t = {"slot", 1, chr}
+ cache[chr] = chr_t
+ end
+ local acc_t = cache[acc]
+ if not acc_t then
+ acc_t = {"slot", 1, acc}
+ cache[acc] = acc_t
+ end
+ local cb = descs[chr].boundingbox
+ local ab = descs[acc].boundingbox
if cb and ab then
- local c_llx, c_lly, c_urx, c_ury = cb[1], cb[2], cb[3], cb[4]
- local a_llx, a_lly, a_urx, a_ury = ab[1], ab[2], ab[3], ab[4]
+ -- 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)*ita_cor
+ local dd = (c_urx - c_llx)*ita_cor
if a_ury < 0 then
- local dy = cap_lly-a_lly
- t.commands = {
- {"push"},
- {"right", dx-dd},
- {"down", -dy}, -- added
- {special, red},
- {"slot", 1, acc},
- {special, black},
- {"pop"},
- {"slot", 1, chr},
- }
+ 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
local dy = cap_lly-a_lly
- t.commands = {
- {"push"},
- {"right", dx+dd},
- {"down", -dy},
- {special, green},
- {"slot", 1, acc},
- {special, black},
- {"pop"},
- {"slot", 1, chr},
- }
+ 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
- t.commands = {
- {"push"},
- {"right", dx+dd},
- {special, blue},
- {"slot", 1, acc},
- {special, black},
- {"pop"},
- {"slot", 1, chr},
- }
+ 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
+ done = true
end
end
chars[i] = t
+ local d = { }
+ for k, v in next, descs[chr] do
+ d[k] = v
+ end
+ d.name = c.adobename or "unknown"
+ -- d.unicode = i
+ descs[i] = d
end
end
end
end
end
+ if done then
+ g.virtualized = true
+ end
end
end
-fonts.vf.aux.combine.commands["complete-composed-characters"] = function(g,v)
- fonts.vf.aux.compose_characters(g)
+vf.aux.combine.commands["complete-composed-characters"] = function(g,v)
+ vf.aux.compose_characters(g)
end
--~ {'special', 'pdf: q ' .. s .. ' 0 0 '.. s .. ' 0 0 cm'},
@@ -209,13 +289,13 @@ fonts.define.methods.install("fallback", { -- todo: auto-fallback with loop over
{ "fake-character", 0x20AC, 'texteuro' }
})
-fonts.vf.aux.combine.commands["enable-force"] = function(g,v)
- fonts.vf.aux.combine.force_composed = true
- fonts.vf.aux.combine.force_fallback = true
+vf.aux.combine.commands["enable-force"] = function(g,v)
+ vf.aux.combine.force_composed = true
+ vf.aux.combine.force_fallback = true
end
-fonts.vf.aux.combine.commands["disable-force"] = function(g,v)
- fonts.vf.aux.combine.force_composed = false
- fonts.vf.aux.combine.force_fallback = false
+vf.aux.combine.commands["disable-force"] = function(g,v)
+ vf.aux.combine.force_composed = false
+ vf.aux.combine.force_fallback = false
end
fonts.define.methods.install("demo-2", {