Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
BorderStyle
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 toPdf
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Annotation;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfNumber;
11use Phpdftk\Pdf\Core\Serializable;
12
13/**
14 * PDF Border Style dictionary (/Type /Border).
15 *
16 * Describes the border drawn around annotations that support it
17 * (Link, FreeText, Line, Square, Circle, Polygon, PolyLine, etc.).
18 * Assigned to the /BS entry of those annotation dictionaries.
19 *
20 * Style (/S) values:
21 *   S - Solid
22 *   D - Dashed
23 *   B - Beveled
24 *   I - Inset
25 *   U - Underline
26 *
27 * Example:
28 *   $bs = new BorderStyle();
29 *   $bs->w = new PdfNumber(2.0);
30 *   $bs->s = new PdfName('D');
31 *   $bs->d = new PdfArray([new PdfNumber(3), new PdfNumber(2)]);
32 *   $annotation->bs = $bs;
33 */
34class BorderStyle implements Serializable
35{
36    public ?PdfNumber $w = null;  // /W - line width (default 1)
37    public ?PdfName $s   = null;  // /S - style (default S = Solid)
38    /** @var PdfArray|null /D - dash array, e.g. [3 2] */
39    public ?PdfArray $d  = null;  // /D - dash pattern (only when S=D)
40
41    public function toPdf(): string
42    {
43        $dict = new PdfDictionary();
44        $dict->set('Type', new PdfName('Border'));
45
46        if ($this->w !== null) {
47            $dict->set('W', $this->w);
48        }
49        if ($this->s !== null) {
50            $dict->set('S', $this->s);
51        }
52        if ($this->d !== null) {
53            $dict->set('D', $this->d);
54        }
55
56        return $dict->toPdf();
57    }
58}