font-off.lua /size: 8413 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
font-off
'
]
=
{
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
local
tonumber
=
tonumber
10
local
lower
=
string
.
lower
11
local
round
=
math
.
round
12
local
setmetatableindex
=
table
.
setmetatableindex
13 14
local
fontloader
=
fontloader
15
----- font_to_table = fontloader.to_table
16
local
open_font
=
fontloader
.
open
17
----- get_font_info = fontloader.info
18
local
close_font
=
fontloader
.
close
19
----- font_fields = fontloader.fields
20 21
-- table={
22
-- ["familyname"]="TeXGyrePagella",
23
-- ["fontname"]="TeXGyrePagella-Regular",
24
-- ["fullname"]="TeXGyrePagella-Regular",
25
-- ["italicangle"]=0,
26
-- ["names"]={
27
-- {
28
-- ["lang"]="English (US)",
29
-- ["names"]={
30
-- ["copyright"]="Copyright 2006, 2009 for TeX Gyre extensions by B. Jackowski and J.M. Nowacki (on behalf of TeX users groups). This work is released under the GUST Font License -- see http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt for details.",
31
-- ["family"]="TeXGyrePagella",
32
-- ["fullname"]="TeXGyrePagella-Regular",
33
-- ["postscriptname"]="TeXGyrePagella-Regular",
34
-- ["preffamilyname"]="TeX Gyre Pagella",
35
-- ["subfamily"]="Regular",
36
-- ["trademark"]="Please refer to the Copyright section for the font trademark attribution notices.",
37
-- ["uniqueid"]="2.004;UKWN;TeXGyrePagella-Regular",
38
-- ["version"]="Version 2.004;PS 2.004;hotconv 1.0.49;makeotf.lib2.0.14853",
39
-- },
40
-- },
41
-- },
42
-- ["pfminfo"]={
43
-- ["avgwidth"]=528,
44
-- ["codepages"]={ 536871315, 0 },
45
-- ["firstchar"]=32,
46
-- ["fstype"]=12,
47
-- ["hhead_ascent"]=1098,
48
-- ["hhead_descent"]=-283,
49
-- ["hheadascent_add"]=0,
50
-- ["hheaddescent_add"]=0,
51
-- ["hheadset"]=1,
52
-- ["lastchar"]=64260,
53
-- ["linegap"]=0,
54
-- ["os2_breakchar"]=32,
55
-- ["os2_capheight"]=692,
56
-- ["os2_defaultchar"]=0,
57
-- ["os2_family_class"]=0,
58
-- ["os2_strikeypos"]=269,
59
-- ["os2_strikeysize"]=50,
60
-- ["os2_subxoff"]=0,
61
-- ["os2_subxsize"]=650,
62
-- ["os2_subyoff"]=75,
63
-- ["os2_subysize"]=600,
64
-- ["os2_supxoff"]=0,
65
-- ["os2_supxsize"]=650,
66
-- ["os2_supyoff"]=350,
67
-- ["os2_supysize"]=600,
68
-- ["os2_typoascent"]=726,
69
-- ["os2_typodescent"]=-274,
70
-- ["os2_typolinegap"]=200,
71
-- ["os2_vendor"]="UKWN",
72
-- ["os2_winascent"]=1098,
73
-- ["os2_windescent"]=283,
74
-- ["os2_xheight"]=449,
75
-- ["panose"]={
76
-- ["armstyle"]="Any",
77
-- ["contrast"]="Any",
78
-- ["familytype"]="Any",
79
-- ["letterform"]="Any",
80
-- ["midline"]="Any",
81
-- ["proportion"]="Any",
82
-- ["serifstyle"]="Any",
83
-- ["strokevariation"]="Any",
84
-- ["weight"]="Book",
85
-- ["xheight"]="Any",
86
-- },
87
-- ["panose_set"]=1,
88
-- ["pfmfamily"]=81,
89
-- ["pfmset"]=1,
90
-- ["subsuper_set"]=1,
91
-- ["typoascent_add"]=0,
92
-- ["typodescent_add"]=0,
93
-- ["unicoderanges"]={ 536871047, 0, 0, 0 },
94
-- ["vheadset"]=0,
95
-- ["vlinegap"]=0,
96
-- ["weight"]=400,
97
-- ["width"]=5,
98
-- ["winascent_add"]=0,
99
-- ["windescent_add"]=0,
100
-- },
101
-- ["units_per_em"]=1000,
102
-- ["version"]="2.004;PS 2.004;hotconv 1.0.49;makeotf.lib2.0.14853",
103
-- ["weight"]="Book",
104
-- }
105 106
-- We had this as temporary solution because we needed a bit more info but in the
107
-- meantime it got an interesting side effect: currently luatex delays loading of e.g.
108
-- glyphs so here we first load and then discard which is a waste. In the past it did
109
-- free memory because a full load was done. One of these things that goes unnoticed.
110
--
111
-- local function get_full_info(...) -- check with taco what we get / could get
112
-- local ff = open_font(...)
113
-- if ff then
114
-- local d = ff -- and font_to_table(ff)
115
-- d.glyphs, d.subfonts, d.gpos, d.gsub, d.lookups = nil, nil, nil, nil, nil
116
-- close_font(ff)
117
-- return d
118
-- else
119
-- return nil, "error in loading font"
120
-- end
121
-- end
122 123
-- Phillip suggested this faster variant but it's still a hack as fontloader.info should
124
-- return these keys/values (and maybe some more) but at least we close the loader which
125
-- might save some memory in the end.
126 127
-- local function get_full_info(name)
128
-- local ff = open_font(name)
129
-- if ff then
130
-- local fields = table.tohash(font_fields(ff),true) -- isn't that one stable
131
-- local d = {
132
-- names = fields.names and ff.names,
133
-- familyname = fields.familyname and ff.familyname,
134
-- fullname = fields.fullname and ff.fullname,
135
-- fontname = fields.fontname and ff.fontname,
136
-- weight = fields.weight and ff.weight,
137
-- italicangle = fields.italicangle and ff.italicangle,
138
-- units = fields.units_per_em and ff.units_per_em,
139
-- designsize = fields.design_size and ff.design_size,
140
-- minsize = fields.design_range_bottom and ff.design_range_bottom,
141
-- maxsize = fields.design_range_top and ff.design_range_top,
142
-- italicangle = fields.italicangle and ff.italicangle,
143
-- pfmweight = pfminfo and pfminfo.weight or 400,
144
-- pfmwidth = pfminfo and pfminfo.width or 5,
145
-- }
146
-- -- setmetatableindex(d,function(t,k)
147
-- -- report_names("warning, trying to access field %a in font table of %a",k,name)
148
-- -- end)
149
-- close_font(ff)
150
-- return d
151
-- else
152
-- return nil, "error in loading font"
153
-- end
154
-- end
155 156
-- more efficient:
157 158
local
fields
=
nil
159 160
local
function
check_names
(
names
)
161
if
names
then
162
for
i
=
1
,
#
names
do
163
local
name
=
names
[
i
]
164
if
lower
(
name
.
lang
)
=
=
"
english (us)
"
then
-- lower added
165
return
name
.
names
166
end
167
end
168
end
169
end
170 171
local
function
get_full_info
(
name
)
172
local
ff
=
open_font
(
name
)
173
if
ff
then
174
-- unfortunately luatex aborts when a field is not available but we just make
175
-- sure that we only access a few known ones
176
local
pfminfo
=
ff
.
pfminfo
or
{
}
177
local
names
=
check_names
(
ff
.
names
)
or
{
}
178
local
weight
=
names
.
weight
or
ff
.
weight
179
local
width
=
names
.
width
-- no: ff.width
180
local
d
=
{
181
fontname
=
ff
.
fontname
,
182
fullname
=
names
.
fullname
or
ff
.
fullname
,
183
family
=
names
.
family
,
184
subfamily
=
names
.
subfamily
,
185
familyname
=
names
.
preffamilyname
or
names
.
family
or
ff
.
familyname
,
186
subfamilyname
=
names
.
prefmodifiers
or
names
.
subfamily
,
187
weight
=
weight
and
lower
(
weight
)
,
188
width
=
width
and
lower
(
width
)
,
189
italicangle
=
round
(
1000
*
(
tonumber
(
ff
.
italicangle
)
or
0
)
)
/
1000
or
0
,
190
units
=
ff
.
units_per_em
,
191
designsize
=
ff
.
design_size
,
192
minsize
=
ff
.
design_range_bottom
,
193
maxsize
=
ff
.
design_range_top
,
194
pfmweight
=
pfminfo
.
weight
or
400
,
195
pfmwidth
=
pfminfo
.
width
or
5
,
196
monospaced
=
pfminfo
.
panose
and
pfminfo
.
panose
.
proportion
=
=
"
Monospaced
"
,
197
}
198
close_font
(
ff
)
199
return
d
200
else
201
return
nil
,
"
error in loading font
"
202
end
203
end
204 205
-- As we have lazy loading anyway, this one still is full and with less code than
206
-- the previous one. But this depends on the garbage collector to kick in and in the
207
-- current version that somehow happens not that often (on my machine I end up with
208
-- some 3 GB extra before that happens).
209 210
-- local function get_full_info(...)
211
-- local ff = open_font(...)
212
-- if ff then
213
-- local d = { } -- ff is userdata so [1] or # fails on it
214
-- setmetatableindex(d,ff)
215
-- return d -- garbage collection will do the close_font(ff)
216
-- else
217
-- return nil, "error in loading font"
218
-- end
219
-- end
220 221
fonts
=
fonts
or
{
}
222
local
handlers
=
fonts
.
handlers
or
{
}
223
fonts
.
handlers
=
handlers
224
local
otf
=
handlers
.
otf
or
{
}
225
handlers
.
otf
=
otf
226
local
readers
=
otf
.
readers
or
{
}
227
otf
.
readers
=
readers
228 229
fontloader
.
fullinfo
=
get_full_info
230
readers
.
getinfo
=
readers
.
getinfo
or
get_full_info
231