Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.37% |
37 / 38 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FormXObject | |
97.37% |
37 / 38 |
|
50.00% |
1 / 2 |
18 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
97.22% |
35 / 36 |
|
0.00% |
0 / 1 |
17 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Graphics\XObject; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\Content\Resources; |
| 8 | use Phpdftk\Pdf\Core\Document\GroupAttributes; |
| 9 | use Phpdftk\Pdf\Core\PdfArray; |
| 10 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 11 | use Phpdftk\Pdf\Core\PdfName; |
| 12 | use Phpdftk\Pdf\Core\PdfNumber; |
| 13 | use Phpdftk\Pdf\Core\PdfReference; |
| 14 | use Phpdftk\Pdf\Core\PdfStream; |
| 15 | use Phpdftk\Pdf\Core\PdfString; |
| 16 | use Phpdftk\Pdf\Core\Serializable; |
| 17 | use Phpdftk\Pdf\Core\PdfVersion; |
| 18 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 19 | |
| 20 | /** |
| 21 | * Form XObject (/Subtype /Form) — ISO 32000-2 §8.10, Table 95. |
| 22 | * |
| 23 | * A self-contained content stream that can be placed on a page. Carries |
| 24 | * its own resource dictionary, optional transparency group, optional |
| 25 | * reference-XObject pointer, and optional metadata. |
| 26 | */ |
| 27 | class FormXObject extends PdfStream |
| 28 | { |
| 29 | public const PDF_TYPE = 'XObject'; |
| 30 | public const PDF_SUBTYPE = 'Form'; |
| 31 | |
| 32 | public PdfArray $bBox; // /BBox - required |
| 33 | public ?PdfArray $matrix = null; // /Matrix |
| 34 | public Resources|PdfDictionary|null $resources = null; // /Resources |
| 35 | public ?PdfName $formType = null; // /FormType |
| 36 | public GroupAttributes|Serializable|null $group = null; // /Group - transparency group |
| 37 | public ?PdfReference $ref = null; // /Ref - reference XObject |
| 38 | public ?PdfReference $metadata = null; // /Metadata - XMP stream |
| 39 | public ?PdfReference $pieceInfo = null; // /PieceInfo |
| 40 | public ?PdfString $lastModified = null; // /LastModified |
| 41 | public ?int $structParent = null; // /StructParent |
| 42 | public ?int $structParents = null; // /StructParents |
| 43 | public ?PdfReference $oc = null; // /OC - optional content |
| 44 | #[RequiresPdfVersion(PdfVersion::V2_0)] |
| 45 | public ?PdfArray $af = null; // /AF - associated files |
| 46 | public ?PdfDictionary $opi = null; // /OPI |
| 47 | public ?PdfReference $measure = null; // /Measure |
| 48 | public ?PdfReference $ptData = null; // /PtData |
| 49 | public ?PdfName $name = null; // /Name - deprecated but permitted |
| 50 | |
| 51 | public function __construct(PdfArray $bBox, string $data = '') |
| 52 | { |
| 53 | parent::__construct(new PdfDictionary(), $data); |
| 54 | $this->bBox = $bBox; |
| 55 | } |
| 56 | |
| 57 | public function toPdf(): string |
| 58 | { |
| 59 | $this->dictionary->set('Type', new PdfName(self::PDF_TYPE)); |
| 60 | $this->dictionary->set('Subtype', new PdfName(self::PDF_SUBTYPE)); |
| 61 | if ($this->formType !== null) { |
| 62 | $this->dictionary->set('FormType', $this->formType); |
| 63 | } |
| 64 | $this->dictionary->set('BBox', $this->bBox); |
| 65 | |
| 66 | if ($this->matrix !== null) { |
| 67 | $this->dictionary->set('Matrix', $this->matrix); |
| 68 | } |
| 69 | if ($this->resources !== null) { |
| 70 | $this->dictionary->set('Resources', $this->resources); |
| 71 | } |
| 72 | if ($this->group !== null) { |
| 73 | $this->dictionary->set('Group', $this->group); |
| 74 | } |
| 75 | if ($this->ref !== null) { |
| 76 | $this->dictionary->set('Ref', $this->ref); |
| 77 | } |
| 78 | if ($this->metadata !== null) { |
| 79 | $this->dictionary->set('Metadata', $this->metadata); |
| 80 | } |
| 81 | if ($this->pieceInfo !== null) { |
| 82 | $this->dictionary->set('PieceInfo', $this->pieceInfo); |
| 83 | } |
| 84 | if ($this->lastModified !== null) { |
| 85 | $this->dictionary->set('LastModified', $this->lastModified); |
| 86 | } |
| 87 | if ($this->structParent !== null) { |
| 88 | $this->dictionary->set('StructParent', new PdfNumber($this->structParent)); |
| 89 | } |
| 90 | if ($this->structParents !== null) { |
| 91 | $this->dictionary->set('StructParents', new PdfNumber($this->structParents)); |
| 92 | } |
| 93 | if ($this->oc !== null) { |
| 94 | $this->dictionary->set('OC', $this->oc); |
| 95 | } |
| 96 | if ($this->af !== null) { |
| 97 | $this->dictionary->set('AF', $this->af); |
| 98 | } |
| 99 | if ($this->opi !== null) { |
| 100 | $this->dictionary->set('OPI', $this->opi); |
| 101 | } |
| 102 | if ($this->measure !== null) { |
| 103 | $this->dictionary->set('Measure', $this->measure); |
| 104 | } |
| 105 | if ($this->ptData !== null) { |
| 106 | $this->dictionary->set('PtData', $this->ptData); |
| 107 | } |
| 108 | if ($this->name !== null) { |
| 109 | $this->dictionary->set('Name', $this->name); |
| 110 | } |
| 111 | |
| 112 | return parent::toPdf(); |
| 113 | } |
| 114 | } |