fonts.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. include "head.inc";
  3. require_once "../dompdf_config.inc.php";
  4. function to_bytes($string) {
  5. $string = strtolower(trim($string));
  6. if (!preg_match("/(.*)([kmgt])/", $string, $matches)) {
  7. return intval($string);
  8. }
  9. list($string, $value, $suffix) = $matches;
  10. switch($suffix) {
  11. case 't': $value *= 1024;
  12. case 'g': $value *= 1024;
  13. case 'm': $value *= 1024;
  14. case 'k': $value *= 1024;
  15. }
  16. return intval($value);
  17. }
  18. ?>
  19. <a name="setup"> </a>
  20. <h2>Font manager</h2>
  21. <ul>
  22. <li style="list-style-image: url('images/star_02.gif');"><a href="#installed-fonts">Installed fonts</a></li>
  23. <li style="list-style-image: url('images/star_02.gif');"><a href="#install-fonts">Install new fonts</a></li>
  24. </ul>
  25. <h3 id="installed-fonts">Installed fonts</h3>
  26. <?php
  27. Font_Metrics::init();
  28. $fonts = Font_Metrics::get_font_families();
  29. $extensions = array("ttf", "afm", "afm.php", "ufm", "ufm.php");
  30. ?>
  31. <button onclick="$('#clear-font-cache-message').load('controller.php?cmd=clear-font-cache', function(){ location.reload(); })">Clear font cache</button>
  32. <span id="clear-font-cache-message"></span>
  33. <table class="setup">
  34. <tr>
  35. <th rowspan="2">Font family</th>
  36. <th rowspan="2">Variants</th>
  37. <th colspan="6">File versions</th>
  38. </tr>
  39. <tr>
  40. <th>TTF</th>
  41. <th>AFM</th>
  42. <th>AFM cache</th>
  43. <th>UFM</th>
  44. <th>UFM cache</th>
  45. </tr>
  46. <?php foreach($fonts as $family => $variants) { ?>
  47. <tr>
  48. <td class="title" rowspan="<?php echo count($variants); ?>">
  49. <?php
  50. echo $family;
  51. if ($family == DOMPDF_DEFAULT_FONT) echo ' <strong>(default)</strong>';
  52. ?>
  53. </td>
  54. <?php
  55. $i = 0;
  56. foreach($variants as $name => $path) {
  57. if ($i > 0) {
  58. echo "<tr>";
  59. }
  60. echo "
  61. <td>
  62. <strong style='width: 10em;'>$name</strong> : $path<br />
  63. </td>";
  64. foreach ($extensions as $ext) {
  65. $v = "";
  66. $class = "";
  67. if (is_readable("$path.$ext")) {
  68. // if not cache file
  69. if (strpos($ext, ".php") === false) {
  70. $class = "ok";
  71. $v = $ext;
  72. }
  73. // cache file
  74. else {
  75. // check if old cache format
  76. $content = file_get_contents("$path.$ext", null, null, null, 50);
  77. if (strpos($content, '$this->')) {
  78. $v = "DEPREC.";
  79. }
  80. else {
  81. ob_start();
  82. $d = include("$path.$ext");
  83. ob_end_clean();
  84. if ($d == 1)
  85. $v = "DEPREC.";
  86. else {
  87. $class = "ok";
  88. $v = $d["_version_"];
  89. }
  90. }
  91. }
  92. }
  93. echo "<td style='width: 2em; text-align: center;' class='$class'>$v</td>";
  94. }
  95. echo "</tr>";
  96. $i++;
  97. }
  98. ?>
  99. <?php } ?>
  100. </table>
  101. <h3 id="install-fonts">Install new fonts</h3>
  102. <script type="text/javascript">
  103. function checkFileName(form) {
  104. var fields = {normal: "Normal", bold: "Bold", bold_italic: "Bold italic", italic: "Italic"};
  105. var pattern = /\.[ot]tf$/i;
  106. var ok = true;
  107. if (!form.elements.family.value) {
  108. alert("The font name is required");
  109. form.elements.family.focus();
  110. return false;
  111. }
  112. $.each(fields, function(key, name){
  113. var value = form.elements["file["+key+"]"].value;
  114. if (!value) return;
  115. if (!value.match(pattern)) {
  116. alert("The font name specified for "+name+" is not a TrueType font");
  117. ok = false;
  118. return false;
  119. }
  120. });
  121. return ok;
  122. }
  123. </script>
  124. <?php
  125. if (auth_ok()) {
  126. $max_size = min(to_bytes(ini_get('post_max_size')), to_bytes(ini_get('upload_max_filesize')));
  127. ?>
  128. <form name="upload-font" method="post" action="controller.php?cmd=install-font" target="upload-font" enctype="multipart/form-data" onsubmit="return checkFileName(this)">
  129. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>" />
  130. <table class="setup">
  131. <tr>
  132. <td class="title">Name</td>
  133. <td><input type="text" name="family" /></td>
  134. <td rowspan="6"><iframe name="upload-font" id="upload-font" style="border: 0; width: 500px;"></iframe></td>
  135. </tr>
  136. <tr>
  137. <td class="title">Normal</td>
  138. <td><input type="file" name="file[normal]" /></td>
  139. </tr>
  140. <tr>
  141. <td class="title">Bold</td>
  142. <td><input type="file" name="file[bold]" /></td>
  143. </tr>
  144. <tr>
  145. <td class="title">Bold italic</td>
  146. <td><input type="file" name="file[bold_italic]" /></td>
  147. </tr>
  148. <tr>
  149. <td class="title">Italic</td>
  150. <td><input type="file" name="file[italic]" /></td>
  151. </tr>
  152. <tr>
  153. <td></td>
  154. <td><button>Install !!</button></td>
  155. </tr>
  156. </table>
  157. </form>
  158. <?php }
  159. else {
  160. echo auth_get_link();
  161. } ?>
  162. <?php include("foot.inc"); ?>