summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/anch-pos.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/anch-pos.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/anch-pos.lua166
1 files changed, 64 insertions, 102 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/anch-pos.lua b/Master/texmf-dist/tex/context/base/mkiv/anch-pos.lua
index ade99279201..e5f58c36ce4 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/anch-pos.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/anch-pos.lua
@@ -20,12 +20,8 @@ more efficient.</p>
-- this is one of the first modules using scanners and we need to replace
-- it by implement and friends
--- we could have namespaces, like p, page, region, columnarea, textarea but then
--- we need virtual table accessors as well as have tag/id accessors ... we don't
--- save much here (at least not now)
-
local tostring, next, rawget, rawset, setmetatable, tonumber = tostring, next, rawget, rawset, setmetatable, tonumber
-local sort = table.sort
+local sort, sortedhash, sortedkeys = table.sort, table.sortedhash, table.sortedkeys
local format, gmatch = string.format, string.gmatch
local rawget = rawget
local lpegmatch = lpeg.match
@@ -44,8 +40,7 @@ local scanners = interfaces.scanners
local commands = commands
local context = context
-
-local ctx_latelua = context.latelua
+local ctxnode = context.nodes.flush
local tex = tex
local texgetcount = tex.getcount
@@ -68,12 +63,12 @@ local getbox = nuts.getbox
local getid = nuts.getid
local getwhd = nuts.getwhd
-local hlist_code = nodes.nodecodes.hlist
+----- hlist_code = nodes.listcodes.hlist
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
@@ -241,6 +236,7 @@ end
-- t[#t+1] = data
-- end
--
+-- --
-- local pages = structures.pages.collected
-- if pages then
-- local last = nil
@@ -330,19 +326,9 @@ local nofpages = nil
-- beware ... we're not sparse here as lua will reserve slots for the nilled
-local getpos, gethpos, getvpos
-
-function jobpositions.registerhandlers(t)
- getpos = t and t.getpos or function() return 0, 0 end
- gethpos = t and t.gethpos or function() return 0 end
- getvpos = t and t.getvpos or function() return 0 end
-end
-
-function jobpositions.getpos () return getpos () end
-function jobpositions.gethpos() return gethpos() end
-function jobpositions.getvpos() return getvpos() end
-
-jobpositions.registerhandlers()
+local getpos = function() getpos = backends.codeinjections.getpos return getpos () end
+local gethpos = function() gethpos = backends.codeinjections.gethpos return gethpos() end
+local getvpos = function() getvpos = backends.codeinjections.getvpos return getvpos() end
local function setall(name,p,x,y,w,h,d,extra)
tobesaved[name] = {
@@ -400,28 +386,9 @@ 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,value) -- ,key
- local data = enhance(value or index)
- 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 index)
- if value then
+local function set(name,index,val) -- ,key
+ local data = enhance(val or index)
+ if val then
container = tobesaved[name]
if not container then
tobesaved[name] = {
@@ -444,11 +411,16 @@ local function get(id,index)
end
end
-------------.setdim = setdim
-jobpositions.setall = setall
-jobpositions.set = set
-jobpositions.setspec = setspec
-jobpositions.get = get
+------------.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
scanners.dosaveposition = compilescanner {
actions = setall, -- name p x y
@@ -470,8 +442,7 @@ scanners.dosavepositionplus = compilescanner {
-- not much gain in keeping stack (inc/dec instead of insert/remove)
-local function b_column(specification)
- local tag = specification.tag
+local function b_column(tag)
local x = gethpos()
tobesaved[tag] = {
r = true,
@@ -482,7 +453,7 @@ local function b_column(specification)
column = tag
end
-local function e_column()
+local function e_column(tag)
local t = tobesaved[column]
if not t then
-- something's wrong
@@ -508,7 +479,7 @@ scanners.bposcolumnregistered = function() -- tag
local tag = scanstring()
insert(columns,tag)
column = tag
- ctx_latelua { action = b_column, tag = tag }
+ ctxnode(new_latelua_node(function() b_column(tag) end))
end
scanners.eposcolumn = function()
@@ -517,42 +488,38 @@ scanners.eposcolumn = function()
end
scanners.eposcolumnregistered = function()
- ctx_latelua { action = e_column }
+ ctxnode(new_latelua_node(e_column))
remove(columns)
column = columns[#columns]
end
-- regions
-local function b_region(specification)
- local tag = specification.tag or specification
+local function b_region(tag)
local last = tobesaved[tag]
local x, y = getpos()
last.x = x ~= 0 and x or nil
last.y = y ~= 0 and y or nil
last.p = texgetcount("realpageno")
- insert(regions,tag) -- todo: fast stack
+ insert(regions,tag)
region = tag
end
-local function e_region(specification)
+local function e_region(correct)
local last = tobesaved[region]
local y = getvpos()
- local x, y = getpos()
- if specification.correct then
+ if correct then
local h = (last.y or 0) - y
last.h = h ~= 0 and h or nil
end
last.y = y ~= 0 and y or nil
- remove(regions) -- todo: fast stack
+ remove(regions)
region = regions[#regions]
end
jobpositions.b_region = b_region
jobpositions.e_region = e_region
-local lastregion
-
local function setregionbox(n,tag,k,lo,ro,to,bo) -- kind
if not tag or tag == "" then
nofregions = nofregions + 1
@@ -560,34 +527,34 @@ local function setregionbox(n,tag,k,lo,ro,to,bo) -- kind
end
local box = getbox(n)
local w, h, d = getwhd(box)
+ local x, y = getpos() -- hm, makes no sense here
tobesaved[tag] = {
- -- p = texgetcount("realpageno"), -- we copy them
- x = 0,
- y = 0,
- w = w ~= 0 and w or nil,
- h = h ~= 0 and h or nil,
- d = d ~= 0 and d or nil,
- k = k ~= 0 and k or nil,
+ -- p = texgetcount("realpageno"), -- we copy them
+ x = x ~= 0 and x or nil, -- was true
+ y = y ~= 0 and y or nil,
+ w = w ~= 0 and w or nil,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ k = k ~= 0 and k or nil,
lo = lo ~= 0 and lo or nil,
ro = ro ~= 0 and ro or nil,
to = to ~= 0 and to or nil,
bo = bo ~= 0 and bo or nil,
}
- lastregion = tag
return tag, box
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 { action = b_region, tag = tag }
- local pop = new_latelua { action = e_region, correct = correct }
+ local push = new_latelua(function() b_region(tag) end)
+ local pop = new_latelua(function() e_region(correct) end)
-- 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
+ -- no :
-- if getid(box) ~= hlist_code then
-- -- report("mark region box assumes a hlist, fix this for %a",tag)
- -- head = hpack(head)
+ -- head = nuts.hpack(head)
-- end
if head then
local tail = find_tail(head)
@@ -617,7 +584,7 @@ end
local nofparagraphs = 0
-scanners.parpos = function()
+scanners.parpos = function() -- todo: relate to localpar (so this is an intermediate variant)
nofparagraphs = nofparagraphs + 1
texsetcount("global","c_anch_positions_paragraph",nofparagraphs)
local box = getbox("strutbox")
@@ -656,14 +623,14 @@ scanners.parpos = function()
if parshape and #parshape > 0 then
t.ps = parshape
end
- local name = f_p_tag(nofparagraphs)
- tobesaved[name] = t
- ctx_latelua { action = enhance, specification = t }
+ local tag = f_p_tag(nofparagraphs)
+ tobesaved[tag] = t
+ ctxnode(new_latelua_node(function() enhance(tobesaved[tag]) end))
end
scanners.dosetposition = function() -- name
local name = scanstring()
- local spec = {
+ tobesaved[name] = {
p = true,
c = column,
r = true,
@@ -672,15 +639,15 @@ scanners.dosetposition = function() -- name
n = nofparagraphs > 0 and nofparagraphs or nil,
r2l = texgetcount("inlinelefttoright") == 1 or nil,
}
- ctx_latelua { action = enhance, specification = spec }
+ ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end))
end
scanners.dosetpositionwhd = function() -- name w h d extra
local name = scanstring()
- local w = scandimen()
- local h = scandimen()
- local d = scandimen()
- local spec = {
+ local w = scandimen()
+ local h = scandimen()
+ local d = scandimen()
+ tobesaved[name] = {
p = true,
c = column,
r = true,
@@ -692,14 +659,14 @@ scanners.dosetpositionwhd = function() -- name w h d extra
n = nofparagraphs > 0 and nofparagraphs or nil,
r2l = texgetcount("inlinelefttoright") == 1 or nil,
}
- ctx_latelua { action = enhance, specification = spec }
+ ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end))
end
scanners.dosetpositionbox = function() -- name box
local name = scanstring()
local box = getbox(scaninteger())
local w, h, d = getwhd(box)
- local spec = {
+ tobesaved[name] = {
p = true,
c = column,
r = true,
@@ -711,15 +678,15 @@ scanners.dosetpositionbox = function() -- name box
n = nofparagraphs > 0 and nofparagraphs or nil,
r2l = texgetcount("inlinelefttoright") == 1 or nil,
}
- ctx_latelua { action = enhance, specification = spec }
+ ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end))
end
scanners.dosetpositionplus = function() -- name w h d extra
local name = scanstring()
- local w = scandimen()
- local h = scandimen()
- local d = scandimen()
- local spec = {
+ local w = scandimen()
+ local h = scandimen()
+ local d = scandimen()
+ tobesaved[name] = {
p = true,
c = column,
r = true,
@@ -732,14 +699,14 @@ scanners.dosetpositionplus = function() -- name w h d extra
e = scanstring(),
r2l = texgetcount("inlinelefttoright") == 1 or nil,
}
- ctx_latelua { action = enhance, specification = spec }
+ ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end))
end
scanners.dosetpositionstrut = function() -- name
local name = scanstring()
local box = getbox("strutbox")
local w, h, d = getwhd(box)
- local spec = {
+ tobesaved[name] = {
p = true,
c = column,
r = true,
@@ -750,7 +717,7 @@ scanners.dosetpositionstrut = function() -- name
n = nofparagraphs > 0 and nofparagraphs or nil,
r2l = texgetcount("inlinelefttoright") == 1 or nil,
}
- ctx_latelua { action = enhance, specification = spec }
+ ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end))
end
scanners.dosetpositionstrutkind = function() -- name
@@ -758,7 +725,7 @@ scanners.dosetpositionstrutkind = function() -- name
local kind = scaninteger()
local box = getbox("strutbox")
local w, h, d = getwhd(box)
- local spec = {
+ tobesaved[name] = {
k = kind,
p = true,
c = column,
@@ -770,7 +737,7 @@ scanners.dosetpositionstrutkind = function() -- name
n = nofparagraphs > 0 and nofparagraphs or nil,
r2l = texgetcount("inlinelefttoright") == 1 or nil,
}
- ctx_latelua { action = enhance, specification = spec }
+ ctxnode(new_latelua_node(function() enhance(tobesaved[name]) end))
end
function jobpositions.getreserved(tag,n)
@@ -1410,11 +1377,6 @@ scanners.markregionboxtaggedkind = function() -- box tag kind
scaninteger(),scandimen(),scandimen(),scandimen(),scandimen())
end
-scanners.reservedautoregiontag = function()
- nofregions = nofregions + 1
- context(f_region(nofregions))
-end
-
-- statistics (at least for the moment, when testing)
-- statistics.register("positions", function()