1if not modules then modules = { } end modules ['node-acc'] = {
2 version = 1.001,
3 comment = "companion to node-ini.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11local nodes, node = nodes, node
12
13local tasks = nodes.tasks
14
15local nuts = nodes.nuts
16local tonut = nodes.tonut
17local tonode = nodes.tonode
18
19local getid = nuts.getid
20local getsubtype = nuts.getsubtype
21local getattr = nuts.getattr
22local getlist = nuts.getlist
23local getchar = nuts.getchar
24local getnext = nuts.getnext
25
26local setattr = nuts.setattr
27local setlink = nuts.setlink
28local setchar = nuts.setchar
29local getwidth = nuts.getwidth
30local setwidth = nuts.setwidth
31
32local nextglyph = nuts.traversers.glyph
33
34local copy_node = nuts.copy
35
36local nodecodes = nodes.nodecodes
37local gluecodes = nodes.gluecodes
38
39local glue_code <const> = nodecodes.glue
40local glyph_code <const> = nodecodes.glyph
41local hlist_code <const> = nodecodes.hlist
42local vlist_code <const> = nodecodes.vlist
43
44local spaceskip_code <const> = gluecodes.spaceskip
45local xspaceskip_code <const> = gluecodes.xspaceskip
46
47local a_characters <const> = attributes.private("characters")
48
49local nofreplaced = 0
50
51local trace = false trackers.register("backend.contenttostring", function(v) trace = v end)
52local slot = nil
53
54
55
56local function injectspaces(head)
57
58
59
60
61 local p, p_id
62 local n = head
63 while n do
64 local id = getid(n)
65 if id == glue_code then
66 if p and getid(p) == glyph_code then
67 local s = getsubtype(n)
68 if s == spaceskip_code or s == xspaceskip_code then
69 local g = copy_node(p)
70 local a = getattr(n,a_characters)
71 setchar(g,slot)
72 setlink(p,g,n)
73 setwidth(n,getwidth(n) - getwidth(g))
74 if a then
75 setattr(g,a_characters,a)
76 end
77 setattr(n,a_characters,0)
78 nofreplaced = nofreplaced + 1
79 end
80 end
81 elseif id == hlist_code or id == vlist_code then
82 injectspaces(getlist(n),slot)
83 end
84 p_id = id
85 p = n
86 n = getnext(n)
87 end
88 return head
89end
90
91nodes.handlers.accessibility = function(head)
92 if trace then
93 if not slot then
94 slot = fonts.helpers.privateslot("visualspace")
95 end
96 else
97 slot = 32
98 end
99 return injectspaces(head,slot)
100end
101
102statistics.register("inserted spaces in output",function()
103 if nofreplaced > 0 then
104 return nofreplaced
105 end
106end)
107 |