Skip to content

Commit eeb48eb

Browse files
authored
Merge pull request #38 from Setasign/development
Prohibited the creation of subsets of unused font instances
2 parents ac9552e + 1541bde commit eeb48eb

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Modules/Font.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class Font
4646
*/
4747
protected $fonts = [];
4848

49+
/**
50+
* All font objects that were ever used by a `setFont()` call.
51+
*
52+
* @var array
53+
*/
54+
protected $usedFonts = [];
55+
4956

5057
/**
5158
* The document module, to get the document instance.
@@ -147,6 +154,8 @@ public function set($family, $style, $size)
147154
}
148155
$this->fontState->fontSize = $size;
149156
}
157+
158+
$this->usedFonts[$fontKey] = $this->fonts[$fontKey];
150159
}
151160

152161
/**
@@ -235,4 +244,12 @@ public function getFonts()
235244
{
236245
return $this->fonts;
237246
}
247+
248+
/**
249+
* @return array
250+
*/
251+
public function getUsedFonts()
252+
{
253+
return $this->usedFonts;
254+
}
238255
}

src/SetaFpdf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public function Output($dest = '', $name = '')
460460
$name = 'doc.pdf';
461461
}
462462

463-
foreach ($this->manager->getFont()->getFonts() as $font) {
463+
foreach ($this->manager->getFont()->getUsedFonts() as $font) {
464464
if ($font instanceof Subset) {
465465
$font->createSubset();
466466
}

tests/functional/SetaFpdf/OutputTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function testCompressedObjectStreams()
5656
$pdf->SetFont('DejaVuSans', 'B', 20);
5757
$pdf->Cell(0, 10, 'TESTING FONT SUBSETTING');
5858

59+
$pdf->AddFont('DejaVuSans', '', __DIR__ . '/../../../assets/fonts/DejaVu/DejaVuSans.ttf');
60+
5961
$document = $pdf->getManager()->getDocument()->get();
6062
$compressor = new ObjectStreamCompressor($document);
6163
$compressor->register();

0 commit comments

Comments
 (0)