Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| OCUsage | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
9 | |
100.00% |
1 / 1 |
| toPdf | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
9 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\Serializable; |
| 9 | use Phpdftk\Pdf\Core\PdfVersion; |
| 10 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 11 | |
| 12 | /** |
| 13 | * Optional content usage dictionary — ISO 32000-2 §8.11.4.4, Table 104. |
| 14 | * |
| 15 | * Holds the nine usage sub-dictionaries that let viewers decide |
| 16 | * whether an OCG should be visible for printing, viewing, exporting, |
| 17 | * etc. Each entry is a PdfDictionary containing the usage-specific |
| 18 | * keys (e.g. /Language /Lang /Preferred for /Language). |
| 19 | * |
| 20 | * Attached to `OCG::$usage` (now `OCUsage|PdfDictionary|null`). |
| 21 | */ |
| 22 | #[RequiresPdfVersion(PdfVersion::V1_5)] |
| 23 | class OCUsage implements Serializable |
| 24 | { |
| 25 | public ?PdfDictionary $creatorInfo = null; // /CreatorInfo |
| 26 | public ?PdfDictionary $language = null; // /Language |
| 27 | public ?PdfDictionary $export = null; // /Export |
| 28 | public ?PdfDictionary $zoom = null; // /Zoom |
| 29 | public ?PdfDictionary $print = null; // /Print |
| 30 | public ?PdfDictionary $view = null; // /View |
| 31 | public ?PdfDictionary $user = null; // /User |
| 32 | public ?PdfDictionary $pageElement = null; // /PageElement |
| 33 | |
| 34 | public function toPdf(): string |
| 35 | { |
| 36 | $dict = new PdfDictionary(); |
| 37 | if ($this->creatorInfo !== null) { |
| 38 | $dict->set('CreatorInfo', $this->creatorInfo); |
| 39 | } |
| 40 | if ($this->language !== null) { |
| 41 | $dict->set('Language', $this->language); |
| 42 | } |
| 43 | if ($this->export !== null) { |
| 44 | $dict->set('Export', $this->export); |
| 45 | } |
| 46 | if ($this->zoom !== null) { |
| 47 | $dict->set('Zoom', $this->zoom); |
| 48 | } |
| 49 | if ($this->print !== null) { |
| 50 | $dict->set('Print', $this->print); |
| 51 | } |
| 52 | if ($this->view !== null) { |
| 53 | $dict->set('View', $this->view); |
| 54 | } |
| 55 | if ($this->user !== null) { |
| 56 | $dict->set('User', $this->user); |
| 57 | } |
| 58 | if ($this->pageElement !== null) { |
| 59 | $dict->set('PageElement', $this->pageElement); |
| 60 | } |
| 61 | return $dict->toPdf(); |
| 62 | } |
| 63 | } |