From 64f6e8fc0c6cb9254a6fe3db0b4ab31c51cf8524 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 4 Apr 2019 14:11:01 +0200 Subject: 2019-04-04 13:38:00 --- tex/context/base/mkiv/anch-pos.lua | 128 +++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 55 deletions(-) (limited to 'tex/context/base/mkiv/anch-pos.lua') diff --git a/tex/context/base/mkiv/anch-pos.lua b/tex/context/base/mkiv/anch-pos.lua index 9438fa2a7..56250e16d 100644 --- a/tex/context/base/mkiv/anch-pos.lua +++ b/tex/context/base/mkiv/anch-pos.lua @@ -44,7 +44,6 @@ local scanners = interfaces.scanners local commands = commands local context = context -local ctxnode = context.nodes.flush local ctx_latelua = context.latelua @@ -75,7 +74,6 @@ local find_tail = nuts.tail local hpack = nuts.hpack local new_latelua = nuts.pool.latelua -local new_latelua_node = nodes.pool.latelua local variables = interfaces.variables local v_text = variables.text @@ -243,7 +241,6 @@ end -- t[#t+1] = data -- end -- --- -- -- local pages = structures.pages.collected -- if pages then -- local last = nil @@ -403,9 +400,29 @@ end -- analyze some files (with lots if margindata) and then when one key optionally -- use that one instead of a table (so, a 3rd / 4th argument: key, e.g. "x") -local function set(name,index,val) -- ,key - local data = enhance(val or index) - if val then +local function set(name,index,value) -- ,key + -- officially there should have been a settobesaved + local data = enhance(value or {}) + if value then + container = tobesaved[name] + if not container then + tobesaved[name] = { + [index] = data + } + else + container[index] = data + end + else + tobesaved[name] = data + end +end + +local function setspec(specification) + local name = specification.name + local index = specification.index + local value = specification.value + local data = enhance(value or {}) + if value then container = tobesaved[name] if not container then tobesaved[name] = { @@ -428,16 +445,11 @@ local function get(id,index) end end -------------.setdim = setdim -jobpositions.setall = setall -jobpositions.set = set -jobpositions.get = get - --- scanners.setpos = setall - --- trackers.enable("tokens.compi*") - --- something weird: the compiler fails us here +------------.setdim = setdim +jobpositions.setall = setall +jobpositions.set = set +jobpositions.setspec = setspec +jobpositions.get = get scanners.dosaveposition = compilescanner { actions = setall, -- name p x y @@ -459,7 +471,8 @@ scanners.dosavepositionplus = compilescanner { -- not much gain in keeping stack (inc/dec instead of insert/remove) -local function b_column(tag) +local function b_column(specification) + local tag = specification.tag local x = gethpos() tobesaved[tag] = { r = true, @@ -470,7 +483,7 @@ local function b_column(tag) column = tag end -local function e_column(tag) +local function e_column() local t = tobesaved[column] if not t then -- something's wrong @@ -496,8 +509,7 @@ scanners.bposcolumnregistered = function() -- tag local tag = scanstring() insert(columns,tag) column = tag --- ctxnode(new_latelua_node(function() b_column(tag) end)) - ctx_latelua(function() b_column(tag) end) + ctx_latelua { action = b_column, tag = tag } end scanners.eposcolumn = function() @@ -506,15 +518,15 @@ scanners.eposcolumn = function() end scanners.eposcolumnregistered = function() --- ctxnode(new_latelua_node(e_column)) - ctx_latelua(e_column) + ctx_latelua { action = e_column } remove(columns) column = columns[#columns] end -- regions -local function b_region(tag) +local function b_region(specification) + local tag = specification.tag or specification local last = tobesaved[tag] local x, y = getpos() last.x = x ~= 0 and x or nil @@ -524,11 +536,11 @@ local function b_region(tag) region = tag end -local function e_region(correct) +local function e_region(specification) local last = tobesaved[region] local y = getvpos() local x, y = getpos() - if correct then + if specification.correct then local h = (last.y or 0) - y last.h = h ~= 0 and h or nil end @@ -569,8 +581,8 @@ end local function markregionbox(n,tag,correct,...) -- correct needs checking local tag, box = setregionbox(n,tag,...) -- todo: check if tostring is needed with formatter - local push = new_latelua(function() b_region(tag) end) - local pop = new_latelua(function() e_region(correct) end) + local push = new_latelua { action = b_region, tag = tag } + local pop = new_latelua { action = e_region, correct = correct } -- maybe we should construct a hbox first (needs experimenting) so that we can avoid some at the tex end local head = getlist(box) -- no, this fails with \framed[region=...] .. needs thinking @@ -604,6 +616,13 @@ function jobpositions.gettobesaved(name,tag) end end +function jobpositions.settobesaved(name,tag,data) + local t = tobesaved[name] + if t and tag and data then + t[tag] = data + end +end + local nofparagraphs = 0 scanners.parpos = function() @@ -645,15 +664,14 @@ scanners.parpos = function() if parshape and #parshape > 0 then t.ps = parshape end - local tag = f_p_tag(nofparagraphs) - tobesaved[tag] = t --- ctxnode(new_latelua_node(function() enhance(tobesaved[tag]) end)) - ctx_latelua(function() enhance(tobesaved[tag]) end) + local name = f_p_tag(nofparagraphs) + tobesaved[name] = t + ctx_latelua { action = enhance, specification = t } end scanners.dosetposition = function() -- name local name = scanstring() - tobesaved[name] = { + local spec = { p = true, c = column, r = true, @@ -662,16 +680,16 @@ scanners.dosetposition = function() -- name n = nofparagraphs > 0 and nofparagraphs or nil, r2l = texgetcount("inlinelefttoright") == 1 or nil, } --- ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end)) - ctx_latelua(function() enhance(tobesaved[name]) end) + tobesaved[name] = spec + ctx_latelua { action = enhance, specification = spec } end scanners.dosetpositionwhd = function() -- name w h d extra local name = scanstring() - local w = scandimen() - local h = scandimen() - local d = scandimen() - tobesaved[name] = { + local w = scandimen() + local h = scandimen() + local d = scandimen() + local spec = { p = true, c = column, r = true, @@ -683,15 +701,15 @@ scanners.dosetpositionwhd = function() -- name w h d extra n = nofparagraphs > 0 and nofparagraphs or nil, r2l = texgetcount("inlinelefttoright") == 1 or nil, } --- ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end)) - ctx_latelua(function() enhance(tobesaved[name]) end) + tobesaved[name] = spec + ctx_latelua { action = enhance, specification = spec } end scanners.dosetpositionbox = function() -- name box local name = scanstring() local box = getbox(scaninteger()) local w, h, d = getwhd(box) - tobesaved[name] = { + local spec = { p = true, c = column, r = true, @@ -703,16 +721,16 @@ scanners.dosetpositionbox = function() -- name box n = nofparagraphs > 0 and nofparagraphs or nil, r2l = texgetcount("inlinelefttoright") == 1 or nil, } --- ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end)) - ctx_latelua(function() enhance(tobesaved[name]) end) + tobesaved[name] = spec + ctx_latelua { action = enhance, specification = spec } end scanners.dosetpositionplus = function() -- name w h d extra local name = scanstring() - local w = scandimen() - local h = scandimen() - local d = scandimen() - tobesaved[name] = { + local w = scandimen() + local h = scandimen() + local d = scandimen() + local spec = { p = true, c = column, r = true, @@ -725,15 +743,15 @@ scanners.dosetpositionplus = function() -- name w h d extra e = scanstring(), r2l = texgetcount("inlinelefttoright") == 1 or nil, } --- ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end)) - ctx_latelua(function() enhance(tobesaved[name]) end) + tobesaved[name] = spec + ctx_latelua { action = enhance, specification = spec } end scanners.dosetpositionstrut = function() -- name local name = scanstring() local box = getbox("strutbox") local w, h, d = getwhd(box) - tobesaved[name] = { + local spec = { p = true, c = column, r = true, @@ -744,8 +762,8 @@ scanners.dosetpositionstrut = function() -- name n = nofparagraphs > 0 and nofparagraphs or nil, r2l = texgetcount("inlinelefttoright") == 1 or nil, } --- ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end)) - ctx_latelua(function() enhance(tobesaved[name]) end) + tobesaved[name] = spec + ctx_latelua { action = enhance, specification = spec } end scanners.dosetpositionstrutkind = function() -- name @@ -753,7 +771,7 @@ scanners.dosetpositionstrutkind = function() -- name local kind = scaninteger() local box = getbox("strutbox") local w, h, d = getwhd(box) - tobesaved[name] = { + local spec = { k = kind, p = true, c = column, @@ -765,8 +783,8 @@ scanners.dosetpositionstrutkind = function() -- name n = nofparagraphs > 0 and nofparagraphs or nil, r2l = texgetcount("inlinelefttoright") == 1 or nil, } --- ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end)) - ctx_latelua(function() enhance(tobesaved[name]) end) + tobesaved[name] = spec + ctx_latelua { action = enhance, specification = spec } end function jobpositions.getreserved(tag,n) -- cgit v1.2.3