PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / trunk
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin vtrunk
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / mpdf / utils / font_dump.php

font_dump.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin trunk, at mpdf/utils/font_dump.php

232 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $min = 0x0020; // Minimum Unicode value to show
18 $max = 0x2FFFF; // Maximum Unicode value to show
19
20 $showmissing = false; // Show all missing unicode blocks / characters
21
22
23 //////////////////////////////////
24 //////////////////////////////////
25 //////////////////////////////////
26
27 set_time_limit(600);
28 ini_set("memory_limit","512M");
29
30 //==============================================================
31 //==============================================================
32 include("../mpdf.php");
33
34 $mpdf=new mPDF('');
35
36 $mpdf->SetDisplayMode('fullpage');
37
38 $mpdf->useSubstitutions = 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 = min($max,131071);
84 } else {
85 $max = min($max,65535);
86 }
87
88
89 $justfinishedblank = false;
90 $justfinishedblankinvalid = false;
91
92 foreach($unicode_ranges AS $urk => $ur) {
93 if (0 >= $ur['startdec'] && 0 <= $ur['enddec']) {
94 $rangekey = $urk;
95 $range = $ur['range'];
96 $rangestart = $ur['starthex'];
97 $rangeend = $ur['endhex'];
98 break;
99 }
100 }
101 $lastrange = $range ;
102 // create HTML content
103 $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
104 $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-weight:bold">'.strtoupper($font).'</td></tr>';
105 $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')</td></tr>';
106 $html .= '<tr><td></td>';
107
108 $html .= '<td></td>';
109 for ($i = 0; $i < 16; $i++) {
110 $html .= '<td><b>-'.sprintf('%X', $i).'</b></td>';
111 }
112
113
114 // print each character
115 for ($i = $min; $i <= $max; ++$i) {
116 if (($i > 0) AND (($i % 16) == 0)) {
117 $notthisline = true;
118 while($notthisline) {
119 for ($j = 0; $j < 16; $j++) {
120 if ($mpdf->_charDefined($cw, ($i + $j))) {
121 //if (isset($cw[($i+$j)])) {
122 $notthisline = false;
123 }
124 }
125 if ($notthisline) {
126 if ($showmissing) {
127 $range = '';
128 foreach($unicode_ranges AS $urk => $ur) {
129 if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
130 $rangekey = $urk;
131 $range = $ur['range'];
132 $rangestart = $ur['starthex'];
133 $rangeend = $ur['endhex'];
134 break;
135 }
136 }
137 $anyvalid = false;
138 for ($j = 0; $j < 16; $j++) {
139 if (isset($unichars[$i+$j])) { $anyvalid = true; break; }
140 }
141 if ($range && $range == $lastrange) {
142 if (!$anyvalid) {
143 if (!$justfinishedblankinvalid) {
144 $html .= '<tr><td colspan="18" style="background-color:#555555; font-size: 4pt;">&nbsp;</td></tr>';
145 }
146 $justfinishedblankinvalid = true;
147 }
148 else if (!$justfinishedblank ) {
149 $html .= '<tr><td colspan="18" style="background-color:#FFAAAA; font-size: 4pt;">&nbsp;</td></tr>';
150 $justfinishedblank = true;
151 }
152 }
153 else if($range) {
154 $html .= '</tr></table><br />';
155 $mpdf->WriteHTML($html); $html = '';
156 $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
157 $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>';
158 $html .= '<tr><td></td>';
159 $html .= '<td></td>';
160 for ($k = 0; $k < 16; $k++) {
161 $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>';
162 }
163 $justfinishedblank = false;
164 $justfinishedblankinvalid = false;
165 }
166 $lastrange = $range ;
167 }
168 $i +=16;
169 if ($i > $max) { break 2; }
170 }
171 }
172 foreach($unicode_ranges AS $urk => $ur) {
173 if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
174 $rangekey = $urk;
175 $range = $ur['range'];
176 $rangestart = $ur['starthex'];
177 $rangeend = $ur['endhex'];
178 break;
179 }
180 }
181
182 if ($i > 0 && ($i % 16) == 0 && ($range != $lastrange)) {
183 $html .= '</tr></table><br />';
184 $mpdf->WriteHTML($html); $html = '';
185 $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
186 $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>';
187 $html .= '<tr><td></td>';
188 $html .= '<td></td>';
189 for ($k = 0; $k < 16; $k++) {
190 $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>';
191 }
192 }
193 $lastrange = $range ;
194 $justfinishedblank = false;
195 $justfinishedblankinvalid = false;
196 $html .= '</tr><tr><td><i>'.(floor($i / 16)*16).'</i></td>';
197 $html .= '<td><b>'.sprintf('%03X', floor($i / 16)).'-</b></td>';
198 }
199
200 // Add dotted circle to any character (mark) with width=0
201 if ($mpdf->_charDefined($cw, $i) && _getCharWidth($cw, $i)==0) { $html .= '<td>&#x25cc;&#'.$i.';</td>'; $counter++; }
202 else {
203 if ($mpdf->_charDefined($cw, $i)) { $html .= '<td>&#'.$i.';</td>'; $counter++; }
204 else if (isset($unichars[$i])) { $html .= '<td style="background-color: #FFAAAA;"></td>'; }
205 else { $html .= '<td style="background-color: #555555;"></td>'; }
206 }
207 }
208
209 if (($i % 16) > 0) {
210 for ($j = ($i % 16); $j < 16; ++$j) { $html .= '<td style="background-color: #555555;"></td>'; }
211 }
212 $html .= '</tr></table><br />';
213 //==============================================================
214 function _getCharWidth(&$cw, $u, $isdef=true) {
215 if ($u==0) { $w = false; }
216 else { $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); }
217 if ($w == 65535) { return 0; }
218 else if ($w) { return $w; }
219 else if ($isdef) { return false; }
220 else { return 0; }
221 }
222 //==============================================================
223 $mpdf->WriteHTML($html); // Separate Paragraphs defined by font
224
225 $mpdf->Output();
226 exit;
227
228 //==============================================================
229 //==============================================================
230 //==============================================================
231 //==============================================================
232