- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfont_names.php
More file actions
240 lines (213 loc) · 7.32 KB
/
font_names.php
File metadata and controls
240 lines (213 loc) · 7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
namespace Mpdf;
use Mpdf\Fonts\FontCache;
/**
* This script examines your font directory.
* By default this will examine the font directory defined by $mpdf->fontDir
* You can optionally output just the font samples as a PDF file by setting $pdf=true.
*/
$pdf = false;
require_once '../vendor/autoload.php';
$mpdf = new Mpdf(['mode' => 's']);
$fontCache = new FontCache(new Cache($mpdf->fontTempDir));
$mpdf->useSubstitutions = true;
$ttfdir = $mpdf->fontDir;
$ttf = new TTFontFileAnalysis($fontCache, $mpdf->getFontDescriptor());
$tempfontdata = array();
$tempsansfonts = array();
$tempseriffonts = array();
$tempmonofonts = array();
$tempfonttrans = array();
$ff = scandir($ttfdir);
foreach ($ff as $f) {
$ret = array();
$isTTC = false;
if (strtolower(substr($f, -4, 4)) == '.ttc' || strtolower(substr($f, -5, 5)) == '.ttcf') { // Mac ttcf
$isTTC = true;
$ttf->getTTCFonts($ttfdir . '/' . $f);
$nf = $ttf->numTTCFonts;
for ($i = 1; $i <= $nf; $i++) {
$ret[] = $ttf->extractCoreInfo($ttfdir . '/' . $f, $i);
}
} else if (strtolower(substr($f, -4, 4)) == '.ttf' || strtolower(substr($f, -4, 4)) == '.otf') {
$ret[] = $ttf->extractCoreInfo($ttfdir . '/' . $f);
}
for ($i = 0; $i < count($ret); $i++) {
if (!is_array($ret[$i])) {
if (!$pdf) {
echo $ret[$i] . '<br />';
}
} else {
$tfname = $ret[$i][0];
$bold = $ret[$i][1];
$italic = $ret[$i][2];
$fname = strtolower($tfname);
$fname = preg_replace('/[ ()]/', '', $fname);
$tempfonttrans[$tfname] = $fname;
$style = '';
if ($bold) {
$style .= 'B';
}
if ($italic) {
$style .= 'I';
}
if (!$style) {
$style = 'R';
}
$tempfontdata[$fname][$style] = $f;
if ($isTTC) {
$tempfontdata[$fname]['TTCfontID'][$style] = $ret[$i][4];
}
//if ($ret[$i][5]) { $tempfontdata[$fname]['rtl'] = true; }
//if ($ret[$i][7]) { $tempfontdata[$fname]['cjk'] = true; }
if ($ret[$i][8]) {
$tempfontdata[$fname]['sip'] = true;
}
if ($ret[$i][9]) {
$tempfontdata[$fname]['smp'] = true;
}
if ($ret[$i][10]) {
$tempfontdata[$fname]['puaag'] = true;
}
if ($ret[$i][11]) {
$tempfontdata[$fname]['pua'] = true;
}
if ($ret[$i][12]) {
$tempfontdata[$fname]['unAGlyphs'] = true;
}
$ftype = $ret[$i][3]; // mono, sans or serif
if ($ftype == 'sans') {
$tempsansfonts[] = $fname;
} else if ($ftype == 'serif') {
$tempseriffonts[] = $fname;
} else if ($ftype == 'mono') {
$tempmonofonts[] = $fname;
}
}
}
}
$tempsansfonts = array_unique($tempsansfonts);
$tempseriffonts = array_unique($tempseriffonts);
$tempmonofonts = array_unique($tempmonofonts);
$tempfonttrans = array_unique($tempfonttrans);
if (!$pdf) {
echo '<h3>Information</h3>';
}
foreach ($tempfontdata as $fname => $v) {
if (!isset($tempfontdata[$fname]['R']) || !$tempfontdata[$fname]['R']) {
if (!$pdf) {
echo 'WARNING - Font file for ' . $fname . ' may be an italic cursive script, or extra-bold etc.<br />';
}
if (isset($tempfontdata[$fname]['I']) && $tempfontdata[$fname]['I']) {
$tempfontdata[$fname]['R'] = $tempfontdata[$fname]['I'];
} else if (isset($tempfontdata[$fname]['B']) && $tempfontdata[$fname]['B']) {
$tempfontdata[$fname]['R'] = $tempfontdata[$fname]['B'];
} else if (isset($tempfontdata[$fname]['BI']) && $tempfontdata[$fname]['BI']) {
$tempfontdata[$fname]['R'] = $tempfontdata[$fname]['BI'];
}
}
if (isset($tempfontdata[$fname]['smp']) && $tempfontdata[$fname]['smp']) {
if (!$pdf) {
echo 'INFO - Font file ' . $fname . ' contains characters in Unicode Plane 1 SMP<br />';
}
$tempfontdata[$fname]['smp'] = false;
}
// if (isset($tempfontdata[$fname]['pua']) && $tempfontdata[$fname]['pua']) {
// if (!$pdf) echo 'INFO - Font file '.$fname.' contains characters in Unicode Private Use Area (U+E000-U+F8FF)<br />';
// }
if (isset($tempfontdata[$fname]['unAGlyphs']) && $tempfontdata[$fname]['unAGlyphs']) {
if (!$pdf) {
echo 'INFO - Font file ' . $fname . ' contains non-indexed Arabic Glyphs "unAGlyphs" (which can be mapped to U+F500-U+F7FF)<br />';
}
if (isset($tempfontdata[$fname]['puaag']) && $tempfontdata[$fname]['puaag']) {
if (!$pdf) {
echo 'WARNING - Font file ' . $fname . ' already includes mapped characters in the part of Unicode Private Use Area which mPDF uses for mapping non-indexed Arabic Glyphs "unAGlyphs" (U+F500-U+F7FF)<br />';
}
}
}
if (isset($tempfontdata[$fname]['sip']) && $tempfontdata[$fname]['sip']) {
if (!$pdf) {
echo 'INFO - Font file ' . $fname . ' contains characters in Unicode Plane 2 SIP<br />';
}
if (preg_match('/^(.*)-extb/', $fname, $fm)) {
if (isset($tempfontdata[($fm[1])]) && $tempfontdata[($fm[1])]) {
$tempfontdata[($fm[1])]['sip-ext'] = $fname;
if (!$pdf) {
echo 'INFO - Font file ' . $fname . ' has been defined as a CJK ext-B for ' . ($fm[1]) . '<br />';
}
} else if (isset($tempfontdata[($fm[1] . '-exta')]) && $tempfontdata[($fm[1] . '-exta')]) {
$tempfontdata[($fm[1] . '-exta')]['sip-ext'] = $fname;
if (!$pdf) {
echo 'INFO - Font file ' . $fname . ' has been defined as a CJK ext-B for ' . ($fm[1] . '-exta') . '<br />';
}
}
}
// else { unset($tempfontdata[$fname]['sip']); }
}
unset($tempfontdata[$fname]['sip']);
unset($tempfontdata[$fname]['smp']);
unset($tempfontdata[$fname]['pua']);
unset($tempfontdata[$fname]['puaag']);
unset($tempfontdata[$fname]['unAGlyphs']);
}
$mpdf->fontdata = array_merge($tempfontdata, $mpdf->fontdata);
$mpdf->available_unifonts = array();
foreach ($mpdf->fontdata as $f => $fs) {
if (isset($fs['R']) && $fs['R']) {
$mpdf->available_unifonts[] = $f;
}
if (isset($fs['B']) && $fs['B']) {
$mpdf->available_unifonts[] = $f . 'B';
}
if (isset($fs['I']) && $fs['I']) {
$mpdf->available_unifonts[] = $f . 'I';
}
if (isset($fs['BI']) && $fs['BI']) {
$mpdf->available_unifonts[] = $f . 'BI';
}
}
$mpdf->default_available_fonts = $mpdf->available_unifonts;
if (!$pdf) {
echo '<hr />';
echo '<h3>Font names as parsed by mPDF</h3>';
}
ksort($tempfonttrans);
$html = '';
foreach ($tempfonttrans as $on => $mn) {
if (!file_exists($ttfdir . '/' . $mpdf->fontdata[$mn]['R'])) {
continue;
}
$ond = '"' . $on . '"';
$html .= '<p style="font-family:' . $on . ';">' . $ond . ' font is available as ' . $mn;
if (isset($mpdf->fontdata[$mn]['sip-ext']) && $mpdf->fontdata[$mn]['sip-ext']) {
$html .= '; CJK ExtB: ' . $mpdf->fontdata[$mn]['sip-ext'];
}
$html .= '</p>';
}
if ($pdf) {
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
}
foreach ($tempfonttrans as $on => $mn) {
$ond = '"' . $on . '"';
echo '<div style="font-family:\'' . $on . '\';">' . $ond . ' font is available as ' . $mn;
if (isset($mpdf->fontdata[$mn]['sip-ext']) && $mpdf->fontdata[$mn]['sip-ext']) {
echo '; CJK ExtB: ' . $mpdf->fontdata[$mn]['sip-ext'];
}
echo '</div>';
}
echo '<hr />';
echo '<h3>Sample fonts config</h3>';
echo '<div>Remember to edit the following arrays to place your preferred default first in order:</div>';
echo '<pre>';
ksort($tempfontdata);
echo '$this->fontdata = ' . var_export($tempfontdata, true) . ";\n";
sort($tempsansfonts);
echo '$this->sans_fonts = array(\'' . implode("', '", $tempsansfonts) . "');\n";
sort($tempseriffonts);
echo '$this->serif_fonts = array(\'' . implode("', '", $tempseriffonts) . "');\n";
sort($tempmonofonts);
echo '$this->mono_fonts = array(\'' . implode("', '", $tempmonofonts) . "');\n";
echo '</pre>';
exit;