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