font-ogr.lua /size: 25 Kb    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
font-ogr
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to font-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
-- Here we deal with graphic variants and for now also color support ends up here
10
-- but that might change. It's lmtx only code.
11 12
if
not
context
then
13
return
14
elseif
CONTEXTLMTXMODE
=
=
0
then
15
return
16
end
17 18
local
tostring
,
tonumber
,
next
,
type
=
tostring
,
tonumber
,
next
,
type
19
local
round
,
max
,
mod
,
div
=
math
.
round
,
math
.
max
,
math
.
mod
,
math
.
div
20
local
find
=
string
.
find
21
local
concat
,
setmetatableindex
,
sortedhash
=
table
.
concat
,
table
.
setmetatableindex
,
table
.
sortedhash
22
local
utfbyte
=
utf
.
byte
23
local
formatters
=
string
.
formatters
24
local
settings_to_hash_strict
,
settings_to_array
=
utilities
.
parsers
.
settings_to_hash_strict
,
utilities
.
parsers
.
settings_to_array
25 26
local
otf
=
fonts
.
handlers
.
otf
27
local
otfregister
=
otf
.
features
.
register
28
otf
.
svgenabled
=
true
29
otf
.
pngenabled
=
true
30 31
-- Just to remind me ... rewritten around the time this was posted on YT which
32
-- was also around the 2019 ctx meeting:
33
--
34
-- Gavin Harrison - "Threatening War" by The Pineapple Thief
35
-- https://www.youtube.com/watch?v=ENF9wth4kwM
36 37
-- todo: svg color plugin
38
-- todo: get rid of double cm in svg (tricky as also elsewhere)
39
-- todo: png offsets (depth)
40
-- todo: maybe collapse indices so that we have less files (harder to debug)
41
-- todo: manage (read: assign) font id's in lua so we know in advance
42 43
-- what here and what in backend ...
44 45
do
46 47
-- This is a prelude to something better but I'm still experimenting.
48 49
local
dropins
=
{
}
50
fonts
.
dropins
=
dropins
51
local
droppedin
=
0
52
local
identifiers
=
fonts
.
hashes
.
identifiers
53 54
function
dropins
.
nextid
(
)
55
droppedin
=
droppedin
-
1
56
return
droppedin
57
end
58 59
-- todo: pass specification table instead
60 61
function
dropins
.
provide
(
method
,
t_tfmdata
,
indexdata
,
...
)
62
local
droppedin
=
dropins
.
nextid
(
)
63
local
t_characters
=
t_tfmdata
.
characters
64
local
t_descriptions
=
t_tfmdata
.
descriptions
65
local
t_properties
=
t_tfmdata
.
properties
66
local
d_tfmdata
=
setmetatableindex
(
{
}
,
t_tfmdata
)
67
local
d_properties
=
setmetatableindex
(
{
}
,
t_properties
)
68
d_tfmdata
.
properties
=
d_properties
69
local
d_characters
=
{
}
-- setmetatableindex({ },t_characters) -- hm, index vs unicode
70
local
d_descriptions
=
{
}
-- setmetatableindex({ },t_descriptions) -- hm, index vs unicode
71
d_tfmdata
.
characters
=
d_characters
72
d_tfmdata
.
descriptions
=
d_descriptions
73
d_properties
.
instance
=
-
droppedin
-- will become an extra element in the hash
74
t_properties
.
virtualized
=
true
75
identifiers
[
droppedin
]
=
d_tfmdata
76
local
fonts
=
t_tfmdata
.
fonts
or
{
}
77
t_tfmdata
.
fonts
=
fonts
78
d_properties
.
format
=
"
type3
"
79
d_properties
.
method
=
method
80
d_properties
.
indexdata
=
{
indexdata
,
...
}
-- can take quite some memory
81
local
slot
=
#
fonts
+
1
82
fonts
[
slot
]
=
{
id
=
droppedin
}
83
return
slot
,
droppedin
,
d_tfmdata
,
d_properties
84
end
85 86
-- todo: delay this, in which case we can be leaner and meaner
87 88
function
dropins
.
clone
(
method
,
tfmdata
,
shapes
,
...
)
-- by index
89
if
method
and
shapes
then
90
local
characters
=
tfmdata
.
characters
91
local
descriptions
=
tfmdata
.
descriptions
92
local
droppedin
,
tfmdrop
,
dropchars
,
dropdescs
,
colrshapes
93
local
idx
=
255
94
local
slot
=
0
95
for
k
,
v
in
next
,
characters
do
96
local
index
=
v
.
index
97
if
index
then
98
local
description
=
descriptions
[
k
]
99
if
description
then
100
local
shape
=
shapes
[
index
]
101
if
shape
then
102
if
idx
>
=
255
then
103
idx
=
1
104
colrshapes
=
setmetatableindex
(
{
}
,
shapes
)
105
slot
,
droppedin
,
tfmdrop
=
dropins
.
provide
(
method
,
tfmdata
,
colrshapes
)
106
dropchars
=
tfmdrop
.
characters
107
dropdescs
=
tfmdrop
.
descriptions
108
else
109
idx
=
idx
+
1
110
end
111
colrshapes
[
idx
]
=
shape
-- so not: description
112
-- todo: prepend
113
v
.
commands
=
{
{
"
slot
"
,
slot
,
idx
}
}
114
-- hack to prevent that type 3 also gets 'use' flags .. todo
115
local
c
=
{
commands
=
false
,
index
=
idx
,
dropin
=
tfmdrop
}
116
local
d
=
{
}
-- { index = idx, dropin = tfmdrop }
117
setmetatableindex
(
c
,
v
)
118
setmetatableindex
(
d
,
description
)
119
dropchars
[
idx
]
=
c
120
dropdescs
[
idx
]
=
d
-- not needed
121
end
122
end
123
end
124
end
125
else
126
-- error
127
end
128
end
129 130
function
dropins
.
swap
(
method
,
tfmdata
,
shapes
,
...
)
-- by unicode
131
if
method
and
shapes
then
132
local
characters
=
tfmdata
.
characters
133
local
descriptions
=
tfmdata
.
descriptions
134
local
droppedin
,
tfmdrop
,
dropchars
,
dropdescs
,
colrshapes
135
local
idx
=
255
136
local
slot
=
0
137
-- we can have a variant where shaped are by unicode and not by index
138
for
k
,
v
in
next
,
characters
do
139
local
description
=
descriptions
[
k
]
140
if
description
then
141
local
shape
=
shapes
[
k
]
142
if
shape
then
143
if
idx
>
=
255
then
144
idx
=
1
145
colrshapes
=
setmetatableindex
(
{
}
,
shapes
)
146
slot
,
droppedin
,
tfmdrop
=
dropins
.
provide
(
method
,
tfmdata
,
colrshapes
)
147
dropchars
=
tfmdrop
.
characters
148
dropdescs
=
tfmdrop
.
descriptions
149
else
150
idx
=
idx
+
1
151
end
152
colrshapes
[
idx
]
=
shape
-- so not: description
153
-- todo: prepend
154
v
.
commands
=
{
{
"
slot
"
,
slot
,
idx
}
}
155
-- hack to prevent that type 3 also gets 'use' flags .. todo
156
local
c
=
{
commands
=
false
,
index
=
idx
,
dropin
=
tfmdrop
}
157
local
d
=
{
}
-- index = idx, dropin = tfmdrop }
158
setmetatableindex
(
c
,
v
)
159
setmetatableindex
(
d
,
description
)
160
dropchars
[
idx
]
=
c
161
dropdescs
[
idx
]
=
d
-- not needed
162
end
163
end
164
end
165
else
166
-- error
167
end
168
end
169 170
end
171 172
do
-- this will move to its own module
173 174
local
dropins
=
fonts
.
dropins
175 176
local
shapes
=
setmetatableindex
(
function
(
t
,
k
)
177
local
v
=
{
178
glyphs
=
{
}
,
179
parameters
=
{
180
units
=
1000
181
}
,
182
}
183
t
[
k
]
=
v
184
return
v
185
end
)
186 187
function
dropins
.
registerglyphs
(
parameters
)
188
local
category
=
parameters
.
name
189
local
target
=
shapes
[
category
]
.
parameters
190
for
k
,
v
in
next
,
parameters
do
191
if
k
~
=
"
glyphs
"
then
192
target
[
k
]
=
v
193
end
194
end
195
end
196 197
function
dropins
.
registerglyph
(
parameters
)
198
local
category
=
parameters
.
category
199
local
unicode
=
parameters
.
unicode
200
local
private
=
parameters
.
private
201
local
unichar
=
parameters
.
unichar
202
if
private
then
203
unicode
=
fonts
.
helpers
.
newprivateslot
(
private
)
204
elseif
type
(
unichar
)
=
=
"
string
"
then
205
unicode
=
utfbyte
(
unichar
)
206
else
207
local
unitype
=
type
(
unicode
)
208
if
unitype
=
=
"
string
"
then
209
local
uninumber
=
tonumber
(
unicode
)
210
if
uninumber
then
211
unicode
=
round
(
uninumber
)
212
else
213
unicode
=
utfbyte
(
unicode
)
214
end
215
elseif
unitype
=
=
"
number
"
then
216
unicode
=
round
(
unicode
)
217
end
218
end
219
if
unicode
then
220
parameters
.
unicode
=
unicode
221
-- print(category,unicode)
222
shapes
[
category
]
.
glyphs
[
unicode
]
=
parameters
223
else
224
-- error
225
end
226
end
227 228
-- local function hascolorspec(t)
229
-- if (t.color or "") ~= "" then
230
-- return true
231
-- elseif (t.fillcolor or "") ~= "" then
232
-- return true
233
-- elseif (t.drawcolor or "") ~= "" then
234
-- return true
235
-- elseif (t.linecolor or "") ~= "" then
236
-- return true
237
-- else
238
-- return false
239
-- end
240
-- end
241 242
local
function
hascolorspec
(
t
)
243
for
k
,
v
in
next
,
t
do
244
if
find
(
k
,
"
color
"
)
then
245
return
true
246
end
247
end
248
return
false
249
end
250 251
local
function
initializemps
(
tfmdata
,
kind
,
value
)
252
if
value
then
253
local
specification
=
settings_to_hash_strict
(
value
)
254
if
not
specification
or
not
next
(
specification
)
then
255
specification
=
{
category
=
value
}
256
end
257
-- todo: multiple categories but then maybe also different
258
-- clones because of the units .. for now we assume the same
259
-- units
260
local
category
=
specification
.
category
261
if
category
and
category
~
=
"
"
then
262
local
categories
=
settings_to_array
(
category
)
263
local
usedshapes
=
nil
264
local
index
=
0
265
local
spread
=
tonumber
(
specification
.
spread
or
0
)
266
local
hascolor
=
hascolorspec
(
specification
)
267
specification
.
spread
=
spread
-- now a number
268
for
i
=
1
,
#
categories
do
269
local
category
=
categories
[
i
]
270
local
mpsshapes
=
shapes
[
category
]
271
if
mpsshapes
then
272
local
properties
=
tfmdata
.
properties
273
local
parameters
=
tfmdata
.
parameters
274
local
characters
=
tfmdata
.
characters
275
local
descriptions
=
tfmdata
.
descriptions
276
local
mpsparameters
=
mpsshapes
.
parameters
277
local
units
=
mpsparameters
.
units
or
1000
278
local
defaultwidth
=
mpsparameters
.
width
or
0
279
local
defaultheight
=
mpsparameters
.
height
or
0
280
local
defaultdepth
=
mpsparameters
.
depth
or
0
281
local
usecolor
=
mpsparameters
.
usecolor
282
local
spread
=
spread
*
units
283
local
defaultcode
=
mpsparameters
.
code
or
"
"
284
local
scale
=
parameters
.
size
/
units
285
if
hascolor
then
286
-- the graphic has color
287
usecolor
=
false
288
else
289
-- do whatever is specified
290
end
291
usedshapes
=
usedshapes
or
{
292
instance
=
"
simplefun
"
,
293
units
=
units
,
294
usecolor
=
usecolor
,
295
specification
=
specification
,
296
shapes
=
mpsshapes
,
297
}
298
-- todo: deal with extensibles and more properties
299
for
unicode
,
shape
in
sortedhash
(
mpsshapes
.
glyphs
)
do
300
-- local oldc = characters[unicode]
301
-- if oldc then
302
index
=
index
+
1
-- todo: somehow we end up with 2 as first entry after 0
303
local
wd
=
shape
.
width
or
defaultwidth
304
local
ht
=
shape
.
height
or
defaultheight
305
local
dp
=
shape
.
depth
or
defaultdepth
306
local
newc
=
{
307
index
=
index
,
-- into usedshapes
308
width
=
scale
*
(
wd
+
spread
)
,
309
height
=
scale
*
ht
,
310
depth
=
scale
*
dp
,
311
unicode
=
unicode
,
312
}
313
--
314
characters
[
unicode
]
=
newc
315
descriptions
[
unicode
]
=
newc
316
--
317
usedshapes
[
unicode
]
=
shape
.
code
or
defaultcode
318
-- end
319
end
320
end
321
end
322
if
usedshapes
then
323
-- todo: different font when units and usecolor changes, maybe move into loop
324
-- above
325
dropins
.
swap
(
"
mps
"
,
tfmdata
,
usedshapes
)
326
end
327
end
328
end
329
end
330 331
-- This kicks in quite late, after features have been checked. So if needed
332
-- substitutions need to be defined with force.
333 334
otfregister
{
335
name
=
"
metapost
"
,
336
description
=
"
metapost glyphs
"
,
337
manipulators
=
{
338
base
=
initializemps
,
339
node
=
initializemps
,
340
}
341
}
342 343
end
344 345
-- This sits here for historcal reasons so for now we keep it here.
346 347
local
startactualtext
=
nil
348
local
stopactualtext
=
nil
349 350
function
otf
.
getactualtext
(
s
)
351
if
not
startactualtext
then
352
startactualtext
=
backends
.
codeinjections
.
startunicodetoactualtextdirect
353
stopactualtext
=
backends
.
codeinjections
.
stopunicodetoactualtextdirect
354
end
355
return
startactualtext
(
s
)
,
stopactualtext
(
)
356
end
357 358
-- This is also somewhat specific.
359 360
local
sharedpalettes
do
361 362
sharedpalettes
=
{
}
363 364
local
colors
=
attributes
.
list
[
attributes
.
private
(
'
color
'
)
]
or
{
}
365
local
transparencies
=
attributes
.
list
[
attributes
.
private
(
'
transparency
'
)
]
or
{
}
366 367
function
otf
.
registerpalette
(
name
,
values
)
368
sharedpalettes
[
name
]
=
values
369
local
color
=
lpdf
.
color
370
local
transparency
=
lpdf
.
transparency
371
local
register
=
colors
.
register
372
for
i
=
1
,
#
values
do
373
local
v
=
values
[
i
]
374
if
v
=
=
"
textcolor
"
then
375
values
[
i
]
=
false
376
else
377
local
c
=
nil
378
local
t
=
nil
379
if
type
(
v
)
=
=
"
table
"
then
380
c
=
register
(
name
,
"
rgb
"
,
381
max
(
round
(
(
v
.
r
or
0
)
*
255
)
,
255
)
/
255
,
382
max
(
round
(
(
v
.
g
or
0
)
*
255
)
,
255
)
/
255
,
383
max
(
round
(
(
v
.
b
or
0
)
*
255
)
,
255
)
/
255
384
)
385
else
386
c
=
colors
[
v
]
387
t
=
transparencies
[
v
]
388
end
389
if
c
and
t
then
390
values
[
i
]
=
color
(
1
,
c
)
.
.
"
"
.
.
transparency
(
t
)
391
elseif
c
then
392
values
[
i
]
=
color
(
1
,
c
)
393
elseif
t
then
394
values
[
i
]
=
color
(
1
,
t
)
395
end
396
end
397
end
398
end
399 400
end
401 402
local
initializeoverlay
do
403 404
-- we should use the proper interface instead but for now:
405 406
local
colors
=
attributes
.
colors
407
local
rgbtocmyk
=
colors
.
rgbtocmyk
408 409
local
f_cmyk
=
formatters
[
"
%.3N %.3f %.3N %.3N k
"
]
410
local
f_rgb
=
formatters
[
"
%.3N %.3f %.3N rg
"
]
411
local
f_gray
=
formatters
[
"
%.3N g
"
]
412 413
local
function
convert
(
t
,
k
)
414
local
v
=
{
}
415
local
m
=
colors
.
model
416
for
i
=
1
,
#
k
do
417
local
p
=
k
[
i
]
418
local
r
,
g
,
b
=
p
[
1
]
/
255
,
p
[
2
]
/
255
,
p
[
3
]
/
255
419
if
r
=
=
g
and
g
=
=
b
then
420
p
=
f_gray
(
r
)
421
elseif
m
=
=
"
cmyk
"
then
422
p
=
f_cmyk
(
rgbtocmyk
(
r
,
g
,
b
)
)
423
else
424
p
=
f_rgb
(
r
,
g
,
b
)
425
end
426
v
[
i
]
=
p
427
end
428
t
[
k
]
=
v
429
return
v
430
end
431 432
initializeoverlay
=
function
(
tfmdata
,
kind
,
value
)
-- we really need the id ... todo
433
if
value
then
434
local
resources
=
tfmdata
.
resources
435
local
palettes
=
resources
.
colorpalettes
436
if
palettes
then
437
--
438
local
converted
=
resources
.
converted
439
if
not
converted
then
440
converted
=
setmetatableindex
(
convert
)
441
resources
.
converted
=
converted
442
end
443
local
colorvalues
=
sharedpalettes
[
value
]
444
local
default
=
false
-- so the text color (bad for icon overloads)
445
if
colorvalues
then
446
default
=
colorvalues
[
#
colorvalues
]
447
else
448
colorvalues
=
converted
[
palettes
[
tonumber
(
value
)
or
1
]
or
palettes
[
1
]
]
or
{
}
449
end
450
local
classes
=
#
colorvalues
451
if
classes
=
=
0
then
452
return
453
end
454
--
455
local
characters
=
tfmdata
.
characters
456
local
descriptions
=
tfmdata
.
descriptions
457
local
droppedin
,
tfmdrop
,
dropchars
,
dropdescs
,
colrshapes
458
local
idx
=
255
459
local
slot
=
0
460
--
461
-- maybe delay in which case we have less fonts as we can be sparse
462
--
463
for
k
,
v
in
next
,
characters
do
464
local
index
=
v
.
index
465
if
index
then
466
local
description
=
descriptions
[
k
]
467
if
description
then
468
local
colorlist
=
description
.
colors
469
if
colorlist
then
470
if
idx
>
=
255
then
471
idx
=
1
472
colrshapes
=
{
}
473
slot
,
droppedin
,
tfmdrop
=
fonts
.
dropins
.
provide
(
"
color
"
,
tfmdata
,
colrshapes
,
colorvalues
)
474
dropchars
=
tfmdrop
.
characters
475
dropdescs
=
tfmdrop
.
descriptions
476
else
477
idx
=
idx
+
1
478
end
479
--
480
colrshapes
[
idx
]
=
description
481
-- todo: use extender
482
local
u
=
{
"
use
"
,
0
}
483
for
i
=
1
,
#
colorlist
do
484
u
[
i
+
2
]
=
colorlist
[
i
]
.
slot
485
end
486
v
.
commands
=
{
u
,
{
"
slot
"
,
slot
,
idx
}
}
487
-- hack to prevent that type 3 also gets 'use' flags .. todo
488
local
c
=
{
commands
=
false
,
index
=
idx
,
dropin
=
tfmdata
}
489
local
d
=
{
}
-- index = idx, dropin = tfmdrop
490
setmetatableindex
(
c
,
v
)
491
setmetatableindex
(
d
,
description
)
492
dropchars
[
idx
]
=
c
493
dropdescs
[
idx
]
=
d
-- not needed
494
end
495
end
496
end
497
end
498
return
true
499
end
500
end
501
end
502 503
fonts
.
handlers
.
otf
.
features
.
register
{
504
name
=
"
colr
"
,
505
description
=
"
color glyphs
"
,
506
manipulators
=
{
507
base
=
initializeoverlay
,
508
node
=
initializeoverlay
,
509
}
510
}
511 512
end
513 514
local
initializesvg
do
515 516
local
report_svg
=
logs
.
reporter
(
"
fonts
"
,
"
svg
"
)
517 518
local
cached
=
true
-- maybe always false (after i've optimized the lot)
519 520
directives
.
register
(
"
fonts.svg.cached
"
,
function
(
v
)
cached
=
v
end
)
521 522
initializesvg
=
function
(
tfmdata
,
kind
,
value
)
-- hm, always value
523
if
value
then
524
local
properties
=
tfmdata
.
properties
525
local
svg
=
properties
.
svg
526
local
hash
=
svg
and
svg
.
hash
527
local
timestamp
=
svg
and
svg
.
timestamp
528
if
not
hash
then
529
return
530
end
531
local
shapes
=
nil
532
local
method
=
nil
533
local
enforce
=
attributes
.
colors
.
model
=
=
"
cmyk
"
534
if
cached
and
not
enforce
then
535
-- we need a different hash than for mkiv, so we append:
536
local
pdfhash
=
hash
.
.
"
-svg
"
537
local
pdffile
=
containers
.
read
(
otf
.
pdfcache
,
pdfhash
)
538
local
pdfshapes
=
pdffile
and
pdffile
.
pdfshapes
539
local
pdftarget
=
file
.
join
(
otf
.
pdfcache
.
writable
,
file
.
addsuffix
(
pdfhash
,
"
pdf
"
)
)
540
if
not
pdfshapes
or
pdffile
.
timestamp
~
=
timestamp
or
not
next
(
pdfshapes
)
or
not
lfs
.
isfile
(
pdftarget
)
then
541
local
svgfile
=
containers
.
read
(
otf
.
svgcache
,
hash
)
542
local
svgshapes
=
svgfile
and
svgfile
.
svgshapes
543
pdfshapes
=
svgshapes
and
metapost
.
svgshapestopdf
(
svgshapes
,
pdftarget
,
report_svg
,
tfmdata
.
parameters
.
units
)
or
{
}
544
-- look at ocl: we should store scale and x and y
545
containers
.
write
(
otf
.
pdfcache
,
pdfhash
,
{
546
pdfshapes
=
pdfshapes
,
547
timestamp
=
timestamp
,
548
}
)
549
end
550
shapes
=
pdfshapes
551
method
=
"
pdf
"
552
else
553
local
mpsfile
=
containers
.
read
(
otf
.
mpscache
,
hash
)
554
local
mpsshapes
=
mpsfile
and
mpsfile
.
mpsshapes
555
if
not
mpsshapes
or
mpsfile
.
timestamp
~
=
timestamp
or
not
next
(
mpsshapes
)
then
556
local
svgfile
=
containers
.
read
(
otf
.
svgcache
,
hash
)
557
local
svgshapes
=
svgfile
and
svgfile
.
svgshapes
558
-- still suboptimal
559
mpsshapes
=
svgshapes
and
metapost
.
svgshapestomp
(
svgshapes
,
report_svg
,
tfmdata
.
parameters
.
units
)
or
{
}
560
if
enforce
then
561
-- cheap conversion, no black component generation
562
mpsshapes
.
preamble
=
"
interim svgforcecmyk := 1;
"
563
end
564
containers
.
write
(
otf
.
mpscache
,
hash
,
{
565
mpsshapes
=
mpsshapes
,
566
timestamp
=
timestamp
,
567
}
)
568
end
569
shapes
=
mpsshapes
570
method
=
"
mps
"
571
end
572
if
shapes
then
573
shapes
.
fixdepth
=
value
=
=
"
fixdepth
"
574
fonts
.
dropins
.
clone
(
method
,
tfmdata
,
shapes
)
575
end
576
return
true
577
end
578
end
579 580
otfregister
{
581
name
=
"
svg
"
,
582
description
=
"
svg glyphs
"
,
583
manipulators
=
{
584
base
=
initializesvg
,
585
node
=
initializesvg
,
586
}
587
}
588 589
end
590 591
local
initializepng
do
592 593
-- If this is really critical we can also use a pdf file as cache but I don't expect
594
-- png fonts to remain used.
595 596
local
colors
=
attributes
.
colors
597 598
local
report_png
=
logs
.
reporter
(
"
fonts
"
,
"
png conversion
"
)
599 600
initializepng
=
function
(
tfmdata
,
kind
,
value
)
-- hm, always value
601
if
value
then
602
local
properties
=
tfmdata
.
properties
603
local
png
=
properties
.
png
604
local
hash
=
png
and
png
.
hash
605
local
timestamp
=
png
and
png
.
timestamp
606
if
not
hash
then
607
return
608
end
609
local
pngfile
=
containers
.
read
(
otf
.
pngcache
,
hash
)
610
local
pngshapes
=
pngfile
and
pngfile
.
pngshapes
611
if
pngshapes
then
612
if
colors
.
model
=
=
"
cmyk
"
then
613
pngshapes
.
enforcecmyk
=
true
614
end
615
fonts
.
dropins
.
clone
(
"
png
"
,
tfmdata
,
pngshapes
)
616
end
617
return
true
618
end
619
end
620 621
otfregister
{
622
name
=
"
sbix
"
,
623
description
=
"
sbix glyphs
"
,
624
manipulators
=
{
625
base
=
initializepng
,
626
node
=
initializepng
,
627
}
628
}
629 630
otfregister
{
631
name
=
"
cblc
"
,
632
description
=
"
cblc glyphs
"
,
633
manipulators
=
{
634
base
=
initializepng
,
635
node
=
initializepng
,
636
}
637
}
638 639
end
640 641
do
642 643
-- I need to check jpeg and such but will do that when I run into
644
-- it.
645 646
local
function
initializecolor
(
tfmdata
,
kind
,
value
)
647
if
value
=
=
"
auto
"
then
648
return
649
initializeoverlay
(
tfmdata
,
kind
,
value
)
or
650
initializesvg
(
tfmdata
,
kind
,
value
)
or
651
initializepng
(
tfmdata
,
kind
,
value
)
652
elseif
value
=
=
"
overlay
"
then
653
return
initializeoverlay
(
tfmdata
,
kind
,
value
)
654
elseif
value
=
=
"
svg
"
then
655
return
initializesvg
(
tfmdata
,
kind
,
value
)
656
elseif
value
=
=
"
png
"
or
value
=
=
"
bitmap
"
then
657
return
initializepng
(
tfmdata
,
kind
,
value
)
658
else
659
-- forget about it
660
end
661
end
662 663
otfregister
{
664
name
=
"
color
"
,
665
description
=
"
color glyphs
"
,
666
manipulators
=
{
667
base
=
initializecolor
,
668
node
=
initializecolor
,
669
}
670
}
671 672
end
673