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
8 namespace FontLib\Table;
10 use FontLib\TrueType\File;
12 use FontLib\BinaryStream;
15 * Generic Font table directory entry.
17 * @package php-font-lib
19 class DirectoryEntry extends BinaryStream {
28 protected $font_table;
30 public $entryLength = 4;
39 static function computeChecksum($data) {
44 $data = str_pad($data, $len + (4 - $mod), "\0");
52 for ($i = 0; $i < $len; $i += 4) {
53 $hi += (ord($data[$i]) << 8) + ord($data[$i + 1]);
54 $lo += (ord($data[$i + 2]) << 8) + ord($data[$i + 3]);
60 return ($hi << 8) + $lo;
63 function __construct(File $font) {
69 $this->tag = $this->font->read(4);
72 function open($filename, $mode = self::modeRead) {
76 function setTable(Table $font_table) {
77 $this->font_table = $font_table;
80 function encode($entry_offset) {
81 Font::d("\n==== $this->tag ====");
82 //Font::d("Entry offset = $entry_offset");
84 $data = $this->font_table;
87 $table_offset = $font->pos();
88 $this->offset = $table_offset;
89 $table_length = $data->encode();
91 $font->seek($table_offset);
92 $table_data = $font->read($table_length);
94 $font->seek($entry_offset);
96 $font->write($this->tag, 4);
97 $font->writeUInt32(self::computeChecksum($table_data));
98 $font->writeUInt32($table_offset);
99 $font->writeUInt32($table_length);
101 Font::d("Bytes written = $table_length");
103 $font->seek($table_offset + $table_length);
113 function startRead() {
114 $this->font->seek($this->offset);
121 function startWrite() {
122 $this->font->seek($this->offset);
125 function endWrite() {