Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Name | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
7 | |
0.00% |
0 / 1 |
| __construct | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
7 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Pdf\Build\Font\TrueType\Table; |
| 15 | |
| 16 | use Pop\Pdf\Build\Font; |
| 17 | use Pop\Utils\ArrayObject as Data; |
| 18 | |
| 19 | /** |
| 20 | * NAME table class |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Pdf |
| 24 | * @author Nick Sagona, III <dev@noladev.com> |
| 25 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 5.2.2 |
| 28 | */ |
| 29 | class Name extends AbstractTable |
| 30 | { |
| 31 | |
| 32 | /** |
| 33 | * Font table properties |
| 34 | * @var array |
| 35 | */ |
| 36 | protected array $properties = []; |
| 37 | |
| 38 | /** |
| 39 | * TrueType font info names |
| 40 | * @var array |
| 41 | */ |
| 42 | protected array $names = [ |
| 43 | 0 => 'copyright', |
| 44 | 1 => 'fontFamily', |
| 45 | 2 => 'fontSubFamily', |
| 46 | 3 => 'uniqueId', |
| 47 | 4 => 'fullName', |
| 48 | 5 => 'version', |
| 49 | 6 => 'postscriptName', |
| 50 | 7 => 'trademark', |
| 51 | 8 => 'manufacturer', |
| 52 | 9 => 'designer', |
| 53 | 10 => 'description', |
| 54 | 11 => 'vendorUrl', |
| 55 | 12 => 'designerUrl', |
| 56 | 13 => 'license', |
| 57 | 14 => 'licenseUrl', |
| 58 | 16 => 'preferredFamily', |
| 59 | 17 => 'preferredSubFamily', |
| 60 | 18 => 'compatibleFull', |
| 61 | 19 => 'sampleText' |
| 62 | ]; |
| 63 | |
| 64 | /** |
| 65 | * Constructor |
| 66 | * |
| 67 | * Instantiate a TTF 'name' table object. |
| 68 | * |
| 69 | * @param Font\TrueType $font |
| 70 | */ |
| 71 | public function __construct(Font\TrueType $font) |
| 72 | { |
| 73 | $tableInfo = $font->tableInfo; |
| 74 | |
| 75 | if (!isset($tableInfo['name'])) { |
| 76 | $tableInfo['name'] = []; |
| 77 | } |
| 78 | |
| 79 | $tableInfo['name']['header'] = new Data( |
| 80 | unpack( |
| 81 | 'nformatSelector/' . |
| 82 | 'nnameRecordsCount/' . |
| 83 | 'nstorageOffset', $font->read($font->tableInfo['name']->offset, 6) |
| 84 | ) |
| 85 | ); |
| 86 | |
| 87 | $font->tableInfo = $tableInfo; |
| 88 | |
| 89 | $bytePos = $font->tableInfo['name']->offset + 6; |
| 90 | |
| 91 | for ($j = 0; $j < $font->tableInfo['name']->header->nameRecordsCount; $j++) { |
| 92 | $ttfRecord = unpack( |
| 93 | 'nplatformId/' . |
| 94 | 'nencodingId/' . |
| 95 | 'nlanguageId/' . |
| 96 | 'nnameId/' . |
| 97 | 'nlength/' . |
| 98 | 'noffset', $font->read($bytePos, 12) |
| 99 | ); |
| 100 | |
| 101 | $ttfRecordOffset = $bytePos + 12; |
| 102 | $nextBytePos = $font->tableInfo['name']->offset + $font->tableInfo['name']->header->storageOffset + $ttfRecord['offset']; |
| 103 | |
| 104 | $ttfValue = $font->read($nextBytePos, $ttfRecord['length']); |
| 105 | |
| 106 | if ($ttfRecord['platformId'] != 1) { |
| 107 | $ttfValue = @iconv('UTF-16be', 'UTF-8//TRANSLIT', $ttfValue); |
| 108 | } |
| 109 | if (($ttfValue != '') && isset($ttfRecord['nameId']) && isset($this->names[$ttfRecord['nameId']])) { |
| 110 | $this->properties[$this->names[$ttfRecord['nameId']]] = $ttfValue; |
| 111 | } |
| 112 | |
| 113 | $bytePos = $ttfRecordOffset; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | } |