|
1 |
| -<?php |
2 |
| -/** |
3 |
| - * @package php-font-lib |
4 |
| - * @link http://php-font-lib.googlecode.com/ |
5 |
| - * @author Fabien Ménager <[email protected]> |
6 |
| - * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
7 |
| - * @version $Id: font.cls.php 41 2012-02-04 18:01:38Z fabien.menager $ |
8 |
| - */ |
9 |
| - |
10 |
| -/** |
11 |
| - * Generic font file. |
12 |
| - * |
13 |
| - * @package php-font-lib |
14 |
| - */ |
15 |
| -class Font { |
16 |
| - static $debug = false; |
17 |
| - |
18 |
| - /** |
19 |
| - * @param string $file The font file |
20 |
| - * @return Font_TrueType $file |
21 |
| - */ |
22 |
| - public static function load($file) { |
23 |
| - $header = file_get_contents($file, false, null, null, 4); |
24 |
| - $class = null; |
25 |
| - |
26 |
| - switch($header) { |
27 |
| - case "\x00\x01\x00\x00": |
28 |
| - case "true": |
29 |
| - case "typ1": |
30 |
| - $class = "Font_TrueType"; break; |
31 |
| - |
32 |
| - case "OTTO": |
33 |
| - $class = "Font_OpenType"; break; |
34 |
| - |
35 |
| - case "wOFF": |
36 |
| - $class = "Font_WOFF"; break; |
37 |
| - |
38 |
| - case "ttcf": |
39 |
| - $class = "Font_TrueType_Collection"; break; |
40 |
| - |
41 |
| - // Unknown type or EOT |
42 |
| - default: |
43 |
| - $magicNumber = file_get_contents($file, false, null, 34, 2); |
44 |
| - |
45 |
| - if ($magicNumber === "LP") { |
46 |
| - $class = "Font_EOT"; |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - if ($class) { |
51 |
| - require_once dirname(__FILE__)."/".strtolower($class).".cls.php"; |
52 |
| - |
53 |
| - $obj = new $class; |
54 |
| - $obj->load($file); |
55 |
| - |
56 |
| - return $obj; |
57 |
| - } |
58 |
| - } |
59 |
| - |
60 |
| - static function d($str) { |
61 |
| - if (!self::$debug) return; |
62 |
| - echo "$str\n"; |
63 |
| - } |
64 |
| - |
65 |
| - static function UTF16ToUTF8($str) { |
66 |
| - return mb_convert_encoding($str, "utf-8", "utf-16"); |
67 |
| - } |
68 |
| - |
69 |
| - static function UTF8ToUTF16($str) { |
70 |
| - return mb_convert_encoding($str, "utf-16", "utf-8"); |
71 |
| - } |
72 |
| -} |
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package php-font-lib |
| 4 | + * @link http://php-font-lib.googlecode.com/ |
| 5 | + * @author Fabien Ménager <[email protected]> |
| 6 | + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 7 | + * @version $Id$ |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Generic font file. |
| 12 | + * |
| 13 | + * @package php-font-lib |
| 14 | + */ |
| 15 | +class Font { |
| 16 | + static $debug = false; |
| 17 | + |
| 18 | + /** |
| 19 | + * @param string $file The font file |
| 20 | + * @return Font_TrueType $file |
| 21 | + */ |
| 22 | + public static function load($file) { |
| 23 | + $header = file_get_contents($file, false, null, null, 4); |
| 24 | + $class = null; |
| 25 | + |
| 26 | + switch($header) { |
| 27 | + case "\x00\x01\x00\x00": |
| 28 | + case "true": |
| 29 | + case "typ1": |
| 30 | + $class = "Font_TrueType"; break; |
| 31 | + |
| 32 | + case "OTTO": |
| 33 | + $class = "Font_OpenType"; break; |
| 34 | + |
| 35 | + case "wOFF": |
| 36 | + $class = "Font_WOFF"; break; |
| 37 | + |
| 38 | + case "ttcf": |
| 39 | + $class = "Font_TrueType_Collection"; break; |
| 40 | + |
| 41 | + // Unknown type or EOT |
| 42 | + default: |
| 43 | + $magicNumber = file_get_contents($file, false, null, 34, 2); |
| 44 | + |
| 45 | + if ($magicNumber === "LP") { |
| 46 | + $class = "Font_EOT"; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + if ($class) { |
| 51 | + require_once dirname(__FILE__)."/".strtolower($class).".cls.php"; |
| 52 | + |
| 53 | + $obj = new $class; |
| 54 | + $obj->load($file); |
| 55 | + |
| 56 | + return $obj; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + static function d($str) { |
| 61 | + if (!self::$debug) return; |
| 62 | + echo "$str\n"; |
| 63 | + } |
| 64 | + |
| 65 | + static function UTF16ToUTF8($str) { |
| 66 | + return mb_convert_encoding($str, "utf-8", "utf-16"); |
| 67 | + } |
| 68 | + |
| 69 | + static function UTF8ToUTF16($str) { |
| 70 | + return mb_convert_encoding($str, "utf-16", "utf-8"); |
| 71 | + } |
| 72 | +} |
0 commit comments