Skip to content

Commit e4eed7e

Browse files
committed
Fixed font-issue in FpdfTpl
1 parent ba671ba commit e4eed7e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/FpdfTplTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function endTemplate()
302302

303303
$fontKey = $this->FontFamily . $this->FontStyle;
304304
if ($fontKey) {
305-
$this->CurrentFont =& $this->fonts[$fontKey];
305+
$this->CurrentFont = $this->fonts[$fontKey];
306306
} else {
307307
unset($this->CurrentFont);
308308
}

tests/functional/FpdfTplTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,36 @@ public function testGroupXObjectParameter()
418418
$tplObject = $parser->getIndirectObject(6);
419419
$this->assertFalse(isset($tplObject->value->value->value['Group']));
420420
}
421+
422+
/**
423+
* In the past the CurrentFont property was stored by-reference. This was removed in FPDF 1.85 but in
424+
* FpdfTpl the property was still set by-reference, which results in duplicate font-names.
425+
*/
426+
public function testCurrentFontByReferenceIssue()
427+
{
428+
$myPdf = new class() extends FpdfTpl {
429+
public function Header()
430+
{
431+
$this->SetFont('Arial', 'B', 16);
432+
$this->Cell(0, 5, 'Test Header');
433+
}
434+
435+
function Footer()
436+
{
437+
$this->SetY(-15);
438+
$this->SetFont('Arial','I',8);
439+
$this->SetTextColor(128);
440+
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
441+
}
442+
};
443+
444+
$pdf = new $myPdf();
445+
$pdf->AddPage();
446+
$pdf->beginTemplate();
447+
$pdf->endTemplate();
448+
$pdfString = $pdf->Output('S');
449+
450+
$this->assertEquals(1, \substr_count($pdfString, '/F2 '));
451+
$this->assertEquals(1, \substr_count($pdfString, '/F1 '));
452+
}
421453
}

0 commit comments

Comments
 (0)