diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/typo-dig.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/typo-dig.lua | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/Master/texmf-dist/tex/context/base/typo-dig.lua b/Master/texmf-dist/tex/context/base/typo-dig.lua index 62d17fa3bb7..67849c6d47b 100644 --- a/Master/texmf-dist/tex/context/base/typo-dig.lua +++ b/Master/texmf-dist/tex/context/base/typo-dig.lua @@ -19,18 +19,32 @@ 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 texattribute = tex.attribute +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 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 @@ -55,7 +69,6 @@ digits.actions = { } local actions = digits.actions local a_digits = attributes.private("digits") -digits.attribute = a_digits -- at some point we can manipulate the glyph node so then i need -- to rewrite this then @@ -67,29 +80,34 @@ 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 end end -actions[1] = function(head,start,attribute,attr) - local font = start.font - local char = start.char +actions[1] = function(head,start,attr) + local font = getfont(start) + local char = getchar(start) 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 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", @@ -102,25 +120,28 @@ actions[1] = function(head,start,attribute,attr) return head, start, false end -local function process(namespace,attribute,head) +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[attribute] + if getid(current) == glyph_code then + local attr = getattr(current,a_digits) if attr and attr > 0 then - current[attribute] = 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,attribute,attr) + head, current, ok = action(head,current,attr) done = done and ok elseif trace_digits then report_digits("unknown digit trigger %a",attr) 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 @@ -148,15 +169,9 @@ function digits.set(n) -- number or 'reset' n = unsetvalue end end - texattribute[a_digits] = n + texsetattribute(a_digits,n) end -digits.handler = nodes.installattributehandler { -- we could avoid this wrapper - name = "digits", - namespace = digits, - processor = process, -} - -- interface commands.setdigitsmanipulation = digits.set |