Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
22 / 22 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| FreeTextAnnotation | |
100.00% |
22 / 22 |
|
100.00% |
3 / 3 |
11 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getSubtype | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
9 | |||
| 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\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfNumber; |
| 10 | use Phpdftk\Pdf\Core\PdfReference; |
| 11 | use Phpdftk\Pdf\Core\PdfString; |
| 12 | use Phpdftk\Pdf\Core\PdfVersion; |
| 13 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 14 | |
| 15 | /** |
| 16 | * Free text annotation (/Subtype /FreeText). |
| 17 | * Renders text directly on the page surface. |
| 18 | */ |
| 19 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 20 | class FreeTextAnnotation extends MarkupAnnotation |
| 21 | { |
| 22 | public PdfString $da; // /DA - default appearance - required |
| 23 | public ?int $q = null; // /Q - justification |
| 24 | public ?PdfString $rc = null; // /RC - rich content |
| 25 | public ?PdfString $ds = null; // /DS - default style |
| 26 | public ?PdfReference $cl = null; // /CL - callout line |
| 27 | public ?PdfName $it = null; // /IT - intent |
| 28 | public ?BorderEffect $be = null; // /BE - border effect |
| 29 | public ?PdfArray $rd = null; // /RD - rectangle differences |
| 30 | public ?PdfName $le = null; // /LE - line ending |
| 31 | |
| 32 | public function __construct(\Phpdftk\Pdf\Core\PdfArray $rect, PdfString $da) |
| 33 | { |
| 34 | parent::__construct($rect); |
| 35 | $this->da = $da; |
| 36 | } |
| 37 | |
| 38 | public function getSubtype(): string |
| 39 | { |
| 40 | return 'FreeText'; |
| 41 | } |
| 42 | |
| 43 | public function toPdf(): string |
| 44 | { |
| 45 | $dict = $this->buildDictionary(); |
| 46 | $dict->set('DA', $this->da); |
| 47 | |
| 48 | if ($this->q !== null) { |
| 49 | $dict->set('Q', new PdfNumber($this->q)); |
| 50 | } |
| 51 | if ($this->rc !== null) { |
| 52 | $dict->set('RC', $this->rc); |
| 53 | } |
| 54 | if ($this->ds !== null) { |
| 55 | $dict->set('DS', $this->ds); |
| 56 | } |
| 57 | if ($this->cl !== null) { |
| 58 | $dict->set('CL', $this->cl); |
| 59 | } |
| 60 | if ($this->it !== null) { |
| 61 | $dict->set('IT', $this->it); |
| 62 | } |
| 63 | if ($this->be !== null) { |
| 64 | $dict->set('BE', $this->be); |
| 65 | } |
| 66 | if ($this->rd !== null) { |
| 67 | $dict->set('RD', $this->rd); |
| 68 | } |
| 69 | if ($this->le !== null) { |
| 70 | $dict->set('LE', $this->le); |
| 71 | } |
| 72 | |
| 73 | return $dict->toPdf(); |
| 74 | } |
| 75 | } |