font_dump.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. $min = 0x0020; // Minimum Unicode value to show
  14. $max = 0x2FFFF; // Maximum Unicode value to show
  15. $showmissing = false; // Show all missing unicode blocks / characters
  16. //////////////////////////////////
  17. //////////////////////////////////
  18. //////////////////////////////////
  19. set_time_limit(600);
  20. ini_set("memory_limit","512M");
  21. //==============================================================
  22. //==============================================================
  23. include("../mpdf.php");
  24. $mpdf=new mPDF('');
  25. $mpdf->SetDisplayMode('fullpage');
  26. $mpdf->useSubstitutions = true;
  27. $mpdf->simpleTables = true;
  28. // force fonts to be embedded whole i.e. NOT susbet
  29. $mpdf->percentSubset = 0;
  30. //==============================================================
  31. //==============================================================
  32. //==============================================================
  33. //==============================================================
  34. // This generates a .mtx.php file if not already generated
  35. $mpdf->WriteHTML('<style>td { border: 0.1mm solid #555555; } body { font-weight: normal; }</style>');
  36. $mpdf->WriteHTML('<h3 style="font-family:'.$font.'">'.strtoupper($font).'</h3>'); // Separate Paragraphs defined by font
  37. $html = '';
  38. //==============================================================
  39. //==============================================================
  40. //==============================================================
  41. //==============================================================
  42. $unifile = file('UnicodeData.txt');
  43. $unichars = array();
  44. foreach($unifile AS $line) {
  45. if ($smp && preg_match('/^(1[0-9A-Za-z]{4});/',$line,$m)) {
  46. $unichars[hexdec($m[1])] = hexdec($m[1]);
  47. }
  48. else if (preg_match('/^([0-9A-Za-z]{4});/',$line,$m)) {
  49. $unichars[hexdec($m[1])] = hexdec($m[1]);
  50. }
  51. }
  52. // loads array $unicode_ranges
  53. include('UnicodeRanges.php');
  54. //==============================================================
  55. //==============================================================
  56. $cw = file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  57. if (!$cw) { die("Error - Must be able to read font metrics file: "._MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  58. $counter=0;
  59. include(_MPDF_TTFONTDATAPATH.$font.'.mtx.php');
  60. if ($smp) {
  61. $max = min($max,131071);
  62. }
  63. else {
  64. $max = min($max,65535);
  65. }
  66. $justfinishedblank = false;
  67. $justfinishedblankinvalid = false;
  68. foreach($unicode_ranges AS $urk => $ur) {
  69. if (0 >= $ur['startdec'] && 0 <= $ur['enddec']) {
  70. $rangekey = $urk;
  71. $range = $ur['range'];
  72. $rangestart = $ur['starthex'];
  73. $rangeend = $ur['endhex'];
  74. break;
  75. }
  76. }
  77. $lastrange = $range ;
  78. // create HTML content
  79. $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
  80. $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-weight:bold">'.strtoupper($font).'</td></tr>';
  81. $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart .'-U+'.$rangeend.')</td></tr>';
  82. $html .= '<tr><td></td>';
  83. $html .= '<td></td>';
  84. for ($i = 0; $i < 16; $i++) {
  85. $html .= '<td><b>-'.sprintf('%X', $i).'</b></td>';
  86. }
  87. // print each character
  88. for ($i = $min; $i <= $max; ++$i) {
  89. if (($i > 0) AND (($i % 16) == 0)) {
  90. $notthisline = true;
  91. while($notthisline) {
  92. for ($j = 0; $j < 16; $j++) {
  93. if ($mpdf->_charDefined($cw, ($i + $j))) {
  94. //if (isset($cw[($i+$j)])) {
  95. $notthisline = false;
  96. }
  97. }
  98. if ($notthisline) {
  99. if ($showmissing) {
  100. $range = '';
  101. foreach($unicode_ranges AS $urk => $ur) {
  102. if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
  103. $rangekey = $urk;
  104. $range = $ur['range'];
  105. $rangestart = $ur['starthex'];
  106. $rangeend = $ur['endhex'];
  107. break;
  108. }
  109. }
  110. $anyvalid = false;
  111. for ($j = 0; $j < 16; $j++) {
  112. if (isset($unichars[$i+$j])) { $anyvalid = true; break; }
  113. }
  114. if ($range && $range == $lastrange) {
  115. if (!$anyvalid) {
  116. if (!$justfinishedblankinvalid) {
  117. $html .= '<tr><td colspan="18" style="background-color:#555555; font-size: 4pt;">&nbsp;</td></tr>';
  118. }
  119. $justfinishedblankinvalid = true;
  120. }
  121. else if (!$justfinishedblank ) {
  122. $html .= '<tr><td colspan="18" style="background-color:#FFAAAA; font-size: 4pt;">&nbsp;</td></tr>';
  123. $justfinishedblank = true;
  124. }
  125. }
  126. else if($range) {
  127. $html .= '</tr></table><br />';
  128. $mpdf->WriteHTML($html); $html = '';
  129. $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
  130. $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>';
  131. $html .= '<tr><td></td>';
  132. $html .= '<td></td>';
  133. for ($k = 0; $k < 16; $k++) {
  134. $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>';
  135. }
  136. $justfinishedblank = false;
  137. $justfinishedblankinvalid = false;
  138. }
  139. $lastrange = $range ;
  140. }
  141. $i +=16;
  142. if ($i > $max) { break 2; }
  143. }
  144. }
  145. foreach($unicode_ranges AS $urk => $ur) {
  146. if ($i >= $ur['startdec'] && $i <= $ur['enddec']) {
  147. $rangekey = $urk;
  148. $range = $ur['range'];
  149. $rangestart = $ur['starthex'];
  150. $rangeend = $ur['endhex'];
  151. break;
  152. }
  153. }
  154. if ($i > 0 && ($i % 16) == 0 && ($range != $lastrange)) {
  155. $html .= '</tr></table><br />';
  156. $mpdf->WriteHTML($html); $html = '';
  157. $html .= '<table cellpadding="2" cellspacing="0" style="font-family:'.$font.';text-align:center; border-collapse: collapse; ">';
  158. $html .= '<tr><td colspan="18" style="font-family:dejavusanscondensed;font-size:8pt;font-weight:bold">'.strtoupper($range).' (U+'.$rangestart.'-U+'.$rangeend.')</td></tr>';
  159. $html .= '<tr><td></td>';
  160. $html .= '<td></td>';
  161. for ($k = 0; $k < 16; $k++) {
  162. $html .= '<td><b>-'.sprintf('%X', $k).'</b></td>';
  163. }
  164. }
  165. $lastrange = $range ;
  166. $justfinishedblank = false;
  167. $justfinishedblankinvalid = false;
  168. $html .= '</tr><tr><td><i>'.(floor($i / 16)*16).'</i></td>';
  169. $html .= '<td><b>'.sprintf('%03X', floor($i / 16)).'-</b></td>';
  170. }
  171. // Add dotted circle to any character (mark) with width=0
  172. if ($mpdf->_charDefined($cw, $i) && _getCharWidth($cw, $i)==0) { $html .= '<td>&#x25cc;&#'.$i.';</td>'; $counter++; }
  173. else {
  174. if ($mpdf->_charDefined($cw, $i)) { $html .= '<td>&#'.$i.';</td>'; $counter++; }
  175. else if (isset($unichars[$i])) { $html .= '<td style="background-color: #FFAAAA;"></td>'; }
  176. else { $html .= '<td style="background-color: #555555;"></td>'; }
  177. }
  178. }
  179. if (($i % 16) > 0) {
  180. for ($j = ($i % 16); $j < 16; ++$j) { $html .= '<td style="background-color: #555555;"></td>'; }
  181. }
  182. $html .= '</tr></table><br />';
  183. //==============================================================
  184. function _getCharWidth(&$cw, $u, $isdef=true) {
  185. if ($u==0) { $w = false; }
  186. else { $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); }
  187. if ($w == 65535) { return 0; }
  188. else if ($w) { return $w; }
  189. else if ($isdef) { return false; }
  190. else { return 0; }
  191. }
  192. //==============================================================
  193. $mpdf->WriteHTML($html); // Separate Paragraphs defined by font
  194. $mpdf->Output();
  195. exit;
  196. //==============================================================
  197. //==============================================================
  198. //==============================================================
  199. //==============================================================