composer package updates
[openemr.git] / vendor / phenx / php-font-lib / src / FontLib / Table / Type / loca.php
blobcbc2a2004b1059b0fb676072af43a151fad45f70
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 */
9 namespace FontLib\Table\Type;
10 use FontLib\Table\Table;
12 /**
13 * `loca` font table.
15 * @package php-font-lib
17 class loca extends Table {
18 protected function _parse() {
19 $font = $this->getFont();
20 $offset = $font->pos();
22 $indexToLocFormat = $font->getData("head", "indexToLocFormat");
23 $numGlyphs = $font->getData("maxp", "numGlyphs");
25 $font->seek($offset);
27 $data = array();
29 // 2 bytes
30 if ($indexToLocFormat == 0) {
31 $d = $font->read(($numGlyphs + 1) * 2);
32 $loc = unpack("n*", $d);
34 for ($i = 0; $i <= $numGlyphs; $i++) {
35 $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] * 2 : 0;
39 // 4 bytes
40 else {
41 if ($indexToLocFormat == 1) {
42 $d = $font->read(($numGlyphs + 1) * 4);
43 $loc = unpack("N*", $d);
45 for ($i = 0; $i <= $numGlyphs; $i++) {
46 $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] : 0;
51 $this->data = $data;
54 function _encode() {
55 $font = $this->getFont();
56 $data = $this->data;
58 $indexToLocFormat = $font->getData("head", "indexToLocFormat");
59 $numGlyphs = $font->getData("maxp", "numGlyphs");
60 $length = 0;
62 // 2 bytes
63 if ($indexToLocFormat == 0) {
64 for ($i = 0; $i <= $numGlyphs; $i++) {
65 $length += $font->writeUInt16($data[$i] / 2);
69 // 4 bytes
70 else {
71 if ($indexToLocFormat == 1) {
72 for ($i = 0; $i <= $numGlyphs; $i++) {
73 $length += $font->writeUInt32($data[$i]);
78 return $length;