Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Head
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
1
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 * HEAD 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 Head extends AbstractTable
28{
29
30    /**
31     * Font table properties
32     * @var array
33     */
34    protected array $properties = [];
35
36    /**
37     * Constructor
38     *
39     * Instantiate a TTF 'head' table object.
40     *
41     * @param  \Pop\Pdf\Build\Font\TrueType $font
42     */
43    public function __construct(\Pop\Pdf\Build\Font\TrueType $font)
44    {
45        $bytePos = $font->tableInfo['head']->offset;
46
47        $tableVersionNumberBytes = $font->read($bytePos, 4);
48        $tableVersionNumber      = $font->readFixed(16, 16, $tableVersionNumberBytes);
49
50        $bytePos += 4;
51
52        $fontRevisionBytes = $font->read($bytePos, 4);
53        $fontRevision      = $font->readFixed(16, 16, $fontRevisionBytes);
54
55        $versionArray = [
56            'tableVersionNumber' => $tableVersionNumber,
57            'fontRevision'       => $fontRevision
58        ];
59
60        $bytePos += 4;
61
62        $headerArray = unpack(
63            'NcheckSumAdjustment/' .
64            'NmagicNumber/' .
65            'nflags/' .
66            'nunitsPerEm', $font->read($bytePos, 12)
67        );
68
69        $bytePos += 28;
70        $bBox = unpack(
71            'nxMin/' .
72            'nyMin/' .
73            'nxMax/' .
74            'nyMax', $font->read($bytePos, 8)
75        );
76        $bBox = $font->shiftToSigned($bBox);
77
78        $bytePos += 14;
79        $indexToLocFormat = unpack('nindexToLocFormat', $font->read($bytePos, 2));
80        $headerArray['indexToLocFormat'] = $font->shiftToSigned($indexToLocFormat['indexToLocFormat']);
81
82        $this->properties = array_merge($versionArray, $headerArray, $bBox);
83    }
84
85}