summaryrefslogtreecommitdiff
path: root/tex/context/base/trac-vis.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/trac-vis.lua')
-rw-r--r--tex/context/base/trac-vis.lua175
1 files changed, 77 insertions, 98 deletions
diff --git a/tex/context/base/trac-vis.lua b/tex/context/base/trac-vis.lua
index df4909c3e..dc8bcc5e7 100644
--- a/tex/context/base/trac-vis.lua
+++ b/tex/context/base/trac-vis.lua
@@ -34,10 +34,8 @@ local formatters = string.formatters
-- todo: inline concat (more efficient)
local nodecodes = nodes.nodecodes
-local disc_code = nodecodes.disc
local kern_code = nodecodes.kern
local glyph_code = nodecodes.glyph
-local disc_code = nodecodes.disc
local hlist_code = nodecodes.hlist
local vlist_code = nodecodes.vlist
local glue_code = nodecodes.glue
@@ -60,11 +58,9 @@ local rightskip_code = gluecodes.rightskip
local whatsitcodes = nodes.whatsitcodes
-local concat_nodes = nodes.concat
local hpack_nodes = node.hpack
local vpack_nodes = node.vpack
-local hpack_string = typesetters.hpack
-local fast_hpack_string = typesetters.fast_hpack
+local fast_hpack_string = nodes.typesetters.fast_hpack
local copy_node = node.copy
local copy_list = node.copy_list
local free_node = node.free
@@ -74,8 +70,9 @@ local insert_node_after = node.insert_after
local fast_hpack = nodes.fasthpack
local traverse_nodes = node.traverse
-local tex_attribute = tex.attribute
-local tex_box = tex.box
+local texgetattribute = tex.getattribute
+local texsetattribute = tex.setattribute
+local texgetbox = tex.getbox
local unsetvalue = attributes.unsetvalue
local current_font = font.current
@@ -158,7 +155,7 @@ local preset_all = preset_makeup + modes.fontkern + modes.whatsit + modes.gly
function visualizers.setfont(id)
usedfont = id or current_font()
exheight = exheights[usedfont]
- emwidth = emwidths[usedfont]
+ emwidth = emwidths[usedfont]
end
-- we can preset a bunch of bits
@@ -204,18 +201,12 @@ local function setvisual(n,a,what) -- this will become more efficient when we ha
a = preset_makeup
else
a = setbit(a,preset_makeup)
- -- for i=1,#modes_makeup do
- -- a = setvisual(modes_makeup[i],a)
- -- end
end
elseif n == "boxes" then
if not a or a == 0 or a == unsetvalue then
a = preset_boxes
else
a = setbit(a,preset_boxes)
- -- for i=1,#modes_boxes do
- -- a = setvisual(modes_boxes[i],a)
- -- end
end
elseif n == "all" then
if what == false then
@@ -224,9 +215,6 @@ local function setvisual(n,a,what) -- this will become more efficient when we ha
a = preset_all
else
a = setbit(a,preset_all)
- -- for i=1,#modes_all do
- -- a = setvisual(modes_all[i],a)
- -- end
end
else
local m = modes[n]
@@ -256,11 +244,11 @@ local function setvisual(n,a,what) -- this will become more efficient when we ha
end
function visualizers.setvisual(n)
- tex_attribute[a_visual] = setvisual(n,tex_attribute[a_visual])
+ texsetattribute(a_visual,setvisual(n,texgetattribute(a_visual)))
end
function visualizers.setlayer(n)
- tex_attribute[a_layer] = layers[n] or unsetvalue
+ texsetattribute(a_layer,layers[n] or unsetvalue)
end
commands.setvisual = visualizers.setvisual
@@ -271,7 +259,7 @@ function commands.visual(n)
end
local function set(mode,v)
- tex_attribute[a_visual] = setvisual(mode,tex_attribute[a_visual],v)
+ texsetattribute(a_visual,setvisual(mode,texgetattribute(a_visual),v))
end
for mode, value in next, modes do
@@ -314,11 +302,7 @@ local function sometext(str,layer,color,textcolor) -- we can just paste verbatim
if textcolor then
setlistcolor(text.list,textcolor)
end
- local info = concat_nodes {
- rule,
- kern,
- text,
- }
+ local info = rule .. kern .. text
setlisttransparency(info,c_zero)
info = fast_hpack(info)
if layer then
@@ -352,10 +336,7 @@ local function fontkern(head,current)
setlisttransparency(list,c_text_d)
settransparency(rule,c_text_d)
text.shift = -5 * exheight
- info = concat_nodes {
- rule,
- text,
- }
+ info = rule .. text
info = fast_hpack(info)
info[a_layer] = l_fontkern
info.width = 0
@@ -432,12 +413,15 @@ end
local b_cache = { }
-local function ruledbox(head,current,vertical,layer,what,simple)
+local function ruledbox(head,current,vertical,layer,what,simple,previous)
local wd = current.width
if wd ~= 0 then
- local ht, dp = current.height, current.depth
- local next, prev = current.next, current.prev
- current.next, current.prev = nil, nil
+ local ht = current.height
+ local dp = current.depth
+ local next = current.next
+ local prev = previous -- current.prev ... prev can be wrong in math mode
+ current.next = nil
+ current.prev = nil
local linewidth = emwidth/10
local baseline, baseskip
if dp ~= 0 and ht ~= 0 then
@@ -446,19 +430,16 @@ local function ruledbox(head,current,vertical,layer,what,simple)
if not baseline then
-- due to an optimized leader color/transparency we need to set the glue node in order
-- to trigger this mechanism
- local leader = concat_nodes {
- new_glue(2*linewidth), -- 2.5
- new_rule(6*linewidth,linewidth,0), -- 5.0
- new_glue(2*linewidth), -- 2.5
- }
+ local leader = new_glue(2*linewidth) .. new_rule(6*linewidth,linewidth,0) .. new_glue(2*linewidth)
-- setlisttransparency(leader,c_text)
leader = fast_hpack(leader)
-- setlisttransparency(leader,c_text)
baseline = new_glue(0)
baseline.leader = leader
baseline.subtype = cleaders_code
- baseline.spec.stretch = 65536
- baseline.spec.stretch_order = 2
+ local spec = baseline.spec
+ spec.stretch = 65536
+ spec.stretch_order = 2
setlisttransparency(baseline,c_text)
b_cache.baseline = baseline
end
@@ -480,10 +461,7 @@ local function ruledbox(head,current,vertical,layer,what,simple)
this = b_cache[what]
if not this then
local text = fast_hpack_string(what,usedfont)
- this = concat_nodes {
- new_kern(-text.width),
- text,
- }
+ this = new_kern(-text.width) .. text
setlisttransparency(this,c_text)
this = fast_hpack(this)
this.width = 0
@@ -492,27 +470,24 @@ local function ruledbox(head,current,vertical,layer,what,simple)
b_cache[what] = this
end
end
- local info = concat_nodes {
- this and copy_list(this) or nil, -- this also triggers the right mode (else sometimes no whatits)
- new_rule(linewidth,ht,dp),
- new_rule(wd-2*linewidth,-dp+linewidth,dp),
- new_rule(linewidth,ht,dp),
- new_kern(-wd+linewidth),
- new_rule(wd-2*linewidth,ht,-ht+linewidth),
- baseskip,
- baseline,
- }
+ -- we need to trigger the right mode (else sometimes no whatits)
+ local info =
+ (this and copy_list(this) or nil) ..
+ new_rule(linewidth,ht,dp) ..
+ new_rule(wd-2*linewidth,-dp+linewidth,dp) ..
+ new_rule(linewidth,ht,dp) ..
+ new_kern(-wd+linewidth) ..
+ new_rule(wd-2*linewidth,ht,-ht+linewidth)
+ if baseskip then
+ info = info .. baseskip .. baseline
+ end
setlisttransparency(info,c_text)
info = fast_hpack(info)
info.width = 0
info.height = 0
info.depth = 0
info[a_layer] = layer
- local info = concat_nodes {
- current,
- new_kern(-wd),
- info,
- }
+ local info = current .. new_kern(-wd) .. info
info = fast_hpack(info,wd)
if vertical then
info = vpack_nodes(info)
@@ -522,12 +497,12 @@ local function ruledbox(head,current,vertical,layer,what,simple)
next.prev = info
end
if prev then
-if prev.id == gluespec_code then
- -- weird, how can this happen, an inline glue-spec
-else
- info.prev = prev
- prev.next = info
-end
+ if prev.id == gluespec_code then
+ -- weird, how can this happen, an inline glue-spec
+ else
+ info.prev = prev
+ prev.next = info
+ end
end
if head == current then
return info, info
@@ -539,27 +514,30 @@ end
end
end
-local function ruledglyph(head,current)
+local function ruledglyph(head,current,previous)
local wd = current.width
if wd ~= 0 then
- local ht, dp = current.height, current.depth
- local next, prev = current.next, current.prev
- current.next, current.prev = nil, nil
+ local ht = current.height
+ local dp = current.depth
+ local next = current.next
+ local prev = previous
+ current.next = nil
+ current.prev = nil
local linewidth = emwidth/20
local baseline
if dp ~= 0 and ht ~= 0 then
baseline = new_rule(wd-2*linewidth,linewidth,0)
end
local doublelinewidth = 2*linewidth
- local info = concat_nodes {
- new_rule(linewidth,ht,dp),
- new_rule(wd-doublelinewidth,-dp+linewidth,dp),
- new_rule(linewidth,ht,dp),
- new_kern(-wd+linewidth),
- new_rule(wd-doublelinewidth,ht,-ht+linewidth),
- new_kern(-wd+doublelinewidth),
- baseline,
- }
+ -- could be a pdf rule
+ local info =
+ new_rule(linewidth,ht,dp) ..
+ new_rule(wd-doublelinewidth,-dp+linewidth,dp) ..
+ new_rule(linewidth,ht,dp) ..
+ new_kern(-wd+linewidth) ..
+ new_rule(wd-doublelinewidth,ht,-ht+linewidth) ..
+ new_kern(-wd+doublelinewidth) ..
+ baseline
setlistcolor(info,c_glyph)
setlisttransparency(info,c_glyph_d)
info = fast_hpack(info)
@@ -567,11 +545,7 @@ local function ruledglyph(head,current)
info.height = 0
info.depth = 0
info[a_layer] = l_glyph
- local info = concat_nodes {
- current,
- new_kern(-wd),
- info,
- }
+ local info = current .. new_kern(-wd) .. info
info = fast_hpack(info)
info.width = wd
if next then
@@ -622,6 +596,8 @@ local tags = {
-- false = "HS",
}
+-- we sometimes pass previous as we can have issues in math (not watertight for all)
+
local function ruledglue(head,current,vertical)
local spec = current.spec
local width = spec.width
@@ -721,9 +697,10 @@ local function visualize(head,vertical)
local trace_glyph = false
local trace_simple = false
local trace_user = false
- local current = head
+ local current = head
+ local previous = nil
+ local attr = unsetvalue
local prev_trace_fontkern = nil
- local attr = unsetvalue
while current do
local id = current.id
local a = current[a_visual] or unsetvalue
@@ -762,7 +739,7 @@ local function visualize(head,vertical)
current[a_layer] = l_strut
elseif id == glyph_code then
if trace_glyph then
- head, current = ruledglyph(head,current)
+ head, current = ruledglyph(head,current,previous)
end
elseif id == disc_code then
if trace_glyph then
@@ -812,7 +789,7 @@ local function visualize(head,vertical)
current.list = visualize(content,false)
end
if trace_hbox then
- head, current = ruledbox(head,current,false,l_hbox,"H__",trace_simple)
+ head, current = ruledbox(head,current,false,l_hbox,"H__",trace_simple,previous)
end
elseif id == vlist_code then
local content = current.list
@@ -820,9 +797,9 @@ local function visualize(head,vertical)
current.list = visualize(content,true)
end
if trace_vtop then
- head, current = ruledbox(head,current,true,l_vtop,"_T_",trace_simple)
+ head, current = ruledbox(head,current,true,l_vtop,"_T_",trace_simple,previous)
elseif trace_vbox then
- head, current = ruledbox(head,current,true,l_vbox,"__V",trace_simple)
+ head, current = ruledbox(head,current,true,l_vbox,"__V",trace_simple,previous)
end
elseif id == whatsit_code then
if trace_whatsit then
@@ -833,7 +810,8 @@ local function visualize(head,vertical)
head, current = user(head,current)
end
end
- current = current.next
+ previous = current
+ current = current.next
end
return head
end
@@ -865,13 +843,13 @@ end
function visualizers.handler(head)
if usedfont then
starttiming(visualizers)
- -- local l = tex_attribute[a_layer]
- -- local v = tex_attribute[a_visual]
- -- tex_attribute[a_layer] = unsetvalue
- -- tex_attribute[a_visual] = unsetvalue
+ -- local l = texgetattribute(a_layer)
+ -- local v = texgetattribute(a_visual)
+ -- texsetattribute(a_layer,unsetvalue)
+ -- texsetattribute(a_visual,unsetvalue)
head = visualize(head)
- -- tex_attribute[a_layer] = l
- -- tex_attribute[a_visual] = v
+ -- texsetattribute(a_layer,l)
+ -- texsetattribute(a_visual,v)
-- -- cleanup()
stoptiming(visualizers)
end
@@ -879,7 +857,8 @@ function visualizers.handler(head)
end
function visualizers.box(n)
- tex_box[n].list = visualizers.handler(tex_box[n].list)
+ local box = texgetbox(n)
+ box.list = visualizers.handler(box.list)
end
local last = nil
@@ -911,7 +890,7 @@ end
function visualizers.markfonts(list)
last, used = 0, { }
- markfonts(type(n) == "number" and tex_box[n].list or n)
+ markfonts(type(n) == "number" and texgetbox(n).list or n)
end
function commands.markfonts(n)