Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package php-font-lib
  4. * @link https://github.com/PhenX/php-font-lib
  5. * @author Fabien Ménager <fabien.menager@gmail.com>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. */
  8.  
  9. namespace FontLib;
  10.  
  11. /**
  12. * Generic font file.
  13. *
  14. * @package php-font-lib
  15. */
  16. class Font {
  17. static $debug = false;
  18.  
  19. /**
  20. * @param string $file The font file
  21. *
  22. * @return TrueType\File|null $file
  23. */
  24. public static function load($file) {
  25. $header = file_get_contents($file, false, null, null, 4);
  26. $class = null;
  27.  
  28. switch ($header) {
  29. case "\x00\x01\x00\x00":
  30. case "true":
  31. case "typ1":
  32. $class = "TrueType\\File";
  33. break;
  34.  
  35. case "OTTO":
  36. $class = "OpenType\\File";
  37. break;
  38.  
  39. case "wOFF":
  40. $class = "WOFF\\File";
  41. break;
  42.  
  43. case "ttcf":
  44. $class = "TrueType\\Collection";
  45. break;
  46.  
  47. // Unknown type or EOT
  48. default:
  49. $magicNumber = file_get_contents($file, false, null, 34, 2);
  50.  
  51. if ($magicNumber === "LP") {
  52. $class = "EOT\\File";
  53. }
  54. }
  55.  
  56. if ($class) {
  57. $class = "FontLib\\$class";
  58.  
  59. /** @var TrueType\File $obj */
  60. $obj = new $class;
  61. $obj->load($file);
  62.  
  63. return $obj;
  64. }
  65.  
  66. return null;
  67. }
  68.  
  69. static function d($str) {
  70. if (!self::$debug) {
  71. return;
  72. }
  73. echo "$str\n";
  74. }
  75.  
  76. static function UTF16ToUTF8($str) {
  77. return mb_convert_encoding($str, "utf-8", "utf-16");
  78. }
  79.  
  80. static function UTF8ToUTF16($str) {
  81. return mb_convert_encoding($str, "utf-16", "utf-8");
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement