diff options
Diffstat (limited to 'tex/context/base/spac-ali.lua')
-rw-r--r-- | tex/context/base/spac-ali.lua | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/tex/context/base/spac-ali.lua b/tex/context/base/spac-ali.lua index 25cc6cd66..880da6213 100644 --- a/tex/context/base/spac-ali.lua +++ b/tex/context/base/spac-ali.lua @@ -10,13 +10,26 @@ local div = math.div local format = string.format local tasks = nodes.tasks -local appendaction = tasks.appendaction -local prependaction = tasks.prependaction -local disableaction = tasks.disableaction local enableaction = tasks.enableaction -local slide_nodes = node.slide -local hpack_nodes = node.hpack -- nodes.fasthpack not really faster here +local nuts = nodes.nuts +local nodepool = nuts.pool + +local tonode = nuts.tonode +local tonut = nuts.tonut + +local getfield = nuts.getfield +local setfield = nuts.setfield +local getnext = nuts.getnext +local getprev = nuts.getprev +local getid = nuts.getid +local getlist = nuts.getlist +local getattr = nuts.getattr +local setattr = nuts.setattr +local getsubtype = nuts.getsubtype + +local hpack_nodes = nuts.hpack -- nodes.fasthpack not really faster here +local linked_nodes = nuts.linked local unsetvalue = attributes.unsetvalue @@ -27,8 +40,6 @@ local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist local line_code = listcodes.line -local nodepool = nodes.pool - local new_stretch = nodepool.stretch local a_realign = attributes.private("realign") @@ -56,10 +67,10 @@ local function handler(head,leftpage,realpageno) local current = head local done = false while current do - local id = current.id + local id = getid(current) if id == hlist_code then - if current.subtype == line_code then - local a = current[a_realign] + if getsubtype(current) == line_code then + local a = getattr(current,a_realign) if not a or a == 0 then -- skip else @@ -75,12 +86,12 @@ local function handler(head,leftpage,realpageno) action = leftpage and 2 or 1 end if action == 1 then - current.list = hpack_nodes(current.list .. new_stretch(3),current.width,"exactly") + setfield(current,"list",hpack_nodes(linked_nodes(getlist(current),new_stretch(3)),getfield(current,"width"),"exactly")) if trace_realign then report_realign("flushing left, align %a, page %a, realpage %a",align,pageno,realpageno) end elseif action == 2 then - current.list = hpack_nodes(new_stretch(3) .. current.list,current.width,"exactly") + setfield(current,"list",hpack_nodes(linked_nodes(new_stretch(3),getlist(current)),getfield(current,"width"),"exactly")) if trace_realign then report_realign("flushing right. align %a, page %a, realpage %a",align,pageno,realpageno) end @@ -90,14 +101,14 @@ local function handler(head,leftpage,realpageno) done = true nofrealigned = nofrealigned + 1 end - current[a_realign] = unsetvalue + setattr(current,a_realign,unsetvalue) end end - handler(current.list,leftpage,realpageno) + handler(getlist(current),leftpage,realpageno) elseif id == vlist_code then - handler(current.list,leftpage,realpageno) + handler(getlist(current),leftpage,realpageno) end - current = current.next + current = getnext(current) end return head, done end @@ -105,7 +116,8 @@ end function alignments.handler(head) local leftpage = isleftpage(true,false) local realpageno = texgetcount("realpageno") - return handler(head,leftpage,realpageno) + local head, done = handler(tonut(head),leftpage,realpageno) + return tonode(head), done end local enabled = false @@ -121,7 +133,11 @@ function alignments.set(n) texsetattribute(a_realign,texgetcount("realpageno") * 10 + n) end -commands.setrealign = alignments.set +interfaces.implement { + name = "setrealign", + actions = alignments.set, + arguments = "integer", +} statistics.register("realigning", function() if nofrealigned > 0 then |