1if not modules then modules = { } end modules [ ' node-tst ' ] = {
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 chardata = characters . data
12local nodecodes = nodes . nodecodes
13local gluecodes = nodes . gluecodes
14
15local glue_code = nodecodes . glue
16local penalty_code = nodecodes . penalty
17local kern_code = nodecodes . kern
18local glyph_code = nodecodes . glyph
19local whatsit_code = nodecodes . whatsit
20local hlist_code = nodecodes . hlist
21
22local leftskip_code = gluecodes . leftskip
23local rightskip_code = gluecodes . rightskip
24local abovedisplayshortskip_code = gluecodes . abovedisplayshortskip
25local belowdisplayshortskip_code = gluecodes . belowdisplayshortskip
26
27local nuts = nodes . nuts
28
29local getnext = nuts . getnext
30local getprev = nuts . getprev
31local getid = nuts . getid
32local getchar = nuts . getchar
33local getsubtype = nuts . getsubtype
34local getkern = nuts . getkern
35local getpenalty = nuts . getpenalty
36local getwidth = nuts . getwidth
37
38local find_node_tail = nuts . tail
39
40function nuts . leftmarginwidth ( n )
41 while n do
42 local id = getid ( n )
43 if id = = glue_code then
44 return getsubtype ( n ) = = leftskip_code and getwidth ( n ) or 0
45 elseif id = = whatsit_code then
46 n = getnext ( n )
47 elseif id = = hlist_code then
48 return getwidth ( n )
49 else
50 break
51 end
52 end
53 return 0
54end
55
56function nuts . rightmarginwidth ( n )
57 if n then
58 n = find_node_tail ( n )
59 while n do
60 local id = getid ( n )
61 if id = = glue_code then
62 return getsubtype ( n ) = = rightskip_code and getwidth ( n ) or 0
63 elseif id = = whatsit_code then
64 n = getprev ( n )
65 else
66 break
67 end
68 end
69 end
70 return false
71end
72
73function nuts . somespace ( n , all )
74 if n then
75 local id = getid ( n )
76 if id = = glue_code then
77 return ( all or ( getwidth ( n ) ~ = 0 ) ) and glue_code
78 elseif id = = kern_code then
79 return ( all or ( getkern ( n ) ~ = 0 ) ) and kern
80 elseif id = = glyph_code then
81 local category = chardata [ getchar ( n ) ] . category
82
83 return ( category = = " zs " ) and glyph_code
84 end
85 end
86 return false
87end
88
89function nuts . somepenalty ( n , value )
90 if n then
91 local id = getid ( n )
92 if id = = penalty_code then
93 if value then
94 return getpenalty ( n ) = = value
95 else
96 return true
97 end
98 end
99 end
100 return false
101end
102
103function nuts . is_display_math ( head )
104 local n = getprev ( head )
105 while n do
106 local id = getid ( n )
107 if id = = penalty_code then
108 elseif id = = glue_code then
109 if getsubtype ( n ) = = abovedisplayshortskip_code then
110 return true
111 end
112 else
113 break
114 end
115 n = getprev ( n )
116 end
117 n = getnext ( head )
118 while n do
119 local id = getid ( n )
120 if id = = penalty_code then
121 elseif id = = glue_code then
122 if getsubtype ( n ) = = belowdisplayshortskip_code then
123 return true
124 end
125 else
126 break
127 end
128 n = getnext ( n )
129 end
130 return false
131end
132
133nodes . leftmarginwidth = nodes . vianuts ( nuts . leftmarginwidth )
134nodes . rightmarginwidth = nodes . vianuts ( nuts . rightmarginwidth )
135nodes . somespace = nodes . vianuts ( nuts . somespace )
136nodes . somepenalty = nodes . vianuts ( nuts . somepenalty )
137nodes . is_display_math = nodes . vianuts ( nuts . is_display_math )
138 |