Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Mar 25, 2024
1 parent 9cd9925 commit db27eb4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.1
2.2.2
2 changes: 1 addition & 1 deletion src/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/OutFont.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ 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');
}
}

$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"
Expand Down
26 changes: 14 additions & 12 deletions src/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@
* @phpstan-type TTextSplit array{
* 'pos': int,
* 'ord': int,
* 'wordwidth': float,
* 'spaces': int,
* 'septype': string,
* 'wordwidth': float,
* 'totwidth': float,
* 'totspacewidth': float,
* }
*
* @phpstan-type TTextDims array{
* 'chars': int,
* 'spaces': int,
* 'words': int,
* 'totwidth': float,
* 'totspacewidth': float,
* 'words': int,
* 'split': array<int, TTextSplit>,
* }
*
Expand Down Expand Up @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -368,30 +369,31 @@ 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))),
];
if ($words > 0) {
$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,
];
}
Expand Down
5 changes: 3 additions & 2 deletions test/StackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit db27eb4

Please sign in to comment.