summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-ext.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-07-27 17:53:52 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-07-27 17:53:52 +0200
commitab56ea38d2f4f5b521ef097bac92812f6070ef55 (patch)
treee5f2ba9e66f1b1ef8f7b32f91aed0d744a14a0da /tex/context/base/mkiv/font-ext.lua
parentf7bfb1deb04d4ad101dbabf4d635d33cd98aa0a1 (diff)
downloadcontext-ab56ea38d2f4f5b521ef097bac92812f6070ef55.tar.gz
2017-07-27 16:23:00
Diffstat (limited to 'tex/context/base/mkiv/font-ext.lua')
-rw-r--r--tex/context/base/mkiv/font-ext.lua228
1 files changed, 162 insertions, 66 deletions
diff --git a/tex/context/base/mkiv/font-ext.lua b/tex/context/base/mkiv/font-ext.lua
index 8e0971ca6..46309c324 100644
--- a/tex/context/base/mkiv/font-ext.lua
+++ b/tex/context/base/mkiv/font-ext.lua
@@ -37,8 +37,12 @@ local registerafmfeature = handlers.afm.features.register
local fontdata = hashes.identifiers
local fontproperties = hashes.properties
+local constructors = fonts.constructors
+local getprivate = constructors.getprivate
+
local allocate = utilities.storage.allocate
local settings_to_array = utilities.parsers.settings_to_array
+local settings_to_hash = utilities.parsers.settings_to_hash
local getparameters = utilities.parsers.getparameters
local gettexdimen = tex.getdimen
local family_font = node.family_font
@@ -46,6 +50,13 @@ local family_font = node.family_font
local setmetatableindex = table.setmetatableindex
local implement = interfaces.implement
+local variables = interfaces.variables
+
+
+local v_background = variables.background
+local v_frame = variables.frame
+local v_empty = variables.empty
+local v_none = variables.none
-- -- -- -- -- --
-- shared
@@ -647,15 +658,13 @@ local function manipulatedimensions(tfmdata,key,value)
depth = (spec[3] or 0) * exheight
end
if width > 0 then
- local resources = tfmdata.resources
local additions = { }
- local private = resources.private
for unicode, old_c in next, characters do
local oldwidth = old_c.width
if oldwidth ~= width then
-- Defining the tables in one step is more efficient
-- than adding fields later.
- private = private + 1
+ local private = getprivate(tfmdata)
local new_c
local commands = {
{ "right", (width - oldwidth) / 2 },
@@ -693,13 +702,12 @@ local function manipulatedimensions(tfmdata,key,value)
end
setmetatableindex(new_c,old_c)
characters[unicode] = new_c
- additions[private] = old_c
+ additions[private] = old_c
end
end
for k, v in next, additions do
characters[k] = v
end
- resources.private = private
elseif height > 0 and depth > 0 then
for unicode, old_c in next, characters do
old_c.height = height
@@ -741,80 +749,172 @@ registerafmfeature(dimensions_specification)
-- local gray = { "pdf", "origin", "/Tr1 gs .75 g" }
-- local black = { "pdf", "origin", "/Tr0 gs 0 g" }
--- sort of obsolete as we now have \showglyphs
+
+-- boundingbox={yes|background|frame|empty|<color>}
local push = { "push" }
local pop = { "pop" }
-local gray = { "pdf", "origin", ".75 g" }
-local black = { "pdf", "origin", "0 g" }
--- local gray = { "pdf", ".75 g" }
--- local black = { "pdf", "0 g" }
-local downcache = { } -- handy for huge cjk fonts
-local rulecache = { } -- handy for huge cjk fonts
+----- gray = { "pdf", "origin", ".75 g .75 G" }
+----- black = { "pdf", "origin", "0 g 0 G" }
+----- gray = { "pdf", ".75 g" }
+----- black = { "pdf", "0 g" }
-setmetatableindex(downcache,function(t,d)
- local v = { "down", d }
- t[d] = v
+-- local bp = number.dimenfactors.bp
+--
+-- local downcache = setmetatableindex(function(t,d)
+-- local v = { "down", d }
+-- t[d] = v
+-- return v
+-- end)
+--
+-- local backcache = setmetatableindex(function(t,h)
+-- local h = h * bp
+-- local v = setmetatableindex(function(t,w)
+-- -- local v = { "rule", h, w }
+-- local v = { "pdf", "origin", formatters["0 0 %0.6F %0.6F re F"](w*bp,h) }
+-- t[w] = v
+-- return v
+-- end)
+-- t[h] = v
+-- return v
+-- end)
+--
+-- local forecache = setmetatableindex(function(t,h)
+-- local h = h * bp
+-- local v = setmetatableindex(function(t,w)
+-- local v = { "pdf", "origin", formatters["%0.6F w 0 0 %0.6F %0.6F re S"](0.25*65536*bp,w*bp,h) }
+-- t[w] = v
+-- return v
+-- end)
+-- t[h] = v
+-- return v
+-- end)
+
+local bp = number.dimenfactors.bp
+local r = 0.25*65536*bp
+
+local backcache = setmetatableindex(function(t,h)
+ local h = h * bp
+ local v = setmetatableindex(function(t,d)
+ local d = d * bp
+ local v = setmetatableindex(function(t,w)
+ local v = { "pdf", "origin", formatters["%0.6F w 0 %0.6F %0.6F %0.6F re f"](r,-d,w*bp,h+d) }
+ t[w] = v
+ return v
+ end)
+ t[d] = v
+ return v
+ end)
+ t[h] = v
return v
end)
-setmetatableindex(rulecache,function(t,h)
- local v = { }
- t[h] = v
- setmetatableindex(v,function(t,w)
- local v = { "rule", h, w }
- t[w] = v
+local forecache = setmetatableindex(function(t,h)
+ local h = h * bp
+ local v = setmetatableindex(function(t,d)
+ local d = d * bp
+ local v = setmetatableindex(function(t,w)
+ -- the frame goes through the boundingbox
+ -- local v = { "pdf", "origin", formatters["[] 0 d 0 J %0.6F w 0 %0.6F %0.6F %0.6F re S"](r,-d,w*bp,h+d) }
+ local v = { "pdf", "origin", formatters["[] 0 d 0 J %0.6F w %0.6F %0.6F %0.6F %0.6F re S"](r,r/2,-d+r/2,w*bp-r,h+d-r) }
+ t[w] = v
+ return v
+ end)
+ t[d] = v
return v
end)
+ t[h] = v
return v
end)
+local startcolor = nil
+local stopcolor = nil
+
local function showboundingbox(tfmdata,key,value)
if value then
- local vfspecials = backends.pdf.tables.vfspecials
- local gray = vfspecials and (vfspecials.rulecolors[value] or vfspecials.rulecolors.palegray) or gray
+ if not backcolors then
+ local vfspecials = backends.pdf.tables.vfspecials
+ startcolor = vfspecials.startcolor
+ stopcolor = vfspecials.stopcolor
+ end
local characters = tfmdata.characters
- local resources = tfmdata.resources
local additions = { }
- local private = resources.private
+ local rulecache = backcache
+ local showchar = true
+ local color = "palegray"
+ if type(value) == "string" then
+ value = settings_to_array(value)
+ for i=1,#value do
+ local v = value[i]
+ if v == v_frame then
+ rulecache = forecache
+ elseif v == v_background then
+ rulecache = backcache
+ elseif v == v_empty then
+ showchar = false
+ elseif v == v_none then
+ color = nil
+ else
+ color = v
+ end
+ end
+ end
+ local gray = color and startcolor(color) or nil
+ local black = gray and stopcolor or nil
for unicode, old_c in next, characters do
- private = private + 1
- local width = old_c.width or 0
- local height = old_c.height or 0
- local depth = old_c.depth or 0
- local new_c
- if depth == 0 then
- new_c = {
- width = width,
- height = height,
- commands = {
- push,
- gray,
- rulecache[height][width],
- black,
- pop,
- { "slot", 1, private },
- -- { "slot", 0, private },
- }
+ local private = getprivate(tfmdata)
+ local width = old_c.width or 0
+ local height = old_c.height or 0
+ local depth = old_c.depth or 0
+ local char = showchar and { "slot", 1, private } or nil -- { "slot", 0, private }
+ -- local new_c
+ -- if depth == 0 then
+ -- new_c = {
+ -- width = width,
+ -- height = height,
+ -- commands = {
+ -- push,
+ -- gray,
+ -- rulecache[height][width],
+ -- black,
+ -- pop,
+ -- char,
+ -- }
+ -- }
+ -- else
+ -- new_c = {
+ -- width = width,
+ -- height = height,
+ -- depth = depth,
+ -- commands = {
+ -- push,
+ -- downcache[depth],
+ -- gray,
+ -- rulecache[height+depth][width],
+ -- black,
+ -- pop,
+ -- char,
+ -- }
+ -- }
+ -- end
+ local rule = rulecache[height][depth][width]
+ local new_c = {
+ width = width,
+ height = height,
+ depth = depth,
+ commands = gray and {
+ -- push,
+ gray,
+ rule,
+ black,
+ -- pop,
+ char,
+ } or {
+ rule,
+ char,
}
- else
- new_c = {
- width = width,
- height = height,
- depth = depth,
- commands = {
- push,
- downcache[depth],
- gray,
- rulecache[height+depth][width],
- black,
- pop,
- { "slot", 1, private },
- -- { "slot", 0, private },
- }
- }
- end
+ }
setmetatableindex(new_c,old_c)
characters[unicode] = new_c
additions[private] = old_c
@@ -822,7 +922,6 @@ local function showboundingbox(tfmdata,key,value)
for k, v in next, additions do
characters[k] = v
end
- resources.private = private
end
end
@@ -1115,7 +1214,7 @@ do
end
end
- fonts.constructors.newfeatures.otf.register {
+ constructors.newfeatures.otf.register {
name = "extraprivates",
description = "extra privates",
default = true,
@@ -1251,15 +1350,13 @@ do -- another hack for a crappy font
local function additalictowidth(tfmdata,key,value)
local characters = tfmdata.characters
- local resources = tfmdata.resources
local additions = { }
- local private = resources.private
for unicode, old_c in next, characters do
-- maybe check for math
local oldwidth = old_c.width
local olditalic = old_c.italic
if olditalic and olditalic ~= 0 then
- private = private + 1
+ local private = getprivate(tfmdata)
local new_c = {
width = oldwidth + olditalic,
height = old_c.height,
@@ -1279,7 +1376,6 @@ do -- another hack for a crappy font
for k, v in next, additions do
characters[k] = v
end
- resources.private = private
end
registerotffeature {