Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.92% |
47 / 49 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Glyf | |
95.92% |
47 / 49 |
|
0.00% |
0 / 1 |
10 | |
0.00% |
0 / 1 |
__construct | |
95.92% |
47 / 49 |
|
0.00% |
0 / 1 |
10 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Pdf\Build\Font\TrueType\Table; |
15 | |
16 | /** |
17 | * GLYF table class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Pdf |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 5.0.0 |
25 | */ |
26 | class Glyf extends AbstractTable |
27 | { |
28 | |
29 | /** |
30 | * Font table properties |
31 | * @var array |
32 | */ |
33 | protected array $properties = [ |
34 | 'glyphs' => [], |
35 | 'glyphWidths' => [] |
36 | ]; |
37 | |
38 | /** |
39 | * Constructor |
40 | * |
41 | * Instantiate a TTF 'glyf' table object. |
42 | * |
43 | * @param \Pop\Pdf\Build\Font\TrueType $font |
44 | */ |
45 | public function __construct(\Pop\Pdf\Build\Font\TrueType $font) |
46 | { |
47 | $locaLength = count($font->tables['loca']->offsets); |
48 | $j = 0; |
49 | |
50 | foreach ($font->tables['loca']->offsets as $offset) { |
51 | $bytePos = $font->tableInfo['glyf']->offset + $offset; |
52 | $ary = unpack( |
53 | 'nnumberOfContours/' . |
54 | 'nxMin/' . |
55 | 'nyMin/' . |
56 | 'nxMax/' . |
57 | 'nyMax', $font->read($bytePos, 10) |
58 | ); |
59 | $ary = $font->shiftToSigned($ary); |
60 | $ary['xMin'] = $font->toEmSpace($ary['xMin']); |
61 | $ary['yMin'] = $font->toEmSpace($ary['yMin']); |
62 | $ary['xMax'] = $font->toEmSpace($ary['xMax']); |
63 | $ary['yMax'] = $font->toEmSpace($ary['yMax']); |
64 | $ary['width'] = $ary['xMin'] + $ary['xMax']; |
65 | $this->properties['glyphWidths'][] = $ary['width']; |
66 | |
67 | $bytePos += 10; |
68 | $ary['endPtsOfContours'] = []; |
69 | $ary['instructionLength'] = null; |
70 | $ary['instructions'] = null; |
71 | $ary['flags'] = null; |
72 | |
73 | // The simple and composite glyph descriptions may not be necessary. |
74 | // If simple glyph. |
75 | if ($ary['numberOfContours'] > 0) { |
76 | for ($i = 0; $i < $ary['numberOfContours']; $i++) { |
77 | $ar = unpack('nendPt', $font->read($bytePos, 2)); |
78 | $ary['endPtsOfContours'][$i] = $ar['endPt']; |
79 | $bytePos += 2; |
80 | } |
81 | $ar = unpack('ninstructionLength', $font->read($bytePos, 2)); |
82 | $ary['instructionLength'] = $ar['instructionLength']; |
83 | $bytePos += 2; |
84 | if ($ary['instructionLength'] > 0) { |
85 | for ($i = 0; $i < $ary['instructionLength']; $i++) { |
86 | $byte = $font->read($bytePos, 1); |
87 | if (strlen($byte) != 0) { |
88 | $ar = unpack('Cinstruction', $byte); |
89 | $ary['instructions'][$i] = $ar['instruction']; |
90 | $bytePos++; |
91 | } else { |
92 | $ary['instructions'][$i] = null; |
93 | } |
94 | } |
95 | } |
96 | $bytePos++; |
97 | $byte = $font->read($bytePos, 1); |
98 | if (strlen($byte) != 0) { |
99 | $ar = unpack('Cflags', $byte); |
100 | $ary['flags'] = $ar['flags']; |
101 | } else { |
102 | $ary['flags'] = 0; |
103 | } |
104 | if ($j < ($locaLength - 1)) { |
105 | $this->properties['glyphs'][] = $ary; |
106 | } |
107 | // Stopped here. Still need to get the x & y coordinates of the simple glyph. |
108 | // Else, if composite glyph. |
109 | } else { |
110 | if ($j < ($locaLength - 1)) { |
111 | // Composite glyph goes here. |
112 | } |
113 | } |
114 | $j++; |
115 | } |
116 | } |
117 | |
118 | } |