summaryrefslogtreecommitdiff
path: root/tex/context/base/typo-dig.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/typo-dig.lua')
-rw-r--r--tex/context/base/typo-dig.lua71
1 files changed, 48 insertions, 23 deletions
diff --git a/tex/context/base/typo-dig.lua b/tex/context/base/typo-dig.lua
index ef05e62da..c753a0352 100644
--- a/tex/context/base/typo-dig.lua
+++ b/tex/context/base/typo-dig.lua
@@ -19,10 +19,24 @@ local report_digits = logs.reporter("typesetting","digits")
local nodes, node = nodes, node
-local hpack_node = node.hpack
-local traverse_id = node.traverse_id
-local insert_node_before = node.insert_before
-local insert_node_after = node.insert_after
+local nuts = nodes.nuts
+local tonut = nuts.tonut
+local tonode = nuts.tonode
+
+local getnext = nuts.getnext
+local getprev = nuts.getprev
+local getfont = nuts.getfont
+local getchar = nuts.getchar
+local getid = nuts.getid
+local getfield = nuts.getfield
+local setfield = nuts.setfield
+local getattr = nuts.getattr
+local setattr = nuts.setattr
+
+local hpack_node = nuts.hpack
+local traverse_id = nuts.traverse_id
+local insert_node_before = nuts.insert_before
+local insert_node_after = nuts.insert_after
local texsetattribute = tex.setattribute
local unsetvalue = attributes.unsetvalue
@@ -30,7 +44,7 @@ local unsetvalue = attributes.unsetvalue
local nodecodes = nodes.nodecodes
local glyph_code = nodecodes.glyph
-local nodepool = nodes.pool
+local nodepool = nuts.pool
local tasks = nodes.tasks
local new_glue = nodepool.glue
@@ -66,16 +80,20 @@ function nodes.aligned(head,start,stop,width,how)
if how == "flushleft" or how == "middle" then
head, stop = insert_node_after(head,stop,new_glue(0,65536,65536))
end
- local prv, nxt = start.prev, stop.next
- start.prev, stop.next = nil, nil
+ local prv = getprev(start)
+ local nxt = getnext(stop)
+ setfield(start,"prev",nil)
+ setfield(stop,"next",nil)
local packed = hpack_node(start,width,"exactly") -- no directional mess here, just lr
if prv then
- prv.next, packed.prev = packed, prv
+ setfield(prv,"next",packed)
+ setfield(packed,"prev",prv)
end
if nxt then
- nxt.prev, packed.next = packed, nxt
+ setfield(nxt,"prev",packed)
+ setfield(packed,"next",nxt)
end
- if packed.prev then
+ if getprev(packed) then
return head, packed
else
return packed, packed
@@ -83,16 +101,16 @@ function nodes.aligned(head,start,stop,width,how)
end
actions[1] = function(head,start,attr)
- local font = start.font
- local char = start.char
- local unic = chardata[font][char].tounicode
- local what = unic and tonumber(unic,16) or char
- if charbase[what].category == "nd" then
- local oldwidth, newwidth = start.width, getdigitwidth(font)
+ local font = getfont(start)
+ local char = getchar(start)
+ local unic = chardata[font][char].unicode or char
+ if charbase[unic].category == "nd" then -- ignore unic tables
+ local oldwidth = getfield(start,"width")
+ local newwidth = getdigitwidth(font)
if newwidth ~= oldwidth then
if trace_digits then
report_digits("digit trigger %a, instance %a, char %C, unicode %U, delta %s",
- attr%100,div(attr,100),char,what,newwidth-oldwidth)
+ attr%100,div(attr,100),char,unic,newwidth-oldwidth)
end
head, start = nodes.aligned(head,start,start,newwidth,"middle")
return head, start, true
@@ -102,12 +120,13 @@ actions[1] = function(head,start,attr)
end
function digits.handler(head)
+ head = tonut(head)
local done, current, ok = false, head, false
while current do
- if current.id == glyph_code then
- local attr = current[a_digits]
+ if getid(current) == glyph_code then
+ local attr = getattr(current,a_digits)
if attr and attr > 0 then
- current[a_digits] = unsetvalue
+ setattr(current,a_digits,unsetvalue)
local action = actions[attr%100] -- map back to low number
if action then
head, current, ok = action(head,current,attr)
@@ -117,9 +136,11 @@ function digits.handler(head)
end
end
end
- current = current and current.next
+ if current then
+ current = getnext(current)
+ end
end
- return head, done
+ return tonode(head), done
end
local m, enabled = 0, false -- a trick to make neighbouring ranges work
@@ -152,4 +173,8 @@ end
-- interface
-commands.setdigitsmanipulation = digits.set
+interfaces.implement {
+ name = "setdigitsmanipulation",
+ actions = digits.set,
+ arguments = "string"
+}