Debian Codegraph @

vendor/dompdf/php-font-lib/src/FontLib/Table/Table.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 namespace FontLib\Table;
8
9 use FontLib\TrueType\File;
10 use FontLib\Font;
11 use FontLib\BinaryStream;
12
13 /**
14 * Generic font table.
15 *
16 * @package php-font-lib
17 */
18 class Table extends BinaryStream {
19 /**
20 * @var DirectoryEntry
21 */
22 protected $entry;
23 protected $def = array();
24
25 public $data;
26
27 final public function __construct(DirectoryEntry $entry) {
28 $this->entry = $entry;
29 $entry->setTable($this);
30 }
31
32 /**
33 * @return File
34 */
35 public function getFont() {
36 return $this->entry->getFont();
37 }
38
39 protected function _encode() {
40 if (empty($this->data)) {
41 Font::d(" >> Table is empty");
42
43 return 0;
44 }
45
46 return $this->getFont()->pack($this->def, $this->data);
47 }
48
49 protected function _parse() {
50 $this->data = $this->getFont()->unpack($this->def);
51 }
52
53 protected function _parseRaw() {
54 $this->data = $this->getFont()->read($this->entry->length);
55 }
56
57 protected function _encodeRaw() {
58 return $this->getFont()->write($this->data, $this->entry->length);
59 }
60
61 public function toHTML() {
62 return "<pre>" . var_export($this->data, true) . "</pre>";
63 }
64
65 final public function encode() {
66 $this->entry->startWrite();
67
68 if (false && empty($this->def)) {
69 $length = $this->_encodeRaw();
70 }
71 else {
72 $length = $this->_encode();
73 }
74
75 $this->entry->endWrite();
76
77 return $length;
78 }
79
80 final public function parse() {
81 $this->entry->startRead();
82
83 if (false && empty($this->def)) {
84 $this->_parseRaw();
85 }
86 else {
87 $this->_parse();
88 }
89
90 $this->entry->endRead();
91 }
92 }