summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/node-nut.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/node-nut.lua')
-rw-r--r--tex/context/base/mkiv/node-nut.lua244
1 files changed, 182 insertions, 62 deletions
diff --git a/tex/context/base/mkiv/node-nut.lua b/tex/context/base/mkiv/node-nut.lua
index cec272bcf..0c6714667 100644
--- a/tex/context/base/mkiv/node-nut.lua
+++ b/tex/context/base/mkiv/node-nut.lua
@@ -133,19 +133,90 @@ if not direct.setwhd then
end
end
-nuts.getwhd = direct.getwhd
-nuts.setwhd = direct.setwhd
-
-nuts.getfield = direct.getfield
-nuts.getnext = direct.getnext
-nuts.getprev = direct.getprev
-nuts.getid = direct.getid
-nuts.getattr = direct.get_attribute or direct.has_attribute or direct.getfield
-nuts.getchar = direct.getchar
-nuts.getfont = direct.getfont
-nuts.getsubtype = direct.getsubtype
-nuts.getlist = direct.getlist -- only hlist and vlist !
-nuts.getleader = direct.getleader
+if not direct.getcomponents then
+
+ local getfield = direct.getfield
+ local setfield = direct.setfield
+ local setsubtype = direct.setsubtype
+
+ local attributelist_code = nodecodes.attributelist
+
+ function direct.getcomponents(n) return getfield(n,"components") end
+ function direct.setcomponents(n,c) setfield(n,"components",c) end
+ function direct.getkern(n) return getfield(n,"kern") end
+ function direct.getwidth(n) return getfield(n,"width") end
+ function direct.setwidth(n,w) return setfield(n,"width",w) end
+ function direct.getheight(n) return getfield(n,"height") end
+ function direct.setheight(n,h) return setfield(n,"height",h) end
+ function direct.getdepth(n) return getfield(n,"depth") end
+ function direct.setdepth(n,d) return setfield(n,"depth",d) end
+ function direct.getshift(n) return getfield(n,"shift") end
+ function direct.setshift(n,s) return setfield(n,"shift",s) end
+ function direct.getpenalty(n) return getfield(n,"penalty") end
+ function direct.setpenalty(n,p) setfield(n,"penalty",p) end
+ function direct.getdir(n) return getfield(n,"dir") end
+ function direct.setdir(n,p) setfield(n,"dir",p) end
+ function direct.getlanguage(n) return getfield(n,"lang") end
+ function direct.setlanguage(n,l) return setfield(n,"lang",l) end
+ function direct.getattributelist(n) getfield(n,"attr") end
+
+ function direct.getnucleus(n) return getfield(n,"nucleus") end
+ function direct.setnucleus(n,p) return setfield(n,"nucleus",p) end
+ function direct.getsup(n) return getfield(n,"sup") end
+ function direct.setsup(n,p) return setfield(n,"sup",p) end
+ function direct.getsub(n) return getfield(n,"sub") end
+ function direct.setsub(n,p) return setfield(n,"sub",p) end
+
+ function direct.setattributelist(n,a)
+ if a and type(a) ~= attributelist_code then
+ a = getfield(a,"attr")
+ end
+ setfield(n,"attr",a)
+ end
+
+ function direct.setkern(n,k,s)
+ setfield(n,"kern",k)
+ if s then
+ setsubtype(n,s)
+ end
+ end
+
+ function direct.setfont(n,f,c)
+ setfield(n,"font",f)
+ if c then
+ setfield(n,"char",f)
+ end
+ end
+
+ function direct.getoffsets(n)
+ return getfield(n,"xoffset"), getfield(n,"yoffset")
+ end
+
+ function direct.setoffsets(n,x,y)
+ if x then
+ setfield(n,"xoffset",x)
+ end
+ if y then
+ setfield(n,"yoffset",y)
+ end
+ end
+
+end
+
+-- if LUATEXVERSION < 1.004 then
+-- local gc = direct.getcomponents
+-- getcomponents = function(n) local c = gc(n) return c ~= 0 and c or nil end
+-- end
+
+-- local hash = table.setmetatableindex("number")
+-- local ga = direct.get_attribute
+-- function direct.get_attribute(n,a)
+-- hash[a] = hash[a] + 1
+-- return ga(n,a)
+-- end
+-- function nuts.reportattr()
+-- inspect(hash)
+-- end
-- local function track(name)
-- local n = 0
@@ -163,12 +234,6 @@ nuts.getleader = direct.getleader
-- setters
-nuts.setfield = direct.setfield
-nuts.setattr = direct.set_attribute or setfield
-
-nuts.getbox = direct.getbox
-nuts.setbox = direct.setbox
-
-- helpers
nuts.tostring = direct.tostring
@@ -199,6 +264,10 @@ nuts.is_direct = direct.is_direct
nuts.is_nut = direct.is_direct
nuts.first_glyph = direct.first_glyph
nuts.has_glyph = direct.has_glyph or direct.first_glyph
+nuts.count = direct.count
+nuts.length = direct.length
+nuts.find_attribute = direct.find_attribute
+nuts.unset_attribute = direct.unset_attribute
nuts.current_attr = direct.current_attr
nuts.has_field = direct.has_field
@@ -228,56 +297,95 @@ if not direct.mlist_to_hlist then -- needed
end
-if LUATEXVERSION < 0.97 then
-
- local getglue = direct.getglue
-
- function direct.is_zero_glue(n)
- local width, stretch, shrink = getglue(n)
- return width == 0 and stretch == 0 and shrink == 0
- end
-
-end
-
-if not direct.rangedimensions then -- LUATEXVERSION < 0.99
-
- local dimensions = direct.dimensions
- local getfield = direct.getfield
- local find_tail = direct.tail
+nuts.getfield = direct.getfield
+nuts.setfield = direct.setfield
- function direct.rangedimensions(parent,first,last)
- return dimensions(
- getfield(parent,"glue_set"), getfield(parent,"glue_sign"), getfield(parent,"glue_order"),
- first, last or find_tail(first), getfield(parent,"dir")
- )
- end
+nuts.getnext = direct.getnext
+nuts.setnext = direct.setnext
- nuts.rangedimensions = direct.rangedimensions
+nuts.getid = direct.getid
-end
+nuts.getprev = direct.getprev
+nuts.setprev = direct.setprev
-local getglue = direct.getglue
-local setglue = direct.setglue
-local is_zero_glue = direct.is_zero_glue
+nuts.getattr = direct.get_attribute
+nuts.setattr = direct.set_attribute
+nuts.takeattr = direct.unset_attribute -- ?
+nuts.is_zero_glue = direct.is_zero_glue
nuts.effective_glue = direct.effective_glue
-nuts.getglue = getglue
-nuts.setglue = setglue
-nuts.is_zero_glue = is_zero_glue
+
+nuts.getglue = direct.getglue
+nuts.setglue = direct.setglue
nuts.getdisc = direct.getdisc
-nuts.getwhd = direct.getwhd
nuts.setdisc = direct.setdisc
+nuts.getdiscretionary = direct.getdisc
+nuts.setdiscretionary = direct.setdisc
+
+nuts.getwhd = direct.getwhd
+nuts.setwhd = direct.setwhd
+nuts.getwidth = direct.getwidth
+nuts.setwidth = direct.setwidth
+nuts.getheight = direct.getheight
+nuts.setheight = direct.setheight
+nuts.getdepth = direct.getdepth
+nuts.setdepth = direct.setdepth
+nuts.getshift = direct.getshift
+nuts.setshift = direct.setshift
+
+nuts.getnucleus = direct.getnucleus
+nuts.setnucleus = direct.setnucleus
+nuts.getsup = direct.getsup
+nuts.setsup = direct.setsup
+nuts.getsub = direct.getsub
+nuts.setsub = direct.setsub
+
+nuts.getchar = direct.getchar
nuts.setchar = direct.setchar
-nuts.setnext = direct.setnext
-nuts.setprev = direct.setprev
-nuts.setboth = direct.setboth
+nuts.getfont = direct.getfont
+nuts.setfont = direct.setfont
+
nuts.getboth = direct.getboth
+nuts.setboth = direct.setboth
nuts.setlink = direct.setlink
+nuts.setsplit = direct.setsplit
+
+nuts.getlist = direct.getlist -- only hlist and vlist !
nuts.setlist = direct.setlist
+nuts.getleader = direct.getleader
nuts.setleader = direct.setleader
+nuts.getcomponents = direct.getcomponents
+nuts.setcomponents = direct.setcomponents
+
+nuts.getsubtype = direct.getsubtype
nuts.setsubtype = direct.setsubtype
+nuts.getlang = direct.getlang
+nuts.setlang = direct.setlang
+nuts.getlanguage = direct.getlang
+nuts.setlanguage = direct.setlang
+
+nuts.getattrlist = direct.getattributelist
+nuts.setattrlist = direct.setattributelist
+nuts.getattributelist = direct.getattributelist
+nuts.setattributelist = direct.setattributelist
+
+nuts.getoffsets = direct.getoffsets
+nuts.setoffsets = direct.setoffsets
+
+nuts.getkern = direct.getkern
+nuts.setkern = direct.setkern
+
+nuts.getdir = direct.getdir
+nuts.setdir = direct.setdir
+
+nuts.getpenalty = direct.getpenalty
+nuts.setpenalty = direct.setpenalty
+
+nuts.getbox = direct.getbox
+nuts.setbox = direct.setbox
+
nuts.is_char = direct.is_char
nuts.ischar = direct.is_char
nuts.is_glyph = direct.is_glyph
@@ -313,6 +421,11 @@ local function remove(head,current,free_too)
return head, current, t
end
+-- alias
+
+nuts.getsurround = nuts.getkern
+nuts.setsurround = nuts.setkern
+
-- bad: we can have prev's being glue_spec
nuts.remove = remove
@@ -326,11 +439,14 @@ function nuts.replace(head,current,new) -- no head returned if false
head, current, new = false, head, current
end
local prev, next = d_getboth(current)
- if next then
- d_setlink(new,next)
- end
- if prev then
- d_setlink(prev,new)
+-- if next then
+-- d_setlink(new,next)
+-- end
+-- if prev then
+-- d_setlink(prev,new)
+-- end
+ if prev or next then
+ d_setlink(prev,new,next)
end
if head then
if head == current then
@@ -344,14 +460,14 @@ function nuts.replace(head,current,new) -- no head returned if false
end
end
-local function count(stack,flat)
+local function countall(stack,flat)
local n = 0
while stack do
local id = d_getid(stack)
if not flat and id == hlist_code or id == vlist_code then
local list = d_getlist(stack)
if list then
- n = n + 1 + count(list) -- self counts too
+ n = n + 1 + countall(list) -- self counts too
else
n = n + 1
end
@@ -363,7 +479,11 @@ local function count(stack,flat)
return n
end
-nuts.count = count
+nuts.countall = countall
+
+function nodes.countall(stack,flat)
+ return countall(tonut(stack),flat)
+end
function nuts.append(head,current,...)
for i=1,select("#",...) do
@@ -379,7 +499,7 @@ function nuts.prepend(head,current,...)
return head, current
end
-function nuts.linked(...)
+function nuts.linked(...) -- slides !
local head, last
for i=1,select("#",...) do
local next = select(i,...)