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
9local nodes, node = nodes, node
10
11local tasks = nodes.tasks
12
13local nuts = nodes.nuts
14local tonut = nodes.tonut
15local tonode = nodes.tonode
16
17local getid = nuts.getid
18local getsubtype = nuts.getsubtype
19local getattr = nuts.getattr
20local getlist = nuts.getlist
21local getchar = nuts.getchar
22local getnext = nuts.getnext
23
24local setattr = nuts.setattr
25local setlink = nuts.setlink
26local setchar = nuts.setchar
27local setsubtype = nuts.setsubtype
28local getwidth = nuts.getwidth
29local setwidth = nuts.setwidth
30
31local nextglyph = nuts.traversers.glyph
32local nextnode = nuts.traversers.node
33
34
35local insertafter = nuts.insertafter
36local copynocomponents = nuts.components.copynocomponents
37
38local nodecodes = nodes.nodecodes
39local gluecodes = nodes.gluecodes
40
41local glue_code = nodecodes.glue
42
43local glyph_code = nodecodes.glyph
44local hlist_code = nodecodes.hlist
45local vlist_code = nodecodes.vlist
46
47local userskip_code = gluecodes.user
48local spaceskip_code = gluecodes.spaceskip
49local xspaceskip_code = gluecodes.xspaceskip
50
51local a_characters = attributes.private("characters")
52
53local nofreplaced = 0
54
55
56
57
58
59
60local trace = false trackers.register("backend.spaces", function(v) trace = v end)
61local slot = nil
62
63local function injectspaces(head)
64 local p, p_id
65 local n = head
66 while n do
67 local id = getid(n)
68 if id == glue_code then
69 if p and getid(p) == glyph_code then
70 local s = getsubtype(n)
71 if s == spaceskip_code or s == xspaceskip_code then
72
73
74 local g = copynocomponents(p)
75 local a = getattr(n,a_characters)
76 setchar(g,slot)
77 setlink(p,g,n)
78 setwidth(n,getwidth(n) - getwidth(g))
79
80 if a then
81 setattr(g,a_characters,a)
82 end
83 setattr(n,a_characters,0)
84 nofreplaced = nofreplaced + 1
85 end
86 end
87 elseif id == hlist_code or id == vlist_code then
88 injectspaces(getlist(n),slot)
89 end
90 p_id = id
91 p = n
92 n = getnext(n)
93 end
94 return head
95end
96
97nodes.handlers.accessibility = function(head)
98 if trace then
99 if not slot then
100 slot = fonts.helpers.privateslot("visualspace")
101 end
102 else
103 slot = 32
104 end
105 return injectspaces(head,slot)
106end
107
108statistics.register("inserted spaces in output",function()
109 if nofreplaced > 0 then
110 return nofreplaced
111 end
112end)
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 |