make_subset.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @package php-font-lib
  4. * @link http://php-font-lib.googlecode.com/
  5. * @author Fabien Ménager <fabien.menager@gmail.com>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. * @version $Id$
  8. */
  9. $fontfile = $_GET["fontfile"];
  10. $name = isset($_GET["name"]) ? $_GET["name"] : null;
  11. if (isset($_POST["subset"])) {
  12. $subset = $_POST["subset"];
  13. ob_start();
  14. require_once "../classes/font.cls.php";
  15. $font = Font::load($fontfile);
  16. $font->parse();
  17. $font->setSubset($subset);
  18. $font->reduce();
  19. header('Content-Type: font/truetype');
  20. header('Content-Disposition: attachment; filename="subset.ttf"');
  21. $tmp = tempnam(sys_get_temp_dir(), "fnt");
  22. $font->open($tmp, Font_Binary_Stream::modeWrite);
  23. $font->encode(array("OS/2"));
  24. $font->close();
  25. ob_end_clean();
  26. readfile($tmp);
  27. unlink($tmp);
  28. return;
  29. } ?>
  30. <!DOCTYPE html>
  31. <html>
  32. <head>
  33. <link rel="stylesheet" href="css/style.css" />
  34. </head>
  35. <body>
  36. <h1><?php echo $name; ?></h1>
  37. <form name="make-subset" method="post" action="?fontfile=<?php echo $fontfile; ?>">
  38. <label>
  39. Insert the text from which you want the glyphs in the subsetted font: <br />
  40. <textarea name="subset" cols="50" rows="20"></textarea>
  41. </label>
  42. <br />
  43. <button type="submit">Make subset!</button>
  44. </form>
  45. </body>
  46. </html>