Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AppearanceDict | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| toPdf | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Annotation; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfReference; |
| 9 | use Phpdftk\Pdf\Core\Serializable; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * PDF Appearance dictionary (ISO 32000-2 Table 170). |
| 15 | * |
| 16 | * Defines the visual appearance of an annotation in various states. |
| 17 | * Assigned to the /AP entry of annotation dictionaries. |
| 18 | * |
| 19 | * Example: |
| 20 | * $ap = new AppearanceDict(); |
| 21 | * $ap->n = new PdfReference($normalAppearance->objectNumber); |
| 22 | * $annotation->ap = $ap; |
| 23 | */ |
| 24 | #[RequiresPdfVersion(PdfVersion::V1_2)] |
| 25 | class AppearanceDict implements Serializable |
| 26 | { |
| 27 | public PdfReference|PdfDictionary|null $n = null; // /N - normal appearance |
| 28 | public PdfReference|PdfDictionary|null $r = null; // /R - rollover appearance |
| 29 | public PdfReference|PdfDictionary|null $d = null; // /D - down appearance |
| 30 | |
| 31 | public function toPdf(): string |
| 32 | { |
| 33 | $dict = new PdfDictionary(); |
| 34 | |
| 35 | if ($this->n !== null) { |
| 36 | $dict->set('N', $this->n); |
| 37 | } |
| 38 | if ($this->r !== null) { |
| 39 | $dict->set('R', $this->r); |
| 40 | } |
| 41 | if ($this->d !== null) { |
| 42 | $dict->set('D', $this->d); |
| 43 | } |
| 44 | |
| 45 | return $dict->toPdf(); |
| 46 | } |
| 47 | } |