diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/anch-pos.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/anch-pos.lua | 175 |
1 files changed, 101 insertions, 74 deletions
diff --git a/Master/texmf-dist/tex/context/base/anch-pos.lua b/Master/texmf-dist/tex/context/base/anch-pos.lua index 2697cecf4e8..c2b62bae7d4 100644 --- a/Master/texmf-dist/tex/context/base/anch-pos.lua +++ b/Master/texmf-dist/tex/context/base/anch-pos.lua @@ -14,6 +14,10 @@ more efficient.</p> -- plus (extra) is obsolete but we will keep it for a while +-- context(new_latelua_node(f_enhance(tag))) +-- => +-- context.lateluafunction(function() f_enhance(tag) end) + -- maybe replace texsp by our own converter (stay at the lua end) -- eventually mp will have large numbers so we can use sp there too @@ -26,14 +30,29 @@ local rawget = rawget local lpegmatch = lpeg.match local insert, remove = table.insert, table.remove local allocate, mark = utilities.storage.allocate, utilities.storage.mark -local texsp, texcount, texbox, texdimen, texsetcount = tex.sp, tex.count, tex.box, tex.dimen, tex.setcount +local texsp = tex.sp ----- texsp = string.todimen -- because we cache this is much faster but no rounding +local texgetcount = tex.getcount +local texsetcount = tex.setcount +local texget = tex.get + local pdf = pdf -- h and v are variables local setmetatableindex = table.setmetatableindex -local new_latelua = nodes.pool.latelua -local find_tail = node.slide + +local nuts = nodes.nuts + +local getfield = nuts.getfield +local setfield = nuts.setfield +local getlist = nuts.getlist +local getbox = nuts.getbox +local getskip = nuts.getskip + +local find_tail = nuts.tail + +local new_latelua = nuts.pool.latelua +local new_latelua_node = nodes.pool.latelua local variables = interfaces.variables local v_text = variables.text @@ -159,9 +178,12 @@ local nofpages = nil -- beware ... we're not sparse here as lua will reserve slots for the nilled +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 setdim(name,w,h,d,extra) -- will be used when we move to sp allover - local x = pdf.h - local y = pdf.v + local x, y = getpos() if x == 0 then x = nil end if y == 0 then y = nil end if w == 0 then w = nil end @@ -170,7 +192,7 @@ local function setdim(name,w,h,d,extra) -- will be used when we move to sp allov if extra == "" then extra = nil end -- todo: sparse tobesaved[name] = { - p = texcount.realpageno, + p = texgetcount("realpageno"), x = x, y = y, w = w, @@ -211,13 +233,16 @@ local function enhance(data) data.r = region end if data.x == true then - data.x = pdf.h - end - if data.y == true then - data.y = pdf.v + if data.y == true then + data.x, data.y = getpos() + else + data.x = gethpos() + end + elseif data.y == true then + data.y = getvpos() end if data.p == true then - data.p = texcount.realpageno + data.p = texgetcount("realpageno") end if data.c == true then data.c = column @@ -269,10 +294,12 @@ commands.setpos = setall -- will become private table (could also become attribute driven but too nasty -- as attributes can bleed e.g. in margin stuff) +-- not much gain in keeping stack (inc/dec instead of insert/remove) + function jobpositions.b_col(tag) tobesaved[tag] = { r = true, - x = pdf.h, + x = gethpos(), w = 0, } insert(columns,tag) @@ -284,24 +311,24 @@ function jobpositions.e_col(tag) if not t then -- something's wrong else - t.w = pdf.h - t.x + t.w = gethpos() - t.x t.r = region end remove(columns) column = columns[#columns] end -function commands.bcolumn(tag,register) +function commands.bcolumn(tag,register) -- name will change insert(columns,tag) column = tag if register then - context(new_latelua(f_b_column(tag))) + context(new_latelua_node(f_b_column(tag))) end end -function commands.ecolumn(register) +function commands.ecolumn(register) -- name will change if register then - context(new_latelua(f_e_column())) + context(new_latelua_node(f_e_column())) end remove(columns) column = columns[#columns] @@ -311,19 +338,19 @@ end function jobpositions.b_region(tag) local last = tobesaved[tag] - last.x = pdf.h -last.y = pdf.v - last.p = texcount.realpageno + last.x, last.y = getpos() + last.p = texgetcount("realpageno") insert(regions,tag) region = tag end function jobpositions.e_region(correct) local last = tobesaved[region] -if correct then - last.h = last.y - pdf.v -end - last.y = pdf.v + local v = getvpos() + if correct then + last.h = last.y - v + end + last.y = v remove(regions) region = regions[#regions] end @@ -333,14 +360,14 @@ function jobpositions.markregionbox(n,tag,correct) nofregions = nofregions + 1 tag = f_region(nofregions) end - local box = texbox[n] - local w = box.width - local h = box.height - local d = box.depth + local box = getbox(n) + local w = getfield(box,"width") + local h = getfield(box,"height") + local d = getfield(box,"depth") tobesaved[tag] = { p = true, x = true, - y = pdf.v, -- true, + y = getvpos(), -- true, w = w ~= 0 and w or nil, h = h ~= 0 and h or nil, d = d ~= 0 and d or nil, @@ -348,18 +375,18 @@ function jobpositions.markregionbox(n,tag,correct) local push = new_latelua(f_b_region(tag)) local pop = new_latelua(f_e_region(tostring(correct))) -- todo: check if tostring is needed with formatter -- maybe we should construct a hbox first (needs experimenting) so that we can avoid some at the tex end - local head = box.list + local head = getlist(box) if head then local tail = find_tail(head) - head.prev = push - push.next = head - pop .prev = tail - tail.next = pop + setfield(head,"prev",push) + setfield(push,"next",head) + setfield(pop,"prev",tail) + setfield(tail,"next",pop) else -- we can have a simple push/pop - push.next = pop - pop.prev = push + setfield(push,"next",pop) + setfield(pop,"prev",push) end - box.list = push + setfield(box,"list",push) end function jobpositions.enhance(name) @@ -368,7 +395,7 @@ end function commands.pos(name,t) tobesaved[name] = t - context(new_latelua(f_enhance(name))) + context(new_latelua_node(f_enhance(name))) end local nofparagraphs = 0 @@ -376,23 +403,23 @@ local nofparagraphs = 0 function commands.parpos() -- todo: relate to localpar (so this is an intermediate variant) nofparagraphs = nofparagraphs + 1 texsetcount("global","c_anch_positions_paragraph",nofparagraphs) - local strutbox = texbox.strutbox + local strutbox = getbox("strutbox") local t = { p = true, c = true, r = true, x = true, y = true, - h = strutbox.height, - d = strutbox.depth, - hs = tex.hsize, + h = getfield(strutbox,"height"), + d = getfield(strutbox,"depth"), + hs = texget("hsize"), } - local leftskip = tex.leftskip.width - local rightskip = tex.rightskip.width - local hangindent = tex.hangindent - local hangafter = tex.hangafter - local parindent = tex.parindent - local parshape = tex.parshape + local leftskip = getfield(getskip("leftskip"),"width") + local rightskip = getfield(getskip("rightskip"),"width") + local hangindent = texget("hangindent") + local hangafter = texget("hangafter") + local parindent = texget("parindent") + local parshape = texget("parshape") if leftskip ~= 0 then t.ls = leftskip end @@ -413,7 +440,7 @@ function commands.parpos() -- todo: relate to localpar (so this is an intermedia end local tag = f_p_tag(nofparagraphs) tobesaved[tag] = t - context(new_latelua(f_enhance(tag))) + context(new_latelua_node(f_enhance(tag))) end function commands.posxy(name) -- can node.write be used here? @@ -425,7 +452,7 @@ function commands.posxy(name) -- can node.write be used here? y = true, n = nofparagraphs > 0 and nofparagraphs or nil, } - context(new_latelua(f_enhance(name))) + context(new_latelua_node(f_enhance(name))) end function commands.poswhd(name,w,h,d) @@ -440,7 +467,7 @@ function commands.poswhd(name,w,h,d) d = d, n = nofparagraphs > 0 and nofparagraphs or nil, } - context(new_latelua(f_enhance(name))) + context(new_latelua_node(f_enhance(name))) end function commands.posplus(name,w,h,d,extra) @@ -456,27 +483,27 @@ function commands.posplus(name,w,h,d,extra) n = nofparagraphs > 0 and nofparagraphs or nil, e = extra, } - context(new_latelua(f_enhance(name))) + context(new_latelua_node(f_enhance(name))) end function commands.posstrut(name,w,h,d) - local strutbox = texbox.strutbox + local strutbox = getbox("strutbox") tobesaved[name] = { p = true, c = column, r = true, x = true, y = true, - h = strutbox.height, - d = strutbox.depth, + h = getfield(strutbox,"height"), + d = getfield(strutbox,"depth"), n = nofparagraphs > 0 and nofparagraphs or nil, } - context(new_latelua(f_enhance(name))) + context(new_latelua_node(f_enhance(name))) end function jobpositions.getreserved(tag,n) if tag == v_column then - local fulltag = f_tag_three(tag,texcount.realpageno,n or 1) + local fulltag = f_tag_three(tag,texgetcount("realpageno"),n or 1) local data = collected[fulltag] if data then return data, fulltag @@ -484,7 +511,7 @@ function jobpositions.getreserved(tag,n) tag = v_text end if tag == v_text then - local fulltag = f_tag_two(tag,texcount.realpageno) + local fulltag = f_tag_two(tag,texgetcount("realpageno")) return collected[fulltag] or false, fulltag end return collected[tag] or false, tag @@ -731,7 +758,7 @@ function commands.MPx(id) if jpi then local x = jpi.x if x and x ~= true and x ~= 0 then - context("%.5fpt",x*pt) + context("%.5Fpt",x*pt) return end end @@ -743,7 +770,7 @@ function commands.MPy(id) if jpi then local y = jpi.y if y and y ~= true and y ~= 0 then - context("%.5fpt",y*pt) + context("%.5Fpt",y*pt) return end end @@ -755,7 +782,7 @@ function commands.MPw(id) if jpi then local w = jpi.w if w and w ~= 0 then - context("%.5fpt",w*pt) + context("%.5Fpt",w*pt) return end end @@ -767,7 +794,7 @@ function commands.MPh(id) if jpi then local h = jpi.h if h and h ~= 0 then - context("%.5fpt",h*pt) + context("%.5Fpt",h*pt) return end end @@ -779,7 +806,7 @@ function commands.MPd(id) if jpi then local d = jpi.d if d and d ~= 0 then - context("%.5fpt",d*pt) + context("%.5Fpt",d*pt) return end end @@ -789,7 +816,7 @@ end function commands.MPxy(id) local jpi = collected[id] if jpi then - context('(%.5fpt,%.5fpt)', + context('(%.5Fpt,%.5Fpt)', jpi.x*pt, jpi.y*pt ) @@ -801,7 +828,7 @@ end function commands.MPll(id) local jpi = collected[id] if jpi then - context('(%.5fpt,%.5fpt)', + context('(%.5Fpt,%.5Fpt)', jpi.x *pt, (jpi.y-jpi.d)*pt ) @@ -813,7 +840,7 @@ end function commands.MPlr(id) local jpi = collected[id] if jpi then - context('(%.5fpt,%.5fpt)', + context('(%.5Fpt,%.5Fpt)', (jpi.x + jpi.w)*pt, (jpi.y - jpi.d)*pt ) @@ -825,7 +852,7 @@ end function commands.MPur(id) local jpi = collected[id] if jpi then - context('(%.5fpt,%.5fpt)', + context('(%.5Fpt,%.5Fpt)', (jpi.x + jpi.w)*pt, (jpi.y + jpi.h)*pt ) @@ -837,7 +864,7 @@ end function commands.MPul(id) local jpi = collected[id] if jpi then - context('(%.5fpt,%.5fpt)', + context('(%.5Fpt,%.5Fpt)', jpi.x *pt, (jpi.y + jpi.h)*pt ) @@ -851,7 +878,7 @@ local function MPpos(id) if jpi then local p = jpi.p if p then - context("%s,%.5fpt,%.5fpt,%.5fpt,%.5fpt,%.5fpt", + context("%s,%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt", p, jpi.x*pt, jpi.y*pt, @@ -909,7 +936,7 @@ local function MPpardata(n) t = collected[tag] end if t then - context("%.5fpt,%.5fpt,%.5fpt,%.5fpt,%s,%.5fpt", + context("%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt,%s,%.5Fpt", t.hs*pt, t.ls*pt, t.rs*pt, @@ -935,7 +962,7 @@ end function commands.MPls(id) local t = collected[id] if t then - context("%.5fpt",t.ls*pt) + context("%.5Fpt",t.ls*pt) else context("0pt") end @@ -944,7 +971,7 @@ end function commands.MPrs(id) local t = collected[id] if t then - context("%.5fpt",t.rs*pt) + context("%.5Fpt",t.rs*pt) else context("0pt") end @@ -977,7 +1004,7 @@ end function commands.MPxywhd(id) local t = collected[id] if t then - context("%.5fpt,%.5fpt,%.5fpt,%.5fpt,%.5fpt", + context("%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt", t.x*pt, t.y*pt, t.w*pt, @@ -1013,7 +1040,7 @@ function commands.doifpositionsonsamepageelse(list,page) end function commands.doifpositionsonthispageelse(list) - doifelse(onsamepage(list,tostring(tex.count.realpageno))) + doifelse(onsamepage(list,tostring(texgetcount("realpageno")))) end function commands.doifelsepositionsused() |