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