diff --git a/VERSION b/VERSION index 3e3c2f1..b1b25a5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.1 +2.2.2 diff --git a/src/Load.php b/src/Load.php index 241159e..959aa49 100644 --- a/src/Load.php +++ b/src/Load.php @@ -368,7 +368,7 @@ protected function findFontDirectories(): array } $parent_font_dir = $dir->findParentDir('fonts', __DIR__); - if ($parent_font_dir !== '') { + if (($parent_font_dir !== '') && ($parent_font_dir !== '/')) { $dirs[] = $parent_font_dir; $glb = glob($parent_font_dir . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR); if ($glb !== false) { diff --git a/src/OutFont.php b/src/OutFont.php index 59824ee..81ada15 100644 --- a/src/OutFont.php +++ b/src/OutFont.php @@ -205,7 +205,7 @@ protected function getTrueTypeUnicode(array $font): string . '<<'; $cidhmap = Identity::CIDHMAP; if ($font['compress']) { - $out .= '/Filter /FlateDecode'; + $out .= ' /Filter /FlateDecode'; $cidhmap = gzcompress($cidhmap); if ($cidhmap === false) { throw new \RuntimeException('Unable to compress CIDHMAP'); @@ -213,8 +213,8 @@ protected function getTrueTypeUnicode(array $font): string } $stream = $this->enc->encryptString($cidhmap, $this->pon); // ToUnicode map for Identity-H - $out .= '/Length ' . strlen($stream) - . '>>' + $out .= ' /Length ' . strlen($stream) + . ' >>' . ' stream' . "\n" . $stream . "\n" . 'endstream' . "\n" diff --git a/src/Stack.php b/src/Stack.php index 222058c..01bef3a 100644 --- a/src/Stack.php +++ b/src/Stack.php @@ -35,8 +35,9 @@ * @phpstan-type TTextSplit array{ * 'pos': int, * 'ord': int, - * 'wordwidth': float, * 'spaces': int, + * 'septype': string, + * 'wordwidth': float, * 'totwidth': float, * 'totspacewidth': float, * } @@ -44,9 +45,9 @@ * @phpstan-type TTextDims array{ * 'chars': int, * 'spaces': int, + * 'words': int, * 'totwidth': float, * 'totspacewidth': float, - * 'words': int, * 'split': array, * } * @@ -241,7 +242,7 @@ public function getOutCurrentFont(): string public function isCurrentByteFont(): bool { $currentFontType = $this->getCurrentFontType(); - return ! (($currentFontType == 'Core') || ($currentFontType == 'TrueType') || ($currentFontType == 'Type1')); + return (($currentFontType == 'Core') || ($currentFontType == 'TrueType') || ($currentFontType == 'Type1')); } /** @@ -250,7 +251,7 @@ public function isCurrentByteFont(): bool public function isCurrentUnicodeFont(): bool { $currentFontType = $this->getCurrentFontType(); - return $currentFontType != 'TrueTypeUnicode' && $currentFontType != 'cidfont0'; + return (($currentFontType == 'TrueTypeUnicode') || ($currentFontType == 'cidfont0')); } /** @@ -354,12 +355,12 @@ public function getOrdArrDims(array $uniarr): array $totwidth = 0; // total string width $totspacewidth = 0; // total space width $words = 0; // total number of words - $spw = $this->getCharWidth(32); // width of a single space $fact = ($this->stack[$this->index]['spacing'] * $this->stack[$this->index]['stretching']); $uniarr[] = 8203; // add null at the end to ensure that the last word is processed $split = []; foreach ($uniarr as $idx => $ord) { $unitype = UnicodeType::UNI[$ord]; + $chrwidth = $this->getCharWidth($ord); // 'B' Paragraph Separator // 'S' Segment Separator // 'WS' Whitespace @@ -368,8 +369,9 @@ public function getOrdArrDims(array $uniarr): array $split[$words] = [ 'pos' => $idx, 'ord' => $ord, - 'wordwidth' => 0, 'spaces' => $spaces, + 'septype' => $unitype, + 'wordwidth' => 0, 'totwidth' => ($totwidth + ($fact * ($idx - 1))), 'totspacewidth' => ($totspacewidth + ($fact * ($spaces - 1))), ]; @@ -377,21 +379,21 @@ public function getOrdArrDims(array $uniarr): array $split[$words]['wordwidth'] = ($split[$words]['totwidth'] - $split[($words - 1)]['totwidth']); } $words++; + if ($unitype == 'WS') { + ++$spaces; + $totspacewidth += $chrwidth; + } } - if ($ord == 32) { - ++$spaces; - $totspacewidth += $spw; - } - $totwidth += $this->getCharWidth($ord); + $totwidth += $chrwidth; } $totwidth += ($fact * ($chars - 1)); $totspacewidth += ($fact * ($spaces - 1)); return [ 'chars' => $chars, 'spaces' => $spaces, + 'words' => $words, 'totwidth' => $totwidth, 'totspacewidth' => $totspacewidth, - 'words' => $words, 'split' => $split, ]; } diff --git a/test/StackTest.php b/test/StackTest.php index 422d24c..b9725f0 100644 --- a/test/StackTest.php +++ b/test/StackTest.php @@ -111,10 +111,10 @@ public function testStack(): void $this->assertEquals('Type1', $type); $ftype = $stack->isCurrentUnicodeFont(); - $this->assertTrue($ftype); + $this->assertFalse($ftype); $ftype = $stack->isCurrentByteFont(); - $this->assertFalse($ftype); + $this->assertTrue($ftype); $uniarr = [65, 173, 300, 32, 65, 173, 300, 32, 65, 173, 300]; $widths = $stack->getOrdArrDims($uniarr); @@ -126,6 +126,7 @@ public function testStack(): void $this->assertEquals(11, $widths['split'][5]['pos']); $this->assertEquals(8203, $widths['split'][5]['ord']); + $this->assertEquals('BN', $widths['split'][5]['septype']); $this->bcAssertEqualsWithDelta(4.92, $widths['split'][5]['wordwidth'], 0.0001); $this->assertEquals(2, $widths['split'][5]['spaces']); $this->bcAssertEqualsWithDelta(60.9384, $widths['split'][5]['totwidth'], 0.0001);