Skip to content

Commit 39a670f

Browse files
Merge pull request #40 from Setasign/development
Fixed #39 usage of subset fonts in footer
2 parents eeb48eb + c5c1194 commit 39a670f

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/Modules/Document.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use setasign\SetaFpdf\Position\Converter;
1414
use setasign\SetaFpdf\SetaFpdf;
1515
use setasign\SetaFpdf\StateBuffer\StateBufferInterface;
16+
use setasign\SetaPDF2\Core\Font\TrueType\Subset;
1617

1718
class Document implements StateBufferInterface
1819
{
@@ -489,6 +490,12 @@ public function output($destination, $name, ?array $displayMode = null)
489490
\call_user_func($this->footerCallable);
490491
$this->pageBreakDisabled = false;
491492

493+
foreach ($this->manager->getFont()->getUsedFonts() as $font) {
494+
if ($font instanceof Subset) {
495+
$font->createSubset();
496+
}
497+
}
498+
492499
self::applyDisplayMode($this->document, $displayMode);
493500
$info = $this->document->getInfo();
494501
$info->setProducer('SetaFPDF ' . SetaFpdf::VERSION);

src/SetaFpdf.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,6 @@ public function Output($dest = '', $name = '')
460460
$name = 'doc.pdf';
461461
}
462462

463-
foreach ($this->manager->getFont()->getUsedFonts() as $font) {
464-
if ($font instanceof Subset) {
465-
$font->createSubset();
466-
}
467-
}
468-
469463
return $this->manager->getDocument()->output($dest, $name, $this->displayMode);
470464
}
471465

tests/visual/SetaFpdf/Special/FooterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace setasign\tests\visual\SetaFpdf\Special;
44

5+
use setasign\SetaFpdf\SetaFpdf;
56
use setasign\tests\TestProxy;
67
use setasign\tests\visual\SetaFpdf\Special\Footer\FPDFCustom;
78
use setasign\tests\visual\SetaFpdf\Special\Footer\SetaFpdfCustom;
@@ -38,4 +39,28 @@ public function testSpecialFooter()
3839

3940
$this->assertProxySame($proxy, 0.4, self::DPI);
4041
}
42+
43+
public function testFooterWithCustomFont()
44+
{
45+
$setaFpdf = new class extends SetaFpdf {
46+
public function Footer()
47+
{
48+
$this->SetY(-15);
49+
$this->Cell(0, 10, 'This is a footer');
50+
}
51+
};
52+
53+
$setaFpdf->AddPage();
54+
$setaFpdf->AddFont('DejaVuSans','', __DIR__ . '/../../../../assets/fonts/DejaVu/DejaVuSans.ttf');
55+
$setaFpdf->SetFont('DejaVuSans', '', 12);
56+
$setaFpdf->Cell(0, 10, 'Hello World');
57+
58+
$testFile = __DIR__ . '/FooterWithCustomFontActualResult.pdf';
59+
$setaFpdf->Output('F', $testFile);
60+
$this->assertPdfsEqual([
61+
__DIR__ . '/FooterWithCustomFontExpectedResult.pdf',
62+
$testFile
63+
], self::DPI, 1, false);
64+
\unlink($testFile);
65+
}
4166
}
Binary file not shown.

0 commit comments

Comments
 (0)