summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/typo-pag.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/typo-pag.lua')
-rw-r--r--tex/context/base/mkiv/typo-pag.lua32
1 files changed, 20 insertions, 12 deletions
diff --git a/tex/context/base/mkiv/typo-pag.lua b/tex/context/base/mkiv/typo-pag.lua
index 355becff6..d6f71c8cc 100644
--- a/tex/context/base/mkiv/typo-pag.lua
+++ b/tex/context/base/mkiv/typo-pag.lua
@@ -34,7 +34,13 @@ local getnext = nuts.getnext
local getprev = nuts.getprev
local getid = nuts.getid
local getattr = nuts.getattr
+local takeattr = nuts.takeattr
local setattr = nuts.setattr
+local getwhd = nuts.getwhd
+local getkern = nuts.getkern
+local setpenalty = nuts.setpenalty
+local getwidth = nuts.getwidth
+local getdepth = nuts.getdepth
local insert_node_after = nuts.insert_after
local new_penalty = nuts.pool.penalty
@@ -42,6 +48,8 @@ local new_penalty = nuts.pool.penalty
local trace_keeptogether = false
local report_keeptogether = logs.reporter("parbuilders","keeptogether")
+local enableaction = nodes.tasks.enableaction
+
local cache = { }
local last = 0
local enabled = false
@@ -56,7 +64,7 @@ function parbuilders.registertogether(line,specification) -- might change
return
end
if not enabled then
- nodes.tasks.enableaction("finalizers","builders.paragraphs.keeptogether")
+ enableaction("finalizers","builders.paragraphs.keeptogether")
end
local a = getattr(line,a_keeptogether)
local c = a and cache[a]
@@ -109,7 +117,7 @@ local function keeptogether(start,a)
if a then
local current = getnext(start)
local previous = start
- local total = getfield(previous,"depth")
+ local total = getdepth(previous)
local slack = specification.slack
local threshold = specification.depth - slack
if trace_keeptogether then
@@ -118,13 +126,14 @@ local function keeptogether(start,a)
while current do
local id = getid(current)
if id == vlist_code or id == hlist_code then
- total = total + getfield(current,"height") + getfield(current,"depth")
+ local wd, ht, dp = getwhd(current)
+ total = total + ht + dp
if trace_keeptogether then
report_keeptogether("%s, index %s, total %p, threshold %p","list",a,total,threshold)
end
if total <= threshold then
if getid(previous) == penalty_code then
- setfield(previous,"penalty",10000)
+ setpenalty(previous,10000)
else
insert_node_after(head,previous,new_penalty(10000))
end
@@ -133,13 +142,13 @@ local function keeptogether(start,a)
end
elseif id == glue_code then
-- hm, breakpoint, maybe turn this into kern
- total = total + getfield(current,"width")
+ total = total + getwidth(current)
if trace_keeptogether then
report_keeptogether("%s, index %s, total %p, threshold %p","glue",a,total,threshold)
end
if total <= threshold then
if getid(previous) == penalty_code then
- setfield(previous,"penalty",10000)
+ setpenalty(previous,10000)
else
insert_node_after(head,previous,new_penalty(10000))
end
@@ -147,13 +156,13 @@ local function keeptogether(start,a)
break
end
elseif id == kern_code then
- total = total + getfield(current,"kern")
+ total = total + getkern(current)
if trace_keeptogether then
report_keeptogether("%s, index %s, total %s, threshold %s","kern",a,total,threshold)
end
if total <= threshold then
if getid(previous) == penalty_code then
- setfield(previous,"penalty",10000)
+ setpenalty(previous,10000)
else
insert_node_after(head,previous,new_penalty(10000))
end
@@ -163,9 +172,9 @@ local function keeptogether(start,a)
elseif id == penalty_code then
if total <= threshold then
if getid(previous) == penalty_code then
- setfield(previous,"penalty",10000)
+ setpenalty(previous,10000)
end
- setfield(current,"penalty",10000)
+ setpenalty(current,10000)
else
break
end
@@ -184,10 +193,9 @@ function parbuilders.keeptogether(head)
local current = tonut(head)
while current do
if getid(current) == hlist_code then
- local a = getattr(current,a_keeptogether)
+ local a = takeattr(current,a_keeptogether)
if a and a > 0 then
keeptogether(current,a)
- setattr(current,a_keeptogether,unsetvalue)
cache[a] = nil
done = true
end