]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | /* | |
4 | This script prints out all characters in a TrueType font file | |
5 | to a PDF document. Point your browser to | |
6 | http://your.domain/your_path_to _mpdf/utils/font_dump.php | |
7 | The font file must be located in /ttfonts/ (or the default font | |
8 | directory defined by _MPDF_TTFONTPATH. | |
9 | By default this will examine the font dejavusanscondensed. | |
10 | You can optionally define an alternative font file to examine by setting | |
11 | the variable below (must be a relative path, or filesystem path): | |
12 | */ | |
13 | ||
14 | ||
15 | $font = 'dejavusanscondensed'; // Use internal mPDF font-name | |
16 | ||
17 | $showmissing = true; // Show all missing unicode blocks / characters | |
18 | ||
19 | ||
20 | ////////////////////////////////// | |
21 | ////////////////////////////////// | |
22 | ////////////////////////////////// | |
23 | ||
24 | set_time_limit(600); | |
25 | ini_set("memory_limit","256M"); | |
26 | ||
27 | //============================================================== | |
28 | //============================================================== | |
29 | define('_MPDF_URI', '../'); | |
30 | include("../mpdf.php"); | |
31 | ||
32 | $mpdf=new mPDF(''); | |
33 | $mpdf->StartProgressBarOutput(2); | |
34 | ||
35 | $mpdf->SetDisplayMode('fullpage'); | |
36 | ||
37 | $mpdf->useSubstitutions = true; | |
38 | $mpdf->debug = true; | |
39 | $mpdf->simpleTables = true; | |
40 | // force fonts to be embedded whole i.e. NOT susbet | |
41 | $mpdf->percentSubset = 0; | |
42 | ||
43 | //============================================================== | |
44 | //============================================================== | |
45 | //============================================================== | |
46 | //============================================================== | |
47 | ||
48 | // This generates a .mtx.php file if not already generated | |
49 | $mpdf->WriteHTML('<style>td { border: 0.1mm solid #555555; } body { font-weight: normal; }</style>'); | |
50 | $mpdf->WriteHTML('<h3 style="font-family:'.$font.'">'.strtoupper($font).'</h3>'); // Separate Paragraphs defined by font | |
51 | $html = ''; | |
52 | //============================================================== | |
53 | //============================================================== | |
54 | //============================================================== | |
55 | //============================================================== | |
56 | $unifile = file('UnicodeData.txt'); | |
57 | $unichars = array(); | |
58 | ||
59 | foreach($unifile AS $line) { | |
60 | if ($smp && preg_match('/^(1[0-9A-Za-z]{4});/',$line,$m)) { | |
61 | $unichars[hexdec($m[1])] = hexdec($m[1]); | |
62 | } | |
63 | else if (preg_match('/^([0-9A-Za-z]{4});/',$line,$m)) { | |
64 | $unichars[hexdec($m[1])] = hexdec($m[1]); | |
65 | } | |
66 | } | |
67 | ||
68 | // loads array $unicode_ranges | |
69 | include('UnicodeRanges.php'); | |
70 | //============================================================== | |
71 | //============================================================== | |
72 | ||
73 | ||
74 | ||
75 | $cw = file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); | |
76 | if (!$cw) { die("Error - Must be able to read font metrics file: "._MPDF_TTFONTDATAPATH.$font.'.cw.dat'); } | |
77 | $counter=0; | |
78 | ||
79 | ||
80 | include(_MPDF_TTFONTDATAPATH.$font.'.mtx.php'); | |
81 | ||
82 | if ($smp) { | |
83 | $max = 131071; | |
84 | } | |
85 | else { | |
86 | $max = 65535; | |
87 | } | |
88 | ||
89 | ||
90 | $justfinishedblank = false; | |
91 | $justfinishedblankinvalid = false; | |
92 | ||
93 | foreach($unicode_ranges AS $urk => $ur) { | |
94 | if (0 >= $ur['startdec'] && 0 <= $ur['enddec']) { | |
95 | $rangekey = $urk; | |
96 | $range = $ur['range']; | |
97 | $rangestart = $ur['starthex']; | |
98 | $rangeend = $ur['endhex']; | |
99 | break; | |
100 | } | |
101 | } | |
102 | $lastrange = $range ; | |
103 | // create HTML content | |
104 | $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">'; | |
105 | $html .= '<tr><td colspan="18" style="font-family:helvetica;font-weight:bold">'.strtoupper($font).'</td></tr>'; | |
106 | $html .= '<tr><td colspan="18" style="font-family:helvetica;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')</td></tr>'; | |
107 | $html .= '<tr><td></td>'; | |
108 | ||
109 | $html .= '<td></td>'; | |
110 | for ($i = 0; $i < 16; $i++) { | |
111 | $html .= '<td><b>-'.sprintf('%X', $i).'</b></td>'; | |
112 | } | |
113 | ||
114 | ||
115 | // print each character | |
116 | for ($i = 32; $i < $max; ++$i) { | |
117 | if (($i > 0) AND (($i % 16) == 0)) { | |
118 | $notthisline = true; | |
119 | while($notthisline) { | |
120 | for ($j = 0; $j < 16; $j++) { | |
121 | if ($mpdf->_charDefined($cw, ($i + $j))) { | |
122 | //if (isset($cw[($i+$j)])) { | |
123 | $notthisline = false; | |
124 | } | |
125 | } | |
126 | if ($notthisline) { | |
127 | if ($showmissing) { | |
128 | $range = ''; | |
129 | foreach($unicode_ranges AS $urk => $ur) { | |
130 | if ($i >= $ur['startdec'] && $i <= $ur['enddec']) { | |
131 | $rangekey = $urk; | |
132 | $range = $ur['range']; | |
133 | $rangestart = $ur['starthex']; | |
134 | $rangeend = $ur['endhex']; | |
135 | break; | |
136 | } | |
137 | } | |
138 | $anyvalid = false; | |
139 | for ($j = 0; $j < 16; $j++) { | |
140 | if (isset($unichars[$i+$j])) { $anyvalid = true; break; } | |
141 | } | |
142 | if ($range && $range == $lastrange) { | |
143 | if (!$anyvalid) { | |
144 | if (!$justfinishedblankinvalid) { | |
145 | $html .= '<tr><td colspan="18" style="background-color:#555555; font-size: 4pt;"> </td></tr>'; | |
146 | } | |
147 | $justfinishedblankinvalid = true; | |
148 | } | |
149 | else if (!$justfinishedblank ) { | |
150 | $html .= '<tr><td colspan="18" style="background-color:#FFAAAA; font-size: 4pt;"> </td></tr>'; | |
151 | $justfinishedblank = true; | |
152 | } | |
153 | } | |
154 | else if($range) { | |
155 | $html .= '</tr></table><br />'; | |
156 | $mpdf->WriteHTML($html); $html = ''; | |
157 | $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">'; | |
158 | $html .= '<tr><td colspan="18" style="font-family:helvetica;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>'; | |
159 | $html .= '<tr><td></td>'; | |
160 | $html .= '<td></td>'; | |
161 | for ($k = 0; $k < 16; $k++) { | |
162 | $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>'; | |
163 | } | |
164 | $justfinishedblank = false; | |
165 | $justfinishedblankinvalid = false; | |
166 | } | |
167 | $lastrange = $range ; | |
168 | } | |
169 | $i +=16; | |
170 | if ($i > $max) { break 2; } | |
171 | } | |
172 | } | |
173 | foreach($unicode_ranges AS $urk => $ur) { | |
174 | if ($i >= $ur['startdec'] && $i <= $ur['enddec']) { | |
175 | $rangekey = $urk; | |
176 | $range = $ur['range']; | |
177 | $rangestart = $ur['starthex']; | |
178 | $rangeend = $ur['endhex']; | |
179 | break; | |
180 | } | |
181 | } | |
182 | ||
183 | if ($i > 0 && ($i % 16) == 0 && ($range != $lastrange)) { | |
184 | $html .= '</tr></table><br />'; | |
185 | $mpdf->WriteHTML($html); $html = ''; | |
186 | $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">'; | |
187 | $html .= '<tr><td colspan="18" style="font-family:helvetica;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>'; | |
188 | $html .= '<tr><td></td>'; | |
189 | $html .= '<td></td>'; | |
190 | for ($k = 0; $k < 16; $k++) { | |
191 | $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>'; | |
192 | } | |
193 | } | |
194 | $lastrange = $range ; | |
195 | $justfinishedblank = false; | |
196 | $justfinishedblankinvalid = false; | |
197 | $html .= '</tr><tr><td><i>'.(floor($i / 16)*16).'</i></td>'; | |
198 | $html .= '<td><b>'.sprintf('%03X', floor($i / 16)).'-</b></td>'; | |
199 | } | |
200 | if ($mpdf->_charDefined($cw, $i)) { $html .= '<td>&#'.$i.';</td>'; $counter++; } | |
201 | else if (isset($unichars[$i])) { $html .= '<td style="background-color: #FFAAAA;"></td>'; } | |
202 | else { $html .= '<td style="background-color: #555555;"></td>'; } | |
203 | } | |
204 | ||
205 | if (($i % 16) > 0) { | |
206 | for ($j = ($i % 16); $j < 16; ++$j) { $html .= '<td style="background-color: #555555;"></td>'; } | |
207 | } | |
208 | $html .= '</tr></table><br />'; | |
209 | //============================================================== | |
210 | //============================================================== | |
211 | $mpdf->WriteHTML($html); // Separate Paragraphs defined by font | |
212 | ||
213 | $mpdf->Output(); | |
214 | exit; | |
215 | ||
216 | //============================================================== | |
217 | //============================================================== | |
218 | //============================================================== | |
219 | //============================================================== | |
220 | ||
221 | ||
222 | ?> |