| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package php-font-lib |
| 4 |
* @link https://github.com/dompdf/php-font-lib |
| 5 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 6 |
* @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $ |
| 7 |
*/ |
| 8 |
namespace FontLib\Glyph; |
| 9 |
|
| 10 |
use FontLib\Table\Type\glyf; |
| 11 |
use FontLib\TrueType\File; |
| 12 |
use FontLib\BinaryStream; |
| 13 |
|
| 14 |
/** |
| 15 |
* `glyf` font table. |
| 16 |
* |
| 17 |
* @package php-font-lib |
| 18 |
*/ |
| 19 |
class Outline extends BinaryStream { |
| 20 |
/** |
| 21 |
* @var \FontLib\Table\Type\glyf |
| 22 |
*/ |
| 23 |
protected $table; |
| 24 |
|
| 25 |
protected $offset; |
| 26 |
protected $size; |
| 27 |
|
| 28 |
// Data |
| 29 |
public $numberOfContours; |
| 30 |
public $xMin; |
| 31 |
public $yMin; |
| 32 |
public $xMax; |
| 33 |
public $yMax; |
| 34 |
|
| 35 |
/** |
| 36 |
* @var string|null |
| 37 |
*/ |
| 38 |
public $raw; |
| 39 |
|
| 40 |
/** |
| 41 |
* @param glyf $table |
| 42 |
* @param $offset |
| 43 |
* @param $size |
| 44 |
* |
| 45 |
* @return Outline |
| 46 |
*/ |
| 47 |
static function init(glyf $table, $offset, $size, BinaryStream $font) { |
| 48 |
$font->seek($offset); |
| 49 |
|
| 50 |
if ($size === 0 || $font->readInt16() > -1) { |
| 51 |
/** @var OutlineSimple $glyph */ |
| 52 |
$glyph = new OutlineSimple($table, $offset, $size); |
| 53 |
} |
| 54 |
else { |
| 55 |
/** @var OutlineComposite $glyph */ |
| 56 |
$glyph = new OutlineComposite($table, $offset, $size); |
| 57 |
} |
| 58 |
|
| 59 |
$glyph->parse($font); |
| 60 |
|
| 61 |
return $glyph; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @return File |
| 66 |
*/ |
| 67 |
function getFont() { |
| 68 |
return $this->table->getFont(); |
| 69 |
} |
| 70 |
|
| 71 |
function __construct(glyf $table, $offset = null, $size = null) { |
| 72 |
$this->table = $table; |
| 73 |
$this->offset = $offset; |
| 74 |
$this->size = $size; |
| 75 |
} |
| 76 |
|
| 77 |
function parse(BinaryStream $font) { |
| 78 |
$font->seek($this->offset); |
| 79 |
|
| 80 |
$this->raw = $font->read($this->size); |
| 81 |
} |
| 82 |
|
| 83 |
function parseData() { |
| 84 |
$font = $this->getFont(); |
| 85 |
$font->seek($this->offset); |
| 86 |
|
| 87 |
$this->numberOfContours = $font->readInt16(); |
| 88 |
$this->xMin = $font->readFWord(); |
| 89 |
$this->yMin = $font->readFWord(); |
| 90 |
$this->xMax = $font->readFWord(); |
| 91 |
$this->yMax = $font->readFWord(); |
| 92 |
} |
| 93 |
|
| 94 |
function encode() { |
| 95 |
$font = $this->getFont(); |
| 96 |
|
| 97 |
return $font->write($this->raw, mb_strlen((string) $this->raw, '8bit')); |
| 98 |
} |
| 99 |
|
| 100 |
function getSVGContours() { |
| 101 |
// Inherit |
| 102 |
} |
| 103 |
|
| 104 |
function getGlyphIDs() { |
| 105 |
return array(); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
|