Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| OCMD | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |
0.00% |
0 / 1 |
| toPdf | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfObject; |
| 11 | use Phpdftk\Pdf\Core\PdfVersion; |
| 12 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 13 | |
| 14 | /** |
| 15 | * PDF Optional Content Membership Dictionary (ISO 32000-2 Table 97). |
| 16 | * |
| 17 | * Determines visibility based on the state of one or more OCGs. |
| 18 | * |
| 19 | * Example: |
| 20 | * $ocmd = new OCMD(); |
| 21 | * $ocmd->ocgs = new PdfArray([new PdfReference($ocg->objectNumber)]); |
| 22 | * $ocmd->p = new PdfName('AnyOn'); |
| 23 | */ |
| 24 | #[RequiresPdfVersion(PdfVersion::V1_5)] |
| 25 | class OCMD extends PdfObject |
| 26 | { |
| 27 | public const PDF_TYPE = 'OCMD'; |
| 28 | |
| 29 | public ?PdfArray $ocgs = null; // /OCGs - array of OCG refs |
| 30 | public ?PdfName $p = null; // /P - visibility policy (AllOn, AnyOn, AnyOff, AllOff) |
| 31 | public ?PdfArray $ve = null; // /VE - visibility expression |
| 32 | |
| 33 | public function toPdf(): string |
| 34 | { |
| 35 | $dict = new PdfDictionary(); |
| 36 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 37 | |
| 38 | if ($this->ocgs !== null) { |
| 39 | $dict->set('OCGs', $this->ocgs); |
| 40 | } |
| 41 | if ($this->p !== null) { |
| 42 | $dict->set('P', $this->p); |
| 43 | } |
| 44 | if ($this->ve !== null) { |
| 45 | $dict->set('VE', $this->ve); |
| 46 | } |
| 47 | |
| 48 | return $dict->toPdf(); |
| 49 | } |
| 50 | } |