Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AppearanceCharacteristics | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
12 | |
100.00% |
1 / 1 |
| toPdf | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Annotation; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfNumber; |
| 10 | use Phpdftk\Pdf\Core\PdfReference; |
| 11 | use Phpdftk\Pdf\Core\PdfString; |
| 12 | use Phpdftk\Pdf\Core\Serializable; |
| 13 | use Phpdftk\Pdf\Core\PdfVersion; |
| 14 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 15 | |
| 16 | /** |
| 17 | * PDF Widget annotation appearance characteristics (ISO 32000-2 Table 192). |
| 18 | * |
| 19 | * Describes the visual characteristics of a widget annotation's appearance. |
| 20 | * Assigned to the /MK entry of widget annotation dictionaries. |
| 21 | * |
| 22 | * Example: |
| 23 | * $mk = new AppearanceCharacteristics(); |
| 24 | * $mk->r = 90; |
| 25 | * $mk->bc = new PdfArray([new PdfNumber(0), new PdfNumber(0), new PdfNumber(0)]); |
| 26 | * $mk->ca = new PdfString('Submit'); |
| 27 | * $widget->mk = $mk; |
| 28 | */ |
| 29 | #[RequiresPdfVersion(PdfVersion::V1_2)] |
| 30 | class AppearanceCharacteristics implements Serializable |
| 31 | { |
| 32 | public ?int $r = null; // /R - rotation (0, 90, 180, 270) |
| 33 | public ?PdfArray $bc = null; // /BC - border color |
| 34 | public ?PdfArray $bg = null; // /BG - background color |
| 35 | public ?PdfString $ca = null; // /CA - normal caption |
| 36 | public ?PdfString $rc = null; // /RC - rollover caption |
| 37 | public ?PdfString $ac = null; // /AC - alternate caption |
| 38 | public ?PdfReference $i = null; // /I - normal icon |
| 39 | public ?PdfReference $ri = null; // /RI - rollover icon |
| 40 | public ?PdfReference $ix = null; // /IX - alternate icon |
| 41 | public ?PdfDictionary $if_ = null; // /IF - icon fit dict (if is reserved) |
| 42 | public ?int $tp = null; // /TP - text position |
| 43 | |
| 44 | public function toPdf(): string |
| 45 | { |
| 46 | $dict = new PdfDictionary(); |
| 47 | |
| 48 | if ($this->r !== null) { |
| 49 | $dict->set('R', new PdfNumber($this->r)); |
| 50 | } |
| 51 | if ($this->bc !== null) { |
| 52 | $dict->set('BC', $this->bc); |
| 53 | } |
| 54 | if ($this->bg !== null) { |
| 55 | $dict->set('BG', $this->bg); |
| 56 | } |
| 57 | if ($this->ca !== null) { |
| 58 | $dict->set('CA', $this->ca); |
| 59 | } |
| 60 | if ($this->rc !== null) { |
| 61 | $dict->set('RC', $this->rc); |
| 62 | } |
| 63 | if ($this->ac !== null) { |
| 64 | $dict->set('AC', $this->ac); |
| 65 | } |
| 66 | if ($this->i !== null) { |
| 67 | $dict->set('I', $this->i); |
| 68 | } |
| 69 | if ($this->ri !== null) { |
| 70 | $dict->set('RI', $this->ri); |
| 71 | } |
| 72 | if ($this->ix !== null) { |
| 73 | $dict->set('IX', $this->ix); |
| 74 | } |
| 75 | if ($this->if_ !== null) { |
| 76 | $dict->set('IF', $this->if_); |
| 77 | } |
| 78 | if ($this->tp !== null) { |
| 79 | $dict->set('TP', new PdfNumber($this->tp)); |
| 80 | } |
| 81 | |
| 82 | return $dict->toPdf(); |
| 83 | } |
| 84 | } |