Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CIDFont | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
7.06 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
87.50% |
14 / 16 |
|
0.00% |
0 / 1 |
6.07 | |||
| 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\PdfVersion; |
| 14 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 15 | |
| 16 | /** |
| 17 | * CIDFont dictionary (/Type /Font /Subtype /CIDFontType0 or /CIDFontType2). |
| 18 | * Used as the descendant of a Type0 composite font. |
| 19 | */ |
| 20 | #[RequiresPdfVersion(PdfVersion::V1_2)] |
| 21 | class CIDFont extends PdfObject |
| 22 | { |
| 23 | public const PDF_TYPE = 'Font'; |
| 24 | |
| 25 | public PdfName $subtype; // /Subtype /CIDFontType0 or /CIDFontType2 |
| 26 | public PdfName $baseFont; // /BaseFont |
| 27 | public CIDSystemInfo $cidSystemInfo; // /CIDSystemInfo |
| 28 | public ?PdfReference $fontDescriptor = null; // /FontDescriptor |
| 29 | public ?int $dw = null; // /DW default width |
| 30 | public ?PdfArray $w = null; // /W widths |
| 31 | public ?PdfArray $dw2 = null; // /DW2 |
| 32 | public ?PdfArray $w2 = null; // /W2 |
| 33 | |
| 34 | public function __construct( |
| 35 | string $subtype, |
| 36 | string $baseFontName, |
| 37 | CIDSystemInfo $cidSystemInfo, |
| 38 | ) { |
| 39 | $this->subtype = new PdfName($subtype); |
| 40 | $this->baseFont = new PdfName($baseFontName); |
| 41 | $this->cidSystemInfo = $cidSystemInfo; |
| 42 | } |
| 43 | |
| 44 | public function toPdf(): string |
| 45 | { |
| 46 | $dict = new PdfDictionary(); |
| 47 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 48 | $dict->set('Subtype', $this->subtype); |
| 49 | $dict->set('BaseFont', $this->baseFont); |
| 50 | $dict->set('CIDSystemInfo', $this->cidSystemInfo); |
| 51 | |
| 52 | if ($this->fontDescriptor !== null) { |
| 53 | $dict->set('FontDescriptor', $this->fontDescriptor); |
| 54 | } |
| 55 | if ($this->dw !== null) { |
| 56 | $dict->set('DW', new PdfNumber($this->dw)); |
| 57 | } |
| 58 | if ($this->w !== null) { |
| 59 | $dict->set('W', $this->w); |
| 60 | } |
| 61 | if ($this->dw2 !== null) { |
| 62 | $dict->set('DW2', $this->dw2); |
| 63 | } |
| 64 | if ($this->w2 !== null) { |
| 65 | $dict->set('W2', $this->w2); |
| 66 | } |
| 67 | |
| 68 | return $dict->toPdf(); |
| 69 | } |
| 70 | } |