暫無描述

fonts.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 htmlentities($family);
  51. if ($family == DOMPDF_DEFAULT_FONT) {
  52. echo ' <strong>(default)</strong>';
  53. }
  54. ?>
  55. </td>
  56. <?php
  57. $i = 0;
  58. foreach($variants as $name => $path) {
  59. if ($i > 0) {
  60. echo "<tr>";
  61. }
  62. echo "
  63. <td>
  64. <strong style='width: 10em;'>".htmlentities($name)."</strong> : ".htmlentities($path)."<br />
  65. </td>";
  66. foreach ($extensions as $ext) {
  67. $v = "";
  68. $class = "";
  69. if (is_readable("$path.$ext")) {
  70. // if not cache file
  71. if (strpos($ext, ".php") === false) {
  72. $class = "ok";
  73. $v = $ext;
  74. }
  75. // cache file
  76. else {
  77. // check if old cache format
  78. $content = file_get_contents("$path.$ext", null, null, null, 50);
  79. if (strpos($content, '$this->')) {
  80. $v = "DEPREC.";
  81. }
  82. else {
  83. ob_start();
  84. $d = include "$path.$ext";
  85. ob_end_clean();
  86. if ($d == 1)
  87. $v = "DEPREC.";
  88. else {
  89. $class = "ok";
  90. $v = $d["_version_"];
  91. }
  92. }
  93. }
  94. }
  95. echo "<td style='width: 2em; text-align: center;' class='$class'>$v</td>";
  96. }
  97. echo "</tr>";
  98. $i++;
  99. }
  100. ?>
  101. <?php } ?>
  102. </table>
  103. <h3 id="install-fonts">Install new fonts</h3>
  104. <script type="text/javascript">
  105. function checkFileName(form) {
  106. var fields = {
  107. normal: "Normal",
  108. bold: "Bold",
  109. bold_italic: "Bold italic",
  110. italic: "Italic"
  111. };
  112. var pattern = /\.[ot]tf$/i;
  113. var ok = true;
  114. if (!form.elements.family.value) {
  115. alert("The font name is required");
  116. form.elements.family.focus();
  117. return false;
  118. }
  119. $.each(fields, function(key, name){
  120. var value = form.elements["file["+key+"]"].value;
  121. if (!value) return;
  122. if (!value.match(pattern)) {
  123. alert("The font name specified for "+name+" is not a TrueType font");
  124. ok = false;
  125. return false;
  126. }
  127. });
  128. return ok;
  129. }
  130. </script>
  131. <?php
  132. if (auth_ok()) {
  133. $max_size = min(to_bytes(ini_get('post_max_size')), to_bytes(ini_get('upload_max_filesize')));
  134. ?>
  135. <form name="upload-font" method="post" action="controller.php?cmd=install-font" target="upload-font" enctype="multipart/form-data" onsubmit="return checkFileName(this)">
  136. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>" />
  137. <table class="setup">
  138. <tr>
  139. <td class="title">Name</td>
  140. <td><input type="text" name="family" /></td>
  141. <td rowspan="6"><iframe name="upload-font" id="upload-font" style="border: 0; width: 500px;"></iframe></td>
  142. </tr>
  143. <tr>
  144. <td class="title">Normal</td>
  145. <td><input type="file" name="file[normal]" /></td>
  146. </tr>
  147. <tr>
  148. <td class="title">Bold</td>
  149. <td><input type="file" name="file[bold]" /></td>
  150. </tr>
  151. <tr>
  152. <td class="title">Bold italic</td>
  153. <td><input type="file" name="file[bold_italic]" /></td>
  154. </tr>
  155. <tr>
  156. <td class="title">Italic</td>
  157. <td><input type="file" name="file[italic]" /></td>
  158. </tr>
  159. <tr>
  160. <td></td>
  161. <td><button>Install !!</button></td>
  162. </tr>
  163. </table>
  164. </form>
  165. <?php }
  166. else {
  167. echo auth_get_link();
  168. } ?>
  169. <?php include("foot.inc"); ?>