Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
51 / 51 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| FontDescriptor | |
100.00% |
51 / 51 |
|
100.00% |
2 / 2 |
24 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
50 / 50 |
|
100.00% |
1 / 1 |
23 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Font; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfNumber; |
| 11 | use Phpdftk\Pdf\Core\PdfObject; |
| 12 | use Phpdftk\Pdf\Core\PdfReference; |
| 13 | use Phpdftk\Pdf\Core\PdfString; |
| 14 | |
| 15 | /** |
| 16 | * Font Descriptor object (/Type /FontDescriptor). |
| 17 | * Describes the metrics and other attributes of a font program. |
| 18 | */ |
| 19 | class FontDescriptor extends PdfObject |
| 20 | { |
| 21 | public const PDF_TYPE = 'FontDescriptor'; |
| 22 | |
| 23 | public PdfName $fontName; // /FontName - required |
| 24 | public ?PdfString $fontFamily = null; // /FontFamily |
| 25 | public ?PdfName $fontStretch = null; // /FontStretch |
| 26 | public ?int $fontWeight = null; // /FontWeight |
| 27 | public int $flags = 0; // /Flags - required |
| 28 | public ?PdfArray $fontBBox = null; // /FontBBox |
| 29 | public float $italicAngle = 0; // /ItalicAngle - required |
| 30 | public float $ascent = 0; // /Ascent |
| 31 | public float $descent = 0; // /Descent |
| 32 | public float $leading = 0; // /Leading |
| 33 | public float $capHeight = 0; // /CapHeight |
| 34 | public float $xHeight = 0; // /XHeight |
| 35 | public float $stemV = 0; // /StemV |
| 36 | public float $stemH = 0; // /StemH |
| 37 | public float $avgWidth = 0; // /AvgWidth |
| 38 | public float $maxWidth = 0; // /MaxWidth |
| 39 | public float $missingWidth = 0; // /MissingWidth |
| 40 | public ?PdfReference $fontFile = null; // /FontFile (Type1) |
| 41 | public ?PdfReference $fontFile2 = null; // /FontFile2 (TrueType) |
| 42 | public ?PdfReference $fontFile3 = null; // /FontFile3 (other) |
| 43 | public ?PdfString $charSet = null; // /CharSet |
| 44 | public ?PdfDictionary $style = null; // /Style |
| 45 | public ?PdfString $lang = null; // /Lang |
| 46 | public ?PdfDictionary $fd = null; // /FD - glyph metric overrides |
| 47 | public ?PdfReference $cidSet = null; // /CIDSet - subset CIDFont stream |
| 48 | |
| 49 | public function __construct(PdfName $fontName) |
| 50 | { |
| 51 | $this->fontName = $fontName; |
| 52 | } |
| 53 | |
| 54 | public function toPdf(): string |
| 55 | { |
| 56 | $dict = new PdfDictionary(); |
| 57 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 58 | $dict->set('FontName', $this->fontName); |
| 59 | $dict->set('Flags', new PdfNumber($this->flags)); |
| 60 | $dict->set('ItalicAngle', new PdfNumber($this->italicAngle)); |
| 61 | |
| 62 | if ($this->fontFamily !== null) { |
| 63 | $dict->set('FontFamily', $this->fontFamily); |
| 64 | } |
| 65 | if ($this->fontStretch !== null) { |
| 66 | $dict->set('FontStretch', $this->fontStretch); |
| 67 | } |
| 68 | if ($this->fontWeight !== null) { |
| 69 | $dict->set('FontWeight', new PdfNumber($this->fontWeight)); |
| 70 | } |
| 71 | if ($this->fontBBox !== null) { |
| 72 | $dict->set('FontBBox', $this->fontBBox); |
| 73 | } |
| 74 | if ($this->ascent != 0) { |
| 75 | $dict->set('Ascent', new PdfNumber($this->ascent)); |
| 76 | } |
| 77 | if ($this->descent != 0) { |
| 78 | $dict->set('Descent', new PdfNumber($this->descent)); |
| 79 | } |
| 80 | if ($this->leading != 0) { |
| 81 | $dict->set('Leading', new PdfNumber($this->leading)); |
| 82 | } |
| 83 | if ($this->capHeight != 0) { |
| 84 | $dict->set('CapHeight', new PdfNumber($this->capHeight)); |
| 85 | } |
| 86 | if ($this->xHeight != 0) { |
| 87 | $dict->set('XHeight', new PdfNumber($this->xHeight)); |
| 88 | } |
| 89 | if ($this->stemV != 0) { |
| 90 | $dict->set('StemV', new PdfNumber($this->stemV)); |
| 91 | } |
| 92 | if ($this->stemH != 0) { |
| 93 | $dict->set('StemH', new PdfNumber($this->stemH)); |
| 94 | } |
| 95 | if ($this->avgWidth != 0) { |
| 96 | $dict->set('AvgWidth', new PdfNumber($this->avgWidth)); |
| 97 | } |
| 98 | if ($this->maxWidth != 0) { |
| 99 | $dict->set('MaxWidth', new PdfNumber($this->maxWidth)); |
| 100 | } |
| 101 | if ($this->missingWidth != 0) { |
| 102 | $dict->set('MissingWidth', new PdfNumber($this->missingWidth)); |
| 103 | } |
| 104 | if ($this->fontFile !== null) { |
| 105 | $dict->set('FontFile', $this->fontFile); |
| 106 | } |
| 107 | if ($this->fontFile2 !== null) { |
| 108 | $dict->set('FontFile2', $this->fontFile2); |
| 109 | } |
| 110 | if ($this->fontFile3 !== null) { |
| 111 | $dict->set('FontFile3', $this->fontFile3); |
| 112 | } |
| 113 | if ($this->charSet !== null) { |
| 114 | $dict->set('CharSet', $this->charSet); |
| 115 | } |
| 116 | if ($this->style !== null) { |
| 117 | $dict->set('Style', $this->style); |
| 118 | } |
| 119 | if ($this->lang !== null) { |
| 120 | $dict->set('Lang', $this->lang); |
| 121 | } |
| 122 | if ($this->fd !== null) { |
| 123 | $dict->set('FD', $this->fd); |
| 124 | } |
| 125 | if ($this->cidSet !== null) { |
| 126 | $dict->set('CIDSet', $this->cidSet); |
| 127 | } |
| 128 | |
| 129 | return $dict->toPdf(); |
| 130 | } |
| 131 | } |