Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
21 / 21 |
CRAP | |
100.00% |
1 / 1 |
| AdditionalActions | |
100.00% |
25 / 25 |
|
100.00% |
21 / 21 |
22 | |
100.00% |
1 / 1 |
| set | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| onWillClose | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onWillSave | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onDidSave | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onWillPrint | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onDidPrint | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onPageOpen | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onPageClose | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onMouseEnter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onMouseExit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onMouseDown | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onMouseUp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onFocus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onBlur | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onPageVisible | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onPageInvisible | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onKeystroke | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onFormat | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onValidate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onCalculate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
4 / 4 |
|
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\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfObject; |
| 9 | use Phpdftk\Pdf\Core\PdfReference; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * Additional-actions dictionary โ ISO 32000-2 ยง12.6.3, Tables 194โ197. |
| 15 | * |
| 16 | * Referenced from `/AA` on a Catalog, Page, Annotation, or Form field. |
| 17 | * The set of valid trigger-event keys depends on the parent type: |
| 18 | * |
| 19 | * - Catalog: WC WS DS WP DP |
| 20 | * - Page: O C |
| 21 | * - Annotation: E X D U Fo Bl PO PC PV PI |
| 22 | * - Form Field: K F V C |
| 23 | * |
| 24 | * This class is permissive: it holds arbitrary trigger โ action entries |
| 25 | * and does not enforce which keys are legal for which parent. The |
| 26 | * helper methods cover the common triggers; uncommon ones can be set |
| 27 | * via `$this->set($trigger, $action)`. |
| 28 | */ |
| 29 | #[RequiresPdfVersion(PdfVersion::V1_2)] |
| 30 | class AdditionalActions extends PdfObject |
| 31 | { |
| 32 | /** @var array<string, Action|PdfReference> trigger key => action */ |
| 33 | public array $triggers = []; |
| 34 | |
| 35 | public function set(string $trigger, Action|PdfReference $action): self |
| 36 | { |
| 37 | $this->triggers[$trigger] = $action; |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | // -- Catalog triggers ------------------------------------------------ |
| 42 | public function onWillClose(Action|PdfReference $a): self |
| 43 | { |
| 44 | return $this->set('WC', $a); |
| 45 | } |
| 46 | public function onWillSave(Action|PdfReference $a): self |
| 47 | { |
| 48 | return $this->set('WS', $a); |
| 49 | } |
| 50 | public function onDidSave(Action|PdfReference $a): self |
| 51 | { |
| 52 | return $this->set('DS', $a); |
| 53 | } |
| 54 | public function onWillPrint(Action|PdfReference $a): self |
| 55 | { |
| 56 | return $this->set('WP', $a); |
| 57 | } |
| 58 | public function onDidPrint(Action|PdfReference $a): self |
| 59 | { |
| 60 | return $this->set('DP', $a); |
| 61 | } |
| 62 | |
| 63 | // -- Page triggers --------------------------------------------------- |
| 64 | public function onPageOpen(Action|PdfReference $a): self |
| 65 | { |
| 66 | return $this->set('O', $a); |
| 67 | } |
| 68 | public function onPageClose(Action|PdfReference $a): self |
| 69 | { |
| 70 | return $this->set('C', $a); |
| 71 | } |
| 72 | |
| 73 | // -- Annotation triggers -------------------------------------------- |
| 74 | public function onMouseEnter(Action|PdfReference $a): self |
| 75 | { |
| 76 | return $this->set('E', $a); |
| 77 | } |
| 78 | public function onMouseExit(Action|PdfReference $a): self |
| 79 | { |
| 80 | return $this->set('X', $a); |
| 81 | } |
| 82 | public function onMouseDown(Action|PdfReference $a): self |
| 83 | { |
| 84 | return $this->set('D', $a); |
| 85 | } |
| 86 | public function onMouseUp(Action|PdfReference $a): self |
| 87 | { |
| 88 | return $this->set('U', $a); |
| 89 | } |
| 90 | public function onFocus(Action|PdfReference $a): self |
| 91 | { |
| 92 | return $this->set('Fo', $a); |
| 93 | } |
| 94 | public function onBlur(Action|PdfReference $a): self |
| 95 | { |
| 96 | return $this->set('Bl', $a); |
| 97 | } |
| 98 | public function onPageVisible(Action|PdfReference $a): self |
| 99 | { |
| 100 | return $this->set('PV', $a); |
| 101 | } |
| 102 | public function onPageInvisible(Action|PdfReference $a): self |
| 103 | { |
| 104 | return $this->set('PI', $a); |
| 105 | } |
| 106 | |
| 107 | // -- Form field triggers -------------------------------------------- |
| 108 | public function onKeystroke(Action|PdfReference $a): self |
| 109 | { |
| 110 | return $this->set('K', $a); |
| 111 | } |
| 112 | public function onFormat(Action|PdfReference $a): self |
| 113 | { |
| 114 | return $this->set('F', $a); |
| 115 | } |
| 116 | public function onValidate(Action|PdfReference $a): self |
| 117 | { |
| 118 | return $this->set('V', $a); |
| 119 | } |
| 120 | public function onCalculate(Action|PdfReference $a): self |
| 121 | { |
| 122 | return $this->set('C', $a); |
| 123 | } |
| 124 | |
| 125 | public function toPdf(): string |
| 126 | { |
| 127 | $dict = new PdfDictionary(); |
| 128 | foreach ($this->triggers as $trigger => $action) { |
| 129 | $dict->set($trigger, $action); |
| 130 | } |
| 131 | return $dict->toPdf(); |
| 132 | } |
| 133 | } |