node-cmp.lmt /size: 6161 b    last modification: 2023-12-21 09:44
1if not modules then modules = { } end modules ['node-cmp'] = {
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-- This is a LuaTeX compatibility module. The code below is no longer
10-- present in node-met or node-aux. These functions are rarely used.
11
12if node.count then
13    return
14end
15
16local type = type
17
18local node     = node
19local direct   = node.direct
20local todirect = direct.tovaliddirect
21local tonode   = direct.tonode
22
23local count  = direct.count
24local length = direct.length
25local slide  = direct.slide
26
27function node.count(id,first,last)
28    return count(id,first and todirect(first), last and todirect(last) or nil)
29end
30
31function node.length(first,last)
32    return length(first and todirect(first), last and todirect(last) or nil)
33end
34
35function node.slide(n)
36    if n then
37        n = slide(todirect(n))
38        if n then
39            return tonode(n)
40        end
41    end
42    return nil
43end
44
45local hyphenating = direct.hyphenating
46local ligaturing  = direct.ligaturing
47local kerning     = direct.kerning
48
49-- kind of inconsistent
50
51function node.hyphenating(first,last)
52    if first then
53        local h, t = hyphenating(todirect(first), last and todirect(last) or nil)
54        return h and tonode(h) or nil, t and tonode(t) or nil, true
55    else
56        return nil, false
57    end
58end
59
60function node.ligaturing(first,last)
61    if first then
62        local h, t = ligaturing(todirect(first), last and todirect(last) or nil)
63        return h and tonode(h) or nil, t and tonode(t) or nil, true
64    else
65        return nil, false
66    end
67end
68
69function node.kerning(first,last)
70    if first then
71        local h, t = kerning(todirect(first), last and todirect(last) or nil)
72        return h and tonode(h) or nil, t and tonode(t) or nil, true
73    else
74        return nil, false
75    end
76 end
77
78local protectglyph    = direct.protectglyph
79local unprotectglyph  = direct.unprotectglyph
80local protectglyphs   = direct.protectglyphs
81local unprotectglyphs = direct.unprotectglyphs
82
83function node.protectglyphs(first,last)
84    protectglyphs(todirect(first), last and todirect(last) or nil)
85end
86
87function node.unprotectglyphs(first,last)
88    unprotectglyphs(todirect(first), last and todirect(last) or nil)
89end
90
91function node.protectglyph(first)
92    protectglyph(todirect(first))
93end
94
95function node.unprotectglyph(first)
96    unprotectglyph(todirect(first))
97end
98
99local flattendiscretionaries = direct.flattendiscretionaries
100local checkdiscretionaries   = direct.checkdiscretionaries
101local checkdiscretionary     = direct.checkdiscretionary
102
103function node.flattendiscretionaries(first)
104    local h, count = flattendiscretionaries(todirect(first))
105    return tonode(h), count
106end
107
108function node.checkdiscretionaries(n) checkdiscretionaries(todirect(n)) end
109function node.checkdiscretionary  (n) checkdiscretionary  (todirect(n)) end
110
111local hpack        = direct.hpack
112local vpack        = direct.vpack
113local mlisttohlist = direct.mlisttohlist
114
115function node.hpack(head,...)
116    local h, badness = hpack(head and todirect(head) or nil,...)
117    return tonode(h), badness
118end
119
120function node.vpack(head,...)
121    local h, badness = vpack(head and todirect(head) or nil,...)
122    return tonode(h), badness
123end
124
125function node.mlisttohlist(head,...)
126    return tonode(mlisttohlist(head and todirect(head) or nil,...))
127end
128
129local endofmath      = direct.endofmath
130local findattribute  = direct.findattribute
131----- firstglyph     = direct.firstglyph
132----- firstchar      = direct.firstchar
133
134function node.endofmath(n)
135    if n then
136        n = endofmath(todirect(n))
137        if n then
138            return tonode(n)
139        end
140    end
141    return nil
142end
143
144function node.findattribute(n,a)
145    if n then
146        local v, n = findattribute(todirect(n),a)
147        if n then
148            return v, tonode(n)
149        end
150    end
151    return nil
152end
153
154-- function node.firstglyph(first,last)
155--     local n = firstglyph(todirect(first), last and todirect(last) or nil)
156--     return n and tonode(n) or nil
157-- end
158--
159-- function node.firstchar(first,last)
160--     local n = firstchar(todirect(first), last and todirect(last) or nil)
161--     return n and tonode(n) or nil
162-- end
163
164local dimensions      = direct.dimensions
165local rangedimensions = direct.rangedimensions
166local effectiveglue   = direct.effectiveglue
167
168function node.dimensions(a,b,c,d,e)
169    if type(a) == "userdata" then
170        a = todirect(a)
171        if type(b) == "userdata" then
172            b = todirect(b)
173        end
174        return dimensions(a,b)
175    else
176        d = todirect(d)
177        if type(e) == "userdata" then
178            e = todirect(e)
179        end
180        return dimensions(a,b,c,d,e)
181    end
182    return 0, 0, 0
183end
184
185function node.rangedimensions(parent,first,last)
186    return rangedimenensions(todirect(parent),todirect(first),last and todirect(last))
187end
188
189function node.effectiveglue(list,parent)
190    return effectiveglue(list and todirect(list) or nil,parent and todirect(parent) or nil)
191end
192
193local usesfont            = direct.usesfont
194local hasglyph            = direct.hasglyph
195local protrusionskippable = direct.protrusionskippable
196
197function node.usesfont           (n,f) return usesfont(todirect(n),f)          end
198function node.hasglyph           (n)   return hasglyph(todirect(n))            end
199function node.protrusionskippable(n)   return protrusionskippable(todirect(n)) end
200
201local makeextensible = direct.make_extensible
202local lastnode       = direct.lastnode
203
204function node.makeextensible(...) local n = makeextensible(...) return n and tonode(n) or nil end
205function node.lastnode      ()    local n = lastnode()          return n and tonode(n) or nil end
206
207local iszeroglue = direct.iszeroglue
208local getglue    = direct.getglue
209local setglue    = direct.setglue
210
211function node.iszeroglue(n)     return iszeroglue(todirect(n))     end
212function node.getglue   (n)     return getglue   (todirect(n))     end
213function node.setglue   (n,...) return setglue   (todirect(n),...) end
214
215node.family_font = tex.getfontoffamily
216