1if not modules then modules = { } end modules ['node-ini'] = {
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 next, type, tostring = next, type, tostring
12local gsub = string.gsub
13local concat, remove = table.concat, table.remove
14local sortedhash, sortedkeys, swapped = table.sortedhash, table.sortedkeys, table.swapped
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46nodes = nodes or { }
47local nodes = nodes
48nodes.handlers = nodes.handlers or { }
49
50local mark = utilities.storage.mark
51local allocate = utilities.storage.allocate
52local formatcolumns = utilities.formatters.formatcolumns
53
54local getsubtypes = node.subtypes
55local getvalues = node.values
56
57tex.magicconstants = {
58 running = -1073741824,
59 maxdimen = 1073741823,
60 trueinch = 4736286,
61}
62
63local listcodes = mark(getsubtypes("list"))
64local rulecodes = mark(getsubtypes("rule"))
65local dircodes = mark(getsubtypes("dir"))
66local glyphcodes = mark(getsubtypes("glyph"))
67local disccodes = mark(getsubtypes("disc"))
68local gluecodes = mark(getsubtypes("glue"))
69local fillcodes = mark(getsubtypes("fill"))
70local boundarycodes = mark(getsubtypes("boundary"))
71local penaltycodes = mark(getsubtypes("penalty"))
72local kerncodes = mark(getsubtypes("kern"))
73local margincodes = mark(getsubtypes("marginkern"))
74local mathcodes = mark(getsubtypes("math"))
75local noadcodes = mark(getsubtypes("noad"))
76local radicalcodes = mark(getsubtypes("radical"))
77local accentcodes = mark(getsubtypes("accent"))
78local fencecodes = mark(getsubtypes("fence"))
79
80local parcodes = allocate { [0] = "vmode_par", "local_box", "hmode_par", "penalty", "math" }
81
82local function simplified(t)
83 local r = { }
84 for k, v in next, t do
85 r[k] = gsub(v,"_","")
86 end
87 return r
88end
89
90local nodecodes = simplified(node.types())
91local whatcodes = simplified(node.whatsits and node.whatsits() or { })
92
93local usercodes = allocate {
94 [ 97] = "attribute",
95 [100] = "number",
96 [102] = "float",
97 [108] = "lua",
98 [110] = "node",
99 [115] = "string",
100 [116] = "token"
101}
102
103local noadoptions = allocate {
104 set = 0x08,
105 unused_1 = 0x00 + 0x08,
106 unused_2 = 0x01 + 0x08,
107 axis = 0x02 + 0x08,
108 no_axis = 0x04 + 0x08,
109 exact = 0x10 + 0x08,
110 left = 0x11 + 0x08,
111 middle = 0x12 + 0x08,
112 right = 0x14 + 0x08,
113}
114
115local dirvalues = allocate {
116 [0] = "lefttoright",
117 [1] = "righttoleft",
118}
119
120local literalvalues = allocate {
121 [0] = "origin",
122 [1] = "page",
123 [2] = "always",
124 [3] = "raw",
125 [4] = "text",
126 [5] = "font",
127 [6] = "special",
128}
129
130local gluevalues = mark(getvalues("glue"))
131
132gluecodes = allocate(swapped(gluecodes,gluecodes))
133dircodes = allocate(swapped(dircodes,dircodes))
134boundarycodes = allocate(swapped(boundarycodes,boundarycodes))
135noadcodes = allocate(swapped(noadcodes,noadcodes))
136radicalcodes = allocate(swapped(radicalcodes,radicalcodes))
137nodecodes = allocate(swapped(nodecodes,nodecodes))
138whatcodes = allocate(swapped(whatcodes,whatcodes))
139listcodes = allocate(swapped(listcodes,listcodes))
140glyphcodes = allocate(swapped(glyphcodes,glyphcodes))
141kerncodes = allocate(swapped(kerncodes,kerncodes))
142penaltycodes = allocate(swapped(penaltycodes,penaltycodes))
143mathcodes = allocate(swapped(mathcodes,mathcodes))
144fillcodes = allocate(swapped(fillcodes,fillcodes))
145margincodes = allocate(swapped(margincodes,margincodes))
146disccodes = allocate(swapped(disccodes,disccodes))
147accentcodes = allocate(swapped(accentcodes,accentcodes))
148fencecodes = allocate(swapped(fencecodes,fencecodes))
149parcodes = allocate(swapped(parcodes,parcodes))
150rulecodes = allocate(swapped(rulecodes,rulecodes))
151usercodes = allocate(swapped(usercodes,usercodes))
152noadoptions = allocate(swapped(noadoptions,noadoptions))
153dirvalues = allocate(swapped(dirvalues,dirvalues))
154gluevalues = allocate(swapped(gluevalues,gluevalues))
155literalvalues = allocate(swapped(literalvalues,literalvalues))
156
157if not nodecodes.delimiter then
158
159 local d = nodecodes.delim
160 nodecodes.delimiter = d
161 nodecodes[d] = "delimiter"
162 nodecodes.delim = nil
163end
164
165if not nodecodes.par then
166
167 local p = nodecodes.localpar
168 nodecodes.par = p
169 nodecodes[p] = "par"
170end
171
172if not nodecodes.insert then
173
174 local i = nodecodes.ins
175 nodecodes.insert = i
176 nodecodes[i] = "insert"
177 nodecodes.ins = nil
178end
179
180if not gluecodes.indentskip then
181 gluecodes.indentskip = gluecodes.userskip
182 gluecodes.lefthangskip = gluecodes.userskip
183 gluecodes.righthangskip = gluecodes.userskip
184 gluecodes.correctionskip = gluecodes.userskip
185 gluecodes.intermathskip = gluecodes.userskip
186 gluecodes.parfillleftskip = gluecodes.parfillskip
187 gluecodes.parfillrightskip = gluecodes.parfillskip
188end
189
190if not whatcodes.literal then
191 whatcodes.literal = whatcodes.pdfliteral
192 whatcodes.lateliteral = whatcodes.pdflateliteral
193 whatcodes.save = whatcodes.pdfsave
194 whatcodes.restore = whatcodes.pdfrestore
195 whatcodes.setmatrix = whatcodes.pdfsetmatrix
196end
197
198nodes.gluecodes = gluecodes
199nodes.dircodes = dircodes
200nodes.boundarycodes = boundarycodes
201nodes.noadcodes = noadcodes
202nodes.nodecodes = nodecodes
203nodes.whatcodes = whatcodes
204nodes.listcodes = listcodes
205nodes.glyphcodes = glyphcodes
206nodes.kerncodes = kerncodes
207nodes.penaltycodes = penaltycodes
208nodes.mathcodes = mathcodes
209nodes.fillcodes = fillcodes
210nodes.margincodes = margincodes
211nodes.disccodes = disccodes
212nodes.accentcodes = accentcodes
213nodes.radicalcodes = radicalcodes
214nodes.fencecodes = fencecodes
215nodes.parcodes = parcodes
216nodes.rulecodes = rulecodes
217nodes.usercodes = usercodes
218nodes.noadoptions = noadoptions
219nodes.dirvalues = dirvalues
220nodes.gluevalues = gluevalues
221nodes.literalvalues = literalvalues
222
223nodes.subtypes = allocate {
224 [nodecodes.accent] = accentcodes,
225 [nodecodes.boundary] = boundarycodes,
226 [nodecodes.dir] = dircodes,
227 [nodecodes.disc] = disccodes,
228 [nodecodes.fence] = fencecodes,
229 [nodecodes.glue] = gluecodes,
230 [nodecodes.glyph] = glyphcodes,
231 [nodecodes.hlist] = listcodes,
232 [nodecodes.kern] = kerncodes,
233 [nodecodes.par] = parcodes,
234
235 [nodecodes.math] = mathcodes,
236 [nodecodes.noad] = noadcodes,
237 [nodecodes.penalty] = penaltycodes,
238 [nodecodes.radical] = radicalcodes,
239 [nodecodes.rule] = rulecodes,
240
241 [nodecodes.vlist] = listcodes,
242 [nodecodes.whatsit] = whatcodes,
243 [nodecodes.marginkern] = margincodes
244}
245
246table.setmetatableindex(nodes.subtypes,function(t,k)
247 local v = { }
248 t[k] = v
249 return v
250end)
251
252
253
254nodes.skipcodes = gluecodes
255nodes.directioncodes = dircodes
256nodes.whatsitcodes = whatcodes
257nodes.marginkerncodes = margincodes
258nodes.discretionarycodes = disccodes
259nodes.directionvalues = dirvalues
260nodes.skipvalues = gluevalues
261nodes.literalvalues = literalvalues
262
263glyphcodes.glyph = glyphcodes.character
264
265listcodes.row = listcodes.alignment
266listcodes.column = listcodes.alignment
267
268kerncodes.kerning = kerncodes.fontkern
269
270kerncodes.italiccorrection = kerncodes.italiccorrection or 1
271
272literalvalues.direct = literalvalues.always
273
274nodes.codes = allocate {
275 glue = skipcodes,
276 boundary = boundarycodes,
277 noad = noadcodes,
278 node = nodecodes,
279 hlist = listcodes,
280 vlist = listcodes,
281 glyph = glyphcodes,
282 kern = kerncodes,
283 penalty = penaltycodes,
284 math = mathnodes,
285 fill = fillcodes,
286 margin = margincodes,
287 disc = disccodes,
288 whatsit = whatcodes,
289 accent = accentcodes,
290 fence = fencecodes,
291 rule = rulecodes,
292 user = usercodes,
293 noadoptions = noadoptions,
294}
295
296nodes.noadoptions = {
297 set = 0x08,
298 unused_1 = 0x00 + 0x08,
299 unused_2 = 0x01 + 0x08,
300 axis = 0x02 + 0x08,
301 no_axis = 0x04 + 0x08,
302 exact = 0x10 + 0x08,
303 left = 0x11 + 0x08,
304 middle = 0x12 + 0x08,
305 right = 0x14 + 0x08,
306}
307
308local report_codes = logs.reporter("nodes","codes")
309
310function nodes.showcodes()
311 local t = { }
312 for name, codes in sortedhash(nodes.codes) do
313 local sorted = sortedkeys(codes)
314 for i=1,#sorted do
315 local s = sorted[i]
316 if type(s) ~= "number" then
317 t[#t+1] = { name, s, codes[s] }
318 end
319 end
320 end
321 formatcolumns(t)
322 for k=1,#t do
323 report_codes (t[k])
324 end
325end
326
327trackers.register("system.showcodes", nodes.showcodes)
328
329
330
331
332if node.fix_node_lists then
333 node.fix_node_lists(false)
334end
335 |