diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/node-shp.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/node-shp.lua | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/node-shp.lua b/Master/texmf-dist/tex/context/base/mkiv/node-shp.lua index 306e38f6a58..2e7a3529a54 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/node-shp.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/node-shp.lua @@ -13,51 +13,50 @@ local format = string.format local concat, sortedpairs = table.concat, table.sortedpairs local setmetatableindex = table.setmetatableindex -local nodecodes = nodes.nodecodes -local whatsitcodes = nodes.whatsitcodes -local disccodes = nodes.disccodes +local nodecodes = nodes.nodecodes +local whatsitcodes = nodes.whatsitcodes +local disccodes = nodes.disccodes -local tasks = nodes.tasks -local handlers = nodes.handlers +local tasks = nodes.tasks +local handlers = nodes.handlers -local hlist_code = nodecodes.hlist -local vlist_code = nodecodes.vlist -local disc_code = nodecodes.disc -local whatsit_code = nodecodes.whatsit +local hlist_code = nodecodes.hlist +local vlist_code = nodecodes.vlist +local disc_code = nodecodes.disc +local whatsit_code = nodecodes.whatsit -local discretionarydisc_code = disccodes.discretionary +local fulldisc_code = disccodes.discretionary -local implement = interfaces.implement +local texgetbox = tex.getbox -local nuts = nodes.nuts -local tonut = nuts.tonut -local tonode = nuts.tonode -local remove_node = nuts.remove +local implement = interfaces.implement -local nextnode = nuts.traversers.node +local nuts = nodes.nuts +local tonut = nuts.tonut +local tonode = nuts.tonode +local remove_node = nuts.remove +local traverse_nodes = nuts.traverse -local setfield = nuts.setfield -local setlink = nuts.setlink -local setprev = nuts.setprev -local setnext = nuts.setnext -local getid = nuts.getid -local getdisc = nuts.getdisc -local getboth = nuts.getboth -local getnext = nuts.getnext -local getlist = nuts.getlist -local getsubtype = nuts.getsubtype +local setfield = nuts.setfield +local setlink = nuts.setlink +local setprev = nuts.setprev +local setnext = nuts.setnext +local getid = nuts.getid +local getdisc = nuts.getdisc +local getboth = nuts.getboth +local getnext = nuts.getnext +local getlist = nuts.getlist +local getsubtype = nuts.getsubtype -local setlist = nuts.setlist +local setlist = nuts.setlist -local getbox = nuts.getbox - -local removables = { +local removables = { [whatsitcodes.open] = true, [whatsitcodes.close] = true, [whatsitcodes.write] = true, [whatsitcodes.savepos] = true, [whatsitcodes.latelua] = true, - -- [whatsitcodes.pdfdest] = true, + [whatsitcodes.pdfdest] = true, } -- About 10% of the nodes make no sense for the backend. By (at least) @@ -73,7 +72,7 @@ local function cleanup_redundant(head) -- better name is: flatten_page while start do local id = getid(start) if id == disc_code then - if getsubtype(start) == discretionarydisc_code then + if getsubtype(start) == fulldisc_code then local _, _, replace, _, _ tail = getdisc(start,true) if replace then local prev, next = getboth(start) @@ -118,8 +117,6 @@ local function cleanup_redundant(head) -- better name is: flatten_page return head end -handlers.cleanuppage = cleanup_redundant -- nut - local function cleanup_flushed(head) -- rough local start = head while start do @@ -146,20 +143,26 @@ local function cleanup_flushed(head) -- rough return head end -function handlers.cleanupbox(box) - cleanup_flushed(getbox(box)) +function handlers.cleanuppage(head) + return tonode(cleanup_redundant(tonut(head))), true +end + +function handlers.cleanupbox(head) + return tonode(cleanup_flushed(tonut(head))), true end local actions = tasks.actions("shipouts") -function handlers.finalizebox(box) - actions(getbox(box)) -- nut +function handlers.finalize(head,where) -- problem, attr loaded before node, todo ... + return actions(head,where) end +-- handlers.finalize = actions + -- interface -implement { name = "cleanupbox", actions = handlers.cleanupbox, arguments = "integer" } -implement { name = "finalizebox", actions = handlers.finalizebox, arguments = "integer" } +implement { name = "cleanupbox", actions = { texgetbox, cleanup_flushed }, arguments = "integer" } +implement { name = "finalizebox", actions = { texgetbox, actions }, arguments = "integer" } -- just in case we want to optimize lookups: @@ -189,7 +192,8 @@ local function count(head,data,subcategory) -- no components, pre, post, replace .. can maybe an option .. but -- we use this for optimization so it makes sense to look the the -- main node only - for n, id in nextnode, tonut(head) do + for n in traverse_nodes(tonut(head)) do + local id = getid(n) local dn = data[nodecodes[id]] -- we could use id and then later convert to nodecodes dn[subcategory] = dn[subcategory] + 1 if id == hlist_code or id == vlist_code then |