font_dump.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /*
  3. This script prints out all characters in a TrueType font file
  4. to a PDF document. Point your browser to
  5. http://your.domain/your_path_to _mpdf/utils/font_dump.php
  6. The font file must be located in /ttfonts/ (or the default font
  7. directory defined by _MPDF_TTFONTPATH.
  8. By default this will examine the font dejavusanscondensed.
  9. You can optionally define an alternative font file to examine by setting
  10. the variable below (must be a relative path, or filesystem path):
  11. */
  12. $font = 'dejavusanscondensed'; // Use internal mPDF font-name
  13. $showmissing = true; // Show all missing unicode blocks / characters
  14. //////////////////////////////////
  15. //////////////////////////////////
  16. //////////////////////////////////
  17. set_time_limit(600);
  18. ini_set("memory_limit","256M");
  19. //==============================================================
  20. //==============================================================
  21. define('_MPDF_URI', '../');
  22. include("../mpdf.php");
  23. $mpdf=new mPDF('');
  24. $mpdf->StartProgressBarOutput(2);
  25. $mpdf->SetDisplayMode('fullpage');
  26. $mpdf->useSubstitutions = false;
  27. $mpdf->debug = true;
  28. $mpdf->simpleTables = true;
  29. //==============================================================
  30. //==============================================================
  31. //==============================================================
  32. //==============================================================
  33. // This generates a .mtx.php file if not already generated
  34. $mpdf->WriteHTML('<style>td { border: 0.1mm solid #555555; } body { font-weight: normal; }</style>');
  35. $mpdf->WriteHTML('<h3 style="font-family:'.$font.'">'.strtoupper($font).'</h3>'); // Separate Paragraphs defined by font
  36. $html = '';
  37. //==============================================================
  38. //==============================================================
  39. //==============================================================
  40. //==============================================================
  41. $unifile = file('UnicodeData.txt');
  42. $unichars = array();
  43. foreach($unifile AS $line) {
  44. if ($smp && preg_match('/^(1[0-9A-Za-z]{4});/',$line,$m)) {
  45. $unichars[hexdec($m[1])] = hexdec($m[1]);
  46. }
  47. else if (preg_match('/^([0-9A-Za-z]{4});/',$line,$m)) {
  48. $unichars[hexdec($m[1])] = hexdec($m[1]);
  49. }
  50. }
  51. // loads array $unicode_ranges
  52. include('UnicodeRanges.php');
  53. //==============================================================
  54. //==============================================================
  55. $cw = file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  56. if (!$cw) { die("Error - Must be able to read font metrics file: "._MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  57. $counter=0;
  58. include(_MPDF_TTFONTDATAPATH.$font.'.mtx.php');
  59. if ($smp) {
  60. $max = 131071;
  61. }
  62. else {
  63. $max = 65535;
  64. }
  65. $justfinishedblank = false;
  66. $justfinishedblankinvalid = false;
  67. foreach($unicode_ranges AS $urk => $ur) {
  68. if (0 >= $ur['startdec'] && 0 <= $ur['enddec']) {
  69. $rangekey = $urk;
  70. $range = $ur['range'];
  71. $rangestart = $ur['starthex'];
  72. $rangeend = $ur['endhex'];
  73. break;
  74. }
  75. }
  76. $lastrange = $range ;
  77. // create HTML content
  78. $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
  79. $html .= '<tr><td colspan="18" style="font-family:helvetica;font-weight:bold">'.strtoupper($font).'</td></tr>';
  80. $html .= '<tr><td colspan="18" style="font-family:helvetica;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')</td></tr>';
  81. $html .= '<tr><td></td>';
  82. $html .= '<td></td>';
  83. for ($i = 0; $i < 16; $i++) {
  84. $html .= '<td><b>-'.sprintf('%X', $i).'</b></td>';
  85. }
  86. // print each character
  87. for ($i = 32; $i < $max; ++$i) {
  88. if (($i > 0) AND (($i % 16) == 0)) {
  89. $notthisline = true;
  90. while($notthisline) {
  91. for ($j = 0; $j < 16; $j++) {
  92. if ($mpdf->_charDefined($cw, ($i + $j))) {
  93. //if (isset($cw[($i+$j)])) {
  94. $notthisline = false;
  95. }
  96. }
  97. if ($notthisline) {
  98. if ($showmissing) {
  99. $range = '';
  100. foreach($unicode_ranges AS $urk => $ur) {
  101. if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
  102. $rangekey = $urk;
  103. $range = $ur['range'];
  104. $rangestart = $ur['starthex'];
  105. $rangeend = $ur['endhex'];
  106. break;
  107. }
  108. }
  109. $anyvalid = false;
  110. for ($j = 0; $j < 16; $j++) {
  111. if (isset($unichars[$i+$j])) { $anyvalid = true; break; }
  112. }
  113. if ($range && $range == $lastrange) {
  114. if (!$anyvalid) {
  115. if (!$justfinishedblankinvalid) {
  116. $html .= '<tr><td colspan="18" style="background-color:#555555; font-size: 4pt;">&nbsp;</td></tr>';
  117. }
  118. $justfinishedblankinvalid = true;
  119. }
  120. else if (!$justfinishedblank ) {
  121. $html .= '<tr><td colspan="18" style="background-color:#FFAAAA; font-size: 4pt;">&nbsp;</td></tr>';
  122. $justfinishedblank = true;
  123. }
  124. }
  125. else if($range) {
  126. $html .= '</tr></table><br />';
  127. $mpdf->WriteHTML($html); $html = '';
  128. $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
  129. $html .= '<tr><td colspan="18" style="font-family:helvetica;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>';
  130. $html .= '<tr><td></td>';
  131. $html .= '<td></td>';
  132. for ($k = 0; $k < 16; $k++) {
  133. $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>';
  134. }
  135. $justfinishedblank = false;
  136. $justfinishedblankinvalid = false;
  137. }
  138. $lastrange = $range ;
  139. }
  140. $i +=16;
  141. if ($i > $max) { break 2; }
  142. }
  143. }
  144. foreach($unicode_ranges AS $urk => $ur) {
  145. if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
  146. $rangekey = $urk;
  147. $range = $ur['range'];
  148. $rangestart = $ur['starthex'];
  149. $rangeend = $ur['endhex'];
  150. break;
  151. }
  152. }
  153. if ($i > 0 && ($i % 16) == 0 && ($range != $lastrange)) {
  154. $html .= '</tr></table><br />';
  155. $mpdf->WriteHTML($html); $html = '';
  156. $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
  157. $html .= '<tr><td colspan="18" style="font-family:helvetica;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>';
  158. $html .= '<tr><td></td>';
  159. $html .= '<td></td>';
  160. for ($k = 0; $k < 16; $k++) {
  161. $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>';
  162. }
  163. }
  164. $lastrange = $range ;
  165. $justfinishedblank = false;
  166. $justfinishedblankinvalid = false;
  167. $html .= '</tr><tr><td><i>'.(floor($i / 16)*16).'</i></td>';
  168. $html .= '<td><b>'.sprintf('%03X', floor($i / 16)).'-</b></td>';
  169. }
  170. if ($mpdf->_charDefined($cw, $i)) { $html .= '<td>&#'.$i.';</td>'; $counter++; }
  171. else if (isset($unichars[$i])) { $html .= '<td style="background-color: #FFAAAA;"></td>'; }
  172. else { $html .= '<td style="background-color: #555555;"></td>'; }
  173. }
  174. if (($i % 16) > 0) {
  175. for ($j = ($i % 16); $j < 16; ++$j) { $html .= '<td style="background-color: #555555;"></td>'; }
  176. }
  177. $html .= '</tr></table><br />';
  178. //==============================================================
  179. //==============================================================
  180. $mpdf->WriteHTML($html); // Separate Paragraphs defined by font
  181. $mpdf->Output();
  182. exit;
  183. //==============================================================
  184. //==============================================================
  185. //==============================================================
  186. //==============================================================
  187. ?>