node-cmp.lua /size: 5712 b    last modification: 2020-07-01 14:35
1
if
node
.
count
then
2
return
3
end
4 5
local
type
=
type
6 7
local
node
=
node
8
local
direct
=
node
.
direct
9
local
todirect
=
direct
.
tovaliddirect
10
local
tonode
=
direct
.
tonode
11 12
local
count
=
direct
.
count
13
local
length
=
direct
.
length
14
local
slide
=
direct
.
slide
15 16
function
node
.
count
(
id
,
first
,
last
)
17
return
count
(
id
,
first
and
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
18
end
19 20
function
node
.
length
(
first
,
last
)
21
return
length
(
first
and
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
22
end
23 24
function
node
.
slide
(
n
)
25
if
n
then
26
n
=
slide
(
todirect
(
n
)
)
27
if
n
then
28
return
tonode
(
n
)
29
end
30
end
31
return
nil
32
end
33 34
local
hyphenating
=
direct
.
hyphenating
35
local
ligaturing
=
direct
.
ligaturing
36
local
kerning
=
direct
.
kerning
37 38
-- kind of inconsistent
39 40
function
node
.
hyphenating
(
first
,
last
)
41
if
first
then
42
local
h
,
t
=
hyphenating
(
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
43
return
h
and
tonode
(
h
)
or
nil
,
t
and
tonode
(
t
)
or
nil
,
true
44
else
45
return
nil
,
false
46
end
47
end
48 49
function
node
.
ligaturing
(
first
,
last
)
50
if
first
then
51
local
h
,
t
=
ligaturing
(
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
52
return
h
and
tonode
(
h
)
or
nil
,
t
and
tonode
(
t
)
or
nil
,
true
53
else
54
return
nil
,
false
55
end
56
end
57 58
function
node
.
kerning
(
first
,
last
)
59
if
first
then
60
local
h
,
t
=
kerning
(
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
61
return
h
and
tonode
(
h
)
or
nil
,
t
and
tonode
(
t
)
or
nil
,
true
62
else
63
return
nil
,
false
64
end
65
end
66 67
local
protect_glyph
=
direct
.
protect_glyph
68
local
unprotect_glyph
=
direct
.
unprotect_glyph
69
local
protect_glyphs
=
direct
.
protect_glyphs
70
local
unprotect_glyphs
=
direct
.
unprotect_glyphs
71 72
function
node
.
protect_glyphs
(
first
,
last
)
73
protect_glyphs
(
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
74
end
75 76
function
node
.
unprotect_glyphs
(
first
,
last
)
77
unprotect_glyphs
(
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
78
end
79 80
function
node
.
protect_glyph
(
first
)
81
protect_glyph
(
todirect
(
first
)
)
82
end
83 84
function
node
.
unprotect_glyph
(
first
)
85
unprotect_glyph
(
todirect
(
first
)
)
86
end
87 88
local
flatten_discretionaries
=
direct
.
flatten_discretionaries
89
local
check_discretionaries
=
direct
.
check_discretionaries
90
local
check_discretionary
=
direct
.
check_discretionary
91 92
function
node
.
flatten_discretionaries
(
first
)
93
local
h
,
count
=
flatten_discretionaries
(
todirect
(
first
)
)
94
return
tonode
(
h
)
,
count
95
end
96 97
function
node
.
check_discretionaries
(
n
)
98
check_discretionaries
(
todirect
(
n
)
)
99
end
100 101
function
node
.
check_discretionary
(
n
)
102
check_discretionary
(
todirect
(
n
)
)
103
end
104 105
local
hpack
=
direct
.
hpack
106
local
vpack
=
direct
.
vpack
107
local
list_to_hlist
=
direct
.
mlist_to_hlist
108 109
function
node
.
hpack
(
head
,
...
)
110
local
h
,
badness
=
hpack
(
head
and
todirect
(
head
)
or
nil
,
...
)
111
return
tonode
(
h
)
,
badness
112
end
113 114
function
node
.
vpack
(
head
,
...
)
115
local
h
,
badness
=
vpack
(
head
and
todirect
(
head
)
or
nil
,
...
)
116
return
tonode
(
h
)
,
badness
117
end
118 119
function
node
.
mlist_to_hlist
(
head
,
...
)
120
return
tonode
(
mlist_to_hlist
(
head
and
todirect
(
head
)
or
nil
,
...
)
)
121
end
122 123
local
end_of_math
=
direct
.
end_of_math
124
local
find_attribute
=
direct
.
find_attribute
125
local
first_glyph
=
direct
.
first_glyph
126 127
function
node
.
end_of_math
(
n
)
128
if
n
then
129
n
=
end_of_math
(
todirect
(
n
)
)
130
if
n
then
131
return
tonode
(
n
)
132
end
133
end
134
return
nil
135
end
136 137
function
node
.
find_attribute
(
n
,
a
)
138
if
n
then
139
local
v
,
n
=
find_attribute
(
todirect
(
n
)
,
a
)
140
if
n
then
141
return
v
,
tonode
(
n
)
142
end
143
end
144
return
nil
145
end
146 147
function
node
.
first_glyph
(
first
,
last
)
148
local
n
=
first_glyph
(
todirect
(
first
)
,
last
and
todirect
(
last
)
or
nil
)
149
return
n
and
tonode
(
n
)
or
nil
150
end
151 152
local
dimensions
=
direct
.
dimensions
153
local
rangedimensions
=
direct
.
rangedimensions
154
local
effective_glue
=
direct
.
effective_glue
155 156
function
node
.
dimensions
(
a
,
b
,
c
,
d
,
e
)
157
if
type
(
a
)
=
=
"
userdata
"
then
158
a
=
todirect
(
a
)
159
if
type
(
b
)
=
=
"
userdata
"
then
160
b
=
todirect
(
b
)
161
end
162
return
dimensions
(
a
,
b
)
163
else
164
d
=
todirect
(
d
)
165
if
type
(
e
)
=
=
"
userdata
"
then
166
e
=
todirect
(
e
)
167
end
168
return
dimensions
(
a
,
b
,
c
,
d
,
e
)
169
end
170
return
0
,
0
,
0
171
end
172 173
function
node
.
rangedimensions
(
parent
,
first
,
last
)
174
return
rangedimenensions
(
todirect
(
parent
)
,
todirect
(
first
)
,
last
and
todirect
(
last
)
)
175
end
176 177
function
node
.
effective_glue
(
list
,
parent
)
178
return
effective_glue
(
list
and
todirect
(
list
)
or
nil
,
parent
and
todirect
(
parent
)
or
nil
)
179
end
180 181
local
uses_font
=
direct
.
uses_font
182
local
has_glyph
=
direct
.
has_glyph
183
local
protrusion_skippable
=
direct
.
protrusion_skippable
184
local
prepend_prevdepth
=
direct
.
prepend_prevdepth
185
local
make_extensible
=
direct
.
make_extensible
186 187
function
node
.
uses_font
(
n
,
f
)
188
return
uses_font
(
todirect
(
n
)
,
f
)
189
end
190 191
function
node
.
has_glyph
(
n
)
192
return
has_glyph
(
todirect
(
n
)
)
193
end
194 195
function
node
.
protrusion_skippable
(
n
)
196
return
protrusion_skippable
(
todirect
(
n
)
)
197
end
198 199
function
node
.
prepend_prevdepth
(
n
)
200
local
n
,
d
=
prepend_prevdepth
(
todirect
(
n
)
)
201
return
tonode
(
n
)
,
d
202
end
203 204
function
node
.
make_extensible
(
...
)
205
local
n
=
make_extensible
(
...
)
206
return
n
and
tonode
(
n
)
or
nil
207
end
208 209
local
last_node
=
direct
.
last_node
210 211
function
node
.
last_node
(
)
212
local
n
=
last_node
(
)
213
return
n
and
tonode
(
n
)
or
nil
214
end
215 216
local
is_zero_glue
=
direct
.
is_zero_glue
217
local
getglue
=
direct
.
getglue
218
local
setglue
=
direct
.
setglue
219 220
function
node
.
is_zero_glue
(
n
)
221
return
is_zero_glue
(
todirect
(
n
)
)
222
end
223 224
function
node
.
get_glue
(
n
)
225
return
get_glue
(
todirect
(
n
)
)
226
end
227 228
function
node
.
set_glue
(
n
)
229
return
set_glue
(
todirect
(
n
)
)
230
end
231 232
node
.
family_font
=
tex
.
getfontoffamily
233