diff options
author | Hans Hagen <pragma@wxs.nl> | 2018-09-02 00:04:51 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2018-09-02 00:04:51 +0200 |
commit | fd9c4ecd4421d087de21bef1e53d8ffb016285b0 (patch) | |
tree | 64606204adcabe2f197984ca8d063891b770bace /tex/context/base/mkiv/pack-rul.lua | |
parent | 2106beefbc854f77a92264c815d3cf2b3460f0b6 (diff) | |
download | context-fd9c4ecd4421d087de21bef1e53d8ffb016285b0.tar.gz |
2018-09-01 23:20:00
Diffstat (limited to 'tex/context/base/mkiv/pack-rul.lua')
-rw-r--r-- | tex/context/base/mkiv/pack-rul.lua | 173 |
1 files changed, 31 insertions, 142 deletions
diff --git a/tex/context/base/mkiv/pack-rul.lua b/tex/context/base/mkiv/pack-rul.lua index fbffa4ec3..c89335220 100644 --- a/tex/context/base/mkiv/pack-rul.lua +++ b/tex/context/base/mkiv/pack-rul.lua @@ -57,6 +57,7 @@ local flush_node = nuts.flush local nexthlist = nuts.traversers.hlist local nextvlist = nuts.traversers.vlist +local nextlist = nuts.traversers.list local checkformath = false @@ -79,24 +80,26 @@ local function doreshapeframedbox(n) if boxwidth ~= 0 then -- and h.subtype == vlist_code local list = getlist(box) if list then - local function check(n,repack) + local hdone = false + for n, id, subtype, list in nextlist, list do -- no dir etc needed local width, height, depth = getwhd(n) if not firstheight then firstheight = height end lastdepth = depth noflines = noflines + 1 - local l = getlist(n) - if l then - if repack then - local subtype = getsubtype(n) + if list then + if id == hlist_code then if subtype == box_code or subtype == line_code then - lastlinelength = list_dimensions(l,getdir(n)) + -- lastlinelength = list_dimensions(list,getdir(n)) + lastlinelength = list_dimensions(list,getdirection(n)) else lastlinelength = width end + hdone = true else lastlinelength = width + -- vdone = true end if lastlinelength > maxwidth then maxwidth = lastlinelength @@ -110,26 +113,14 @@ local function doreshapeframedbox(n) totalwidth = totalwidth + lastlinelength end end - local hdone = false - for h in nexthlist, list do -- no dir etc needed - check(h,true) - hdone = true - end - -- local vdone = false - for v in nextvlist, list do -- no dir etc needed - check(v,false) - -- vdone = true - end if not firstheight then -- done) elseif maxwidth ~= 0 then if hdone then - for h in nexthlist, list do - local l = getlist(h) - if l then - local subtype = getsubtype(h) + for h, id, subtype, list in nextlist, list do + if list and id == hlist_code then if subtype == box_code or subtype == line_code then - local p = hpack(l,maxwidth,'exactly',getdir(h)) -- multiple return value + local p = hpack(list,maxwidth,'exactly',getdir(h)) -- multiple return value local set, order, sign = getboxglue(p) setboxglue(h,set,order,sign) setlist(p) @@ -167,108 +158,6 @@ local function doreshapeframedbox(n) texsetdimen("global","framedaveragewidth",averagewidth) end -if LUATEXVERSION >= 1.080 then - - local traverse_list = node.direct.traverse_list - - local nextlist = nuts.traversers.list - - -- local function doreshapeframedbox(n) - doreshapeframedbox = function(n) - local box = getbox(n) - local noflines = 0 - local nofnonzero = 0 - local firstheight = nil - local lastdepth = nil - local lastlinelength = 0 - local minwidth = 0 - local maxwidth = 0 - local totalwidth = 0 - local averagewidth = 0 - local boxwidth = getwidth(box) - if boxwidth ~= 0 then -- and h.subtype == vlist_code - local list = getlist(box) - if list then - local hdone = false - for n, id, subtype, list in nextlist, list do -- no dir etc needed - local width, height, depth = getwhd(n) - if not firstheight then - firstheight = height - end - lastdepth = depth - noflines = noflines + 1 - if list then - if id == hlist_code then - if subtype == box_code or subtype == line_code then - -- lastlinelength = list_dimensions(list,getdir(n)) - lastlinelength = list_dimensions(list,getdirection(n)) - else - lastlinelength = width - end - hdone = true - else - lastlinelength = width - -- vdone = true - end - if lastlinelength > maxwidth then - maxwidth = lastlinelength - end - if lastlinelength < minwidth or minwidth == 0 then - minwidth = lastlinelength - end - if lastlinelength > 0 then - nofnonzero = nofnonzero + 1 - end - totalwidth = totalwidth + lastlinelength - end - end - if not firstheight then - -- done) - elseif maxwidth ~= 0 then - if hdone then - for h, id, subtype, list in nextlist, list do - if list and id == hlist_code then - if subtype == box_code or subtype == line_code then - local p = hpack(list,maxwidth,'exactly',getdir(h)) -- multiple return value - local set, order, sign = getboxglue(p) - setboxglue(h,set,order,sign) - setlist(p) - flush_node(p) - elseif checkformath and subtype == equation_code then - -- display formulas use a shift - if nofnonzero == 1 then - setshift(h,0) - end - end - setwidth(h,maxwidth) - end - end - end - -- if vdone then - -- for v in nextvlist, list do - -- local width = getwidth(n) - -- if width > maxwidth then - -- setwidth(v,maxwidth) - -- end - -- end - -- end - setwidth(box,maxwidth) - averagewidth = noflines > 0 and totalwidth/noflines or 0 - else -- e.g. empty math {$ $} or \hbox{} or ... - setwidth(box,0) - end - end - end - texsetcount("global","framednoflines",noflines) - texsetdimen("global","framedfirstheight",firstheight or 0) -- also signal - texsetdimen("global","framedlastdepth",lastdepth or 0) - texsetdimen("global","framedminwidth",minwidth) - texsetdimen("global","framedmaxwidth",maxwidth) - texsetdimen("global","framedaveragewidth",averagewidth) - end - -end - local function doanalyzeframedbox(n) -- traverse_list local box = getbox(n) local noflines = 0 @@ -277,7 +166,7 @@ local function doanalyzeframedbox(n) -- traverse_list if getwidth(box) ~= 0 then local list = getlist(box) if list then - local function check(n) + for n in nexthlist, list do local width, height, depth = getwhd(n) if not firstheight then firstheight = height @@ -285,11 +174,13 @@ local function doanalyzeframedbox(n) -- traverse_list lastdepth = depth noflines = noflines + 1 end - for h in nexthlist, list do - check(h) - end - for v in nextvlist, list do - check(v) + for n in nextvlist, list do + local width, height, depth = getwhd(n) + if not firstheight then + firstheight = height + end + lastdepth = depth + noflines = noflines + 1 end end end @@ -315,16 +206,11 @@ local function maxboxwidth(box) end local lastlinelength = 0 local maxwidth = 0 - local function check(n,repack) + for n, subtype in nexthlist, list do -- no dir etc needed local l = getlist(n) if l then - if repack then - local subtype = getsubtype(n) - if subtype == box_code or subtype == line_code then - lastlinelength = list_dimensions(l,getdir(n)) - else - lastlinelength = getwidth(n) - end + if subtype == box_code or subtype == line_code then + lastlinelength = list_dimensions(l,getdir(n)) else lastlinelength = getwidth(n) end @@ -333,11 +219,14 @@ local function maxboxwidth(box) end end end - for h in nexthlist, list do -- no dir etc needed - check(h,true) - end - for v in nextvlist, list do -- no dir etc needed - check(v,false) + for n, subtype in nextvlist, list do -- no dir etc needed + local l = getlist(n) + if l then + lastlinelength = getwidth(n) + if lastlinelength > maxwidth then + maxwidth = lastlinelength + end + end end return maxwidth end |