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 = nodecodes.glue
40local glyph_code = nodecodes.glyph
41local hlist_code = nodecodes.hlist
42local vlist_code = nodecodes.vlist
43
44local spaceskip_code = gluecodes.spaceskip
45local xspaceskip_code = gluecodes.xspaceskip
46
47local a_characters = attributes.private("characters")
48
49local nofreplaced = 0
50
51
52
53
54
55
56local trace = false trackers.register("backend.spaces", function(v) trace = v end)
57local slot = nil
58
59local function injectspaces(head)
60
61
62
63
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 local g = copy_node(p)
73 local a = getattr(n,a_characters)
74 setchar(g,slot)
75 setlink(p,g,n)
76 setwidth(n,getwidth(n) - getwidth(g))
77 if a then
78 setattr(g,a_characters,a)
79 end
80 setattr(n,a_characters,0)
81 nofreplaced = nofreplaced + 1
82 end
83 end
84 elseif id == hlist_code or id == vlist_code then
85 injectspaces(getlist(n),slot)
86 end
87 p_id = id
88 p = n
89 n = getnext(n)
90 end
91 return head
92end
93
94nodes.handlers.accessibility = function(head)
95 if trace then
96 if not slot then
97 slot = fonts.helpers.privateslot("visualspace")
98 end
99 else
100 slot = 32
101 end
102 return injectspaces(head,slot)
103end
104
105statistics.register("inserted spaces in output",function()
106 if nofreplaced > 0 then
107 return nofreplaced
108 end
109end)
110 |