summaryrefslogtreecommitdiff
path: root/tex/context/base/typo-bld.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/typo-bld.lua')
-rw-r--r--tex/context/base/typo-bld.lua112
1 files changed, 111 insertions, 1 deletions
diff --git a/tex/context/base/typo-bld.lua b/tex/context/base/typo-bld.lua
index 69d72e28c..ade171c5d 100644
--- a/tex/context/base/typo-bld.lua
+++ b/tex/context/base/typo-bld.lua
@@ -1,4 +1,4 @@
-if not modules then modules = { } end modules ['typo-bld'] = { -- was node-par
+if modules then modules = { } end modules ['typo-bld'] = { -- was node-par
version = 1.001,
comment = "companion to typo-bld.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
@@ -287,3 +287,113 @@ implement { name = "startparbuilder", actions = constructors.start, arguments
implement { name = "stopparbuilder", actions = constructors.stop }
implement { name = "enableparbuilder", actions = constructors.enable }
implement { name = "disableparbuilder", actions = constructors.disable }
+
+-- Here are some tracers:
+
+local new_kern = nodes.pool.kern
+local new_rule = nodes.pool.rule
+local hpack = nodes.hpack
+local setcolor = nodes.tracers.colors.set
+local listtoutf = nodes.listtoutf
+
+local report_hpack = logs.reporter("hpack routine")
+local report_vpack = logs.reporter("vpack routine")
+
+-- overflow|badness w h d dir
+
+local function vpack_quality(how,n,detail,first,last)
+ if last <= 0 then
+ report_vpack("%s vbox",how)
+ elseif first > 0 and first < last then
+ report_vpack("%s vbox at line %i - %i",how,first,last)
+ else
+ report_vpack("%s vbox at line %i",how,last)
+ end
+end
+
+trackers.register("builders.vpack.quality",function(v)
+ callback.register("vpack_quality",v and report_vpack_quality or nil)
+end)
+
+local report, show = false, false
+
+local function hpack_quality(how,detail,n,first,last)
+ if report then
+ local str = listtoutf(n.head,"",true,nil,true)
+ if last <= 0 then
+ report_hpack("%s hbox: %s",how,str)
+ elseif first > 0 and first < last then
+ report_hpack("%s hbox at line %i - %i: %s",how,first,last,str)
+ else
+ report_hpack("%s hbox at line %i: %s",how,last,str)
+ end
+ end
+ if show then
+ local width = 2*65536
+ local height = n.height
+ local depth = n.depth
+ local dir = n.dir
+ if height < 4*65526 then
+ height = 4*65526
+ end
+ if depth < 2*65526 then
+ depth = 2*65526
+ end
+ local rule = new_rule(width,height,depth)
+ rule.dir = dir
+ if how == "overfull" then
+ setcolor(rule,"red")
+ local kern = new_kern(-detail)
+ kern.next = rule
+ rule.prev = kern
+ rule = kern
+ elseif how == "underfull" then
+ setcolor(rule,"blue")
+ elseif how == "loose" then
+ setcolor(rule,"magenta")
+ elseif how == "tight" then
+ setcolor(rule,"cyan")
+ end
+ rule = hpack(rule)
+ rule.width = 0
+ rule.dir = dir
+ return rule
+ end
+end
+
+trackers.register("builders.hpack.quality",function(v)
+ report = v
+ callback.register("hpack_quality",(report or show) and hpack_quality or nil)
+end)
+
+trackers.register("builders.hpack.overflow",function(v)
+ show = v
+ callback.register("hpack_quality",(report or show) and hpack_quality or nil)
+end)
+
+-- local ignoredepth = - 65536000
+--
+-- callback.register("append_to_vlist_filter", function(box,location,prevdepth,mirrored)
+-- if prevdepth > ignoredepth then
+-- local b = tex.baselineskip
+-- local d = b.width - prevdepth
+-- local g = nil
+-- if mirrored then
+-- d = d - box.depth
+-- else
+-- d = d - box.height
+-- end
+-- if d < tex.lineskiplimit then
+-- g = nodes.pool.glue()
+-- g.spec = tex.lineskip
+-- else
+-- g = nodes.pool.baselineskip(d)
+-- end
+-- g.next = box
+-- box.prev = g
+-- return g, mirrored and box.height or box.depth
+-- else
+-- return box, mirrored and box.height or box.depth
+-- end
+-- end)
+--