woocommerce-pos
/
vendor_prefixed
/
dompdf
/
php-font-lib
/
src
/
FontLib
/
Glyph
/
OutlineComposite.php
OutlineComposite.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/dompdf/php-font-lib/src/FontLib/Glyph/OutlineComposite.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package php-font-lib |
| 5 | * @link https://github.com/dompdf/php-font-lib |
| 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 | namespace WCPOS\Vendor\FontLib\Glyph; |
| 10 | |
| 11 | /** |
| 12 | * Composite glyph outline |
| 13 | * |
| 14 | * @package php-font-lib |
| 15 | */ |
| 16 | class OutlineComposite extends Outline |
| 17 | { |
| 18 | const ARG_1_AND_2_ARE_WORDS = 0x1; |
| 19 | const ARGS_ARE_XY_VALUES = 0x2; |
| 20 | const ROUND_XY_TO_GRID = 0x4; |
| 21 | const WE_HAVE_A_SCALE = 0x8; |
| 22 | const MORE_COMPONENTS = 0x20; |
| 23 | const WE_HAVE_AN_X_AND_Y_SCALE = 0x40; |
| 24 | const WE_HAVE_A_TWO_BY_TWO = 0x80; |
| 25 | const WE_HAVE_INSTRUCTIONS = 0x100; |
| 26 | const USE_MY_METRICS = 0x200; |
| 27 | const OVERLAP_COMPOUND = 0x400; |
| 28 | /** |
| 29 | * @var OutlineComponent[] |
| 30 | */ |
| 31 | public $components = array(); |
| 32 | function getGlyphIDs() |
| 33 | { |
| 34 | if (empty($this->components)) { |
| 35 | $this->parseData(); |
| 36 | } |
| 37 | $glyphIDs = array(); |
| 38 | foreach ($this->components as $_component) { |
| 39 | $glyphIDs[] = $_component->glyphIndex; |
| 40 | $_glyph = $this->table->data[$_component->glyphIndex]; |
| 41 | if ($_glyph !== $this) { |
| 42 | $glyphIDs = \array_merge($glyphIDs, $_glyph->getGlyphIDs()); |
| 43 | } |
| 44 | } |
| 45 | return $glyphIDs; |
| 46 | } |
| 47 | /*function parse() { |
| 48 | //$this->parseData(); |
| 49 | }*/ |
| 50 | function parseData() |
| 51 | { |
| 52 | parent::parseData(); |
| 53 | $font = $this->getFont(); |
| 54 | do { |
| 55 | $flags = $font->readUInt16(); |
| 56 | $glyphIndex = $font->readUInt16(); |
| 57 | $a = 1.0; |
| 58 | $b = 0.0; |
| 59 | $c = 0.0; |
| 60 | $d = 1.0; |
| 61 | $e = 0.0; |
| 62 | $f = 0.0; |
| 63 | $point_compound = null; |
| 64 | $point_component = null; |
| 65 | $instructions = null; |
| 66 | if ($flags & self::ARG_1_AND_2_ARE_WORDS) { |
| 67 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
| 68 | $e = $font->readInt16(); |
| 69 | $f = $font->readInt16(); |
| 70 | } else { |
| 71 | $point_compound = $font->readUInt16(); |
| 72 | $point_component = $font->readUInt16(); |
| 73 | } |
| 74 | } else { |
| 75 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
| 76 | $e = $font->readInt8(); |
| 77 | $f = $font->readInt8(); |
| 78 | } else { |
| 79 | $point_compound = $font->readUInt8(); |
| 80 | $point_component = $font->readUInt8(); |
| 81 | } |
| 82 | } |
| 83 | if ($flags & self::WE_HAVE_A_SCALE) { |
| 84 | $a = $d = $font->readInt16(); |
| 85 | } elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
| 86 | $a = $font->readInt16(); |
| 87 | $d = $font->readInt16(); |
| 88 | } elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
| 89 | $a = $font->readInt16(); |
| 90 | $b = $font->readInt16(); |
| 91 | $c = $font->readInt16(); |
| 92 | $d = $font->readInt16(); |
| 93 | } |
| 94 | //if ($flags & self::WE_HAVE_INSTRUCTIONS) { |
| 95 | // |
| 96 | //} |
| 97 | $component = new OutlineComponent(); |
| 98 | $component->flags = $flags; |
| 99 | $component->glyphIndex = $glyphIndex; |
| 100 | $component->a = $a; |
| 101 | $component->b = $b; |
| 102 | $component->c = $c; |
| 103 | $component->d = $d; |
| 104 | $component->e = $e; |
| 105 | $component->f = $f; |
| 106 | $component->point_compound = $point_compound; |
| 107 | $component->point_component = $point_component; |
| 108 | $component->instructions = $instructions; |
| 109 | $this->components[] = $component; |
| 110 | } while ($flags & self::MORE_COMPONENTS); |
| 111 | if ($flags & self::WE_HAVE_INSTRUCTIONS) { |
| 112 | $numInstr = $font->readUInt16(); |
| 113 | $instr = $font->read($numInstr); |
| 114 | $this->components[\count($this->components) - 1]->instructions = \pack('n', $numInstr) . $instr; |
| 115 | } |
| 116 | } |
| 117 | function encode() |
| 118 | { |
| 119 | $font = $this->getFont(); |
| 120 | $gids = $font->getSubset(); |
| 121 | $size = $font->writeInt16(-1); |
| 122 | $size += $font->writeFWord($this->xMin); |
| 123 | $size += $font->writeFWord($this->yMin); |
| 124 | $size += $font->writeFWord($this->xMax); |
| 125 | $size += $font->writeFWord($this->yMax); |
| 126 | foreach ($this->components as $_i => $_component) { |
| 127 | $flags = 0; |
| 128 | if ($_component->point_component === null && $_component->point_compound === null) { |
| 129 | $flags |= self::ARGS_ARE_XY_VALUES; |
| 130 | if (\abs($_component->e) > 0x7f || \abs($_component->f) > 0x7f) { |
| 131 | $flags |= self::ARG_1_AND_2_ARE_WORDS; |
| 132 | } |
| 133 | } elseif ($_component->point_component > 0xff || $_component->point_compound > 0xff) { |
| 134 | $flags |= self::ARG_1_AND_2_ARE_WORDS; |
| 135 | } |
| 136 | if ($_component->b == 0 && $_component->c == 0) { |
| 137 | if ($_component->a == $_component->d) { |
| 138 | if ($_component->a != 1.0) { |
| 139 | $flags |= self::WE_HAVE_A_SCALE; |
| 140 | } |
| 141 | } else { |
| 142 | $flags |= self::WE_HAVE_AN_X_AND_Y_SCALE; |
| 143 | } |
| 144 | } else { |
| 145 | $flags |= self::WE_HAVE_A_TWO_BY_TWO; |
| 146 | } |
| 147 | if ($_i < \count($this->components) - 1) { |
| 148 | $flags |= self::MORE_COMPONENTS; |
| 149 | } elseif ($_component->instructions !== null) { |
| 150 | $flags |= self::WE_HAVE_INSTRUCTIONS; |
| 151 | } |
| 152 | $size += $font->writeUInt16($flags); |
| 153 | $new_gid = \array_search($_component->glyphIndex, $gids); |
| 154 | $size += $font->writeUInt16($new_gid); |
| 155 | if ($flags & self::ARG_1_AND_2_ARE_WORDS) { |
| 156 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
| 157 | $size += $font->writeInt16($_component->e); |
| 158 | $size += $font->writeInt16($_component->f); |
| 159 | } else { |
| 160 | $size += $font->writeUInt16($_component->point_compound); |
| 161 | $size += $font->writeUInt16($_component->point_component); |
| 162 | } |
| 163 | } else { |
| 164 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
| 165 | $size += $font->writeInt8($_component->e); |
| 166 | $size += $font->writeInt8($_component->f); |
| 167 | } else { |
| 168 | $size += $font->writeUInt8($_component->point_compound); |
| 169 | $size += $font->writeUInt8($_component->point_component); |
| 170 | } |
| 171 | } |
| 172 | if ($flags & self::WE_HAVE_A_SCALE) { |
| 173 | $size += $font->writeInt16($_component->a); |
| 174 | } elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
| 175 | $size += $font->writeInt16($_component->a); |
| 176 | $size += $font->writeInt16($_component->d); |
| 177 | } elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
| 178 | $size += $font->writeInt16($_component->a); |
| 179 | $size += $font->writeInt16($_component->b); |
| 180 | $size += $font->writeInt16($_component->c); |
| 181 | $size += $font->writeInt16($_component->d); |
| 182 | } |
| 183 | } |
| 184 | if ($_component->instructions !== null) { |
| 185 | $size += $font->write($_component->instructions, \strlen($_component->instructions)); |
| 186 | } |
| 187 | return $size; |
| 188 | } |
| 189 | public function getSVGContours() |
| 190 | { |
| 191 | $contours = array(); |
| 192 | /** @var \FontLib\Table\Type\glyf $glyph_data */ |
| 193 | $glyph_data = $this->getFont()->getTableObject("glyf"); |
| 194 | /** @var Outline[] $glyphs */ |
| 195 | $glyphs = $glyph_data->data; |
| 196 | foreach ($this->components as $component) { |
| 197 | $_glyph = $glyphs[$component->glyphIndex]; |
| 198 | if ($_glyph !== $this) { |
| 199 | $contours[] = array("contours" => $_glyph->getSVGContours(), "transform" => $component->getMatrix()); |
| 200 | } |
| 201 | } |
| 202 | return $contours; |
| 203 | } |
| 204 | } |
| 205 |