Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Loca
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Pdf\Build\Font\TrueType\Table;
16
17/**
18 * LOCA table class
19 *
20 * @category   Pop
21 * @package    Pop\Pdf
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    6.0.0
26 */
27class Loca extends AbstractTable
28{
29
30    /**
31     * Font table properties
32     * @var array
33     */
34    protected array $properties = [
35        'offsets' => []
36    ];
37
38    /**
39     * Constructor
40     *
41     * Instantiate a TTF 'loca' table object.
42     *
43     * @param  \Pop\Pdf\Build\Font\TrueType $font
44     */
45    public function __construct(\Pop\Pdf\Build\Font\TrueType $font)
46    {
47        $bytePos    = $font->tableInfo['loca']->offset;
48        $format     = ($font->header->indexToLocFormat == 1) ? 'N' : 'n';
49        $byteLength = ($font->header->indexToLocFormat == 1) ? 4 : 2;
50        $multiplier = ($font->header->indexToLocFormat == 1) ? 1 : 2;
51
52        $count      = $font->numberOfGlyphs + 1;
53        $totalBytes = $count * $byteLength;
54        $values     = array_values(unpack($format . '*', $font->read($bytePos, $totalBytes)));
55
56        for ($i = 0; $i < $count; $i++) {
57            $this->properties['offsets'][$i] = $values[$i] * $multiplier;
58        }
59    }
60
61}