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_names.php

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

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