]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/utils/font_coverage.php
3 /* This script prints out the Unicode coverage of all TrueType font files
4 in your font directory.
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):
17 //////////////////////////////////
18 //////////////////////////////////
19 //////////////////////////////////
23 ini_set("memory_limit","256M");
25 //==============================================================
26 //==============================================================
27 include("../mpdf.php");
29 $mpdf=new mPDF('','A4-L','','',10,10,10,10);
30 $mpdf->SetDisplayMode('fullpage');
31 $mpdf->useSubstitutions
= true;
33 $mpdf->simpleTables
= true;
37 else { $ttfdir
= _MPDF_TTFONTPATH
; }
41 $mqr=ini_get("magic_quotes_runtime");
42 if ($mqr) { set_magic_quotes_runtime(0); }
43 if (!class_exists('TTFontFile_Analysis', false)) { include(_MPDF_PATH
.'classes/ttfontsuni_analysis.php'); }
45 //==============================================================
48 //==============================================================
49 //==============================================================
50 $unifile = file('UnicodeData.txt');
52 foreach($unifile AS $line) {
53 if (preg_match('/<control>/',$line,$m)) {
57 else if (preg_match('/^([12]{0,1}[0-9A-Za-z]{4});<(.*?), Last>/',$line,$m)) {
58 if ($rangename && $rangename == $m[2]) {
59 $endrange = hexdec($m[1]);
60 for ($i=$startrange;$i<=$endrange; $i++
) {
66 else if (preg_match('/^([12]{0,1}[0-9A-Za-z]{4});<(.*?), First>/',$line,$m)) {
67 $startrange = hexdec($m[1]);
70 else if (preg_match('/^([12]{0,1}[0-9A-Za-z]{4});/',$line,$m)) {
71 $unichars[hexdec($m[1])] = hexdec($m[1]);
76 // loads array $unicode_ranges
77 include('UnicodeRanges.php');
78 //==============================================================
79 $html = '<html><head><style>td { border: 0.1mm solid #555555; }
80 body { font-weight: normal; font-family: helvetica;font-size:8pt; }
81 td { font-family: helvetica;font-size:8pt; vertical-align: top;}
82 </style></head><body>';
84 //==============================================================
85 $ff = scandir($ttfdir);
86 $tempfontdata = array();
88 $ttf = new TTFontFile_Analysis();
91 if (strtolower(substr($f,-4,4))=='.ttf' || strtolower(substr($f,-4,4))=='.otf') {
92 $ret[] = $ttf->extractCoreInfo($ttfdir.$f);
94 for ($i=0; $i<count($ret); $i++
) {
95 if (is_array($ret[$i])) {
96 $tfname = $ret[$i][0];
98 $italic = $ret[$i][2];
99 $fname = strtolower($tfname );
100 $fname = preg_replace('/[ ()]/','',$fname );
101 //$tempfonttrans[$tfname] = $fname;
103 if ($bold) { $style
.= 'B'; }
104 if ($italic) { $style
.= 'I'; }
106 $tempfontdata[$fname]['file'] = $f;
108 $tempfontdata[$fname]['TTCfontID'] = $ret[$i][4];
117 $fullcovers = array();
118 $nearlycovers = array();
119 ksort($tempfontdata);
121 $nofgroups = ceil(count($unicode_ranges)/$ningroup);
123 //==============================================================
126 for ($urgp = 0; $urgp < $nofgroups; $urgp++
) {
129 $html .= '<table cellpadding="2" cellspacing="0" style="page-break-inside:avoid; text-align:center; border-collapse: collapse; ">';
130 $html .= '<thead><tr><td></td>';
132 foreach($unicode_ranges AS $urk => $ur) {
133 if ($urk >= ($urgp*$ningroup) && $urk < (($urgp+
1)*$ningroup)) {
135 $range = $ur['range'];
136 $rangestart = $ur['starthex'];
137 $rangeend = $ur['endhex'];
138 $html .= '<td style="font-family:helvetica;font-size:8pt;font-weight:bold;">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')</td>';
141 $html .= '</tr></thead>';
144 foreach ($tempfontdata AS $fname => $v) {
146 if (file_exists((_MPDF_TTFONTDATAPATH
.$fname.'.cw.dat'))) { $cw
= file_get_contents(_MPDF_TTFONTDATAPATH
.$fname
.'.cw.dat'); }
148 $mpdf->fontdata
[$fname]['R'] = $tempfontdata[$fname]['file'];
149 $mpdf->AddFont($fname);
150 $cw = file_get_contents(_MPDF_TTFONTDATAPATH
.$fname.'.cw.dat');
154 die("Font data not available for $fname");
160 // create HTML content
162 $html .= '<td>'.$fname.'</td>';
164 foreach($unicode_ranges AS $urk => $ur) {
165 if ($urk >= ($urgp*$ningroup) && $urk < (($urgp+1)*$ningroup)) {
166 if ($ur['pua'] || $ur['reserved'] || $ur['control']) {
167 $html .= '<td style="background
-color
: #000000;"></td>';
171 $range = $ur['range'];
172 $rangestart = $ur['starthex'];
173 $rangeend = $ur['endhex'];
174 $rangestartdec = $ur['startdec'];
175 $rangeenddec = $ur['enddec'];
178 for ($i=$rangestartdec; $i<=$rangeenddec; $i++
) {
179 //if (isset($cw[$i])) { $fontinrange++; }
180 if ($mpdf->_charDefined($cw, $i)) { $fontinrange++
; }
181 if (isset($unichars[$i])) { $uniinrange++
; }
185 $pc = ($fontinrange/$uniinrange);
186 $str = '('.$fontinrange.'/'.$uniinrange.')';
188 $fullcovers[$urk][] = $fname;
189 $html .= '<td style="background-color: #00FF00;"></td>';
192 $fullcovers[$urk][] = $fname;
193 $html .= '<td style="background-color: #00FF00;">'.$str.'</td>';
196 $html .= '<td style="background-color: #AAFFAA;">'.$str.'</td>';
197 $nearlycovers[$urk][] = $fname;
199 else if ($pc>0.75) { $html
.= '<td style="background-color: #00FFAA;">'.$str
.'</td>'; }
200 else if ($pc>0.5) { $html
.= '<td style="background-color: #AAAAFF;">'.$str
.'</td>'; }
201 else if ($pc>0.25) { $html
.= '<td style="background-color: #FFFFAA;">'.$str
.'</td>'; }
202 else { $html
.= '<td style="background-color: #FFAAAA;">'.$str
.'</td>'; }
204 else { $html
.= '<td style="background-color: #555555;">(0/0)</td>'; }
206 else { $html
.= '<td style="background-color: #000000;"></td>'; }
215 //==============================================================
216 $html .= '</table><pagebreak />';
219 $html .= '<h4>Fonts with full coverage of Unicode Ranges</h4>';
221 //$html .= '<tr><td></td><td></td></tr>';
222 foreach($unicode_ranges AS $urk => $ur) {
223 if ($ur['pua'] || $ur['reserved'] || $ur['control']) { continue; }
225 $range = $ur['range'];
226 $rangestart = $ur['starthex'];
227 $rangeend = $ur['endhex'];
229 if ($ur['combining']) { $ext
= 'background-color:#DDDDFF;'; $ext2
= '<br /><span style="color:#AA0000">Special positioning required</span>'; }
230 if ($ur['vertical']) { $ext
= 'background-color:#FFDDDD;'; $ext2
= '<br /><span style="color:#AA0000">Vertical positioning required</span>'; }
231 if ($ur['special']) { $ext
= 'background-color:#FFDDDD;'; $ext2
= '<br /><span style="color:#AA0000">Special processing required</span>'; }
234 $html .= '<tr><td style="font-family:helvetica;font-size:8pt;font-weight:bold;'.$ext.'">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')'.$ext2.'</td>';
235 $arr = $fullcovers[$urk];
236 $narr = $nearlycovers[$urk];
237 if (is_array($arr)) { $html
.= '<td>'. implode(', ',$arr
). '</td></tr>'; }
238 else if (is_array($narr)) { $html
.= '<td style="background-color: #AAAAAA;">'. implode(', ',$narr
). ' (>90%)</td></tr>'; }
239 else { $html
.= '<td style="background-color: #555555;"> </td></tr>'; }
244 //==============================================================
249 //==============================================================
250 //==============================================================
251 //==============================================================
252 //==============================================================