-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathTcpdfFontTest.php
More file actions
83 lines (71 loc) · 2.83 KB
/
Copy pathTcpdfFontTest.php
File metadata and controls
83 lines (71 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
declare(strict_types=1);
/**
* Font and text metrics family tests.
*
* @package com.tecnick.tcpdf
*/
require_once __DIR__ . '/TcpdfTestCase.php';
class TcpdfFontTest extends TcpdfTestCase
{
public function testFontStateAccessors(): void
{
$pdf = $this->newPdf();
$pdf->setFont('times', 'BI', 14);
$this->assertSame('times', $pdf->getFontFamily());
$this->assertSame('BI', $pdf->getFontStyle());
$this->assertSame(14.0, $pdf->getFontSizePt());
$this->assertEqualsWithDelta(14.0 / $pdf->getScaleFactor(), $pdf->getFontSize(), 0.0001);
$pdf->setFontSize(10);
$this->assertSame(10.0, $pdf->getFontSizePt());
$this->assertSame('times', $pdf->getFontFamily());
}
public function testDecorationLettersAreTracked(): void
{
$pdf = $this->newPdf();
$pdf->setFont('helvetica', 'BU', 12);
$this->assertSame('BU', $pdf->getFontStyle());
$this->assertSame('helvetica', $pdf->getFontFamily());
}
public function testStringWidthIsPlausible(): void
{
$pdf = $this->newPdf();
$pdf->setFont('helvetica', '', 12);
$width = $pdf->GetStringWidth('Hello World');
$this->assertIsFloat($width);
// 62.004 points at 12pt helvetica = 21.87 mm.
$this->assertEqualsWithDelta(21.87, $width, 0.1);
$wider = $pdf->GetStringWidth('Hello World Hello World');
$this->assertGreaterThan($width, $wider);
$widths = $pdf->GetStringWidth('abc', '', '', 0, true);
$this->assertIsArray($widths);
$this->assertCount(3, $widths);
}
public function testCharacterHelpers(): void
{
$pdf = $this->newPdf();
$pdf->setFont('helvetica', '', 12);
$this->assertSame(4, $pdf->GetNumChars('abcd'));
$this->assertSame(4, $pdf->GetNumChars('àbcd'), 'multibyte text must count codepoints');
$this->assertGreaterThan(0, $pdf->GetCharWidth('M'));
$this->assertTrue($pdf->isCharDefined(65));
$this->assertGreaterThan(0, $pdf->getFontAscent('helvetica', '', 12));
$this->assertGreaterThan(0, $pdf->getFontDescent('helvetica', '', 12));
}
public function testAddFontRegistersWithoutChangingCurrent(): void
{
$pdf = $this->newPdf();
$pdf->setFont('helvetica', '', 12);
$fontdata = $pdf->AddFont('courier');
$this->assertIsArray($fontdata);
$this->assertSame('courier', $fontdata['family'] ?? null);
$this->assertSame('helvetica', $pdf->getFontFamily(), 'AddFont must not change the current font');
}
public function testFontSubsettingFlag(): void
{
$pdf = $this->newPdf();
$this->assertTrue($pdf->getFontSubsetting(), 'legacy default is true');
$pdf->setFontSubsetting(false);
$this->assertFalse($pdf->getFontSubsetting());
}
}