| 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', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); } |
| 37 |
$ttf = new TTFontFile(); |
| 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 |
|
| 85 |
$ftype = $ret[$i][3]; // mono, sans or serif |
| 86 |
if ($ftype=='sans') { $tempsansfonts[] = $fname; } |
| 87 |
else if ($ftype=='serif') { $tempseriffonts[] = $fname; } |
| 88 |
else if ($ftype=='mono') { $tempmonofonts[] = $fname; } |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
$tempsansfonts = array_unique($tempsansfonts); |
| 94 |
$tempseriffonts = array_unique($tempseriffonts ); |
| 95 |
$tempmonofonts = array_unique($tempmonofonts ); |
| 96 |
$tempfonttrans = array_unique($tempfonttrans); |
| 97 |
|
| 98 |
if (!$pdf) { |
| 99 |
echo '<h3>Information</h3>'; |
| 100 |
} |
| 101 |
|
| 102 |
foreach ($tempfontdata AS $fname => $v) { |
| 103 |
if (!isset($tempfontdata[$fname]['R']) || !$tempfontdata[$fname]['R']) { |
| 104 |
if (!$pdf) echo 'WARNING - Font file for '.$fname.' may be an italic cursive script, or extra-bold etc.<br />'; |
| 105 |
if (isset($tempfontdata[$fname]['I']) && $tempfontdata[$fname]['I']) { |
| 106 |
$tempfontdata[$fname]['R'] = $tempfontdata[$fname]['I']; |
| 107 |
} |
| 108 |
else if (isset($tempfontdata[$fname]['B']) && $tempfontdata[$fname]['B']) { |
| 109 |
$tempfontdata[$fname]['R'] = $tempfontdata[$fname]['B']; |
| 110 |
} |
| 111 |
else if (isset($tempfontdata[$fname]['BI']) && $tempfontdata[$fname]['BI']) { |
| 112 |
$tempfontdata[$fname]['R'] = $tempfontdata[$fname]['BI']; |
| 113 |
} |
| 114 |
} |
| 115 |
if (isset($tempfontdata[$fname]['smp']) && $tempfontdata[$fname]['smp']) { |
| 116 |
if (!$pdf) echo 'INFO - Font file '.$fname.' contains characters in Unicode Plane 1 SMP<br />'; |
| 117 |
$tempfontdata[$fname]['smp'] = false; |
| 118 |
} |
| 119 |
if (isset($tempfontdata[$fname]['sip']) && $tempfontdata[$fname]['sip']) { |
| 120 |
if (!$pdf) echo 'INFO - Font file '.$fname.' contains characters in Unicode Plane 2 SIP<br />'; |
| 121 |
if (preg_match('/^(.*)-extb/',$fname, $fm)) { |
| 122 |
if (isset($tempfontdata[($fm[1])]) && $tempfontdata[($fm[1])]) { |
| 123 |
$tempfontdata[($fm[1])]['sip-ext'] = $fname; |
| 124 |
if (!$pdf) echo 'INFO - Font file '.$fname.' has been defined as a CJK ext-B for '.($fm[1]).'<br />'; |
| 125 |
} |
| 126 |
else if (isset($tempfontdata[($fm[1].'-exta')]) && $tempfontdata[($fm[1].'-exta')]) { |
| 127 |
$tempfontdata[($fm[1].'-exta')]['sip-ext'] = $fname; |
| 128 |
if (!$pdf) echo 'INFO - Font file '.$fname.' has been defined as a CJK ext-B for '.($fm[1].'-exta').'<br />'; |
| 129 |
} |
| 130 |
} |
| 131 |
// else { unset($tempfontdata[$fname]['sip']); } |
| 132 |
} |
| 133 |
unset($tempfontdata[$fname]['sip']); |
| 134 |
unset($tempfontdata[$fname]['smp']); |
| 135 |
} |
| 136 |
|
| 137 |
$mpdf->fontdata = array_merge($tempfontdata ,$mpdf->fontdata); |
| 138 |
|
| 139 |
$mpdf->available_unifonts = array(); |
| 140 |
foreach ($mpdf->fontdata AS $f => $fs) { |
| 141 |
if (isset($fs['R']) && $fs['R']) { $mpdf->available_unifonts[] = $f; } |
| 142 |
if (isset($fs['B']) && $fs['B']) { $mpdf->available_unifonts[] = $f.'B'; } |
| 143 |
if (isset($fs['I']) && $fs['I']) { $mpdf->available_unifonts[] = $f.'I'; } |
| 144 |
if (isset($fs['BI']) && $fs['BI']) { $mpdf->available_unifonts[] = $f.'BI'; } |
| 145 |
} |
| 146 |
|
| 147 |
$mpdf->default_available_fonts = $mpdf->available_unifonts; |
| 148 |
|
| 149 |
if (!$pdf) { |
| 150 |
echo '<hr />'; |
| 151 |
echo '<h3>Font names as parsed by mPDF</h3>'; |
| 152 |
} |
| 153 |
|
| 154 |
ksort($tempfonttrans); |
| 155 |
$html = ''; |
| 156 |
foreach($tempfonttrans AS $on=>$mn) { |
| 157 |
if (!file_exists($ttfdir.$mpdf->fontdata[$mn]['R'])) { continue; } |
| 158 |
$ond = '"'.$on.'"'; |
| 159 |
$html .= '<p style="font-family:'.$on.';">'.$ond.' font is available as '.$mn; |
| 160 |
if (isset($mpdf->fontdata[$mn]['sip-ext']) && $mpdf->fontdata[$mn]['sip-ext']) { |
| 161 |
$html .= '; CJK ExtB: '.$mpdf->fontdata[$mn]['sip-ext']; |
| 162 |
} |
| 163 |
$html .= '</p>'; |
| 164 |
} |
| 165 |
|
| 166 |
if ($pdf) { |
| 167 |
$mpdf->WriteHTML($html); |
| 168 |
$mpdf->Output(); |
| 169 |
exit; |
| 170 |
} |
| 171 |
|
| 172 |
foreach($tempfonttrans AS $on=>$mn) { |
| 173 |
$ond = '"'.$on.'"'; |
| 174 |
echo '<div style="font-family:\''.$on.'\';">'.$ond.' font is available as '.$mn; |
| 175 |
if (isset($mpdf->fontdata[$mn]['sip-ext']) && $mpdf->fontdata[$mn]['sip-ext']) { |
| 176 |
echo '; CJK ExtB: '.$mpdf->fontdata[$mn]['sip-ext']; |
| 177 |
} |
| 178 |
echo '</div>'; |
| 179 |
} |
| 180 |
echo '<hr />'; |
| 181 |
|
| 182 |
echo '<h3>Sample config_fonts.php file</h3>'; |
| 183 |
echo '<div>Remember to edit the following arrays to place your preferred default first in order:</div>'; |
| 184 |
|
| 185 |
echo '<pre>'; |
| 186 |
|
| 187 |
ksort($tempfontdata); |
| 188 |
echo '$this->fontdata = '.var_export($tempfontdata,true).";\n"; |
| 189 |
|
| 190 |
sort($tempsansfonts); |
| 191 |
echo '$this->sans_fonts = array(\''.implode("', '", $tempsansfonts)."');\n"; |
| 192 |
sort($tempseriffonts); |
| 193 |
echo '$this->serif_fonts = array(\''.implode("', '", $tempseriffonts)."');\n"; |
| 194 |
sort($tempmonofonts); |
| 195 |
echo '$this->mono_fonts = array(\''.implode("', '", $tempmonofonts)."');\n"; |
| 196 |
echo '</pre>'; |
| 197 |
|
| 198 |
exit; |
| 199 |
|
| 200 |
?> |