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

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

214 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /* This script examines your font directory.
4 Point your browser to
5 http://your.domain/your_path_to _mpdf/utils/font_names.php
6 By default this will examine the folder /ttfonts/ (or the default font
7 directory defined by _MPDF_TTFONTPATH.
8 You can optionally define an alternative folder to examine by setting
9 the variable checkdir below (must be a relative path, or filesystem path).
10 You can optionally output just the font samples as a PDF file by setting $pdf=true.
11 */
12
13
14 $checkdir = '';
15
16 $pdf = false;
17
18 //////////////////////////////////
19 //////////////////////////////////
20 //////////////////////////////////
21
22 ini_set("memory_limit","256M");
23
24 define('_MPDF_PATH','../');
25
26 include("../mpdf.php");
27 $mpdf=new mPDF('s');
28 $mpdf->useSubstitutions = true;
29 if ($checkdir) {
30 $ttfdir = $checkdir;
31 }
32 else { $ttfdir = _MPDF_TTFONTPATH; }
33
34 $mqr=ini_get("magic_quotes_runtime");
35 if ($mqr) { set_magic_quotes_runtime(0); }
36 if (!class_exists('TTFontFile_Analysis', false)) { include(_MPDF_PATH .'classes/ttfontsuni_analysis.php'); }
37 $ttf = new TTFontFile_Analysis();
38
39 $tempfontdata = array();
40 $tempsansfonts = array();
41 $tempseriffonts = array();
42 $tempmonofonts = array();
43 $tempfonttrans = array();
44
45 $ff = scandir($ttfdir);
46
47 foreach($ff AS $f) {
48 $ret = array();
49 $isTTC = false;
50 if (strtolower(substr($f,-4,4))=='.ttc' || strtolower(substr($f,-5,5))=='.ttcf') { // Mac ttcf
51 $isTTC = true;
52 $ttf->getTTCFonts($ttfdir.$f);
53 $nf = $ttf->numTTCFonts;
54 for ($i=1; $i<=$nf; $i++) {
55 $ret[] = $ttf->extractCoreInfo($ttfdir.$f, $i);
56 }
57 }
58 else if (strtolower(substr($f,-4,4))=='.ttf' || strtolower(substr($f,-4,4))=='.otf' ) {
59 $ret[] = $ttf->extractCoreInfo($ttfdir.$f);
60 }
61 for ($i=0; $i<count($ret); $i++) {
62 if (!is_array($ret[$i])) {
63 if (!$pdf) echo $ret[$i].'<br />';
64 }
65 else {
66 $tfname = $ret[$i][0];
67 $bold = $ret[$i][1];
68 $italic = $ret[$i][2];
69 $fname = strtolower($tfname );
70 $fname = preg_replace('/[ ()]/','',$fname );
71 $tempfonttrans[$tfname] = $fname;
72 $style = '';
73 if ($bold) { $style .= 'B'; }
74 if ($italic) { $style .= 'I'; }
75 if (!$style) { $style = 'R'; }
76 $tempfontdata[$fname][$style] = $f;
77 if ($isTTC) {
78 $tempfontdata[$fname]['TTCfontID'][$style] = $ret[$i][4];
79 }
80 //if ($ret[$i][5]) { $tempfontdata[$fname]['rtl'] = true; }
81 //if ($ret[$i][7]) { $tempfontdata[$fname]['cjk'] = true; }
82 if ($ret[$i][8]) { $tempfontdata[$fname]['sip'] = true; }
83 if ($ret[$i][9]) { $tempfontdata[$fname]['smp'] = true; }
84 if ($ret[$i][10]) { $tempfontdata[$fname]['puaag'] = true; }
85 if ($ret[$i][11]) { $tempfontdata[$fname]['pua'] = true; }
86 if ($ret[$i][12]) { $tempfontdata[$fname]['unAGlyphs'] = true; }
87 $ftype = $ret[$i][3]; // mono, sans or serif
88 if ($ftype=='sans') { $tempsansfonts[] = $fname; }
89 else if ($ftype=='serif') { $tempseriffonts[] = $fname; }
90 else if ($ftype=='mono') { $tempmonofonts[] = $fname; }
91 }
92 }
93
94 }
95 $tempsansfonts = array_unique($tempsansfonts);
96 $tempseriffonts = array_unique($tempseriffonts );
97 $tempmonofonts = array_unique($tempmonofonts );
98 $tempfonttrans = array_unique($tempfonttrans);
99
100 if (!$pdf) {
101 echo '<h3>Information</h3>';
102 }
103
104 foreach ($tempfontdata AS $fname => $v) {
105 if (!isset($tempfontdata[$fname]['R']) || !$tempfontdata[$fname]['R']) {
106 if (!$pdf) echo 'WARNING - Font file for '.$fname.' may be an italic cursive script, or extra-bold etc.<br />';
107 if (isset($tempfontdata[$fname]['I']) && $tempfontdata[$fname]['I']) {
108 $tempfontdata[$fname]['R'] = $tempfontdata[$fname]['I'];
109 }
110 else if (isset($tempfontdata[$fname]['B']) && $tempfontdata[$fname]['B']) {
111 $tempfontdata[$fname]['R'] = $tempfontdata[$fname]['B'];
112 }
113 else if (isset($tempfontdata[$fname]['BI']) && $tempfontdata[$fname]['BI']) {
114 $tempfontdata[$fname]['R'] = $tempfontdata[$fname]['BI'];
115 }
116 }
117 if (isset($tempfontdata[$fname]['smp']) && $tempfontdata[$fname]['smp']) {
118 if (!$pdf) echo 'INFO - Font file '.$fname.' contains characters in Unicode Plane 1 SMP<br />';
119 $tempfontdata[$fname]['smp'] = false;
120 }
121 // if (isset($tempfontdata[$fname]['pua']) && $tempfontdata[$fname]['pua']) {
122 // if (!$pdf) echo 'INFO - Font file '.$fname.' contains characters in Unicode Private Use Area (U+E000-U+F8FF)<br />';
123 // }
124 if (isset($tempfontdata[$fname]['unAGlyphs']) && $tempfontdata[$fname]['unAGlyphs']) {
125 if (!$pdf) echo 'INFO - Font file '.$fname.' contains non-indexed Arabic Glyphs "unAGlyphs" (which can be mapped to U+F500-U+F7FF)<br />';
126 if (isset($tempfontdata[$fname]['puaag']) && $tempfontdata[$fname]['puaag']) {
127 if (!$pdf) echo 'WARNING - Font file '.$fname.' already includes mapped characters in the part of Unicode Private Use Area which mPDF uses for mapping non-indexed Arabic Glyphs "unAGlyphs" (U+F500-U+F7FF)<br />';
128 }
129 }
130 if (isset($tempfontdata[$fname]['sip']) && $tempfontdata[$fname]['sip']) {
131 if (!$pdf) echo 'INFO - Font file '.$fname.' contains characters in Unicode Plane 2 SIP<br />';
132 if (preg_match('/^(.*)-extb/',$fname, $fm)) {
133 if (isset($tempfontdata[($fm[1])]) && $tempfontdata[($fm[1])]) {
134 $tempfontdata[($fm[1])]['sip-ext'] = $fname;
135 if (!$pdf) echo 'INFO - Font file '.$fname.' has been defined as a CJK ext-B for '.($fm[1]).'<br />';
136 }
137 else if (isset($tempfontdata[($fm[1].'-exta')]) && $tempfontdata[($fm[1].'-exta')]) {
138 $tempfontdata[($fm[1].'-exta')]['sip-ext'] = $fname;
139 if (!$pdf) echo 'INFO - Font file '.$fname.' has been defined as a CJK ext-B for '.($fm[1].'-exta').'<br />';
140 }
141 }
142 // else { unset($tempfontdata[$fname]['sip']); }
143 }
144 unset($tempfontdata[$fname]['sip']);
145 unset($tempfontdata[$fname]['smp']);
146 unset($tempfontdata[$fname]['pua']);
147 unset($tempfontdata[$fname]['puaag']);
148 unset($tempfontdata[$fname]['unAGlyphs']);
149 }
150
151 $mpdf->fontdata = array_merge($tempfontdata ,$mpdf->fontdata);
152
153 $mpdf->available_unifonts = array();
154 foreach ($mpdf->fontdata AS $f => $fs) {
155 if (isset($fs['R']) && $fs['R']) { $mpdf->available_unifonts[] = $f; }
156 if (isset($fs['B']) && $fs['B']) { $mpdf->available_unifonts[] = $f.'B'; }
157 if (isset($fs['I']) && $fs['I']) { $mpdf->available_unifonts[] = $f.'I'; }
158 if (isset($fs['BI']) && $fs['BI']) { $mpdf->available_unifonts[] = $f.'BI'; }
159 }
160
161 $mpdf->default_available_fonts = $mpdf->available_unifonts;
162
163 if (!$pdf) {
164 echo '<hr />';
165 echo '<h3>Font names as parsed by mPDF</h3>';
166 }
167
168 ksort($tempfonttrans);
169 $html = '';
170 foreach($tempfonttrans AS $on=>$mn) {
171 if (!file_exists($ttfdir.$mpdf->fontdata[$mn]['R'])) { continue; }
172 $ond = '"'.$on.'"';
173 $html .= '<p style="font-family:'.$on.';">'.$ond.' font is available as '.$mn;
174 if (isset($mpdf->fontdata[$mn]['sip-ext']) && $mpdf->fontdata[$mn]['sip-ext']) {
175 $html .= '; CJK ExtB: '.$mpdf->fontdata[$mn]['sip-ext'];
176 }
177 $html .= '</p>';
178 }
179
180 if ($pdf) {
181 $mpdf->WriteHTML($html);
182 $mpdf->Output();
183 exit;
184 }
185
186 foreach($tempfonttrans AS $on=>$mn) {
187 $ond = '"'.$on.'"';
188 echo '<div style="font-family:\''.$on.'\';">'.$ond.' font is available as '.$mn;
189 if (isset($mpdf->fontdata[$mn]['sip-ext']) && $mpdf->fontdata[$mn]['sip-ext']) {
190 echo '; CJK ExtB: '.$mpdf->fontdata[$mn]['sip-ext'];
191 }
192 echo '</div>';
193 }
194 echo '<hr />';
195
196 echo '<h3>Sample config_fonts.php file</h3>';
197 echo '<div>Remember to edit the following arrays to place your preferred default first in order:</div>';
198
199 echo '<pre>';
200
201 ksort($tempfontdata);
202 echo '$this->fontdata = '.var_export($tempfontdata,true).";\n";
203
204 sort($tempsansfonts);
205 echo '$this->sans_fonts = array(\''.implode("', '", $tempsansfonts)."');\n";
206 sort($tempseriffonts);
207 echo '$this->serif_fonts = array(\''.implode("', '", $tempseriffonts)."');\n";
208 sort($tempmonofonts);
209 echo '$this->mono_fonts = array(\''.implode("', '", $tempmonofonts)."');\n";
210 echo '</pre>';
211
212 exit;
213
214 ?>