addfontttf.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 TrueType 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['ttf'])){
  32. // get font file
  33. $tmp=$HTTP_POST_FILES['ttf']['tmp_name'];
  34. $ttf=$HTTP_POST_FILES['ttf']['name'];
  35. $a=explode('.',$ttf);
  36. if(strtolower($a[1])!='ttf')
  37. die('File is not a .ttf');
  38. if(!move_uploaded_file($tmp,$ttf))
  39. die('Error in upload');
  40. $fontname=$HTTP_POST_VARS['fontname'];
  41. if(empty($fontname))
  42. $fontname=$a[0];
  43. // AFM generation
  44. system("ttf2pt1.exe -a $ttf $fontname");
  45. // MakeFont call
  46. MakeFont($ttf,"$fontname.afm",$HTTP_POST_VARS['enc']);
  47. copy("$fontname.php","../$fontname.php");
  48. unlink("$fontname.php");
  49. if(file_exists("$fontname.z"))
  50. {
  51. copy("$fontname.z","../$fontname.z");
  52. unlink("$fontname.z");
  53. }
  54. else
  55. copy($ttf,"../$ttf");
  56. unlink("$fontname.afm");
  57. unlink("$fontname.t1a");
  58. unlink($ttf);
  59. echo "<script language='javascript'>alert('Font processed');\n";
  60. echo "window.location.href='addfont.php';</script>";
  61. exit;
  62. }
  63. ?>
  64. <!doctype html public "-//W3C//DTD HTML 4.0//EN">
  65. <html>
  66. <head>
  67. <title>Font upload</title>
  68. </head>
  69. <body>
  70. <form action="addfontttf.php" method="post" enctype="multipart/form-data">
  71. <table border="0" cellspacing="5" cellpadding="5" width="300">
  72. <tr>
  73. <th align="left" colspan="2">
  74. Choose the .ttf file:
  75. </th>
  76. </tr>
  77. <tr>
  78. <td align2="left" colspan="2">
  79. <input type="file" name="ttf">
  80. </td>
  81. </tr>
  82. <tr>
  83. <td align="left">
  84. Font name:
  85. </td>
  86. <td align="left">
  87. <input type="text" name="fontname">
  88. </td>
  89. </tr>
  90. <tr>
  91. <td align="left">
  92. Font encoding:
  93. </td>
  94. <td align="left">
  95. <?php EncodingList(); ?>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td align="center">
  100. <input type="reset" name="btnSub" value="Clear">
  101. </td>
  102. <td align="center">
  103. <input type="submit" name="btnSub" value="Send">
  104. </td>
  105. </tr>
  106. </table>
  107. </form>
  108. </body>
  109. </html>