330db0918761e38c74943d5e975353f3d8eb7522
[yaffs-website] / vendor / phenx / php-font-lib / src / FontLib / Glyph / Outline.php
1 <?php
2 /**
3  * @package php-font-lib
4  * @link    https://github.com/PhenX/php-font-lib
5  * @author  Fabien Ménager <fabien.menager@gmail.com>
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 FontLib\Glyph;
10
11 use FontLib\Table\Type\glyf;
12 use FontLib\TrueType\File;
13 use FontLib\BinaryStream;
14
15 /**
16  * `glyf` font table.
17  *
18  * @package php-font-lib
19  */
20 class Outline extends BinaryStream {
21   /**
22    * @var \FontLib\Table\Type\glyf
23    */
24   protected $table;
25
26   protected $offset;
27   protected $size;
28
29   // Data
30   public $numberOfContours;
31   public $xMin;
32   public $yMin;
33   public $xMax;
34   public $yMax;
35
36   public $raw;
37
38   /**
39    * @param glyf $table
40    * @param                 $offset
41    * @param                 $size
42    *
43    * @return Outline
44    */
45   static function init(glyf $table, $offset, $size, BinaryStream $font) {
46     $font->seek($offset);
47
48     if ($font->readInt16() > -1) {
49       /** @var OutlineSimple $glyph */
50       $glyph = new OutlineSimple($table, $offset, $size);
51     }
52     else {
53       /** @var OutlineComposite $glyph */
54       $glyph = new OutlineComposite($table, $offset, $size);
55     }
56
57     $glyph->parse($font);
58
59     return $glyph;
60   }
61
62   /**
63    * @return File
64    */
65   function getFont() {
66     return $this->table->getFont();
67   }
68
69   function __construct(glyf $table, $offset = null, $size = null) {
70     $this->table  = $table;
71     $this->offset = $offset;
72     $this->size   = $size;
73   }
74
75   function parse(BinaryStream $font) {
76     $font->seek($this->offset);
77
78     if (!$this->size) {
79       return;
80     }
81
82     $this->raw = $font->read($this->size);
83   }
84
85   function parseData() {
86     $font = $this->getFont();
87     $font->seek($this->offset);
88
89     $this->numberOfContours = $font->readInt16();
90     $this->xMin             = $font->readFWord();
91     $this->yMin             = $font->readFWord();
92     $this->xMax             = $font->readFWord();
93     $this->yMax             = $font->readFWord();
94   }
95
96   function encode() {
97     $font = $this->getFont();
98
99     return $font->write($this->raw, strlen($this->raw));
100   }
101
102   function getSVGContours() {
103     // Inherit
104   }
105
106   function getGlyphIDs() {
107     return array();
108   }
109 }
110