addfontt1.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /******************************************************************************/
  3. /* Script to add TrueType or Type1 fonts to FPDF */
  4. /* */
  5. /* author: Y. SUGERE */
  6. /* version: 1.0 */
  7. /* date: 2003-04-28 */
  8. /* required files: addfont.php, addfontt1.php, addfontttf.php */
  9. /* other necessary software: pfm2afm, ttf2pt1, fpdf */
  10. /* For more information, see readme.txt */
  11. /* */
  12. /* This file processes Type1 fonts */
  13. /******************************************************************************/
  14. require('makefont.php');
  15. function EncodingList()
  16. {
  17. // list all available encodings
  18. $d=dir('.');
  19. while($f=$d->read())
  20. {
  21. if(preg_match('/([a-z0-9_-]+)\\.map$/i',$f,$res))
  22. $enc[]=$res[1];
  23. }
  24. $d->close();
  25. sort($enc);
  26. echo '<SELECT NAME="enc">';
  27. foreach($enc as $e)
  28. printf('<OPTION %s>%s</OPTION>',$e=='cp1252' ? 'SELECTED': '',$e);
  29. echo '</SELECT>';
  30. }
  31. if(isset($HTTP_POST_FILES['pfb'])){
  32. // get font file
  33. $tmp=$HTTP_POST_FILES['pfb']['tmp_name'];
  34. $pfb=$HTTP_POST_FILES['pfb']['name'];
  35. $a=explode('.',$pfb);
  36. if(strtolower($a[1])!='pfb')
  37. die('File is not a .pfb');
  38. if(!move_uploaded_file($tmp,$pfb))
  39. die('Error in upload');
  40. $fontname=$HTTP_POST_VARS['fontname'];
  41. if(empty($fontname))
  42. $fontname=$a[0];
  43. // get font metric file
  44. $tmp=$HTTP_POST_FILES['fm']['tmp_name'];
  45. $fm=$HTTP_POST_FILES['fm']['name'];
  46. $a=explode('.',$fm);
  47. $fm_type=strtolower($a[1]);
  48. if($fm_type!='pfm' and $fm_type!='afm')
  49. die('File is not .pfm nor .afm');
  50. $fm="$fontname.$fm_type";
  51. if(!move_uploaded_file($tmp,$fm))
  52. die('Error in upload');
  53. if($fm_type=='pfm')
  54. {
  55. // PFM->AFM conversion
  56. system("pfm2afm.exe -a $fm $fontname.afm");
  57. unlink($fm);
  58. $fm="$fontname.afm";
  59. }
  60. // MakeFont call
  61. MakeFont($pfb,$fm,$HTTP_POST_VARS['enc']);
  62. copy("$fontname.php","../$fontname.php");
  63. unlink("$fontname.php");
  64. if(file_exists("$fontname.z"))
  65. {
  66. copy("$fontname.z","../$fontname.z");
  67. unlink("$fontname.z");
  68. }
  69. else
  70. copy($pfb,"../$pfb");
  71. unlink($fm);
  72. unlink($pfb);
  73. echo "<script language='javascript'>alert('Font processed');\n";
  74. echo "window.location.href='addfont.php';</script>";
  75. }
  76. ?>
  77. <!doctype html public "-//W3C//DTD HTML 4.0//EN">
  78. <html>
  79. <head>
  80. <title>Font upload</title>
  81. </head>
  82. <body>
  83. <form action="addfontt1.php" method="post" enctype="multipart/form-data">
  84. <table border="0" cellspacing="5" cellpadding="5" width="300">
  85. <tr>
  86. <th align="left" colspan="2">
  87. Choose the .pfb file:
  88. </th>
  89. </tr>
  90. <tr>
  91. <td align="left" colspan="2">
  92. <input type="file" name="pfb">
  93. </td>
  94. </tr>
  95. <tr>
  96. <th align="left" colspan="2">
  97. Choose the .pfm or .afm file:
  98. </th>
  99. </tr>
  100. <tr>
  101. <td align="left" colspan="2">
  102. <input type="file" name="fm">
  103. </td>
  104. </tr>
  105. <tr>
  106. <td align="left">
  107. Font name:
  108. </td>
  109. <td align="left">
  110. <input type="text" name="fontname">
  111. </td>
  112. </tr>
  113. <tr>
  114. <td align="left">
  115. Font encoding:
  116. </td>
  117. <td align="left">
  118. <?php EncodingList(); ?>
  119. </td>
  120. </tr>
  121. <tr>
  122. <td align="center">
  123. <input type="reset" name="btnSub" value="Clear">
  124. </td>
  125. <td align="center">
  126. <input type="submit" name="btnSub" value="Send">
  127. </td>
  128. </tr>
  129. </table>
  130. </form>
  131. </body>
  132. </html>