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