Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
82.93% |
34 / 41 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Os2 | |
82.93% |
34 / 41 |
|
0.00% |
0 / 1 |
12.72 | |
0.00% |
0 / 1 |
__construct | |
82.93% |
34 / 41 |
|
0.00% |
0 / 1 |
12.72 |
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 | use Pop\Pdf\Build\Font; |
17 | use Pop\Utils\ArrayObject as Data; |
18 | use Pop\Utils\Exception; |
19 | |
20 | /** |
21 | * OS/2 table class |
22 | * |
23 | * @category Pop |
24 | * @package Pop\Pdf |
25 | * @author Nick Sagona, III <dev@nolainteractive.com> |
26 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
27 | * @license http://www.popphp.org/license New BSD License |
28 | * @version 5.0.0 |
29 | */ |
30 | class Os2 extends AbstractTable |
31 | { |
32 | |
33 | /** |
34 | * Font table properties |
35 | * @var array |
36 | */ |
37 | protected array $properties = [ |
38 | 'capHeight' => 0, |
39 | 'embeddable' => true, |
40 | 'flags' => null |
41 | ]; |
42 | |
43 | /** |
44 | * Constructor |
45 | * |
46 | * Instantiate a OTF 'OS/2' table object. |
47 | * |
48 | * @param Font\TrueType $font |
49 | * @throws Exception |
50 | */ |
51 | public function __construct(Font\TrueType $font) |
52 | { |
53 | $this->properties['flags'] = new Data([ |
54 | 'isFixedPitch' => false, |
55 | 'isSerif' => false, |
56 | 'isSymbolic' => false, |
57 | 'isScript' => false, |
58 | 'isNonSymbolic' => false, |
59 | 'isItalic' => false, |
60 | 'isAllCap' => false, |
61 | 'isSmallCap' => false, |
62 | 'isForceBold' => false |
63 | ]); |
64 | |
65 | $bytePos = $font->tableInfo['OS/2']->offset + 8; |
66 | $ary = unpack("nfsType", $font->read($bytePos, 2)); |
67 | $this->properties['embeddable'] = (($ary['fsType'] != 2) && (($ary['fsType'] & 0x200) == 0)); |
68 | |
69 | $bytePos = $font->tableInfo['OS/2']->offset + 30; |
70 | $ary = unpack("nfamily_class", $font->read($bytePos, 2)); |
71 | $familyClass = ($font->shiftToSigned($ary['family_class']) >> 8); |
72 | |
73 | if ((($familyClass >= 1) && ($familyClass <= 5)) || ($familyClass == 7)) { |
74 | $this->properties['flags']['isSerif'] = true; |
75 | } else if ($familyClass == 8) { |
76 | $this->properties['flags']['isSerif'] = false; |
77 | } |
78 | if ($familyClass == 10) { |
79 | $this->properties['flags']['isScript'] = true; |
80 | } |
81 | if ($familyClass == 12) { |
82 | $this->properties['flags']['isSymbolic'] = true; |
83 | $this->properties['flags']['isNonSymbolic'] = false; |
84 | } else { |
85 | $this->properties['flags']['isSymbolic'] = false; |
86 | $this->properties['flags']['isNonSymbolic'] = true; |
87 | } |
88 | |
89 | // Unicode bit-sniffing may not be necessary. |
90 | $bytePos += 3; |
91 | $ary = unpack( |
92 | 'NunicodeRange1/' . |
93 | 'NunicodeRange2/' . |
94 | 'NunicodeRange3/' . |
95 | 'NunicodeRange4', $font->read($bytePos, 16) |
96 | ); |
97 | |
98 | if (($ary['unicodeRange1'] == 1) && ($ary['unicodeRange2'] == 0) && ($ary['unicodeRange3'] == 0) && ($ary['unicodeRange4'] == 0)) { |
99 | $this->properties['flags']['isSymbolic'] = false; |
100 | $this->properties['flags']['isNonSymbolic'] = true; |
101 | } |
102 | |
103 | $bytePos = $font->tableInfo['OS/2']->offset + 76; |
104 | $ary = unpack("ncap/", $font->read($bytePos, 2)); |
105 | $this->properties['flags']['capHeight'] = $font->toEmSpace($font->shiftToSigned($ary['cap'])); |
106 | } |
107 | |
108 | } |