No Description

Table.php 1.8KB

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