PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.8.1
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.8.1
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_coverage.php

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

252 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /* This script prints out the Unicode coverage of all TrueType font files
4 in your font directory.
5 Point your browser to
6 http://your.domain/your_path_to _mpdf/utils/font_coverage.php
7 By default this will examine the folder /ttfonts/ (or the default font
8 directory defined by _MPDF_TTFONTPATH.
9 You can optionally define an alternative folder to examine by setting
10 the variable below (must be a relative path, or filesystem path):
11 */
12
13
14 $checkdir = '';
15
16 //////////////////////////////////
17
18
19 set_time_limit(600);
20 ini_set("memory_limit","256M");
21
22 //==============================================================
23 //==============================================================
24 include("../mpdf.php");
25
26 $mpdf=new mPDF('','A4-L','','',10,10,10,10);
27 $mpdf->SetDisplayMode('fullpage');
28 $mpdf->useSubstitutions = true;
29 $mpdf->debug = true;
30 $mpdf->simpleTables = true;
31 if ($checkdir) {
32 $ttfdir = $checkdir;
33 }
34 else { $ttfdir = _MPDF_TTFONTPATH; }
35
36
37
38 $mqr=ini_get("magic_quotes_runtime");
39 if ($mqr) { set_magic_quotes_runtime(0); }
40 if (!class_exists('TTFontFile_Analysis', false)) { include(_MPDF_PATH .'classes/ttfontsuni_analysis.php'); }
41
42 //==============================================================
43 $smp = true;
44 $maxt = 131071;
45 //==============================================================
46 //==============================================================
47 $unifile = file('UnicodeData.txt');
48 $unichars = array();
49 foreach($unifile AS $line) {
50 if (preg_match('/<control>/',$line,$m)) {
51 $rangename = '';
52 continue;
53 }
54 else if (preg_match('/^([12]{0,1}[0-9A-Za-z]{4});<(.*?), Last>/',$line,$m)) {
55 if ($rangename && $rangename == $m[2]) {
56 $endrange = hexdec($m[1]);
57 for ($i=$startrange;$i<=$endrange; $i++) {
58 $unichars[$i] = $i;
59 }
60 }
61 $rangename = '';
62 }
63 else if (preg_match('/^([12]{0,1}[0-9A-Za-z]{4});<(.*?), First>/',$line,$m)) {
64 $startrange = hexdec($m[1]);
65 $rangename = $m[2];
66 }
67 else if (preg_match('/^([12]{0,1}[0-9A-Za-z]{4});/',$line,$m)) {
68 $unichars[hexdec($m[1])] = hexdec($m[1]);
69 $rangename = '';
70 }
71 }
72
73 // loads array $unicode_ranges
74 include('UnicodeRanges.php');
75 //==============================================================
76 $html = '<html><head><style>td { border: 0.1mm solid #555555; }
77 body { font-weight: normal; font-family: helvetica;font-size:8pt; }
78 td { font-family: helvetica;font-size:8pt; vertical-align: top;}
79 </style></head><body>';
80
81 //==============================================================
82 $ff = scandir($ttfdir);
83 $tempfontdata = array();
84 foreach($ff AS $f) {
85 $ttf = new TTFontFile_Analysis();
86 $ret = array();
87 $isTTC = false;
88 if (strtolower(substr($f,-4,4))=='.ttf' || strtolower(substr($f,-4,4))=='.otf') {
89 $ret[] = $ttf->extractCoreInfo($ttfdir.$f);
90 }
91 for ($i=0; $i<count($ret); $i++) {
92 if (is_array($ret[$i])) {
93 $tfname = $ret[$i][0];
94 $bold = $ret[$i][1];
95 $italic = $ret[$i][2];
96 $fname = strtolower($tfname );
97 $fname = preg_replace('/[ ()]/','',$fname );
98 //$tempfonttrans[$tfname] = $fname;
99 $style = '';
100 if ($bold) { $style .= 'B'; }
101 if ($italic) { $style .= 'I'; }
102 if (!$style) {
103 $tempfontdata[$fname]['file'] = $f;
104 if ($isTTC) {
105 $tempfontdata[$fname]['TTCfontID'] = $ret[$i][4];
106 }
107 }
108 }
109 }
110 unset($ttf);
111
112 }
113
114 $fullcovers = array();
115 $nearlycovers = array();
116 ksort($tempfontdata);
117 $ningroup = 14;
118 $nofgroups = ceil(count($unicode_ranges)/$ningroup);
119
120 //==============================================================
121
122
123 for ($urgp = 0; $urgp < $nofgroups; $urgp++) {
124
125
126 $html .= '<table cellpadding="2" cellspacing="0" style="page-break-inside:avoid; text-align:center; border-collapse: collapse; ">';
127 $html .= '<thead><tr><td></td>';
128
129 foreach($unicode_ranges AS $urk => $ur) {
130 if ($urk >= ($urgp*$ningroup) && $urk < (($urgp+1)*$ningroup)) {
131 $rangekey = $urk;
132 $range = $ur['range'];
133 $rangestart = $ur['starthex'];
134 $rangeend = $ur['endhex'];
135 $html .= '<td style="font-family:helvetica;font-size:8pt;font-weight:bold;">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')</td>';
136 }
137 }
138 $html .= '</tr></thead>';
139
140
141 foreach ($tempfontdata AS $fname => $v) {
142 $cw = '';
143 if (file_exists((_MPDF_TTFONTDATAPATH.$fname.'.cw.dat'))) { $cw = file_get_contents(_MPDF_TTFONTDATAPATH.$fname.'.cw.dat'); }
144 else {
145 $mpdf->fontdata[$fname]['R'] = $tempfontdata[$fname]['file'];
146 $mpdf->AddFont($fname);
147 $cw = file_get_contents(_MPDF_TTFONTDATAPATH.$fname.'.cw.dat');
148 }
149 if (!$cw) {
150 continue;
151 die("Font data not available for $fname");
152 }
153
154 $counter=0;
155 $max = $maxt;
156
157 // create HTML content
158 $html .= '<tr>';
159 $html .= '<td>'.$fname.'</td>';
160
161 foreach($unicode_ranges AS $urk => $ur) {
162 if ($urk >= ($urgp*$ningroup) && $urk < (($urgp+1)*$ningroup)) {
163 if ($ur['pua'] || $ur['reserved'] || $ur['control']) {
164 $html .= '<td style="background-color: #000000;"></td>';
165 }
166 else {
167 $rangekey = $urk;
168 $range = $ur['range'];
169 $rangestart = $ur['starthex'];
170 $rangeend = $ur['endhex'];
171 $rangestartdec = $ur['startdec'];
172 $rangeenddec = $ur['enddec'];
173 $uniinrange = 0;
174 $fontinrange = 0;
175 for ($i=$rangestartdec; $i<=$rangeenddec; $i++) {
176 //if (isset($cw[$i])) { $fontinrange++; }
177 if ($mpdf->_charDefined($cw, $i)) { $fontinrange++; }
178 if (isset($unichars[$i])) { $uniinrange++; }
179 }
180 if ($uniinrange) {
181 if ($fontinrange) {
182 $pc = ($fontinrange/$uniinrange);
183 $str = '('.$fontinrange.'/'.$uniinrange.')';
184 if ($pc==1) {
185 $fullcovers[$urk][] = $fname;
186 $html .= '<td style="background-color: #00FF00;"></td>';
187 }
188 else if ($pc>1) {
189 $fullcovers[$urk][] = $fname;
190 $html .= '<td style="background-color: #00FF00;">'.$str.'</td>';
191 }
192 else if ($pc>=0.9) {
193 $html .= '<td style="background-color: #AAFFAA;">'.$str.'</td>';
194 $nearlycovers[$urk][] = $fname;
195 }
196 else if ($pc>0.75) { $html .= '<td style="background-color: #00FFAA;">'.$str.'</td>'; }
197 else if ($pc>0.5) { $html .= '<td style="background-color: #AAAAFF;">'.$str.'</td>'; }
198 else if ($pc>0.25) { $html .= '<td style="background-color: #FFFFAA;">'.$str.'</td>'; }
199 else { $html .= '<td style="background-color: #FFAAAA;">'.$str.'</td>'; }
200 }
201 else { $html .= '<td style="background-color: #555555;">(0/0)</td>'; }
202 }
203 else { $html .= '<td style="background-color: #000000;"></td>'; }
204 }
205 }
206 }
207
208
209 $html .= '</tr>';
210
211 }
212 //==============================================================
213 $html .= '</table><pagebreak />';
214 }
215
216 $html .= '<h4>Fonts with full coverage of Unicode Ranges</h4>';
217 $html .= '<table>';
218 //$html .= '<tr><td></td><td></td></tr>';
219 foreach($unicode_ranges AS $urk => $ur) {
220 if ($ur['pua'] || $ur['reserved'] || $ur['control']) { continue; }
221 $rangekey = $urk;
222 $range = $ur['range'];
223 $rangestart = $ur['starthex'];
224 $rangeend = $ur['endhex'];
225 $ext = $ext2 = '';
226 if ($ur['combining']) { $ext = 'background-color:#DDDDFF;'; $ext2 = '<br /><span style="color:#AA0000">Special positioning required</span>'; }
227 if ($ur['vertical']) { $ext = 'background-color:#FFDDDD;'; $ext2 = '<br /><span style="color:#AA0000">Vertical positioning required</span>'; }
228 if ($ur['special']) { $ext = 'background-color:#FFDDDD;'; $ext2 = '<br /><span style="color:#AA0000">Special processing required</span>'; }
229
230
231 $html .= '<tr><td style="font-family:helvetica;font-size:8pt;font-weight:bold;'.$ext.'">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')'.$ext2.'</td>';
232 $arr = $fullcovers[$urk];
233 $narr = $nearlycovers[$urk];
234 if (is_array($arr)) { $html .= '<td>'. implode(', ',$arr). '</td></tr>'; }
235 else if (is_array($narr)) { $html .= '<td style="background-color: #AAAAAA;">'. implode(', ',$narr). ' (>90%)</td></tr>'; }
236 else { $html .= '<td style="background-color: #555555;"> </td></tr>'; }
237 }
238 $html.= '</table>';
239
240
241 //==============================================================
242 echo $html;
243
244 exit;
245
246 //==============================================================
247 //==============================================================
248 //==============================================================
249 //==============================================================
250
251
252 ?>