1if not modules then modules = { } end modules ['s-fonts-system'] = {
2 version = 1.001,
3 comment = "companion to s-fonts-system.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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30moduledata.fonts = moduledata.fonts or { }
31moduledata.fonts.system = moduledata.fonts.system or { }
32
33local context = context
34local NC, NR, HL = context.NC, context.NR, context.HL
35local ctx_bold = context.bold
36local ctx_verbatim = context.verbatim
37local lpegmatch = lpeg.match
38local sortedhash = table.sortedhash
39local formatters = string.formatters
40local concat = table.concat
41local lower = string.lower
42local gsub = string.gsub
43local find = string.find
44
45local function allfiles(specification)
46 local pattern = lower(specification.pattern or "")
47 local list = fonts.names.list(pattern,false,true)
48 if list then
49 local files = { }
50 for k, v in next, list do
51 files[file.basename(string.lower(v.filename))] = v
52 end
53 return files
54 end
55end
56
57function moduledata.fonts.system.showinstalled(specification)
58 specification = interfaces.checkedspecification(specification)
59 local files = allfiles(specification)
60 if files then
61 context.starttabulate { "|Tl|Tl|Tl|Tl|Tl|Tl|" }
62 HL()
63 NC() ctx_bold("filename")
64 NC() ctx_bold("fontname")
65 NC() ctx_bold("subfamily")
66 NC() ctx_bold("variant")
67 NC() ctx_bold("weight")
68 NC() ctx_bold("width")
69 NC() NR()
70 HL()
71 for filename, data in table.sortedpairs(files) do
72 NC() context(filename)
73 NC() context(data.fontname)
74 NC() context(data.subfamily)
75 NC() context(data.variant)
76 NC() context(data.weight)
77 NC() context(data.width)
78 NC() NR()
79 end
80 context.stoptabulate()
81 end
82end
83
84function moduledata.fonts.system.cacheinstalled(specification)
85 specification = interfaces.checkedspecification(specification)
86 local files = allfiles(specification)
87 if files then
88 local threshold = tonumber(specification.threshold)
89 local suffixes = specification.suffixes
90 if suffixes then
91 suffixes = utilities.parsers.settings_to_set(suffixes)
92 else
93 suffixes = { otf = true, ttf = true }
94 end
95 for filename, data in table.sortedpairs(files) do
96 if string.find(filename," ") then
97
98 elseif suffixes[file.suffix(filename)] then
99 local fullname = resolvers.findfile(filename)
100 context.start()
101 context.type(fullname)
102 context.par()
103 if threshold and file.size(fullname) > threshold then
104 logs.report("fonts","ignoring : %s",fullname)
105 else
106 logs.report("fonts","caching : %s",fullname)
107 context.definedfont { filename }
108 end
109 context.stop()
110 end
111 end
112 end
113end
114
115local splitter = lpeg.splitat(lpeg.S("._"),true)
116
117local method = 4
118
119function moduledata.fonts.system.showinstalledglyphnames(specification)
120 specification = interfaces.checkedspecification(specification)
121 local paths = caches.getreadablepaths()
122 local files = { }
123 local names = table.setmetatableindex("table")
124 local f_u = formatters["%04X"]
125 for i=1,#paths do
126 local list = dir.glob(paths[i].."/fonts/o*/**." .. utilities.lua.suffixes.tmc)
127 for i=1,#list do
128 files[list[i]] = true
129 end
130 end
131 for filename in table.sortedhash(files) do
132 local fontname = file.nameonly(filename)
133 logs.report("system","fontfile: %s",fontname)
134 local data = table.load(filename)
135 if data then
136 if method == 1 then
137 local unicodes = data.resources.unicodes
138 if unicodes then
139 for n, u in sortedhash(unicodes) do
140 if u >= 0xF0000 or (u >= 0xE000 and u <= 0xF8FF) then
141
142 else
143 local f = lpegmatch(splitter,n) or n
144 if #f > 0 then
145 local t = names[f]
146 t[u] = (t[u] or 0) + 1
147 end
148 end
149 end
150 end
151 elseif method == 2 then
152 local unicodes = data.resources.unicodes
153 if unicodes then
154 for n, u in sortedhash(unicodes) do
155 if u >= 0xF0000 or (u >= 0xE000 and u <= 0xF8FF) then
156
157 else
158 local t = names[n]
159 t[u] = (t[u] or 0) + 1
160 end
161 end
162 end
163 elseif method == 3 then
164 local descriptions = data.descriptions
165 if descriptions then
166 for u, d in sortedhash(descriptions) do
167 local n = d.name
168 local u = d.unicode
169 if n and u then
170 if type(u) == "table" then
171 local t = { }
172 for i=1,#u do
173 t[i] = f_u(u[i])
174 end
175 u = concat(t," ")
176 end
177 local t = names[n]
178 t[u] = (t[u] or 0) + 1
179 end
180 end
181 end
182 elseif method == 4 then
183 local descriptions = data.descriptions
184 if descriptions then
185 for u, d in sortedhash(descriptions) do
186 local n = d.name
187 local u = d.unicode
188 if n and not u and not find(n,"^%.") then
189 local n = names[n]
190 n[#n+1] = fontname
191 end
192 end
193 end
194 else
195
196 end
197 end
198 end
199
200
201 if method == 4 then
202 if next(names) then
203 context.starttabulate { "|l|pl|" }
204 local f_u = formatters["%04X~(%i)"]
205 local f_s = formatters["%s~(%i)"]
206 for k, v in sortedhash(names) do
207 NC() ctx_verbatim(k)
208 NC() context("% t",v)
209 NC() NR()
210 end
211 context.stoptabulate()
212 end
213 table.save("s-fonts-system-glyph-unknowns.lua",names)
214 else
215 if next(names) then
216 context.starttabulate { "|l|pl|" }
217 local f_u = formatters["%04X~(%i)"]
218 local f_s = formatters["%s~(%i)"]
219 for k, v in sortedhash(names) do
220 local t = { }
221 for k, v in sortedhash(v) do
222 if type(k) == "string" then
223 t[#t+1] = f_s(k,v)
224 else
225 t[#t+1] = f_u(k,v)
226 end
227 end
228 NC() ctx_verbatim(k)
229 NC() context("%, t",t)
230 NC() NR()
231 end
232 context.stoptabulate()
233 end
234 table.save("s-fonts-system-glyph-names.lua",names)
235 end
236end
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322 |