summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/page-flt.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/page-flt.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/page-flt.lua115
1 files changed, 80 insertions, 35 deletions
diff --git a/Master/texmf-dist/tex/context/base/page-flt.lua b/Master/texmf-dist/tex/context/base/page-flt.lua
index 74d1e4e8c04..b691dbd45c1 100644
--- a/Master/texmf-dist/tex/context/base/page-flt.lua
+++ b/Master/texmf-dist/tex/context/base/page-flt.lua
@@ -6,18 +6,25 @@ if not modules then modules = { } end modules ['page-flt'] = {
license = "see context related readme files"
}
-local setdimen, setbox, setcount, texbox = tex.setdimen, tex.setbox, tex.setcount, tex.box
+-- floats -> managers.floats
+
local insert, remove = table.insert, table.remove
-local texwrite, texsprint, ctxcatcodes = tex.write, tex.sprint, tex.ctxcatcodes
+local find = string.find
+local setdimen, setcount, texbox = tex.setdimen, tex.setcount, tex.box
local copy_node_list = node.copy_list
local trace_floats = false trackers.register("graphics.floats", function(v) trace_floats = v end) -- name might change
+local report_floats = logs.reporter("structure","floats")
+
+local C, S, P, lpegmatch = lpeg.C, lpeg.S, lpeg.P, lpeg.match
+
-- we use floatbox, floatwidth, floatheight
-- text page leftpage rightpage (todo: top, bottom, margin, order)
-floats = floats or { }
+floats = floats or { }
+local floats = floats
local noffloats, last, default, pushed = 0, nil, "text", { }
@@ -27,6 +34,7 @@ local function initialize()
page = { },
leftpage = { },
rightpage = { },
+ somewhere = { },
}
end
@@ -39,7 +47,7 @@ function floats.stacked(which) -- floats.thenofstacked
end
function floats.thestacked(which)
- return texwrite(#stacks[which or default])
+ return context(#stacks[which or default])
end
function floats.push()
@@ -71,34 +79,48 @@ local function setdimensions(b)
return w, h, d
end
-local function get(stack,n)
- n = n or #stack
- if n > 0 then
- local t = stack[n]
- if t then
- return t, t.box, n
+local function get(stack,n,bylabel)
+ if bylabel then
+ for i=1,#stack do
+ local s = stack[i]
+ local n = string.topattern(tostring(n)) -- to be sure
+ if find(s.data.label,n) then
+ return s, s.box, i
+ end
+ end
+ else
+ n = n or #stack
+ if n > 0 then
+ local t = stack[n]
+ if t then
+ return t, t.box, n
+ end
end
end
end
function floats.save(which,data)
which = which or default
- local stack = stacks[which]
- noffloats = noffloats + 1
local b = texbox.floatbox
- local w, h, d = b.width, b.height, b.depth
- local t = {
- n = noffloats,
- data = data or { },
- box = copy_node_list(b),
- }
- texbox.floatbox = nil
- insert(stack,t)
- setcount("global","savednoffloats",#stacks[default])
- if trace_floats then
- logs.report("floats","saving %s float %s in slot %s (%i,%i,%i)",which,noffloats,#stack,w,h,d)
+ if b then
+ local stack = stacks[which]
+ noffloats = noffloats + 1
+ local w, h, d = b.width, b.height, b.depth
+ local t = {
+ n = noffloats,
+ data = data or { },
+ box = copy_node_list(b),
+ }
+ texbox.floatbox = nil
+ insert(stack,t)
+ setcount("global","savednoffloats",#stacks[default])
+ if trace_floats then
+ report_floats("saving %s float %s in slot %s (%i,%i,%i)",which,noffloats,#stack,w,h,d)
+ else
+ interfaces.showmessage("floatblocks",2,noffloats)
+ end
else
- interfaces.showmessage("floatblocks",2,noffloats)
+ report_floats("unable to save %s float %s (empty)",which,noffloats)
end
end
@@ -113,30 +135,30 @@ function floats.resave(which)
insert(stack,1,last)
setcount("global","savednoffloats",#stacks[default])
if trace_floats then
- logs.report("floats","resaving %s float %s in slot %s (%i,%i,%i)",which,noffloats,#stack,w,h,d)
+ report_floats("resaving %s float %s in slot %s (%i,%i,%i)",which,noffloats,#stack,w,h,d)
else
interfaces.showmessage("floatblocks",2,noffloats)
end
else
- logs.report("floats","unable to resave float")
+ report_floats("unable to resave float")
end
end
-function floats.flush(which,n)
+function floats.flush(which,n,bylabel)
which = which or default
local stack = stacks[which]
- local t, b, n = get(stack,n or 1)
+ local t, b, n = get(stack,n or 1,bylabel)
if t then
local w, h, d = setdimensions(b)
if trace_floats then
- logs.report("floats","flushing %s float %s from slot %s (%i,%i,%i)",which,t.n,n,w,h,d)
+ report_floats("flushing %s float %s from slot %s (%i,%i,%i)",which,t.n,n,w,h,d)
else
interfaces.showmessage("floatblocks",3,t.n)
end
texbox.floatbox = b
last = remove(stack,n)
last.box = nil
- setcount("global","savednoffloats",#stacks[default])
+ setcount("global","savednoffloats",#stacks[default]) -- default?
else
setdimensions()
end
@@ -145,7 +167,7 @@ end
function floats.thevar(name,default)
local value = last and last.data[name] or default
if value and value ~= "" then
- texsprint(ctxcatcodes,value)
+ context(value)
end
end
@@ -156,12 +178,12 @@ function floats.consult(which,n)
if t then
local w, h, d = setdimensions(b)
if trace_floats then
- logs.report("floats","consulting %s float %s in slot %s (%i,%i,%i)",which,t.n,n,w,h,d)
+ report_floats("consulting %s float %s in slot %s (%i,%i,%i)",which,t.n,n,w,h,d)
end
return t, b, n
else
if trace_floats then
- logs.report("floats","nothing to consult")
+ report_floats("nothing to consult")
end
setdimensions()
end
@@ -198,7 +220,7 @@ end
function floats.thecheckedpagefloat(packed)
local result = ""
- if structure.pages.is_odd() then
+ if structures.pages.is_odd() then
if #stacks.rightpage > 0 then
result = "rightpage"
elseif #stacks.page > 0 then
@@ -223,5 +245,28 @@ function floats.thecheckedpagefloat(packed)
end
end
end
- texsprint(ctxcatcodes,result)
+ context(result)
+end
+
+local method = C((1-S(", :"))^1)
+local position = P(":") * C((1-S("*,"))^1) * P("*") * C((1-S(","))^1)
+local label = P(":") * C((1-S(",*: "))^0)
+
+local pattern = method * (label * position + C("") * position + label + C("") * C("") * C(""))
+
+-- table.print { lpeg.match(pattern,"somewhere:blabla,crap") }
+-- table.print { lpeg.match(pattern,"somewhere:1*2") }
+-- table.print { lpeg.match(pattern,"somewhere:blabla:1*2") }
+-- table.print { lpeg.match(pattern,"somewhere::1*2") }
+-- table.print { lpeg.match(pattern,"somewhere,") }
+-- table.print { lpeg.match(pattern,"somewhere") }
+
+function floats.analysemethod(str)
+ if str ~= "" then -- extra check, already done at the tex end
+ local method, label, row, column = lpegmatch(pattern,str)
+ context.setvalue("floatmethod",method or "")
+ context.setvalue("floatlabel", label or "")
+ context.setvalue("floatrow", row or "")
+ context.setvalue("floatcolumn",column or "")
+ end
end