@@ -16,29 +16,29 @@ |
||
16 | 16 | */ |
17 | 17 | class hhea extends Table { |
18 | 18 | protected $def = array( |
19 | - "version" => self::Fixed, |
|
20 | - "ascent" => self::FWord, |
|
21 | - "descent" => self::FWord, |
|
22 | - "lineGap" => self::FWord, |
|
23 | - "advanceWidthMax" => self::uFWord, |
|
24 | - "minLeftSideBearing" => self::FWord, |
|
25 | - "minRightSideBearing" => self::FWord, |
|
26 | - "xMaxExtent" => self::FWord, |
|
27 | - "caretSlopeRise" => self::int16, |
|
28 | - "caretSlopeRun" => self::int16, |
|
29 | - "caretOffset" => self::FWord, |
|
30 | - self::int16, |
|
31 | - self::int16, |
|
32 | - self::int16, |
|
33 | - self::int16, |
|
34 | - "metricDataFormat" => self::int16, |
|
35 | - "numOfLongHorMetrics" => self::uint16, |
|
19 | + "version" => self::Fixed, |
|
20 | + "ascent" => self::FWord, |
|
21 | + "descent" => self::FWord, |
|
22 | + "lineGap" => self::FWord, |
|
23 | + "advanceWidthMax" => self::uFWord, |
|
24 | + "minLeftSideBearing" => self::FWord, |
|
25 | + "minRightSideBearing" => self::FWord, |
|
26 | + "xMaxExtent" => self::FWord, |
|
27 | + "caretSlopeRise" => self::int16, |
|
28 | + "caretSlopeRun" => self::int16, |
|
29 | + "caretOffset" => self::FWord, |
|
30 | + self::int16, |
|
31 | + self::int16, |
|
32 | + self::int16, |
|
33 | + self::int16, |
|
34 | + "metricDataFormat" => self::int16, |
|
35 | + "numOfLongHorMetrics" => self::uint16, |
|
36 | 36 | ); |
37 | 37 | |
38 | 38 | function _encode() { |
39 | - $font = $this->getFont(); |
|
40 | - $this->data["numOfLongHorMetrics"] = count($font->getSubset()); |
|
39 | + $font = $this->getFont(); |
|
40 | + $this->data["numOfLongHorMetrics"] = count($font->getSubset()); |
|
41 | 41 | |
42 | - return parent::_encode(); |
|
42 | + return parent::_encode(); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | \ No newline at end of file |
@@ -26,68 +26,68 @@ |
||
26 | 26 | public $data; |
27 | 27 | |
28 | 28 | final public function __construct(DirectoryEntry $entry) { |
29 | - $this->entry = $entry; |
|
30 | - $entry->setTable($this); |
|
29 | + $this->entry = $entry; |
|
30 | + $entry->setTable($this); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @return File |
35 | 35 | */ |
36 | 36 | public function getFont() { |
37 | - return $this->entry->getFont(); |
|
37 | + return $this->entry->getFont(); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | protected function _encode() { |
41 | - if (empty($this->data)) { |
|
42 | - Font::d(" >> Table is empty"); |
|
41 | + if (empty($this->data)) { |
|
42 | + Font::d(" >> Table is empty"); |
|
43 | 43 | |
44 | - return 0; |
|
45 | - } |
|
44 | + return 0; |
|
45 | + } |
|
46 | 46 | |
47 | - return $this->getFont()->pack($this->def, $this->data); |
|
47 | + return $this->getFont()->pack($this->def, $this->data); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | protected function _parse() { |
51 | - $this->data = $this->getFont()->unpack($this->def); |
|
51 | + $this->data = $this->getFont()->unpack($this->def); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | protected function _parseRaw() { |
55 | - $this->data = $this->getFont()->read($this->entry->length); |
|
55 | + $this->data = $this->getFont()->read($this->entry->length); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | protected function _encodeRaw() { |
59 | - return $this->getFont()->write($this->data, $this->entry->length); |
|
59 | + return $this->getFont()->write($this->data, $this->entry->length); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public function toHTML() { |
63 | - return "<pre>" . var_export($this->data, true) . "</pre>"; |
|
63 | + return "<pre>" . var_export($this->data, true) . "</pre>"; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | final public function encode() { |
67 | - $this->entry->startWrite(); |
|
67 | + $this->entry->startWrite(); |
|
68 | 68 | |
69 | - if (false && empty($this->def)) { |
|
70 | - $length = $this->_encodeRaw(); |
|
71 | - } |
|
72 | - else { |
|
73 | - $length = $this->_encode(); |
|
74 | - } |
|
69 | + if (false && empty($this->def)) { |
|
70 | + $length = $this->_encodeRaw(); |
|
71 | + } |
|
72 | + else { |
|
73 | + $length = $this->_encode(); |
|
74 | + } |
|
75 | 75 | |
76 | - $this->entry->endWrite(); |
|
76 | + $this->entry->endWrite(); |
|
77 | 77 | |
78 | - return $length; |
|
78 | + return $length; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | final public function parse() { |
82 | - $this->entry->startRead(); |
|
82 | + $this->entry->startRead(); |
|
83 | 83 | |
84 | - if (false && empty($this->def)) { |
|
85 | - $this->_parseRaw(); |
|
86 | - } |
|
87 | - else { |
|
88 | - $this->_parse(); |
|
89 | - } |
|
84 | + if (false && empty($this->def)) { |
|
85 | + $this->_parseRaw(); |
|
86 | + } |
|
87 | + else { |
|
88 | + $this->_parse(); |
|
89 | + } |
|
90 | 90 | |
91 | - $this->entry->endRead(); |
|
91 | + $this->entry->endRead(); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | \ No newline at end of file |
@@ -60,7 +60,7 @@ |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | public function toHTML() { |
63 | - return "<pre>" . var_export($this->data, true) . "</pre>"; |
|
63 | + return "<pre>".var_export($this->data, true)."</pre>"; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | final public function encode() { |
@@ -68,8 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | if (false && empty($this->def)) { |
70 | 70 | $length = $this->_encodeRaw(); |
71 | - } |
|
72 | - else { |
|
71 | + } else { |
|
73 | 72 | $length = $this->_encode(); |
74 | 73 | } |
75 | 74 | |
@@ -83,8 +82,7 @@ discard block |
||
83 | 82 | |
84 | 83 | if (false && empty($this->def)) { |
85 | 84 | $this->_parseRaw(); |
86 | - } |
|
87 | - else { |
|
85 | + } else { |
|
88 | 86 | $this->_parse(); |
89 | 87 | } |
90 | 88 |
@@ -15,18 +15,18 @@ |
||
15 | 15 | */ |
16 | 16 | class Header extends \FontLib\TrueType\Header { |
17 | 17 | protected $def = array( |
18 | - "format" => self::uint32, |
|
19 | - "flavor" => self::uint32, |
|
20 | - "length" => self::uint32, |
|
21 | - "numTables" => self::uint16, |
|
22 | - self::uint16, |
|
23 | - "totalSfntSize" => self::uint32, |
|
24 | - "majorVersion" => self::uint16, |
|
25 | - "minorVersion" => self::uint16, |
|
26 | - "metaOffset" => self::uint32, |
|
27 | - "metaLength" => self::uint32, |
|
28 | - "metaOrigLength" => self::uint32, |
|
29 | - "privOffset" => self::uint32, |
|
30 | - "privLength" => self::uint32, |
|
18 | + "format" => self::uint32, |
|
19 | + "flavor" => self::uint32, |
|
20 | + "length" => self::uint32, |
|
21 | + "numTables" => self::uint16, |
|
22 | + self::uint16, |
|
23 | + "totalSfntSize" => self::uint32, |
|
24 | + "majorVersion" => self::uint16, |
|
25 | + "minorVersion" => self::uint16, |
|
26 | + "metaOffset" => self::uint32, |
|
27 | + "metaLength" => self::uint32, |
|
28 | + "metaOrigLength" => self::uint32, |
|
29 | + "privOffset" => self::uint32, |
|
30 | + "privLength" => self::uint32, |
|
31 | 31 | ); |
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -19,63 +19,63 @@ |
||
19 | 19 | */ |
20 | 20 | class File extends \FontLib\TrueType\File { |
21 | 21 | function parseHeader() { |
22 | - if (!empty($this->header)) { |
|
23 | - return; |
|
24 | - } |
|
22 | + if (!empty($this->header)) { |
|
23 | + return; |
|
24 | + } |
|
25 | 25 | |
26 | - $this->header = new Header($this); |
|
27 | - $this->header->parse(); |
|
26 | + $this->header = new Header($this); |
|
27 | + $this->header->parse(); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function load($file) { |
31 | - parent::load($file); |
|
32 | - |
|
33 | - $this->parseTableEntries(); |
|
34 | - $dataOffset = $this->pos() + count($this->directory) * 20; |
|
35 | - |
|
36 | - $fw = $this->getTempFile(false); |
|
37 | - $fr = $this->f; |
|
38 | - |
|
39 | - $this->f = $fw; |
|
40 | - $offset = $this->header->encode(); |
|
41 | - |
|
42 | - foreach ($this->directory as $entry) { |
|
43 | - // Read ... |
|
44 | - $this->f = $fr; |
|
45 | - $this->seek($entry->offset); |
|
46 | - $data = $this->read($entry->length); |
|
47 | - |
|
48 | - if ($entry->length < $entry->origLength) { |
|
49 | - $data = (string) gzuncompress($data); |
|
50 | - } |
|
51 | - |
|
52 | - // Prepare data ... |
|
53 | - $length = mb_strlen($data, '8bit'); |
|
54 | - $entry->length = $entry->origLength = $length; |
|
55 | - $entry->offset = $dataOffset; |
|
56 | - |
|
57 | - // Write ... |
|
58 | - $this->f = $fw; |
|
59 | - |
|
60 | - // Woff Entry |
|
61 | - $this->seek($offset); |
|
62 | - $offset += $this->write($entry->tag, 4); // tag |
|
63 | - $offset += $this->writeUInt32($dataOffset); // offset |
|
64 | - $offset += $this->writeUInt32($length); // length |
|
65 | - $offset += $this->writeUInt32($length); // origLength |
|
66 | - $offset += $this->writeUInt32(DirectoryEntry::computeChecksum($data)); // checksum |
|
67 | - |
|
68 | - // Data |
|
69 | - $this->seek($dataOffset); |
|
70 | - $dataOffset += $this->write($data, $length); |
|
71 | - } |
|
72 | - |
|
73 | - $this->f = $fw; |
|
74 | - $this->seek(0); |
|
75 | - |
|
76 | - // Need to re-parse this, don't know why |
|
77 | - $this->header = null; |
|
78 | - $this->directory = array(); |
|
79 | - $this->parseTableEntries(); |
|
31 | + parent::load($file); |
|
32 | + |
|
33 | + $this->parseTableEntries(); |
|
34 | + $dataOffset = $this->pos() + count($this->directory) * 20; |
|
35 | + |
|
36 | + $fw = $this->getTempFile(false); |
|
37 | + $fr = $this->f; |
|
38 | + |
|
39 | + $this->f = $fw; |
|
40 | + $offset = $this->header->encode(); |
|
41 | + |
|
42 | + foreach ($this->directory as $entry) { |
|
43 | + // Read ... |
|
44 | + $this->f = $fr; |
|
45 | + $this->seek($entry->offset); |
|
46 | + $data = $this->read($entry->length); |
|
47 | + |
|
48 | + if ($entry->length < $entry->origLength) { |
|
49 | + $data = (string) gzuncompress($data); |
|
50 | + } |
|
51 | + |
|
52 | + // Prepare data ... |
|
53 | + $length = mb_strlen($data, '8bit'); |
|
54 | + $entry->length = $entry->origLength = $length; |
|
55 | + $entry->offset = $dataOffset; |
|
56 | + |
|
57 | + // Write ... |
|
58 | + $this->f = $fw; |
|
59 | + |
|
60 | + // Woff Entry |
|
61 | + $this->seek($offset); |
|
62 | + $offset += $this->write($entry->tag, 4); // tag |
|
63 | + $offset += $this->writeUInt32($dataOffset); // offset |
|
64 | + $offset += $this->writeUInt32($length); // length |
|
65 | + $offset += $this->writeUInt32($length); // origLength |
|
66 | + $offset += $this->writeUInt32(DirectoryEntry::computeChecksum($data)); // checksum |
|
67 | + |
|
68 | + // Data |
|
69 | + $this->seek($dataOffset); |
|
70 | + $dataOffset += $this->write($data, $length); |
|
71 | + } |
|
72 | + |
|
73 | + $this->f = $fw; |
|
74 | + $this->seek(0); |
|
75 | + |
|
76 | + // Need to re-parse this, don't know why |
|
77 | + $this->header = null; |
|
78 | + $this->directory = array(); |
|
79 | + $this->parseTableEntries(); |
|
80 | 80 | } |
81 | 81 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | class File extends \FontLib\TrueType\File { |
21 | 21 | function parseHeader() { |
22 | - if (!empty($this->header)) { |
|
22 | + if ( ! empty($this->header)) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 |
@@ -19,16 +19,16 @@ |
||
19 | 19 | public $origLength; |
20 | 20 | |
21 | 21 | function __construct(File $font) { |
22 | - parent::__construct($font); |
|
22 | + parent::__construct($font); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | function parse() { |
26 | - parent::parse(); |
|
26 | + parent::parse(); |
|
27 | 27 | |
28 | - $font = $this->font; |
|
29 | - $this->offset = $font->readUInt32(); |
|
30 | - $this->length = $font->readUInt32(); |
|
31 | - $this->origLength = $font->readUInt32(); |
|
32 | - $this->checksum = $font->readUInt32(); |
|
28 | + $font = $this->font; |
|
29 | + $this->offset = $font->readUInt32(); |
|
30 | + $this->length = $font->readUInt32(); |
|
31 | + $this->origLength = $font->readUInt32(); |
|
32 | + $this->checksum = $font->readUInt32(); |
|
33 | 33 | } |
34 | 34 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | const modeReadWrite = "rb+"; |
39 | 39 | |
40 | 40 | static function backtrace() { |
41 | - var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); |
|
41 | + var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @return bool |
50 | 50 | */ |
51 | 51 | public function load($filename) { |
52 | - return $this->open($filename, self::modeRead); |
|
52 | + return $this->open($filename, self::modeRead); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -62,20 +62,20 @@ discard block |
||
62 | 62 | * @return bool |
63 | 63 | */ |
64 | 64 | public function open($filename, $mode = self::modeRead) { |
65 | - if (!in_array($mode, array(self::modeRead, self::modeWrite, self::modeReadWrite))) { |
|
66 | - throw new \Exception("Unknown file open mode"); |
|
67 | - } |
|
65 | + if (!in_array($mode, array(self::modeRead, self::modeWrite, self::modeReadWrite))) { |
|
66 | + throw new \Exception("Unknown file open mode"); |
|
67 | + } |
|
68 | 68 | |
69 | - $this->f = fopen($filename, $mode); |
|
69 | + $this->f = fopen($filename, $mode); |
|
70 | 70 | |
71 | - return $this->f != false; |
|
71 | + return $this->f != false; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Close the internal file pointer |
76 | 76 | */ |
77 | 77 | public function close() { |
78 | - return fclose($this->f) != false; |
|
78 | + return fclose($this->f) != false; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | * @throws \Exception |
87 | 87 | */ |
88 | 88 | public function setFile($fp) { |
89 | - if (!is_resource($fp)) { |
|
90 | - throw new \Exception('$fp is not a valid resource'); |
|
91 | - } |
|
89 | + if (!is_resource($fp)) { |
|
90 | + throw new \Exception('$fp is not a valid resource'); |
|
91 | + } |
|
92 | 92 | |
93 | - $this->f = $fp; |
|
93 | + $this->f = $fp; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | * @return resource the temporary file pointer resource |
102 | 102 | */ |
103 | 103 | public static function getTempFile($allow_memory = true) { |
104 | - $f = null; |
|
104 | + $f = null; |
|
105 | 105 | |
106 | - if ($allow_memory) { |
|
107 | - $f = fopen("php://temp", "rb+"); |
|
108 | - } |
|
109 | - else { |
|
110 | - $f = fopen(tempnam(sys_get_temp_dir(), "fnt"), "rb+"); |
|
111 | - } |
|
106 | + if ($allow_memory) { |
|
107 | + $f = fopen("php://temp", "rb+"); |
|
108 | + } |
|
109 | + else { |
|
110 | + $f = fopen(tempnam(sys_get_temp_dir(), "fnt"), "rb+"); |
|
111 | + } |
|
112 | 112 | |
113 | - return $f; |
|
113 | + return $f; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return bool True if the $offset position exists in the file |
122 | 122 | */ |
123 | 123 | public function seek($offset) { |
124 | - return fseek($this->f, $offset, SEEK_SET) == 0; |
|
124 | + return fseek($this->f, $offset, SEEK_SET) == 0; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | * @return int The current position |
131 | 131 | */ |
132 | 132 | public function pos() { |
133 | - return ftell($this->f); |
|
133 | + return ftell($this->f); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | public function skip($n) { |
137 | - fseek($this->f, $n, SEEK_CUR); |
|
137 | + fseek($this->f, $n, SEEK_CUR); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -143,176 +143,176 @@ discard block |
||
143 | 143 | * @return string |
144 | 144 | */ |
145 | 145 | public function read($n) { |
146 | - if ($n < 1) { |
|
147 | - return ""; |
|
148 | - } |
|
146 | + if ($n < 1) { |
|
147 | + return ""; |
|
148 | + } |
|
149 | 149 | |
150 | - return (string) fread($this->f, $n); |
|
150 | + return (string) fread($this->f, $n); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | public function write($data, $length = null) { |
154 | - if ($data === null || $data === "" || $data === false) { |
|
155 | - return 0; |
|
156 | - } |
|
154 | + if ($data === null || $data === "" || $data === false) { |
|
155 | + return 0; |
|
156 | + } |
|
157 | 157 | |
158 | - return fwrite($this->f, $data, $length); |
|
158 | + return fwrite($this->f, $data, $length); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | public function readUInt8() { |
162 | - return ord($this->read(1)); |
|
162 | + return ord($this->read(1)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | public function readUInt8Many($count) { |
166 | - return array_values(unpack("C*", $this->read($count))); |
|
166 | + return array_values(unpack("C*", $this->read($count))); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | public function writeUInt8($data) { |
170 | - return $this->write(chr($data), 1); |
|
170 | + return $this->write(chr($data), 1); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | public function readInt8() { |
174 | - $v = $this->readUInt8(); |
|
174 | + $v = $this->readUInt8(); |
|
175 | 175 | |
176 | - if ($v >= 0x80) { |
|
177 | - $v -= 0x100; |
|
178 | - } |
|
176 | + if ($v >= 0x80) { |
|
177 | + $v -= 0x100; |
|
178 | + } |
|
179 | 179 | |
180 | - return $v; |
|
180 | + return $v; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | public function readInt8Many($count) { |
184 | - return array_values(unpack("c*", $this->read($count))); |
|
184 | + return array_values(unpack("c*", $this->read($count))); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | public function writeInt8($data) { |
188 | - if ($data < 0) { |
|
189 | - $data += 0x100; |
|
190 | - } |
|
188 | + if ($data < 0) { |
|
189 | + $data += 0x100; |
|
190 | + } |
|
191 | 191 | |
192 | - return $this->writeUInt8($data); |
|
192 | + return $this->writeUInt8($data); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | public function readUInt16() { |
196 | - $a = unpack("nn", $this->read(2)); |
|
196 | + $a = unpack("nn", $this->read(2)); |
|
197 | 197 | |
198 | - return $a["n"]; |
|
198 | + return $a["n"]; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | public function readUInt16Many($count) { |
202 | - return array_values(unpack("n*", $this->read($count * 2))); |
|
202 | + return array_values(unpack("n*", $this->read($count * 2))); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | public function readUFWord() { |
206 | - return $this->readUInt16(); |
|
206 | + return $this->readUInt16(); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | public function writeUInt16($data) { |
210 | - return $this->write(pack("n", $data), 2); |
|
210 | + return $this->write(pack("n", $data), 2); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | public function writeUFWord($data) { |
214 | - return $this->writeUInt16($data); |
|
214 | + return $this->writeUInt16($data); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | public function readInt16() { |
218 | - $a = unpack("nn", $this->read(2)); |
|
219 | - $v = $a["n"]; |
|
218 | + $a = unpack("nn", $this->read(2)); |
|
219 | + $v = $a["n"]; |
|
220 | 220 | |
221 | - if ($v >= 0x8000) { |
|
222 | - $v -= 0x10000; |
|
223 | - } |
|
221 | + if ($v >= 0x8000) { |
|
222 | + $v -= 0x10000; |
|
223 | + } |
|
224 | 224 | |
225 | - return $v; |
|
225 | + return $v; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | public function readInt16Many($count) { |
229 | - $vals = array_values(unpack("n*", $this->read($count * 2))); |
|
230 | - foreach ($vals as &$v) { |
|
231 | - if ($v >= 0x8000) { |
|
232 | - $v -= 0x10000; |
|
233 | - } |
|
234 | - } |
|
229 | + $vals = array_values(unpack("n*", $this->read($count * 2))); |
|
230 | + foreach ($vals as &$v) { |
|
231 | + if ($v >= 0x8000) { |
|
232 | + $v -= 0x10000; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | |
236 | - return $vals; |
|
236 | + return $vals; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | public function readFWord() { |
240 | - return $this->readInt16(); |
|
240 | + return $this->readInt16(); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | public function writeInt16($data) { |
244 | - if ($data < 0) { |
|
245 | - $data += 0x10000; |
|
246 | - } |
|
244 | + if ($data < 0) { |
|
245 | + $data += 0x10000; |
|
246 | + } |
|
247 | 247 | |
248 | - return $this->writeUInt16($data); |
|
248 | + return $this->writeUInt16($data); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | public function writeFWord($data) { |
252 | - return $this->writeInt16($data); |
|
252 | + return $this->writeInt16($data); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | public function readUInt32() { |
256 | - $a = unpack("NN", $this->read(4)); |
|
256 | + $a = unpack("NN", $this->read(4)); |
|
257 | 257 | |
258 | - return $a["N"]; |
|
258 | + return $a["N"]; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | public function writeUInt32($data) { |
262 | - return $this->write(pack("N", $data), 4); |
|
262 | + return $this->write(pack("N", $data), 4); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | public function readFixed() { |
266 | - $d = $this->readInt16(); |
|
267 | - $d2 = $this->readUInt16(); |
|
266 | + $d = $this->readInt16(); |
|
267 | + $d2 = $this->readUInt16(); |
|
268 | 268 | |
269 | - return round($d + $d2 / 0x10000, 4); |
|
269 | + return round($d + $d2 / 0x10000, 4); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | public function writeFixed($data) { |
273 | - $left = floor($data); |
|
274 | - $right = ($data - $left) * 0x10000; |
|
273 | + $left = floor($data); |
|
274 | + $right = ($data - $left) * 0x10000; |
|
275 | 275 | |
276 | - return $this->writeInt16($left) + $this->writeUInt16($right); |
|
276 | + return $this->writeInt16($left) + $this->writeUInt16($right); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | public function readLongDateTime() { |
280 | - $this->readUInt32(); // ignored |
|
281 | - $date = $this->readUInt32() - 2082844800; |
|
280 | + $this->readUInt32(); // ignored |
|
281 | + $date = $this->readUInt32() - 2082844800; |
|
282 | 282 | |
283 | - # PHP_INT_MIN isn't defined in PHP < 7.0 |
|
284 | - $php_int_min = defined("PHP_INT_MIN") ? PHP_INT_MIN : ~PHP_INT_MAX; |
|
283 | + # PHP_INT_MIN isn't defined in PHP < 7.0 |
|
284 | + $php_int_min = defined("PHP_INT_MIN") ? PHP_INT_MIN : ~PHP_INT_MAX; |
|
285 | 285 | |
286 | - if (is_string($date) || $date > PHP_INT_MAX || $date < $php_int_min) { |
|
287 | - $date = 0; |
|
288 | - } |
|
286 | + if (is_string($date) || $date > PHP_INT_MAX || $date < $php_int_min) { |
|
287 | + $date = 0; |
|
288 | + } |
|
289 | 289 | |
290 | - return date("Y-m-d H:i:s", $date); |
|
290 | + return date("Y-m-d H:i:s", $date); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | public function writeLongDateTime($data) { |
294 | - $date = strtotime($data); |
|
295 | - $date += 2082844800; |
|
294 | + $date = strtotime($data); |
|
295 | + $date += 2082844800; |
|
296 | 296 | |
297 | - return $this->writeUInt32(0) + $this->writeUInt32($date); |
|
297 | + return $this->writeUInt32(0) + $this->writeUInt32($date); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | public function unpack($def) { |
301 | - $d = array(); |
|
302 | - foreach ($def as $name => $type) { |
|
303 | - $d[$name] = $this->r($type); |
|
304 | - } |
|
301 | + $d = array(); |
|
302 | + foreach ($def as $name => $type) { |
|
303 | + $d[$name] = $this->r($type); |
|
304 | + } |
|
305 | 305 | |
306 | - return $d; |
|
306 | + return $d; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | public function pack($def, $data) { |
310 | - $bytes = 0; |
|
311 | - foreach ($def as $name => $type) { |
|
312 | - $bytes += $this->w($type, $data[$name]); |
|
313 | - } |
|
310 | + $bytes = 0; |
|
311 | + foreach ($def as $name => $type) { |
|
312 | + $bytes += $this->w($type, $data[$name]); |
|
313 | + } |
|
314 | 314 | |
315 | - return $bytes; |
|
315 | + return $bytes; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -323,61 +323,61 @@ discard block |
||
323 | 323 | * @return mixed The data that was read |
324 | 324 | */ |
325 | 325 | public function r($type) { |
326 | - switch ($type) { |
|
327 | - case self::uint8: |
|
328 | - return $this->readUInt8(); |
|
329 | - case self::int8: |
|
330 | - return $this->readInt8(); |
|
331 | - case self::uint16: |
|
332 | - return $this->readUInt16(); |
|
333 | - case self::int16: |
|
334 | - return $this->readInt16(); |
|
335 | - case self::uint32: |
|
336 | - return $this->readUInt32(); |
|
337 | - case self::int32: |
|
338 | - return $this->readUInt32(); |
|
339 | - case self::shortFrac: |
|
340 | - return $this->readFixed(); |
|
341 | - case self::Fixed: |
|
342 | - return $this->readFixed(); |
|
343 | - case self::FWord: |
|
344 | - return $this->readInt16(); |
|
345 | - case self::uFWord: |
|
346 | - return $this->readUInt16(); |
|
347 | - case self::F2Dot14: |
|
348 | - return $this->readInt16(); |
|
349 | - case self::longDateTime: |
|
350 | - return $this->readLongDateTime(); |
|
351 | - case self::char: |
|
352 | - return $this->read(1); |
|
353 | - default: |
|
354 | - if (is_array($type)) { |
|
355 | - if ($type[0] == self::char) { |
|
356 | - return $this->read($type[1]); |
|
357 | - } |
|
358 | - if ($type[0] == self::uint16) { |
|
359 | - return $this->readUInt16Many($type[1]); |
|
360 | - } |
|
361 | - if ($type[0] == self::int16) { |
|
362 | - return $this->readInt16Many($type[1]); |
|
363 | - } |
|
364 | - if ($type[0] == self::uint8) { |
|
365 | - return $this->readUInt8Many($type[1]); |
|
366 | - } |
|
367 | - if ($type[0] == self::int8) { |
|
368 | - return $this->readInt8Many($type[1]); |
|
369 | - } |
|
370 | - |
|
371 | - $ret = array(); |
|
372 | - for ($i = 0; $i < $type[1]; $i++) { |
|
373 | - $ret[] = $this->r($type[0]); |
|
374 | - } |
|
375 | - |
|
376 | - return $ret; |
|
377 | - } |
|
378 | - |
|
379 | - return null; |
|
380 | - } |
|
326 | + switch ($type) { |
|
327 | + case self::uint8: |
|
328 | + return $this->readUInt8(); |
|
329 | + case self::int8: |
|
330 | + return $this->readInt8(); |
|
331 | + case self::uint16: |
|
332 | + return $this->readUInt16(); |
|
333 | + case self::int16: |
|
334 | + return $this->readInt16(); |
|
335 | + case self::uint32: |
|
336 | + return $this->readUInt32(); |
|
337 | + case self::int32: |
|
338 | + return $this->readUInt32(); |
|
339 | + case self::shortFrac: |
|
340 | + return $this->readFixed(); |
|
341 | + case self::Fixed: |
|
342 | + return $this->readFixed(); |
|
343 | + case self::FWord: |
|
344 | + return $this->readInt16(); |
|
345 | + case self::uFWord: |
|
346 | + return $this->readUInt16(); |
|
347 | + case self::F2Dot14: |
|
348 | + return $this->readInt16(); |
|
349 | + case self::longDateTime: |
|
350 | + return $this->readLongDateTime(); |
|
351 | + case self::char: |
|
352 | + return $this->read(1); |
|
353 | + default: |
|
354 | + if (is_array($type)) { |
|
355 | + if ($type[0] == self::char) { |
|
356 | + return $this->read($type[1]); |
|
357 | + } |
|
358 | + if ($type[0] == self::uint16) { |
|
359 | + return $this->readUInt16Many($type[1]); |
|
360 | + } |
|
361 | + if ($type[0] == self::int16) { |
|
362 | + return $this->readInt16Many($type[1]); |
|
363 | + } |
|
364 | + if ($type[0] == self::uint8) { |
|
365 | + return $this->readUInt8Many($type[1]); |
|
366 | + } |
|
367 | + if ($type[0] == self::int8) { |
|
368 | + return $this->readInt8Many($type[1]); |
|
369 | + } |
|
370 | + |
|
371 | + $ret = array(); |
|
372 | + for ($i = 0; $i < $type[1]; $i++) { |
|
373 | + $ret[] = $this->r($type[0]); |
|
374 | + } |
|
375 | + |
|
376 | + return $ret; |
|
377 | + } |
|
378 | + |
|
379 | + return null; |
|
380 | + } |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -389,51 +389,51 @@ discard block |
||
389 | 389 | * @return int The number of bytes read |
390 | 390 | */ |
391 | 391 | public function w($type, $data) { |
392 | - switch ($type) { |
|
393 | - case self::uint8: |
|
394 | - return $this->writeUInt8($data); |
|
395 | - case self::int8: |
|
396 | - return $this->writeInt8($data); |
|
397 | - case self::uint16: |
|
398 | - return $this->writeUInt16($data); |
|
399 | - case self::int16: |
|
400 | - return $this->writeInt16($data); |
|
401 | - case self::uint32: |
|
402 | - return $this->writeUInt32($data); |
|
403 | - case self::int32: |
|
404 | - return $this->writeUInt32($data); |
|
405 | - case self::shortFrac: |
|
406 | - return $this->writeFixed($data); |
|
407 | - case self::Fixed: |
|
408 | - return $this->writeFixed($data); |
|
409 | - case self::FWord: |
|
410 | - return $this->writeInt16($data); |
|
411 | - case self::uFWord: |
|
412 | - return $this->writeUInt16($data); |
|
413 | - case self::F2Dot14: |
|
414 | - return $this->writeInt16($data); |
|
415 | - case self::longDateTime: |
|
416 | - return $this->writeLongDateTime($data); |
|
417 | - case self::char: |
|
418 | - return $this->write($data, 1); |
|
419 | - default: |
|
420 | - if (is_array($type)) { |
|
421 | - if ($type[0] == self::char) { |
|
422 | - return $this->write($data, $type[1]); |
|
423 | - } |
|
424 | - |
|
425 | - $ret = 0; |
|
426 | - for ($i = 0; $i < $type[1]; $i++) { |
|
427 | - if (isset($data[$i])) { |
|
428 | - $ret += $this->w($type[0], $data[$i]); |
|
429 | - } |
|
430 | - } |
|
431 | - |
|
432 | - return $ret; |
|
433 | - } |
|
434 | - |
|
435 | - return null; |
|
436 | - } |
|
392 | + switch ($type) { |
|
393 | + case self::uint8: |
|
394 | + return $this->writeUInt8($data); |
|
395 | + case self::int8: |
|
396 | + return $this->writeInt8($data); |
|
397 | + case self::uint16: |
|
398 | + return $this->writeUInt16($data); |
|
399 | + case self::int16: |
|
400 | + return $this->writeInt16($data); |
|
401 | + case self::uint32: |
|
402 | + return $this->writeUInt32($data); |
|
403 | + case self::int32: |
|
404 | + return $this->writeUInt32($data); |
|
405 | + case self::shortFrac: |
|
406 | + return $this->writeFixed($data); |
|
407 | + case self::Fixed: |
|
408 | + return $this->writeFixed($data); |
|
409 | + case self::FWord: |
|
410 | + return $this->writeInt16($data); |
|
411 | + case self::uFWord: |
|
412 | + return $this->writeUInt16($data); |
|
413 | + case self::F2Dot14: |
|
414 | + return $this->writeInt16($data); |
|
415 | + case self::longDateTime: |
|
416 | + return $this->writeLongDateTime($data); |
|
417 | + case self::char: |
|
418 | + return $this->write($data, 1); |
|
419 | + default: |
|
420 | + if (is_array($type)) { |
|
421 | + if ($type[0] == self::char) { |
|
422 | + return $this->write($data, $type[1]); |
|
423 | + } |
|
424 | + |
|
425 | + $ret = 0; |
|
426 | + for ($i = 0; $i < $type[1]; $i++) { |
|
427 | + if (isset($data[$i])) { |
|
428 | + $ret += $this->w($type[0], $data[$i]); |
|
429 | + } |
|
430 | + } |
|
431 | + |
|
432 | + return $ret; |
|
433 | + } |
|
434 | + |
|
435 | + return null; |
|
436 | + } |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -444,6 +444,6 @@ discard block |
||
444 | 444 | * @return string The string |
445 | 445 | */ |
446 | 446 | public function convertUInt32ToStr($uint32) { |
447 | - return chr(($uint32 >> 24) & 0xFF) . chr(($uint32 >> 16) & 0xFF) . chr(($uint32 >> 8) & 0xFF) . chr($uint32 & 0xFF); |
|
447 | + return chr(($uint32 >> 24) & 0xFF) . chr(($uint32 >> 16) & 0xFF) . chr(($uint32 >> 8) & 0xFF) . chr($uint32 & 0xFF); |
|
448 | 448 | } |
449 | 449 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return bool |
63 | 63 | */ |
64 | 64 | public function open($filename, $mode = self::modeRead) { |
65 | - if (!in_array($mode, array(self::modeRead, self::modeWrite, self::modeReadWrite))) { |
|
65 | + if ( ! in_array($mode, array(self::modeRead, self::modeWrite, self::modeReadWrite))) { |
|
66 | 66 | throw new \Exception("Unknown file open mode"); |
67 | 67 | } |
68 | 68 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @throws \Exception |
87 | 87 | */ |
88 | 88 | public function setFile($fp) { |
89 | - if (!is_resource($fp)) { |
|
89 | + if ( ! is_resource($fp)) { |
|
90 | 90 | throw new \Exception('$fp is not a valid resource'); |
91 | 91 | } |
92 | 92 | |
@@ -444,6 +444,6 @@ discard block |
||
444 | 444 | * @return string The string |
445 | 445 | */ |
446 | 446 | public function convertUInt32ToStr($uint32) { |
447 | - return chr(($uint32 >> 24) & 0xFF) . chr(($uint32 >> 16) & 0xFF) . chr(($uint32 >> 8) & 0xFF) . chr($uint32 & 0xFF); |
|
447 | + return chr(($uint32 >> 24) & 0xFF).chr(($uint32 >> 16) & 0xFF).chr(($uint32 >> 8) & 0xFF).chr($uint32 & 0xFF); |
|
448 | 448 | } |
449 | 449 | } |
@@ -105,8 +105,7 @@ |
||
105 | 105 | |
106 | 106 | if ($allow_memory) { |
107 | 107 | $f = fopen("php://temp", "rb+"); |
108 | - } |
|
109 | - else { |
|
108 | + } else { |
|
110 | 109 | $f = fopen(tempnam(sys_get_temp_dir(), "fnt"), "rb+"); |
111 | 110 | } |
112 | 111 |
@@ -15,17 +15,17 @@ |
||
15 | 15 | */ |
16 | 16 | class Header extends \FontLib\Header { |
17 | 17 | protected $def = array( |
18 | - "format" => self::uint32, |
|
19 | - "numTables" => self::uint16, |
|
20 | - "searchRange" => self::uint16, |
|
21 | - "entrySelector" => self::uint16, |
|
22 | - "rangeShift" => self::uint16, |
|
18 | + "format" => self::uint32, |
|
19 | + "numTables" => self::uint16, |
|
20 | + "searchRange" => self::uint16, |
|
21 | + "entrySelector" => self::uint16, |
|
22 | + "rangeShift" => self::uint16, |
|
23 | 23 | ); |
24 | 24 | |
25 | 25 | public function parse() { |
26 | - parent::parse(); |
|
26 | + parent::parse(); |
|
27 | 27 | |
28 | - $format = $this->data["format"]; |
|
29 | - $this->data["formatText"] = $this->convertUInt32ToStr($format); |
|
28 | + $format = $this->data["format"]; |
|
29 | + $this->data["formatText"] = $this->convertUInt32ToStr($format); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -32,18 +32,18 @@ discard block |
||
32 | 32 | protected $numFonts; |
33 | 33 | |
34 | 34 | function parse() { |
35 | - if (isset($this->numFonts)) { |
|
36 | - return; |
|
37 | - } |
|
35 | + if (isset($this->numFonts)) { |
|
36 | + return; |
|
37 | + } |
|
38 | 38 | |
39 | - $this->read(4); // tag name |
|
39 | + $this->read(4); // tag name |
|
40 | 40 | |
41 | - $this->version = $this->readFixed(); |
|
42 | - $this->numFonts = $this->readUInt32(); |
|
41 | + $this->version = $this->readFixed(); |
|
42 | + $this->numFonts = $this->readUInt32(); |
|
43 | 43 | |
44 | - for ($i = 0; $i < $this->numFonts; $i++) { |
|
45 | - $this->collectionOffsets[] = $this->readUInt32(); |
|
46 | - } |
|
44 | + for ($i = 0; $i < $this->numFonts; $i++) { |
|
45 | + $this->collectionOffsets[] = $this->readUInt32(); |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -53,48 +53,48 @@ discard block |
||
53 | 53 | * @return File |
54 | 54 | */ |
55 | 55 | function getFont($fontId) { |
56 | - $this->parse(); |
|
56 | + $this->parse(); |
|
57 | 57 | |
58 | - if (!isset($this->collectionOffsets[$fontId])) { |
|
59 | - throw new OutOfBoundsException(); |
|
60 | - } |
|
58 | + if (!isset($this->collectionOffsets[$fontId])) { |
|
59 | + throw new OutOfBoundsException(); |
|
60 | + } |
|
61 | 61 | |
62 | - if (isset($this->collection[$fontId])) { |
|
63 | - return $this->collection[$fontId]; |
|
64 | - } |
|
62 | + if (isset($this->collection[$fontId])) { |
|
63 | + return $this->collection[$fontId]; |
|
64 | + } |
|
65 | 65 | |
66 | - $font = new File(); |
|
67 | - $font->f = $this->f; |
|
68 | - $font->setTableOffset($this->collectionOffsets[$fontId]); |
|
66 | + $font = new File(); |
|
67 | + $font->f = $this->f; |
|
68 | + $font->setTableOffset($this->collectionOffsets[$fontId]); |
|
69 | 69 | |
70 | - return $this->collection[$fontId] = $font; |
|
70 | + return $this->collection[$fontId] = $font; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | function current() { |
74 | - return $this->getFont($this->position); |
|
74 | + return $this->getFont($this->position); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | function key() { |
78 | - return $this->position; |
|
78 | + return $this->position; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | function next() { |
82 | - return ++$this->position; |
|
82 | + return ++$this->position; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | function rewind() { |
86 | - $this->position = 0; |
|
86 | + $this->position = 0; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | function valid() { |
90 | - $this->parse(); |
|
90 | + $this->parse(); |
|
91 | 91 | |
92 | - return isset($this->collectionOffsets[$this->position]); |
|
92 | + return isset($this->collectionOffsets[$this->position]); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | function count() { |
96 | - $this->parse(); |
|
96 | + $this->parse(); |
|
97 | 97 | |
98 | - return $this->numFonts; |
|
98 | + return $this->numFonts; |
|
99 | 99 | } |
100 | 100 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | function getFont($fontId) { |
56 | 56 | $this->parse(); |
57 | 57 | |
58 | - if (!isset($this->collectionOffsets[$fontId])) { |
|
58 | + if ( ! isset($this->collectionOffsets[$fontId])) { |
|
59 | 59 | throw new OutOfBoundsException(); |
60 | 60 | } |
61 | 61 |
@@ -17,17 +17,17 @@ |
||
17 | 17 | */ |
18 | 18 | class TableDirectoryEntry extends DirectoryEntry { |
19 | 19 | function __construct(File $font) { |
20 | - parent::__construct($font); |
|
20 | + parent::__construct($font); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | function parse() { |
24 | - parent::parse(); |
|
24 | + parent::parse(); |
|
25 | 25 | |
26 | - $font = $this->font; |
|
27 | - $this->checksum = $font->readUInt32(); |
|
28 | - $this->offset = $font->readUInt32(); |
|
29 | - $this->length = $font->readUInt32(); |
|
30 | - $this->entryLength += 12; |
|
26 | + $font = $this->font; |
|
27 | + $this->checksum = $font->readUInt32(); |
|
28 | + $this->offset = $font->readUInt32(); |
|
29 | + $this->length = $font->readUInt32(); |
|
30 | + $this->entryLength += 12; |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 |