Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SetOCGStateAction | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getActionType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Action; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfBoolean; |
| 9 | use Phpdftk\Pdf\Core\PdfVersion; |
| 10 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 11 | |
| 12 | /** |
| 13 | * Set-OCG-state action (/S /SetOCGState) — ISO 32000-2 §12.6.4.12. |
| 14 | * Toggles visibility of optional content groups. |
| 15 | * |
| 16 | * The /State array is a sequence of name + OCG reference pairs, e.g.: |
| 17 | * [/OFF 12 0 R 13 0 R /ON 14 0 R] |
| 18 | */ |
| 19 | #[RequiresPdfVersion(PdfVersion::V1_5)] |
| 20 | class SetOCGStateAction extends Action |
| 21 | { |
| 22 | public PdfArray $state; // /State required |
| 23 | public ?bool $preserveRB = null; // /PreserveRB |
| 24 | |
| 25 | public function __construct(PdfArray $state) |
| 26 | { |
| 27 | $this->state = $state; |
| 28 | } |
| 29 | |
| 30 | public function getActionType(): string |
| 31 | { |
| 32 | return 'SetOCGState'; |
| 33 | } |
| 34 | |
| 35 | public function toPdf(): string |
| 36 | { |
| 37 | $dict = $this->baseDictionary(); |
| 38 | $dict->set('State', $this->state); |
| 39 | if ($this->preserveRB !== null) { |
| 40 | $dict->set('PreserveRB', new PdfBoolean($this->preserveRB)); |
| 41 | } |
| 42 | return $dict->toPdf(); |
| 43 | } |
| 44 | } |