From 57a911021679624d2b00e95a1ca1ff949c7f2ff6 Mon Sep 17 00:00:00 2001 From: ren1244 Date: Sat, 14 Jan 2023 21:06:26 +0800 Subject: [PATCH 1/2] Fix composite glyph --- src/FontLib/Glyph/OutlineComposite.php | 11 ++++++++++ src/FontLib/Table/Type/cvt.php | 27 +++++++++++++++++++++++ src/FontLib/Table/Type/fpgm.php | 27 +++++++++++++++++++++++ src/FontLib/Table/Type/prep.php | 30 ++++++++++++++++++++++++++ src/FontLib/TrueType/File.php | 9 +++++++- 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/FontLib/Table/Type/cvt.php create mode 100644 src/FontLib/Table/Type/fpgm.php create mode 100644 src/FontLib/Table/Type/prep.php diff --git a/src/FontLib/Glyph/OutlineComposite.php b/src/FontLib/Glyph/OutlineComposite.php index 8ab0d2c..8cd1793 100644 --- a/src/FontLib/Glyph/OutlineComposite.php +++ b/src/FontLib/Glyph/OutlineComposite.php @@ -129,6 +129,11 @@ function parseData() { $this->components[] = $component; } while ($flags & self::MORE_COMPONENTS); + if ($flags & self::WE_HAVE_INSTRUCTIONS) { + $numInstr = $font->readUInt16(); + $instr = $font->read($numInstr); + $this->components[count($this->components) - 1]->instructions = pack('n', $numInstr) . $instr; + } } function encode() { @@ -171,6 +176,8 @@ function encode() { if ($_i < count($this->components) - 1) { $flags |= self::MORE_COMPONENTS; + } elseif($_component->instructions !== null) { + $flags |= self::WE_HAVE_INSTRUCTIONS; } $size += $font->writeUInt16($flags); @@ -214,6 +221,10 @@ function encode() { } } + if($_component->instructions !== null) { + $size += $font->write($_component->instructions, strlen($_component->instructions)); + } + return $size; } diff --git a/src/FontLib/Table/Type/cvt.php b/src/FontLib/Table/Type/cvt.php new file mode 100644 index 0000000..cec9ee4 --- /dev/null +++ b/src/FontLib/Table/Type/cvt.php @@ -0,0 +1,27 @@ + + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License + */ + +namespace FontLib\Table\Type; +use FontLib\Table\Table; + +/** + * `cvt ` font table. + * + * @package php-font-lib + */ +class cvt extends Table { + private $rawData; + protected function _parse() { + $font = $this->getFont(); + $font->seek($this->entry->offset); + $this->rawData = $font->read($this->entry->length); + } + function _encode() { + return $this->getFont()->write($this->rawData, $this->entry->length); + } +} \ No newline at end of file diff --git a/src/FontLib/Table/Type/fpgm.php b/src/FontLib/Table/Type/fpgm.php new file mode 100644 index 0000000..3c37c18 --- /dev/null +++ b/src/FontLib/Table/Type/fpgm.php @@ -0,0 +1,27 @@ + + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License + */ + +namespace FontLib\Table\Type; +use FontLib\Table\Table; + +/** + * `fpgm` font table. + * + * @package php-font-lib + */ +class fpgm extends Table { + private $rawData; + protected function _parse() { + $font = $this->getFont(); + $font->seek($this->entry->offset); + $this->rawData = $font->read($this->entry->length); + } + function _encode() { + return $this->getFont()->write($this->rawData, $this->entry->length); + } +} \ No newline at end of file diff --git a/src/FontLib/Table/Type/prep.php b/src/FontLib/Table/Type/prep.php new file mode 100644 index 0000000..c82c17d --- /dev/null +++ b/src/FontLib/Table/Type/prep.php @@ -0,0 +1,30 @@ + + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License + */ + +namespace FontLib\Table\Type; + +use FontLib\Table\Table; + +/** + * `prep` font table. + * + * @package php-font-lib + */ +class prep extends Table +{ + private $rawData; + protected function _parse() { + $font = $this->getFont(); + $font->seek($this->entry->offset); + $this->rawData = $font->read($this->entry->length); + } + function _encode() { + return $this->getFont()->write($this->rawData, $this->entry->length); + } +} diff --git a/src/FontLib/TrueType/File.php b/src/FontLib/TrueType/File.php index 3594479..df4c8e2 100644 --- a/src/FontLib/TrueType/File.php +++ b/src/FontLib/TrueType/File.php @@ -218,12 +218,12 @@ function getSubset() { function encode($tags = array()) { if (!self::$raw) { $tags = array_merge(array("head", "hhea", "cmap", "hmtx", "maxp", "glyf", "loca", "name", "post"), $tags); + $optionalTags = array("cvt ", "fpgm", "prep"); } else { $tags = array_keys($this->directory); } - $num_tables = count($tags); $n = 16; // @todo Font::d("Tables : " . implode(", ", $tags)); @@ -238,6 +238,13 @@ function encode($tags = array()) { $entries[$tag] = $this->directory[$tag]; } + foreach ($optionalTags as $tag) { + if (isset($this->directory[$tag])) { + $entries[$tag] = $this->directory[$tag]; + } + } + + $num_tables = count($entries); $this->header->data["numTables"] = $num_tables; $this->header->encode(); From 13b2be83eac0809e8aa47ffc744cc3051160d960 Mon Sep 17 00:00:00 2001 From: ren1244 Date: Sat, 4 Nov 2023 13:43:35 +0800 Subject: [PATCH 2/2] Fixing review feedback --- src/FontLib/TrueType/File.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/FontLib/TrueType/File.php b/src/FontLib/TrueType/File.php index df4c8e2..84c1277 100644 --- a/src/FontLib/TrueType/File.php +++ b/src/FontLib/TrueType/File.php @@ -217,8 +217,7 @@ function getSubset() { function encode($tags = array()) { if (!self::$raw) { - $tags = array_merge(array("head", "hhea", "cmap", "hmtx", "maxp", "glyf", "loca", "name", "post"), $tags); - $optionalTags = array("cvt ", "fpgm", "prep"); + $tags = array_merge(array("head", "hhea", "cmap", "hmtx", "maxp", "glyf", "loca", "name", "post", "cvt ", "fpgm", "prep"), $tags); } else { $tags = array_keys($this->directory); @@ -238,11 +237,6 @@ function encode($tags = array()) { $entries[$tag] = $this->directory[$tag]; } - foreach ($optionalTags as $tag) { - if (isset($this->directory[$tag])) { - $entries[$tag] = $this->directory[$tag]; - } - } $num_tables = count($entries);