Debian Codegraph @

vendor/dompdf/php-font-lib/src/FontLib/WOFF/File.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\WOFF;
9
10 use FontLib\Table\DirectoryEntry;
11
12 /**
13 * WOFF font file.
14 *
15 * @package php-font-lib
16 *
17 * @property TableDirectoryEntry[] $directory
18 */
19 class File extends \FontLib\TrueType\File {
20 function parseHeader() {
21 if (!empty($this->header)) {
22 return;
23 }
24
25 $this->header = new Header($this);
26 $this->header->parse();
27 }
28
29 public function load($file) {
30 parent::load($file);
31
32 $this->parseTableEntries();
33 $dataOffset = $this->pos() + count($this->directory) * 20;
34
35 $fw = $this->getTempFile(false);
36 $fr = $this->f;
37
38 $this->f = $fw;
39 $offset = $this->header->encode();
40
41 foreach ($this->directory as $entry) {
42 // Read ...
43 $this->f = $fr;
44 $this->seek($entry->offset);
45 $data = $this->read($entry->length);
46
47 if ($entry->length < $entry->origLength) {
48 $data = (string) gzuncompress($data);
49 }
50
51 // Prepare data ...
52 $length = mb_strlen($data, '8bit');
53 $entry->length = $entry->origLength = $length;
54 $entry->offset = $dataOffset;
55
56 // Write ...
57 $this->f = $fw;
58
59 // Woff Entry
60 $this->seek($offset);
61 $offset += $this->write($entry->tag, 4); // tag
62 $offset += $this->writeUInt32($dataOffset); // offset
63 $offset += $this->writeUInt32($length); // length
64 $offset += $this->writeUInt32($length); // origLength
65 $offset += $this->writeUInt32(DirectoryEntry::computeChecksum($data)); // checksum
66
67 // Data
68 $this->seek($dataOffset);
69 $dataOffset += $this->write($data, $length);
70 }
71
72 $this->f = $fw;
73 $this->seek(0);
74
75 // Need to re-parse this, don't know why
76 $this->header = null;
77 $this->directory = array();
78 $this->parseTableEntries();
79 }
80 }