diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-rul.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/node-rul.lua | 158 |
1 files changed, 86 insertions, 72 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-rul.lua b/Master/texmf-dist/tex/context/base/node-rul.lua index 7f49edffc79..09300964ed3 100644 --- a/Master/texmf-dist/tex/context/base/node-rul.lua +++ b/Master/texmf-dist/tex/context/base/node-rul.lua @@ -43,12 +43,12 @@ function nodes.striprange(first,last) -- todo: dir if id == glyph_code or id == disc_code then -- or id == rule_code break else -local prev = last.prev -- luatex < 0.70 has italic correction kern not prev'd -if prev then - last = last.prev -else - break -end + local prev = last.prev -- luatex < 0.70 has italic correction kern not prev'd + if prev then + last = last.prev + else + break + end end end if not last then @@ -62,59 +62,57 @@ end local floor = math.floor -local trace_ruled = false trackers.register("nodes.rules", function(v) trace_ruled = v end) - -local report_ruled = logs.reporter("nodes","rules") +local trace_ruled = false trackers.register("nodes.rules", function(v) trace_ruled = v end) +local report_ruled = logs.reporter("nodes","rules") -local n_tostring = nodes.idstostring -local n_tosequence = nodes.tosequence +local n_tostring = nodes.idstostring +local n_tosequence = nodes.tosequence -local a_ruled = attributes.private('ruled') -local a_color = attributes.private('color') -local a_transparency = attributes.private('transparency') -local a_colorspace = attributes.private('colormodel') +local a_ruled = attributes.private('ruled') +local a_color = attributes.private('color') +local a_transparency = attributes.private('transparency') +local a_colorspace = attributes.private('colormodel') -local insert_before = node.insert_before -local insert_after = node.insert_after -local striprange = nodes.striprange -local list_dimensions = node.dimensions -local has_attribute = node.has_attribute -local set_attribute = node.set_attribute +local insert_node_before = node.insert_before +local insert_node_after = node.insert_after +local striprange = nodes.striprange +local list_dimensions = node.dimensions -local hpack_nodes = node.hpack +local hpack_nodes = node.hpack -local fontdata = fonts.hashes.identifiers -local variables = interfaces.variables -local dimenfactor = fonts.helpers.dimenfactor +local fontdata = fonts.hashes.identifiers +local variables = interfaces.variables +local dimenfactor = fonts.helpers.dimenfactor +local splitdimen = number.splitdimen -local nodecodes = nodes.nodecodes -local skipcodes = nodes.skipcodes -local whatcodes = nodes.whatcodes -local kerncodes = nodes.kerncodes +local nodecodes = nodes.nodecodes +local skipcodes = nodes.skipcodes +local whatcodes = nodes.whatcodes +local kerncodes = nodes.kerncodes -local glyph_code = nodecodes.glyph -local disc_code = nodecodes.disc -local glue_code = nodecodes.glue -local penalty_code = nodecodes.penalty -local kern_code = nodecodes.kern -local hlist_code = nodecodes.hlist -local vlist_code = nodecodes.vlist -local rule_code = nodecodes.rule -local whatsit_code = nodecodes.whatsit +local glyph_code = nodecodes.glyph +local disc_code = nodecodes.disc +local glue_code = nodecodes.glue +local penalty_code = nodecodes.penalty +local kern_code = nodecodes.kern +local hlist_code = nodecodes.hlist +local vlist_code = nodecodes.vlist +local rule_code = nodecodes.rule +local whatsit_code = nodecodes.whatsit -local userskip_code = skipcodes.userskip -local spaceskip_code = skipcodes.spaceskip -local xspaceskip_code = skipcodes.xspaceskip +local userskip_code = skipcodes.userskip +local spaceskip_code = skipcodes.spaceskip +local xspaceskip_code = skipcodes.xspaceskip -local dir_code = whatcodes.dir +local dir_code = whatcodes.dir -local kerning_code = kerncodes.kern +local kerning_code = kerncodes.kern -local nodepool = nodes.pool +local nodepool = nodes.pool -local new_rule = nodepool.rule -local new_kern = nodepool.kern -local new_glue = nodepool.glue +local new_rule = nodepool.rule +local new_kern = nodepool.kern +local new_glue = nodepool.glue -- we can use this one elsewhere too -- @@ -142,7 +140,7 @@ local function processwords(attribute,data,flush,head,parent) -- we have hlistdi while n do local id = n.id if id == glyph_code or id == rule_code then - local aa = has_attribute(n,attribute) + local aa = n[attribute] if aa then if aa == a then if not f then -- ? @@ -195,7 +193,7 @@ local function processwords(attribute,data,flush,head,parent) -- we have hlistdi elseif id == glue_code then -- catch \underbar{a} \underbar{a} (subtype test is needed) local subtype = n.subtype - if continue and has_attribute(n,attribute) and + if continue and n[attribute] and (subtype == userskip_code or subtype == spaceskip_code or subskip == xspaceskip_code) then l = n else @@ -249,7 +247,7 @@ local function flush_ruled(head,f,l,d,level,parent,strip) -- not that fast but a local before = n_tosequence(f,l,true) f, l = striprange(f,l) local after = n_tosequence(f,l,true) - report_ruled("range stripper: %s -> %s",before,after) + report_ruled("range stripper, before %a, after %a",before,after) else f, l = striprange(f,l) end @@ -258,53 +256,69 @@ local function flush_ruled(head,f,l,d,level,parent,strip) -- not that fast but a return head end local w = list_dimensions(parent.glue_set,parent.glue_sign,parent.glue_order,f,l.next) - local method, offset, continue, dy, rulethickness, unit, order, max, ma, ca, ta = - d.method, d.offset, d.continue, d.dy, d.rulethickness, d.unit, d.order, d.max, d.ma, d.ca, d.ta - local e = dimenfactor(unit,fontdata[f.font]) -- what if no glyph node - local colorspace = (ma > 0 and ma) or has_attribute(f,a_colorspace) or 1 - local color = (ca > 0 and ca) or has_attribute(f,a_color) - local transparency = (ta > 0 and ta) or has_attribute(f,a_transparency) + local method, offset, continue, dy, order, max = d.method, d.offset, d.continue, d.dy, d.order, d.max + local rulethickness, unit = d.rulethickness, d.unit + local ma, ca, ta = d.ma, d.ca, d.ta + local colorspace = (ma > 0 and ma) or f[a_colorspace] or 1 + local color = (ca > 0 and ca) or f[a_color] + local transparency = (ta > 0 and ta) or f[a_transparency] local foreground = order == variables.foreground - rulethickness= rulethickness/2 + + local e = dimenfactor(unit,fontdata[f.font]) -- what if no glyph node + + local rt = tonumber(rulethickness) + if rt then + rulethickness = e * rulethickness / 2 + else + local n, u = splitdimen(rulethickness) + if n and u then -- we need to intercept ex and em and % and ... + rulethickness = n * dimenfactor(u,fontdata[f.font]) / 2 + else + rulethickness = 1/5 + end + end + if level > max then level = max end if method == 0 then -- center offset = 2*offset - m = (offset+(level-1)*dy+rulethickness)*e/2 +-- m = (offset+(level-1)*dy+rulethickness)*e/2 + m = (offset+(level-1)*dy)*e/2 + rulethickness/2 else m = 0 end for i=1,level do - local ht = (offset+(i-1)*dy+rulethickness)*e - m - local dp = -(offset+(i-1)*dy-rulethickness)*e + m +-- local ht = (offset+(i-1)*dy+rulethickness)*e - m +-- local dp = -(offset+(i-1)*dy-rulethickness)*e + m + local ht = (offset+(i-1)*dy)*e + rulethickness - m + local dp = -(offset+(i-1)*dy)*e + rulethickness + m local r = new_rule(w,ht,dp) - local v = has_attribute(f,a_viewerlayer) + local v = f[a_viewerlayer] -- quick hack if v then - set_attribute(r,a_viewerlayer,v) + r[a_viewerlayer] = v end -- if color then - set_attribute(r,a_colorspace,colorspace) - set_attribute(r,a_color,color) + r[a_colorspace] = colorspace + r[a_color] = color end if transparency then - set_attribute(r,a_transparency,transparency) + r[a_transparency] = transparency end local k = new_kern(-w) if foreground then - insert_after(head,l,k) - insert_after(head,k,r) + insert_node_after(head,l,k) + insert_node_after(head,k,r) l = r else - head = insert_before(head,f,r) - insert_after(head,r,k) + head = insert_node_before(head,f,r) + insert_node_after(head,r,k) end if trace_ruled then - report_ruled("level: %s, width: %i, height: %i, depth: %i, nodes: %s, text: %s", + report_ruled("level %a, width %p, height %p, depth %p, nodes %a, text %a", level,w,ht,dp,n_tostring(f,l),n_tosequence(f,l,true)) - -- level,r.width,r.height,r.depth,n_tostring(f,l),n_tosequence(f,l,true)) end end return head @@ -361,7 +375,7 @@ local function flush_shifted(head,first,last,data,level,parent,strip) -- not tha local raise = data.dy * dimenfactor(data.unit,fontdata[first.font]) list.shift, list.height, list.depth = raise, height, depth if trace_shifted then - report_shifted("width: %s, nodes: %s, text: %s",width,n_tostring(first,last),n_tosequence(first,last,true)) + report_shifted("width %p, nodes %a, text %a",width,n_tostring(first,last),n_tosequence(first,last,true)) end return head end |