summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-imp-tracing.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/font-imp-tracing.lua')
-rw-r--r--tex/context/base/mkiv/font-imp-tracing.lua110
1 files changed, 110 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/font-imp-tracing.lua b/tex/context/base/mkiv/font-imp-tracing.lua
index e6de494df..6ce445143 100644
--- a/tex/context/base/mkiv/font-imp-tracing.lua
+++ b/tex/context/base/mkiv/font-imp-tracing.lua
@@ -6,7 +6,10 @@ if not modules then modules = { } end modules ['font-imp-tracing'] = {
license = "see context related readme files"
}
+if not context then return end
+
local next, type = next, type
+local concat = table.concat
local formatters = string.formatters
local fonts = fonts
@@ -19,6 +22,7 @@ local settings_to_array = utilities.parsers.settings_to_array
local setmetatableindex = table.setmetatableindex
local helpers = fonts.helpers
+local appendcommandtable = helpers.appendcommandtable
local prependcommands = helpers.prependcommands
local charcommand = helpers.commands.char
@@ -48,6 +52,8 @@ local r = 16384 * bp -- 65536 // 4
local f_1 = formatters["%.6F w 0 %.6F %.6F %.6F re f"]
local f_2 = formatters["[] 0 d 0 J %.6F w %.6F %.6F %.6F %.6F re S"]
+-- change this into w h d instead of h d w
+
local backcache = setmetatableindex(function(t,h)
local h = h * bp
local v = setmetatableindex(function(t,d)
@@ -169,3 +175,107 @@ local specification = {
registerotffeature(specification)
registerafmfeature(specification)
+
+local f_m = formatters["%F %F m"]
+local f_l = formatters["%F %F l"]
+local f_b = formatters["[] 0 d 0 J %.6F w"]
+local f_e = formatters["s"]
+
+local function ladder(list,docolor,nocolor,lst,offset,sign,default)
+ local l = lst[1]
+ local x1 = bp * (offset + l.kern) * sign
+ local y1 = bp * l.height
+ local t = { f_b(r,r/2), f_m(x1,y1) }
+ local n = 2
+ local m = #lst
+ if default > 0 then
+ default = default * bp + r
+ else
+ default = default * bp - r
+ end
+ if m == 1 then
+ n = n + 1 t[n] = f_l(x1,default)
+ else
+ for i=1,m do
+ local l = lst[i]
+ local x2 = bp * (offset + l.kern) * sign
+ local y2 = bp * l.height
+ if i > 1 and y2 == 0 then
+ y2 = default
+ end
+ n = n + 1 t[n] = f_l(x2,y1)
+ n = n + 1 t[n] = f_l(x2,y2)
+ x1, y1 = x2, y2
+ end
+ end
+ n = n + 1 t[n] = f_e()
+ list[#list+1] = docolor
+ list[#list+1] = { "pdf", "origin", concat(t," ") }
+ list[#list+1] = nocolor
+end
+
+local function initialize(tfmdata,key,value)
+ if value then
+ if not backcolors then
+ local vfspecials = backends.pdf.tables.vfspecials
+ startcolor = vfspecials.startcolor
+ stopcolor = vfspecials.stopcolor
+ end
+ local characters = tfmdata.characters
+ local brcolor = startcolor("darkred")
+ local trcolor = startcolor("darkgreen")
+ local blcolor = startcolor("darkblue")
+ local tlcolor = startcolor("darkyellow")
+ local black = stopcolor
+ for unicode, character in next, characters do
+ local mathkern = character.mathkern
+ if mathkern then
+ -- more efficient would be co collect more in one pdf
+ -- directive but this is hardly used so not worth the
+ -- effort
+ local width = character.width or 0
+ local height = character.height or 0
+ local depth = character.depth or 0
+ local list = { }
+ local br = mathkern.bottom_right
+ local tr = mathkern.top_right
+ local bl = mathkern.bottom_left
+ local tl = mathkern.top_left
+ if br then
+ ladder(list,brcolor,black,br,width,1,height)
+ end
+ if tr then
+ ladder(list,trcolor,black,tr,width,1,-depth)
+ end
+ if bl then
+ ladder(list,blcolor,black,bl,0,-1,height)
+ end
+ if tl then
+ ladder(list,tlcolor,black,tl,0,-1,-depth)
+ end
+ if #list > 0 then
+ local commands = character.commands
+ if commands then
+ character.commands = appendcommandtable(commands,list)
+ else
+ list[#list+1] = charcommand[unicode]
+ character.commands = list
+ end
+ end
+ end
+ end
+ end
+end
+
+local specification = {
+ name = "staircase",
+ description = "show staircase kerns",
+ position=1,
+ manipulators = {
+ base = initialize,
+ node = initialize,
+ }
+}
+
+registerotffeature(specification)
+registerafmfeature(specification)