summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/node-scn.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkxl/node-scn.lmt')
-rw-r--r--tex/context/base/mkxl/node-scn.lmt141
1 files changed, 101 insertions, 40 deletions
diff --git a/tex/context/base/mkxl/node-scn.lmt b/tex/context/base/mkxl/node-scn.lmt
index 947b9e25c..1530174c2 100644
--- a/tex/context/base/mkxl/node-scn.lmt
+++ b/tex/context/base/mkxl/node-scn.lmt
@@ -41,6 +41,8 @@ local userskip_code = gluecodes.userskip
local spaceskip_code = gluecodes.spaceskip
local xspaceskip_code = gluecodes.xspaceskip
local leaders_code = gluecodes.leaders
+local rightfillskip_code = gluecodes.rightparfillskip
+local righthangskip_code = gluecodes.righthangskip
local fontkern_code = kerncodes.fontkern
@@ -111,13 +113,15 @@ nuts.striprange = striprange
-- todo: switching inside math
--- handlers
+-- handlers (some are very specialized and demanding)
-local function processwords(attribute,data,flush,head,parent,skip) -- we have hlistdir and local dir
+local maxlevel = 1
+
+local function processwords(nesting,attribute,data,flush,head,parent,skip) -- we have hlistdir and local dir
local n = head
if n then
- local f, l, a, d, i, class
- local continue, leaders, strip, level = false, false, false, true, -1
+ local f, l, a, d, class
+ local continue, leaders, strip, level = false, false, true, -1
while n do
local id = getid(n)
if id == glyph_code
@@ -127,6 +131,36 @@ local function processwords(attribute,data,flush,head,parent,skip) -- we have hl
or id == boundary_code
then
local aa = getattr(n,attribute)
+ -- new approach
+ local dd, ll
+ if aa then
+ dd = data[aa]
+ ll = dd.level or 1
+ if nesting == 1 and ll > maxlevel then
+ maxlevel = ll
+ end
+ if ll == nesting then
+ -- we're okay
+ else
+ while true do
+ local nestingvalue = dd.nestingvalue
+ if nestingvalue then
+ dd = dd.nestingdata
+ ll = dd.level
+ if ll == nesting then
+ aa = nestingvalue
+ break
+ end
+ else
+ -- no matching level found
+ aa = nil
+ dd = nil
+ break
+ end
+ end
+ end
+ end
+ -- old approach
if aa and aa ~= skip then
if aa == a then
if not f then -- ?
@@ -134,99 +168,121 @@ local function processwords(attribute,data,flush,head,parent,skip) -- we have hl
end
l = n
else
- -- possible extensions: when in same class then keep spanning
- local newlevel, newclass = floor(aa/1000), aa%1000 -- will be configurable
- -- strip = not continue or level == 1 -- 0
if f then
- if class == newclass then -- and newlevel > level then
- head = flush(head,f,l,d,level,parent,false), true
+ if class == aa then -- and newlevel > level then
+ head = flush(head,f,l,d,level,parent,false)
else
- head = flush(head,f,l,d,level,parent,strip), true
+ head = flush(head,f,l,d,level,parent,strip)
end
end
f, l, a = n, n, aa
- level, class = newlevel, newclass
- d = data[class]
+ d = dd
+ class = aa
if d then
- local c = d.continue
- leaders = c == v_all
- continue = leaders or c == v_yes
+ continue = d.continue
+ level = d.level or 1
+ leaders = continue == v_all
+ continue = leaders or continue == v_yes
else
continue = true
+ level = 1
+ leaders = false
end
end
else
if f then
- head = flush(head,f,l,d,level,parent,strip), true
+ head = flush(head,f,l,d,level,parent,strip)
end
f, l, a = nil, nil, nil
end
if id == hlist_code then
local list = getlist(n)
if list then
- setlist(n,processwords(attribute,data,flush,list,n,aa))
+ setlist(n,processwords(nesting,attribute,data,flush,list,n,aa))
end
end
--- elseif id == disc_code or id == boundary_code then
--- if f then
--- l = n
--- end
- elseif id == kern_code and getsubtype(n) == fontkern_code then
- if f then
- l = n
+ goto next
+ -- elseif id == disc_code or id == boundary_code then
+ -- if f then
+ -- l = n
+ -- end
+ -- goto next
+ elseif id == kern_code then
+ if getsubtype(n) == fontkern_code then
+ if f then
+ l = n
+ end
+ goto next
+ else
+ goto rest
end
elseif id == math_code then
-- otherwise not consistent: a $b$ c vs a $b+c$ d etc
-- we need a special (optional) go over math variant
if f then
- head = flush(head,f,l,d,level,parent,strip), true
+ head = flush(head,f,l,d,level,parent,strip)
f, l, a = nil, nil, nil
end
+ goto next
elseif id == hlist_code or id == vlist_code then
if f then
- head = flush(head,f,l,d,level,parent,strip), true
+ head = flush(head,f,l,d,level,parent,strip)
f, l, a = nil, nil, nil
end
local list = getlist(n)
if list then
- setlist(n,processwords(attribute,data,flush,list,n,skip))
+ setlist(n,processwords(nesting,attribute,data,flush,list,n,skip))
end
+ goto next
elseif id == dir_code then -- only changes in dir, we assume proper boundaries
if f then
l = n
end
- elseif f then
+ goto next
+ end
+ ::rest::
+ if f then
if continue then
if id == penalty_code then
l = n
+ goto next
-- elseif id == kern_code then
-- l = n
+ -- goto next
elseif id == glue_code then
-- catch \underbar{a} \underbar{a} (subtype test is needed)
local subtype = getsubtype(n)
if getattr(n,attribute) and (subtype == userskip_code or subtype == spaceskip_code or subtype == xspaceskip_code or (leaders and subtype >= leaders_code)) then
l = n
else
- head = flush(head,f,l,d,level,parent,strip), true
+ head = flush(head,f,l,d,level,parent,strip)
f, l, a = nil, nil, nil
end
end
else
- head = flush(head,f,l,d,level,parent,strip), true
+ head = flush(head,f,l,d,level,parent,strip)
f, l, a = nil, nil, nil
end
end
+ ::next::
n = getnext(n)
end
if f then
- head = flush(head,f,l,d,level,parent,strip), true
+ head = flush(head,f,l,d,level,parent,strip)
end
end
return head
end
nuts.processwords = function(attribute,data,flush,head,parent) -- we have hlistdir and local dir
- return processwords(attribute,data,flush,head,parent)
+ -- print("processing words at level "..1)io.flush()
+ maxlevel = 1
+ head = processwords(1,attribute,data,flush,head,parent)
+ for i=2,maxlevel do
+ -- print("processing words at level "..i)io.flush()
+ head = processwords(i,attribute,data,flush,head,parent)
+ end
+ return head
end
-- works on lines !
@@ -240,7 +296,7 @@ local function processranges(attribute,flush,head,parent,depth,skip)
local id = getid(n)
if id == glyph_code or id == rule_code then
local aa = getattr(n,attribute)
--- if aa and (not skip or aa ~= skip) then
+ -- if aa and (not skip or aa ~= skip) then
if aa then
if aa == a then
if not f then
@@ -249,13 +305,13 @@ local function processranges(attribute,flush,head,parent,depth,skip)
l = n
else
if f then
- head = flush(head,f,l,a,parent,depth), true
+ head = flush(head,f,l,a,parent,depth)
end
f, l, a = n, n, aa
end
else
if f then
- head = flush(head,f,l,a,parent,depth), true
+ head = flush(head,f,l,a,parent,depth)
end
f, l, a = nil, nil, nil
end
@@ -265,16 +321,21 @@ local function processranges(attribute,flush,head,parent,depth,skip)
else
-- weird
end
- elseif id == kern_code and getsubtype(n) == fontkern_code then
- if f then
- l = n
+ elseif id == kern_code then
+ if getsubtype(n) == fontkern_code then
+ if f then
+ l = n
+ end
end
-- elseif id == penalty_code then
elseif id == glue_code then
-- todo: leaders
+-- if getsubtype(n) == rightfillskip_code or getsubtype(n) == righthangskip_code then
+-- break
+-- end
elseif id == hlist_code or id == vlist_code then
local aa = getattr(n,attribute)
--- if aa and (not skip or aa ~= skip) then
+ -- if aa and (not skip or aa ~= skip) then
if aa then
if aa == a then
if not f then
@@ -301,7 +362,7 @@ local function processranges(attribute,flush,head,parent,depth,skip)
n = getnext(n)
end
if f then
- head = flush(head,f,l,a,parent,depth), true
+ head = flush(head,f,l,a,parent,depth)
end
end
return head