diff --git a/src/FontLib/Font.php b/src/FontLib/Font.php index 8661288..d42ee12 100644 --- a/src/FontLib/Font.php +++ b/src/FontLib/Font.php @@ -59,7 +59,7 @@ public static function load($file) { } if ($class) { - $class = "FontLib\\$class"; + $class = __NAMESPACE__ . "\\$class"; /** @var TrueType\File $obj */ $obj = new $class; diff --git a/src/FontLib/TrueType/File.php b/src/FontLib/TrueType/File.php index f4c797a..e148f16 100644 --- a/src/FontLib/TrueType/File.php +++ b/src/FontLib/TrueType/File.php @@ -276,7 +276,7 @@ function getUnicodeCharMap() { return $glyphIndexArray; } } - + return null; } @@ -380,11 +380,6 @@ function parseHeader() { $this->header->parse(); } - function getFontType(){ - $class_parts = explode("\\", get_class($this)); - return $class_parts[1]; - } - function parseTableEntries() { $this->parseHeader(); @@ -396,9 +391,7 @@ function parseTableEntries() { return; } - - $type = $this->getFontType(); - $class = "FontLib\\$type\\TableDirectoryEntry"; + $class = __NAMESPACE__ . "\\TableDirectoryEntry"; for ($i = 0; $i < $this->header->data["numTables"]; $i++) { /** @var TableDirectoryEntry $entry */ @@ -413,20 +406,26 @@ function normalizeFUnit($value, $base = 1000) { return round($value * ($base / $this->getData("head", "unitsPerEm"))); } + private function tableClass(string $name_canon): string { + $root = __NAMESPACE__; + $root = substr($root, 0, strrpos($root, '\\')); + return $root . '\\Table\\Type\\' . $name_canon; + } + protected function readTable($tag) { $this->parseTableEntries(); if (!self::$raw) { $name_canon = preg_replace("/[^a-z0-9]/", "", strtolower($tag)); - $class = "FontLib\\Table\\Type\\$name_canon"; + $class = $this->tableClass($name_canon); if (!isset($this->directory[$tag]) || !@class_exists($class)) { return; } } else { - $class = "FontLib\\Table\\Table"; + $class = Table::class; } /** @var Table $table */