PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.16
Yatra – Travel Booking & Tour Operator Software v3.0.16
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / vendor / phenx / php-font-lib / src / FontLib / Glyph / OutlineComposite.php

OutlineComposite.php in Yatra – Travel Booking & Tour Operator Software 3.0.16, at vendor/phenx/php-font-lib/src/FontLib/Glyph/OutlineComposite.php

253 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package php-font-lib
4 * @link https://github.com/dompdf/php-font-lib
5 * @author Fabien Ménager <[email protected]>
6 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
7 * @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $
8 */
9
10 namespace FontLib\Glyph;
11
12 /**
13 * Composite glyph outline
14 *
15 * @package php-font-lib
16 */
17 class OutlineComposite extends Outline {
18 const ARG_1_AND_2_ARE_WORDS = 0x0001;
19 const ARGS_ARE_XY_VALUES = 0x0002;
20 const ROUND_XY_TO_GRID = 0x0004;
21 const WE_HAVE_A_SCALE = 0x0008;
22 const MORE_COMPONENTS = 0x0020;
23 const WE_HAVE_AN_X_AND_Y_SCALE = 0x0040;
24 const WE_HAVE_A_TWO_BY_TWO = 0x0080;
25 const WE_HAVE_INSTRUCTIONS = 0x0100;
26 const USE_MY_METRICS = 0x0200;
27 const OVERLAP_COMPOUND = 0x0400;
28
29 /**
30 * @var OutlineComponent[]
31 */
32 public $components = array();
33
34 function getGlyphIDs() {
35 if (empty($this->components)) {
36 $this->parseData();
37 }
38
39 $glyphIDs = array();
40 foreach ($this->components as $_component) {
41 $glyphIDs[] = $_component->glyphIndex;
42
43 $_glyph = $this->table->data[$_component->glyphIndex];
44
45 if ($_glyph !== $this) {
46 $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs());
47 }
48 }
49
50 return $glyphIDs;
51 }
52
53 /*function parse() {
54 //$this->parseData();
55 }*/
56
57 function parseData() {
58 parent::parseData();
59
60 $font = $this->getFont();
61
62 do {
63 $flags = $font->readUInt16();
64 $glyphIndex = $font->readUInt16();
65
66 $a = 1.0;
67 $b = 0.0;
68 $c = 0.0;
69 $d = 1.0;
70 $e = 0.0;
71 $f = 0.0;
72
73 $point_compound = null;
74 $point_component = null;
75
76 $instructions = null;
77
78 if ($flags & self::ARG_1_AND_2_ARE_WORDS) {
79 if ($flags & self::ARGS_ARE_XY_VALUES) {
80 $e = $font->readInt16();
81 $f = $font->readInt16();
82 }
83 else {
84 $point_compound = $font->readUInt16();
85 $point_component = $font->readUInt16();
86 }
87 }
88 else {
89 if ($flags & self::ARGS_ARE_XY_VALUES) {
90 $e = $font->readInt8();
91 $f = $font->readInt8();
92 }
93 else {
94 $point_compound = $font->readUInt8();
95 $point_component = $font->readUInt8();
96 }
97 }
98
99 if ($flags & self::WE_HAVE_A_SCALE) {
100 $a = $d = $font->readInt16();
101 }
102 elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) {
103 $a = $font->readInt16();
104 $d = $font->readInt16();
105 }
106 elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) {
107 $a = $font->readInt16();
108 $b = $font->readInt16();
109 $c = $font->readInt16();
110 $d = $font->readInt16();
111 }
112
113 //if ($flags & self::WE_HAVE_INSTRUCTIONS) {
114 //
115 //}
116
117 $component = new OutlineComponent();
118 $component->flags = $flags;
119 $component->glyphIndex = $glyphIndex;
120 $component->a = $a;
121 $component->b = $b;
122 $component->c = $c;
123 $component->d = $d;
124 $component->e = $e;
125 $component->f = $f;
126 $component->point_compound = $point_compound;
127 $component->point_component = $point_component;
128 $component->instructions = $instructions;
129
130 $this->components[] = $component;
131 } while ($flags & self::MORE_COMPONENTS);
132 if ($flags & self::WE_HAVE_INSTRUCTIONS) {
133 $numInstr = $font->readUInt16();
134 $instr = $font->read($numInstr);
135 $this->components[count($this->components) - 1]->instructions = pack('n', $numInstr) . $instr;
136 }
137 }
138
139 function encode() {
140 $font = $this->getFont();
141
142 $gids = $font->getSubset();
143
144 $size = $font->writeInt16(-1);
145 $size += $font->writeFWord($this->xMin);
146 $size += $font->writeFWord($this->yMin);
147 $size += $font->writeFWord($this->xMax);
148 $size += $font->writeFWord($this->yMax);
149
150 foreach ($this->components as $_i => $_component) {
151 $flags = 0;
152 if ($_component->point_component === null && $_component->point_compound === null) {
153 $flags |= self::ARGS_ARE_XY_VALUES;
154
155 if (abs($_component->e) > 0x7F || abs($_component->f) > 0x7F) {
156 $flags |= self::ARG_1_AND_2_ARE_WORDS;
157 }
158 }
159 elseif ($_component->point_component > 0xFF || $_component->point_compound > 0xFF) {
160 $flags |= self::ARG_1_AND_2_ARE_WORDS;
161 }
162
163 if ($_component->b == 0 && $_component->c == 0) {
164 if ($_component->a == $_component->d) {
165 if ($_component->a != 1.0) {
166 $flags |= self::WE_HAVE_A_SCALE;
167 }
168 }
169 else {
170 $flags |= self::WE_HAVE_AN_X_AND_Y_SCALE;
171 }
172 }
173 else {
174 $flags |= self::WE_HAVE_A_TWO_BY_TWO;
175 }
176
177 if ($_i < count($this->components) - 1) {
178 $flags |= self::MORE_COMPONENTS;
179 } elseif($_component->instructions !== null) {
180 $flags |= self::WE_HAVE_INSTRUCTIONS;
181 }
182
183 $size += $font->writeUInt16($flags);
184
185 $new_gid = array_search($_component->glyphIndex, $gids);
186 $size += $font->writeUInt16($new_gid);
187
188 if ($flags & self::ARG_1_AND_2_ARE_WORDS) {
189 if ($flags & self::ARGS_ARE_XY_VALUES) {
190 $size += $font->writeInt16($_component->e);
191 $size += $font->writeInt16($_component->f);
192 }
193 else {
194 $size += $font->writeUInt16($_component->point_compound);
195 $size += $font->writeUInt16($_component->point_component);
196 }
197 }
198 else {
199 if ($flags & self::ARGS_ARE_XY_VALUES) {
200 $size += $font->writeInt8($_component->e);
201 $size += $font->writeInt8($_component->f);
202 }
203 else {
204 $size += $font->writeUInt8($_component->point_compound);
205 $size += $font->writeUInt8($_component->point_component);
206 }
207 }
208
209 if ($flags & self::WE_HAVE_A_SCALE) {
210 $size += $font->writeInt16($_component->a);
211 }
212 elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) {
213 $size += $font->writeInt16($_component->a);
214 $size += $font->writeInt16($_component->d);
215 }
216 elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) {
217 $size += $font->writeInt16($_component->a);
218 $size += $font->writeInt16($_component->b);
219 $size += $font->writeInt16($_component->c);
220 $size += $font->writeInt16($_component->d);
221 }
222 }
223
224 if($_component->instructions !== null) {
225 $size += $font->write($_component->instructions, strlen($_component->instructions));
226 }
227
228 return $size;
229 }
230
231 public function getSVGContours() {
232 $contours = array();
233
234 /** @var \FontLib\Table\Type\glyf $glyph_data */
235 $glyph_data = $this->getFont()->getTableObject("glyf");
236
237 /** @var Outline[] $glyphs */
238 $glyphs = $glyph_data->data;
239
240 foreach ($this->components as $component) {
241 $_glyph = $glyphs[$component->glyphIndex];
242
243 if ($_glyph !== $this) {
244 $contours[] = array(
245 "contours" => $_glyph->getSVGContours(),
246 "transform" => $component->getMatrix(),
247 );
248 }
249 }
250
251 return $contours;
252 }
253 }