Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
| Link | |
100.00% |
24 / 24 |
|
100.00% |
10 / 10 |
14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| setXTarget | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setYTarget | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setZTarget | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setPageTarget | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getXTarget | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getYTarget | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getZTarget | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPageTarget | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStream | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Pdf\Document\Page\Annotation; |
| 15 | |
| 16 | /** |
| 17 | * Pdf page link annotation class |
| 18 | * |
| 19 | * @category Pop |
| 20 | * @package Pop\Pdf |
| 21 | * @author Nick Sagona, III <dev@noladev.com> |
| 22 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
| 23 | * @license https://www.popphp.org/license New BSD License |
| 24 | * @version 5.2.2 |
| 25 | */ |
| 26 | class Link extends AbstractAnnotation |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * Internal x-position target to link to on internal page |
| 31 | * @var int |
| 32 | */ |
| 33 | protected int $xTarget = 0; |
| 34 | |
| 35 | /** |
| 36 | * Internal y-position target to link to on internal page |
| 37 | * @var int |
| 38 | */ |
| 39 | protected int $yTarget = 0; |
| 40 | |
| 41 | /** |
| 42 | * Internal z-position target (zoom) to link to on internal page |
| 43 | * @var int |
| 44 | */ |
| 45 | protected int $zTarget = 0; |
| 46 | |
| 47 | /** |
| 48 | * Internal page object index target to link to |
| 49 | * @var ?int |
| 50 | */ |
| 51 | protected ?int $pageTarget = null; |
| 52 | |
| 53 | /** |
| 54 | * Constructor |
| 55 | * |
| 56 | * Instantiate a PDF link annotation object. |
| 57 | * |
| 58 | * @param int $width |
| 59 | * @param int $height |
| 60 | * @param int $xTarget |
| 61 | * @param int $yTarget |
| 62 | */ |
| 63 | public function __construct(int $width, int $height, int $xTarget, int $yTarget) |
| 64 | { |
| 65 | parent::__construct($width, $height); |
| 66 | |
| 67 | $this->setXTarget($xTarget); |
| 68 | $this->setYTarget($yTarget); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Set the X target |
| 73 | * |
| 74 | * @param int $xTarget |
| 75 | * @return Link |
| 76 | */ |
| 77 | public function setXTarget(int $xTarget): Link |
| 78 | { |
| 79 | $this->xTarget = $xTarget; |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Set the Y target |
| 85 | * |
| 86 | * @param int $yTarget |
| 87 | * @return Link |
| 88 | */ |
| 89 | public function setYTarget(int $yTarget): Link |
| 90 | { |
| 91 | $this->yTarget = $yTarget; |
| 92 | return $this; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Set the Z (zoom) target |
| 97 | * |
| 98 | * @param int $zTarget |
| 99 | * @return Link |
| 100 | */ |
| 101 | public function setZTarget(int $zTarget): Link |
| 102 | { |
| 103 | $this->zTarget = $zTarget; |
| 104 | return $this; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Set the page target |
| 109 | * |
| 110 | * @param int $pageTarget |
| 111 | * @return Link |
| 112 | */ |
| 113 | public function setPageTarget(int $pageTarget): Link |
| 114 | { |
| 115 | $this->pageTarget = $pageTarget; |
| 116 | return $this; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Get the X target |
| 121 | * |
| 122 | * @return int |
| 123 | */ |
| 124 | public function getXTarget(): int |
| 125 | { |
| 126 | return $this->xTarget; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get the Y target |
| 131 | * |
| 132 | * @return int |
| 133 | */ |
| 134 | public function getYTarget(): int |
| 135 | { |
| 136 | return $this->yTarget; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Get the Z (zoom) target |
| 141 | * |
| 142 | * @return int |
| 143 | */ |
| 144 | public function getZTarget(): int |
| 145 | { |
| 146 | return $this->zTarget; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Get the page target |
| 151 | * |
| 152 | * @return ?int |
| 153 | */ |
| 154 | public function getPageTarget(): ?int |
| 155 | { |
| 156 | return $this->pageTarget; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Get the annotation stream |
| 161 | * |
| 162 | * @param int $i |
| 163 | * @param int $x |
| 164 | * @param int $y |
| 165 | * @param int $pageIndex |
| 166 | * @param array $kids |
| 167 | * @return string |
| 168 | */ |
| 169 | public function getStream(int $i, int $x, int $y, int $pageIndex, array $kids): string |
| 170 | { |
| 171 | // Assemble the border parameters |
| 172 | $border = $this->hRadius . ' ' . $this->vRadius . ' ' . $this->borderWidth; |
| 173 | if (($this->dashGap != 0) && ($this->dashLength != 0)) { |
| 174 | $border .= ' [' . $this->dashGap . ' ' . $this->dashLength . ']'; |
| 175 | } |
| 176 | |
| 177 | $pageTargetIndex = (($this->pageTarget !== null) && isset($kids[$this->pageTarget - 1])) ? |
| 178 | $kids[$this->pageTarget - 1] : |
| 179 | $pageIndex; |
| 180 | |
| 181 | return "{$i} 0 obj\n<<\n /Type /Annot\n /Subtype /Link\n /Rect [{$x} {$y} " . ($this->width + $x) . |
| 182 | " " . ($this->height + $y) . "]\n /Border [" . $border . "]\n /Dest [" . $pageTargetIndex . |
| 183 | " 0 R /XYZ {$this->xTarget} {$this->yTarget} {$this->zTarget}]\n>>\nendobj\n\n"; |
| 184 | } |
| 185 | |
| 186 | } |