diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/typo-pag.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/typo-pag.lua | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/typo-pag.lua b/Master/texmf-dist/tex/context/base/mkiv/typo-pag.lua index 355becff667..d6f71c8cc2c 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/typo-pag.lua +++ b/Master/texmf-dist/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 |