Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Font
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
9
100.00% covered (success)
100.00%
1 / 1
 toPdf
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
9
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Font;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfObject;
11use Phpdftk\Pdf\Core\PdfReference;
12
13/**
14 * Base PDF Font object (/Type /Font).
15 */
16class Font extends PdfObject
17{
18    public const PDF_TYPE = 'Font';
19
20    public ?PdfName $subtype = null;             // /Subtype
21    public ?PdfName $baseFont = null;            // /BaseFont
22    public ?int $firstChar = null;               // /FirstChar
23    public ?int $lastChar = null;                // /LastChar
24    public ?PdfArray $widths = null;             // /Widths
25    public ?PdfReference $fontDescriptor = null; // /FontDescriptor
26    public PdfReference|PdfName|null $encoding = null; // /Encoding
27    public ?PdfReference $toUnicode = null;      // /ToUnicode
28
29    public function toPdf(): string
30    {
31        $dict = new PdfDictionary();
32        $dict->set('Type', new PdfName(self::PDF_TYPE));
33
34        if ($this->subtype !== null) {
35            $dict->set('Subtype', $this->subtype);
36        }
37        if ($this->baseFont !== null) {
38            $dict->set('BaseFont', $this->baseFont);
39        }
40        if ($this->firstChar !== null) {
41            $dict->set('FirstChar', $this->firstChar);
42        }
43        if ($this->lastChar !== null) {
44            $dict->set('LastChar', $this->lastChar);
45        }
46        if ($this->widths !== null) {
47            $dict->set('Widths', $this->widths);
48        }
49        if ($this->fontDescriptor !== null) {
50            $dict->set('FontDescriptor', $this->fontDescriptor);
51        }
52        if ($this->encoding !== null) {
53            $dict->set('Encoding', $this->encoding);
54        }
55        if ($this->toUnicode !== null) {
56            $dict->set('ToUnicode', $this->toUnicode);
57        }
58
59        return $dict->toPdf();
60    }
61}