Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Url | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setUrl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStream | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://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 url annotation class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Pdf |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 5.0.0 |
25 | */ |
26 | class Url extends AbstractAnnotation |
27 | { |
28 | |
29 | /** |
30 | * External URL to link to |
31 | * @var ?string |
32 | */ |
33 | protected ?string $url = null; |
34 | |
35 | /** |
36 | * Constructor |
37 | * |
38 | * Instantiate a PDF URL annotation object. |
39 | * |
40 | * @param int $width |
41 | * @param int $height |
42 | * @param string $url |
43 | */ |
44 | public function __construct(int $width, int $height, string $url) |
45 | { |
46 | parent::__construct($width, $height); |
47 | $this->setUrl($url); |
48 | } |
49 | |
50 | /** |
51 | * Set the URL |
52 | * |
53 | * @param string $url |
54 | * @return Url |
55 | */ |
56 | public function setUrl(string $url): Url |
57 | { |
58 | $this->url = $url; |
59 | return $this; |
60 | } |
61 | |
62 | /** |
63 | * Get the URL link |
64 | * |
65 | * @return ?string |
66 | */ |
67 | public function getUrl(): ?string |
68 | { |
69 | return $this->url; |
70 | } |
71 | |
72 | /** |
73 | * Get the annotation stream |
74 | * |
75 | * @param int $i |
76 | * @param int $x |
77 | * @param int $y |
78 | * @return string |
79 | */ |
80 | public function getStream(int $i, int $x, int $y): string |
81 | { |
82 | // Assemble the border parameters |
83 | $border = $this->hRadius . ' ' . $this->vRadius . ' ' . $this->borderWidth; |
84 | if (($this->dashGap != 0) && ($this->dashLength != 0)) { |
85 | $border .= ' [' . $this->dashGap . ' ' . $this->dashLength . ']'; |
86 | } |
87 | |
88 | // Return the stream |
89 | return "{$i} 0 obj\n<<\n /Type /Annot\n /Subtype /Link\n /Rect [{$x} {$y} " . ($this->width + $x) . |
90 | " " . ($this->height + $y) . "]\n /Border [" . $border . "]\n /A <</S /URI /URI (" . |
91 | $this->url . ")>>\n>>\nendobj\n\n"; |
92 | } |
93 | |
94 | } |