1if not modules then modules = { } end modules ['math-fnt'] = {
2 version = 1.001,
3 comment = "companion to math-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
11
12local round = math.round
13local setmetatableindex = table.setmetatableindex
14
15local nuts = nodes.nuts
16local tonut = nodes.tonut
17local tonode = nodes.tonode
18local nodepool = nuts.pool
19
20local vlist_code <const> = nodes.nodecodes.vlist
21
22local new_hlist = nodepool.hlist
23local new_vlist = nodepool.vlist
24
25local new_glyph = nuts.newmathglyph
26
27local getattrlst = nuts.getattributelist
28local setattrlst = nuts.setattributelist
29local setwhd = nuts.setwhd
30local getwhd = nuts.getwhd
31local getid = nuts.getid
32
33local chardata = fonts.hashes.characters
34local addcharacters = font.addcharacters
35
36
37
38
39local cache = setmetatableindex(function(t,width)
40 local v = setmetatableindex(function(t,height)
41 local v = setmetatableindex(function(t,depth)
42 local v = setmetatableindex(function(t,font)
43 local v = setmetatableindex(function(t,char)
44 t[char] = v
45 return v
46 end)
47 t[font] = v
48 return v
49 end)
50 t[depth] = v
51 return v
52 end)
53 t[height] = v
54 return v
55 end)
56 t[width] = v
57 return v
58end)
59
60local enabled = "both" directives.register("math.extensibles", function(v) enabled = v end)
61
62
63
64local function register_extensible(font,char,style,att,box)
65 if enabled then
66
67 local fontdata = chardata[font]
68 local oldchar = fontdata[char]
69 if oldchar and not oldchar.keepvirtual then
70 if enabled == true or enabled == "both" or oldchar.partsorientation == enabled then
71
72 else
73 return
74 end
75 local bx = tonut(box)
76
77
78
79
80
81
82 local id = getid(bx)
83 local al = tonut(att)
84 local wd, ht, dp = getwhd(bx)
85 local unicode = oldchar.unicode or char
86
87 local oldcommands = oldchar.oldcommands
88 local newcommands = oldchar.commands
89 if oldcommands then
90 oldchar.commands = oldcommands
91 end
92
93 local p = fonts.hashes.parameters[font]
94 local sx = round(1000/(p.extendfactor or 1)) or 1000
95 local sy = round(1000/(p.squeezefactor or 1)) or 1000
96
97
98
99
100
101
102
103
104
105
106 local private = cache[wd][ht][dp][font][unicode]
107 if private then
108nodes.flushlist(box)
109 else
110 private = fonts.helpers.setboxdirectly(font,unicode,box,true)
111 cache[wd][ht][dp][font][unicode] = private
112 end
113 local glyph = new_glyph(font,private,al)
114 setattrlst(glyph,al)
115 nuts.setscales(glyph,1000,sx,sy)
116
117
118
119
120
121
122
123 local n = new_hlist(glyph)
124
125 if newcommands then
126 oldchar.commands = newcommands
127 end
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 setwhd(n,wd,ht,dp)
151 setattrlst(n,al)
152 if id == vlist_code then
153 n = new_vlist(n)
154 setwhd(n,wd,ht,dp)
155 setattrlst(n,al)
156 end
157 return tonode(n)
158 end
159 end
160end
161
162callbacks.register("register_extensible",register_extensible,"register math extensible construct")
163 |