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
9 namespace FontLib\WOFF
;
11 use FontLib\Table\DirectoryEntry
;
16 * @package php-font-lib
18 * @property TableDirectoryEntry[] $directory
20 class File
extends \FontLib\TrueType\File
{
21 function parseHeader() {
22 if (!empty($this->header
)) {
26 $this->header
= new Header($this);
27 $this->header
->parse();
30 public function load($file) {
33 $this->parseTableEntries();
34 $dataOffset = $this->pos() +
count($this->directory
) * 20;
36 $fw = $this->getTempFile(false);
40 $offset = $this->header
->encode();
42 foreach ($this->directory
as $entry) {
45 $this->seek($entry->offset
);
46 $data = $this->read($entry->length
);
48 if ($entry->length
< $entry->origLength
) {
49 $data = gzuncompress($data);
53 $length = strlen($data);
54 $entry->length
= $entry->origLength
= $length;
55 $entry->offset
= $dataOffset;
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
69 $this->seek($dataOffset);
70 $dataOffset +
= $this->write($data, $length);
76 // Need to re-parse this, don't know why
78 $this->directory
= array();
79 $this->parseTableEntries();