- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfont_dump.php
More file actions
242 lines (199 loc) · 6.85 KB
/
font_dump.php
File metadata and controls
242 lines (199 loc) · 6.85 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
241
242
<?php
namespace Mpdf;
use Mpdf\Fonts\FontCache;
/*
* This script prints out all characters in a TrueType font file to a PDF document.
*
* By default this will examine the font directory defined by $mpdf->fontDir
* By default this will examine the font dejavusanscondensed.
*
* You can optionally define an alternative font file to examine by setting
* the variable below (must be a relative path, or filesystem path):
*/
$fontName = 'dejavusanscondensed'; // Use internal mPDF font-name
$min = 0x0020; // Minimum Unicode value to show
$max = 0x2FFFF; // Maximum Unicode value to show
$showmissing = false; // Show all missing unicode blocks / characters
require_once '../vendor/autoload.php';
$mpdf = new Mpdf();
$fontCache = new FontCache(new Cache($mpdf->tempDir . '/ttfontdata'));
$mpdf->SetDisplayMode('fullpage');
$mpdf->useSubstitutions = true;
$mpdf->simpleTables = true;
// force fonts to be embedded whole i.e. NOT susbet
$mpdf->percentSubset = 0;
// This generates a .mtx.json file if not already generated
$mpdf->WriteHTML('<style>td { border: 0.1mm solid #555555; } body { font-weight: normal; }</style>');
$mpdf->WriteHTML('<h3 style="font-family:' . $fontName . '">' . strtoupper($fontName) . '</h3>'); // Separate Paragraphs defined by font
$font = $fontCache->jsonLoad($fontName . '.mtx.json');
$html = '';
$unifile = file(__DIR__ . '/data/UnicodeData.txt');
$unichars = array();
foreach ($unifile as $line) {
if (isset($font['smp']) && preg_match('/^(1[0-9A-Za-z]{4});/', $line, $m)) {
$unichars[hexdec($m[1])] = hexdec($m[1]);
} elseif (preg_match('/^([0-9A-Za-z]{4});/', $line, $m)) {
$unichars[hexdec($m[1])] = hexdec($m[1]);
}
}
$unicode_ranges = require __DIR__ . '/data/UnicodeRanges.php';
$cw = $fontCache->load($fontName . '.cw.dat');
if (!$cw) {
die("Error - Must be able to read font metrics file: " . $fontCache->tempFilename($fontName . '.cw.dat'));
}
$counter = 0;
if (isset($font['smp'])) {
$max = min($max, 131071);
} else {
$max = min($max, 65535);
}
$justfinishedblank = false;
$justfinishedblankinvalid = false;
foreach ($unicode_ranges as $urk => $ur) {
if (0 >= $ur['startdec'] && 0 <= $ur['enddec']) {
$rangekey = $urk;
$range = $ur['range'];
$rangestart = $ur['starthex'];
$rangeend = $ur['endhex'];
break;
}
}
$lastrange = $range;
// create HTML content
$html .= '<table cellpadding="2" cellspacing="0" style="font-family:' . $fontName . ';text-align:center; border-collapse: collapse; ">';
$html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-weight:bold">' . strtoupper($fontName) . '</td></tr>';
$html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">' . strtoupper($range) . ' (U+' . $rangestart . '-U+' . $rangeend . ')</td></tr>';
$html .= '<tr><td></td>';
$html .= '<td></td>';
for ($i = 0; $i < 16; $i++) {
$html .= '<td><b>-' . sprintf('%X', $i) . '</b></td>';
}
// print each character
for ($i = $min; $i <= $max; ++$i) {
if (($i > 0) && (($i % 16) == 0)) {
$notthisline = true;
while ($notthisline) {
for ($j = 0; $j < 16; $j++) {
if ($mpdf->_charDefined($cw, ($i + $j))) {
//if (isset($cw[($i+$j)])) {
$notthisline = false;
}
}
if ($notthisline) {
if ($showmissing) {
$range = '';
foreach ($unicode_ranges as $urk => $ur) {
if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
$rangekey = $urk;
$range = $ur['range'];
$rangestart = $ur['starthex'];
$rangeend = $ur['endhex'];
break;
}
}
$anyvalid = false;
for ($j = 0; $j < 16; $j++) {
if (isset($unichars[$i + $j])) {
$anyvalid = true;
break;
}
}
if ($range && $range == $lastrange) {
if (!$anyvalid) {
if (!$justfinishedblankinvalid) {
$html .= '<tr><td colspan="18" style="background-color:#555555; font-size: 4pt;"> </td></tr>';
}
$justfinishedblankinvalid = true;
} elseif (!$justfinishedblank) {
$html .= '<tr><td colspan="18" style="background-color:#FFAAAA; font-size: 4pt;"> </td></tr>';
$justfinishedblank = true;
}
} elseif ($range) {
$html .= '</tr></table><br />';
$mpdf->WriteHTML($html);
$html = '';
$html .= '<table cellpadding="2" cellspacing="0" style="font-family:' . $fontName . ';text-align:center; border-collapse: collapse; ">';
$html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">' . strtoupper($range) . ' (U+' . $rangestart . '-U+' . $rangeend . ')</td></tr>';
$html .= '<tr><td></td>';
$html .= '<td></td>';
for ($k = 0; $k < 16; $k++) {
$html .= '<td><b>-' . sprintf('%X', $k) . '</b></td>';
}
$justfinishedblank = false;
$justfinishedblankinvalid = false;
}
$lastrange = $range;
}
$i += 16;
if ($i > $max) {
break 2;
}
}
}
foreach ($unicode_ranges as $urk => $ur) {
if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
$rangekey = $urk;
$range = $ur['range'];
$rangestart = $ur['starthex'];
$rangeend = $ur['endhex'];
break;
}
}
if ($i > 0 && ($i % 16) == 0 && ($range != $lastrange)) {
$html .= '</tr></table><br />';
$mpdf->WriteHTML($html);
$html = '';
$html .= '<table cellpadding="2" cellspacing="0" style="font-family:' . $fontName . ';text-align:center; border-collapse: collapse; ">';
$html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">' . strtoupper($range) . ' (U+' . $rangestart . '-U+' . $rangeend . ')</td></tr>';
$html .= '<tr><td></td>';
$html .= '<td></td>';
for ($k = 0; $k < 16; $k++) {
$html .= '<td><b>-' . sprintf('%X', $k) . '</b></td>';
}
}
$lastrange = $range;
$justfinishedblank = false;
$justfinishedblankinvalid = false;
$html .= '</tr><tr><td><i>' . (floor($i / 16) * 16) . '</i></td>';
$html .= '<td><b>' . sprintf('%03X', floor($i / 16)) . '-</b></td>';
}
// Add dotted circle to any character (mark) with width=0
if ($mpdf->_charDefined($cw, $i) && _getCharWidth($cw, $i) == 0) {
$html .= '<td>◌&#' . $i . ';</td>';
$counter++;
} else {
if ($mpdf->_charDefined($cw, $i)) {
$html .= '<td>&#' . $i . ';</td>';
$counter++;
} elseif (isset($unichars[$i])) {
$html .= '<td style="background-color: #FFAAAA;"></td>';
} else {
$html .= '<td style="background-color: #555555;"></td>';
}
}
}
if (($i % 16) > 0) {
for ($j = ($i % 16); $j < 16; ++$j) {
$html .= '<td style="background-color: #555555;"></td>';
}
}
$html .= '</tr></table><br />';
function _getCharWidth(&$cw, $u, $isdef = true)
{
if ($u == 0) {
$w = false;
} else {
$w = (ord($cw[$u * 2]) << 8) + ord($cw[$u * 2 + 1]);
}
if ($w == 65535) {
return 0;
} elseif ($w) {
return $w;
} elseif ($isdef) {
return false;
} else {
return 0;
}
}
$mpdf->WriteHTML($html);
$mpdf->Output();