summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/node-acc.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkxl/node-acc.lmt')
-rw-r--r--Master/texmf-dist/tex/context/base/mkxl/node-acc.lmt112
1 files changed, 112 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkxl/node-acc.lmt b/Master/texmf-dist/tex/context/base/mkxl/node-acc.lmt
new file mode 100644
index 00000000000..2c3302a3ea7
--- /dev/null
+++ b/Master/texmf-dist/tex/context/base/mkxl/node-acc.lmt
@@ -0,0 +1,112 @@
+if not modules then modules = { } end modules ['node-acc'] = {
+ version = 1.001,
+ comment = "companion to node-ini.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- see mkiv lua module for some experimental unused code
+
+local nodes, node = nodes, node
+
+local tasks = nodes.tasks
+
+local nuts = nodes.nuts
+local tonut = nodes.tonut
+local tonode = nodes.tonode
+
+local getid = nuts.getid
+local getsubtype = nuts.getsubtype
+local getattr = nuts.getattr
+local getlist = nuts.getlist
+local getchar = nuts.getchar
+local getnext = nuts.getnext
+
+local setattr = nuts.setattr
+local setlink = nuts.setlink
+local setchar = nuts.setchar
+local setsubtype = nuts.setsubtype
+local getwidth = nuts.getwidth
+local setwidth = nuts.setwidth
+
+local nextglyph = nuts.traversers.glyph
+local nextnode = nuts.traversers.node
+
+local copy_node = nuts.copy
+local insert_after = nuts.insert_after
+
+local nodecodes = nodes.nodecodes
+local gluecodes = nodes.gluecodes
+
+local glue_code = nodecodes.glue
+local glyph_code = nodecodes.glyph
+local hlist_code = nodecodes.hlist
+local vlist_code = nodecodes.vlist
+
+local userskip_code = gluecodes.user
+local spaceskip_code = gluecodes.spaceskip
+local xspaceskip_code = gluecodes.xspaceskip
+
+local a_characters = attributes.private("characters")
+
+local nofreplaced = 0
+
+-- todo: nbsp etc
+-- todo: collapse kerns (not needed, backend does this)
+-- todo: maybe cache as we now create many nodes
+-- todo: check for subtype related to spacing (13/14 but most seems to be user anyway)
+
+local trace = false trackers.register("backend.spaces", function(v) trace = v end)
+local slot = nil
+
+local function injectspaces(head)
+ -- This can become two fast loops or we just move this to the backend where we can
+ -- also check for spaces (it actually is rather old code that relates to tagging
+ -- and so, which was implemented rather early in the mkiv saga).
+ local p, p_id
+ local n = head
+ while n do
+ local id = getid(n)
+ if id == glue_code then
+ if p and getid(p) == glyph_code then
+ local s = getsubtype(n)
+ if s == spaceskip_code or s == xspaceskip_code then
+ local g = copy_node(p)
+ local a = getattr(n,a_characters)
+ setchar(g,slot)
+ setlink(p,g,n)
+ setwidth(n,getwidth(n) - getwidth(g))
+ if a then
+ setattr(g,a_characters,a)
+ end
+ setattr(n,a_characters,0)
+ nofreplaced = nofreplaced + 1
+ end
+ end
+ elseif id == hlist_code or id == vlist_code then
+ injectspaces(getlist(n),slot)
+ end
+ p_id = id
+ p = n
+ n = getnext(n)
+ end
+ return head
+end
+
+nodes.handlers.accessibility = function(head)
+ if trace then
+ if not slot then
+ slot = fonts.helpers.privateslot("visualspace")
+ end
+ else
+ slot = 32
+ end
+ return injectspaces(head,slot)
+end
+
+statistics.register("inserted spaces in output",function()
+ if nofreplaced > 0 then
+ return nofreplaced
+ end
+end)