1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22\startluacode
23
24local lower = string . lower
25local filesuffix = file . suffix
26local findfile = resolvers . find_file
27
28local report = logs . reporter ( " fonts " , " precache " )
29
30function fonts . names . precache ( )
31 local handlers = fonts . handlers
32 if not handlers then
33 report ( " no handlers available " )
34 return
35 end
36 local otfloader = handlers . otf and handlers . otf . load
37 local afmloader = handlers . afm and handlers . afm . load
38 if not ( otfloader or afmloader ) then
39 report ( " no otf or afm handler available " )
40 return
41 end
42 fonts . names . load ( )
43 local data = fonts . names . data
44 if not data then
45 report ( " no font data available " )
46 return
47 end
48 local specifications = data . specifications
49 if not specifications then
50 report ( " no font specifications available " )
51 return
52 end
53 local n = 0
54 for i = 1 , # specifications do
55 local specification = specifications [ i ]
56 local filename = specification . filename
57 local cleanfilename = specification . cleanfilename
58 local foundfile = findfile ( filename )
59 if foundfile and foundfile ~ = " " then
60 local suffix = lower ( filesuffix ( foundfile ) )
61 if suffix = = " otf " or suffix = = " ttf " then
62 if otfloader then
63 report ( " caching otf file: %s " , foundfile )
64 otfloader ( foundfile )
65 n = n + 1
66 end
67 elseif suffix = = " afm " then
68 if afmloader then
69 report ( " caching afm file: %s " , foundfile )
70 afmloader ( foundfile )
71 n = n + 1
72 end
73 end
74 end
75 end
76 report ( " %s files out of %s cached " , n , # specifications )
77end
78
79\stopluacode
80
81\starttext
82
83\setuppapersize
84 [ A 4 , landscape ]
85
86\setuplayout
87 [ width = middle ,
88 height = middle ,
89 footer = 0 pt ,
90 header = 1 cm ,
91 headerdistance = 0 cm ,
92 backspace = 5 mm ,
93 topspace = 5 mm ]
94
95\setupbodyfont
96 [ dejavu , 6 pt , tt ]
97
98\startmode [ * first ]
99 \startluacode
100 fonts . names . precache ( )
101 \stopluacode
102\stopmode
103
104\startluacode
105 fonts . names . load ( )
106
107 local specifications = fonts . names . data . specifications
108
109 local sorted = { }
110 local hashed = { }
111
112 for i = 1 , # specifications do
113 local filename = specifications [ i ] . cleanfilename
114 sorted [ i ] = filename
115 hashed [ filename ] = i
116 end
117
118 table . sort ( sorted )
119
120 local context = context
121 local basename = file . basename
122
123 local NC = context . NC
124 local NR = context . NR
125 local HL = context . HL
126 local bold = context . bold
127
128 context . starttabulate { " |||||||||| " }
129 HL ( )
130 NC ( ) bold ( " format " )
131 NC ( ) bold ( " cleanfilename " )
132 NC ( ) bold ( " filename " )
133
134
135 NC ( ) bold ( " fullname " )
136 NC ( ) bold ( " rawname " )
137 NC ( ) bold ( " style " )
138 NC ( ) bold ( " variant " )
139 NC ( ) bold ( " weight " )
140 NC ( ) bold ( " width " )
141 NC ( ) NR ( )
142 HL ( )
143 for i = 1 , # sorted do
144 local specification = specifications [ hashed [ sorted [ i ] ] ]
145 NC ( ) context ( specification . format )
146 NC ( ) context ( specification . cleanfilename )
147 NC ( ) context ( basename ( specification . filename ) )
148
149
150 NC ( ) context ( specification . fullname )
151 NC ( ) context ( specification . rawname )
152 NC ( ) context ( specification . style )
153 NC ( ) context ( specification . variant )
154 NC ( ) context ( specification . weight )
155 NC ( ) context ( specification . width )
156 NC ( ) NR ( )
157 end
158 context . stoptabulate ( )
159\stopluacode
160
161\stoptext
162 |