Debian Codegraph @

vendor/dompdf/php-font-lib/src/FontLib/Font.php

raw
1 <?php
2 /**
3 * @package php-font-lib
4 * @link https://github.com/dompdf/php-font-lib
5 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
6 */
7
8 namespace FontLib;
9
10 use FontLib\Exception\FontNotFoundException;
11
12 /**
13 * Generic font file.
14 *
15 * @package php-font-lib
16 */
17 class Font {
18 static $debug = false;
19
20 /**
21 * @param string $file The font file
22 *
23 * @return TrueType\File|null $file
24 */
25 public static function load($file) {
26 if(!file_exists($file)){
27 throw new FontNotFoundException($file);
28 }
29
30 $header = file_get_contents($file, false, null, 0, 4);
31 $class = null;
32
33 switch ($header) {
34 case "\x00\x01\x00\x00":
35 case "true":
36 case "typ1":
37 $class = "TrueType\\File";
38 break;
39
40 case "OTTO":
41 $class = "OpenType\\File";
42 break;
43
44 case "wOFF":
45 $class = "WOFF\\File";
46 break;
47
48 case "ttcf":
49 $class = "TrueType\\Collection";
50 break;
51
52 // Unknown type or EOT
53 default:
54 $magicNumber = file_get_contents($file, false, null, 34, 2);
55
56 if ($magicNumber === "LP") {
57 $class = "EOT\\File";
58 }
59 }
60
61 if ($class) {
62 $class = "FontLib\\$class";
63
64 /** @var TrueType\File $obj */
65 $obj = new $class;
66 $obj->load($file);
67
68 return $obj;
69 }
70
71 return null;
72 }
73
74 static function d($str) {
75 if (!self::$debug) {
76 return;
77 }
78 echo "$str\n";
79 }
80
81 static function UTF16ToUTF8($str) {
82 return mb_convert_encoding($str, "utf-8", "utf-16");
83 }
84
85 static function UTF8ToUTF16($str) {
86 return mb_convert_encoding($str, "utf-16", "utf-8");
87 }
88 }