Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Hmtx | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | declare(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 | */ |
| 15 | namespace Pop\Pdf\Build\Font\TrueType\Table; |
| 16 | |
| 17 | /** |
| 18 | * HMTX 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 | */ |
| 27 | class Hmtx extends AbstractTable |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Font table properties |
| 32 | * @var array |
| 33 | */ |
| 34 | protected array $properties = [ |
| 35 | 'glyphWidths' => [] |
| 36 | ]; |
| 37 | |
| 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * Instantiate a TTF 'hmtx' 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['hmtx']->offset; |
| 48 | |
| 49 | $count = $font->numberOfHMetrics; |
| 50 | $totalBytes = $count * 4; |
| 51 | $values = array_values(unpack('n*', $font->read($bytePos, $totalBytes))); |
| 52 | |
| 53 | for ($i = 0; $i < $count; $i++) { |
| 54 | $this->properties['glyphWidths'][$i] = $font->shiftToSigned($values[$i * 2]); |
| 55 | } |
| 56 | |
| 57 | while (count($this->properties['glyphWidths']) < $font->numberOfGlyphs) { |
| 58 | $this->properties['glyphWidths'][] = end($this->properties['glyphWidths']); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | } |