Bez popisu

Outline.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. use FontLib\Table\Type\glyf;
  11. use FontLib\TrueType\File;
  12. use FontLib\BinaryStream;
  13. /**
  14. * `glyf` font table.
  15. *
  16. * @package php-font-lib
  17. */
  18. class Outline extends BinaryStream {
  19. /**
  20. * @var \FontLib\Table\Type\glyf
  21. */
  22. protected $table;
  23. protected $offset;
  24. protected $size;
  25. // Data
  26. public $numberOfContours;
  27. public $xMin;
  28. public $yMin;
  29. public $xMax;
  30. public $yMax;
  31. /**
  32. * @var string|null
  33. */
  34. public $raw;
  35. /**
  36. * @param glyf $table
  37. * @param $offset
  38. * @param $size
  39. *
  40. * @return Outline
  41. */
  42. static function init(glyf $table, $offset, $size, BinaryStream $font) {
  43. $font->seek($offset);
  44. if ($font->readInt16() > -1) {
  45. /** @var OutlineSimple $glyph */
  46. $glyph = new OutlineSimple($table, $offset, $size);
  47. }
  48. else {
  49. /** @var OutlineComposite $glyph */
  50. $glyph = new OutlineComposite($table, $offset, $size);
  51. }
  52. $glyph->parse($font);
  53. return $glyph;
  54. }
  55. /**
  56. * @return File
  57. */
  58. function getFont() {
  59. return $this->table->getFont();
  60. }
  61. function __construct(glyf $table, $offset = null, $size = null) {
  62. $this->table = $table;
  63. $this->offset = $offset;
  64. $this->size = $size;
  65. }
  66. function parse(BinaryStream $font) {
  67. $font->seek($this->offset);
  68. $this->raw = $font->read($this->size);
  69. }
  70. function parseData() {
  71. $font = $this->getFont();
  72. $font->seek($this->offset);
  73. $this->numberOfContours = $font->readInt16();
  74. $this->xMin = $font->readFWord();
  75. $this->yMin = $font->readFWord();
  76. $this->xMax = $font->readFWord();
  77. $this->yMax = $font->readFWord();
  78. }
  79. function encode() {
  80. $font = $this->getFont();
  81. return $font->write($this->raw, mb_strlen((string) $this->raw, '8bit'));
  82. }
  83. function getSVGContours() {
  84. // Inherit
  85. }
  86. function getGlyphIDs() {
  87. return array();
  88. }
  89. }