X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fphenx%2Fphp-font-lib%2Fsrc%2FFontLib%2FTable%2FType%2Fglyf.php;fp=vendor%2Fphenx%2Fphp-font-lib%2Fsrc%2FFontLib%2FTable%2FType%2Fglyf.php;h=1fbec3fd512033ce80b3fd78263d070538b31c79;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/vendor/phenx/php-font-lib/src/FontLib/Table/Type/glyf.php b/vendor/phenx/php-font-lib/src/FontLib/Table/Type/glyf.php new file mode 100644 index 000000000..1fbec3fd5 --- /dev/null +++ b/vendor/phenx/php-font-lib/src/FontLib/Table/Type/glyf.php @@ -0,0 +1,154 @@ + + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License + */ + +namespace FontLib\Table\Type; + +use FontLib\Table\Table; +use FontLib\Glyph\Outline; +use FontLib\Glyph\OutlineSimple; + +/** + * `glyf` font table. + * + * @package php-font-lib + * @property Outline[] $data + */ +class glyf extends Table { + protected function _parse() { + $font = $this->getFont(); + $offset = $font->pos(); + + $loca = $font->getData("loca"); + $real_loca = array_slice($loca, 0, -1); // Not the last dummy loca entry + + $data = array(); + + foreach ($real_loca as $gid => $location) { + $_offset = $offset + $loca[$gid]; + $_size = $loca[$gid + 1] - $loca[$gid]; + $data[$gid] = Outline::init($this, $_offset, $_size, $font); + } + + $this->data = $data; + } + + public function getGlyphIDs($gids = array()) { + $glyphIDs = array(); + + foreach ($gids as $_gid) { + $_glyph = $this->data[$_gid]; + $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); + } + + return array_unique(array_merge($gids, $glyphIDs)); + } + + public function toHTML() { + $max = 160; + $font = $this->getFont(); + + $head = $font->getData("head"); + $head_json = json_encode($head); + + $os2 = $font->getData("OS/2"); + $os2_json = json_encode($os2); + + $hmtx = $font->getData("hmtx"); + $hmtx_json = json_encode($hmtx); + + $names = $font->getData("post", "names"); + $glyphIndexArray = array_flip($font->getUnicodeCharMap()); + + $width = (abs($head["xMin"]) + $head["xMax"]); + $height = (abs($head["yMin"]) + $head["yMax"]); + + $ratio = 1; + if ($width > $max || $height > $max) { + $ratio = max($width, $height) / $max; + $width = round($width / $ratio); + $height = round($height / $ratio); + } + + $n = 500; + + $s = "

" . "Only the first $n simple glyphs are shown (" . count($this->data) . " total) +
Simple glyph
+
Composite glyph
+ Zoom: +

+ "; + + foreach ($this->data as $g => $glyph) { + if ($n-- <= 0) { + break; + } + + $glyph->parseData(); + + $shape = array( + "SVGContours" => $glyph->getSVGContours(), + "xMin" => $glyph->xMin, + "yMin" => $glyph->yMin, + "xMax" => $glyph->xMax, + "yMax" => $glyph->yMax, + ); + $shape_json = json_encode($shape); + + $type = ($glyph instanceof OutlineSimple ? "simple" : "composite"); + $char = isset($glyphIndexArray[$g]) ? $glyphIndexArray[$g] : 0; + $name = isset($names[$g]) ? $names[$g] : sprintf("uni%04x", $char); + $char = $char ? "&#{$glyphIndexArray[$g]};" : ""; + + $s .= "
+ $g + $char + $name + "; + + if ($type == "composite") { + foreach ($glyph->getGlyphIDs() as $_id) { + $s .= "$_id "; + } + } + + $s .= "
+ +
+ "; + } + + return $s; + } + + + protected function _encode() { + $font = $this->getFont(); + $subset = $font->getSubset(); + $data = $this->data; + + $loca = array(); + + $length = 0; + foreach ($subset as $gid) { + $loca[] = $length; + $length += $data[$gid]->encode(); + } + + $loca[] = $length; // dummy loca + $font->getTableObject("loca")->data = $loca; + + return $length; + } +} \ No newline at end of file