node-tst.lua /size: 4131 b    last modification: 2020-07-01 14:35
1
if
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 9
local
nodes
,
node
=
nodes
,
node
10 11
local
chardata
=
characters
.
data
12
local
nodecodes
=
nodes
.
nodecodes
13
local
gluecodes
=
nodes
.
gluecodes
14 15
local
glue_code
=
nodecodes
.
glue
16
local
penalty_code
=
nodecodes
.
penalty
17
local
kern_code
=
nodecodes
.
kern
18
local
glyph_code
=
nodecodes
.
glyph
19
local
whatsit_code
=
nodecodes
.
whatsit
20
local
hlist_code
=
nodecodes
.
hlist
21 22
local
leftskip_code
=
gluecodes
.
leftskip
23
local
rightskip_code
=
gluecodes
.
rightskip
24
local
abovedisplayshortskip_code
=
gluecodes
.
abovedisplayshortskip
25
local
belowdisplayshortskip_code
=
gluecodes
.
belowdisplayshortskip
26 27
local
nuts
=
nodes
.
nuts
28 29
local
getnext
=
nuts
.
getnext
30
local
getprev
=
nuts
.
getprev
31
local
getid
=
nuts
.
getid
32
local
getchar
=
nuts
.
getchar
33
local
getsubtype
=
nuts
.
getsubtype
34
local
getkern
=
nuts
.
getkern
35
local
getpenalty
=
nuts
.
getpenalty
36
local
getwidth
=
nuts
.
getwidth
37 38
local
find_node_tail
=
nuts
.
tail
39 40
function
nuts
.
leftmarginwidth
(
n
)
-- todo: three values
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
54
end
55 56
function
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
71
end
72 73
function
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
-- temp: or 0
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
-- maybe more category checks are needed
83
return
(
category
=
=
"
zs
"
)
and
glyph_code
84
end
85
end
86
return
false
87
end
88 89
function
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
101
end
102 103
function
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
131
end
132 133
nodes
.
leftmarginwidth
=
nodes
.
vianuts
(
nuts
.
leftmarginwidth
)
134
nodes
.
rightmarginwidth
=
nodes
.
vianuts
(
nuts
.
rightmarginwidth
)
135
nodes
.
somespace
=
nodes
.
vianuts
(
nuts
.
somespace
)
136
nodes
.
somepenalty
=
nodes
.
vianuts
(
nuts
.
somepenalty
)
137
nodes
.
is_display_math
=
nodes
.
vianuts
(
nuts
.
is_display_math
)
138