diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2014-05-12 08:14:15 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2014-05-12 08:14:15 +0200 |
commit | 83222078cd1f2f9d2c12279653c48dfd70390f1c (patch) | |
tree | 9203c42487d7c5671db8b124571e713ab8397f14 /tex/context/base/pack-rul.lua | |
parent | 4fac60d85ade0f051d411be40d5502f360a28402 (diff) | |
download | context-83222078cd1f2f9d2c12279653c48dfd70390f1c.tar.gz |
2014-05-08 11:19:00
Diffstat (limited to 'tex/context/base/pack-rul.lua')
-rw-r--r-- | tex/context/base/pack-rul.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tex/context/base/pack-rul.lua b/tex/context/base/pack-rul.lua index 5796da800..0c29eb5f1 100644 --- a/tex/context/base/pack-rul.lua +++ b/tex/context/base/pack-rul.lua @@ -14,6 +14,8 @@ if not modules then modules = { } end modules ['pack-rul'] = { -- challenge: adapt glue_set -- setfield(h,"glue_set", getfield(h,"glue_set") * getfield(h,"width")/maxwidth -- interesting ... doesn't matter much +local type = type + local hlist_code = nodes.nodecodes.hlist local vlist_code = nodes.nodecodes.vlist local box_code = nodes.listcodes.box @@ -29,6 +31,7 @@ local setfield = nuts.setfield local getnext = nuts.getnext local getprev = nuts.getprev local getlist = nuts.getlist +local getid = nuts.getid local getsubtype = nuts.getsubtype local getbox = nuts.getbox @@ -152,3 +155,44 @@ function commands.doanalyzeframedbox(n) texsetdimen("global","framedfirstheight",firstheight or 0) texsetdimen("global","framedlastdepth",lastdepth or 0) end + + +function nodes.maxboxwidth(box) + local boxwidth = getfield(box,"width") + if boxwidth == 0 then + return 0 + end + local list = getlist(box) + if not list then + return 0 + end + if getid(box) == hlist_code then + return boxwidth + end + local lastlinelength = 0 + local maxwidth = 0 + local function check(n,repack) + local l = getlist(n) + if l then + if repack then + local subtype = getsubtype(n) + if subtype == box_code or subtype == line_code then + lastlinelength = node_dimensions(l,getfield(n,"dir")) + else + lastlinelength = getfield(n,"width") + end + else + lastlinelength = getfield(n,"width") + end + if lastlinelength > maxwidth then + maxwidth = lastlinelength + end + end + end + for h in traverse_id(hlist_code,list) do -- no dir etc needed + check(h,true) + end + for v in traverse_id(vlist_code,list) do -- no dir etc needed + check(v,false) + end +end |