Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
41 / 41 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
Text | |
100.00% |
41 / 41 |
|
100.00% |
10 / 10 |
26 | |
100.00% |
1 / 1 |
setMultiline | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setPassword | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setFileSelect | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setDoNotSpellCheck | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setDoNotScroll | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setComb | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setRichText | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
isMultiline | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isPassword | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStream | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
10 |
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\Field; |
15 | |
16 | use Pop\Color\Color; |
17 | |
18 | /** |
19 | * Pdf page button field class |
20 | * |
21 | * @category Pop |
22 | * @package Pop\Pdf |
23 | * @author Nick Sagona, III <dev@nolainteractive.com> |
24 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
25 | * @license http://www.popphp.org/license New BSD License |
26 | * @version 5.0.0 |
27 | */ |
28 | class Text extends AbstractField |
29 | { |
30 | |
31 | /** |
32 | * Set multiline |
33 | * |
34 | * @return Text |
35 | */ |
36 | public function setMultiline(): Text |
37 | { |
38 | if (!in_array(13, $this->flagBits)) { |
39 | $this->flagBits[] = 13; |
40 | } |
41 | return $this; |
42 | } |
43 | |
44 | /** |
45 | * Set password |
46 | * |
47 | * @return Text |
48 | */ |
49 | public function setPassword(): Text |
50 | { |
51 | if (!in_array(14, $this->flagBits)) { |
52 | $this->flagBits[] = 14; |
53 | } |
54 | return $this; |
55 | } |
56 | |
57 | /** |
58 | * Set file select |
59 | * |
60 | * @return Text |
61 | */ |
62 | public function setFileSelect(): Text |
63 | { |
64 | if (!in_array(21, $this->flagBits)) { |
65 | $this->flagBits[] = 21; |
66 | } |
67 | return $this; |
68 | } |
69 | |
70 | /** |
71 | * Set do not spell check |
72 | * |
73 | * @return Text |
74 | */ |
75 | public function setDoNotSpellCheck(): Text |
76 | { |
77 | if (!in_array(23, $this->flagBits)) { |
78 | $this->flagBits[] = 23; |
79 | } |
80 | return $this; |
81 | } |
82 | |
83 | /** |
84 | * Set do not scroll |
85 | * |
86 | * @return Text |
87 | */ |
88 | public function setDoNotScroll(): Text |
89 | { |
90 | if (!in_array(24, $this->flagBits)) { |
91 | $this->flagBits[] = 24; |
92 | } |
93 | return $this; |
94 | } |
95 | |
96 | /** |
97 | * Set comb |
98 | * |
99 | * @return Text |
100 | */ |
101 | public function setComb(): Text |
102 | { |
103 | if (!in_array(25, $this->flagBits)) { |
104 | $this->flagBits[] = 25; |
105 | } |
106 | return $this; |
107 | } |
108 | |
109 | /** |
110 | * Set rich text |
111 | * |
112 | * @return Text |
113 | */ |
114 | public function setRichText(): Text |
115 | { |
116 | if (!in_array(26, $this->flagBits)) { |
117 | $this->flagBits[] = 26; |
118 | } |
119 | return $this; |
120 | } |
121 | |
122 | /** |
123 | * Is multiline |
124 | * |
125 | * @return bool |
126 | */ |
127 | public function isMultiline(): bool |
128 | { |
129 | return in_array(13, $this->flagBits); |
130 | } |
131 | |
132 | /** |
133 | * Is password |
134 | * |
135 | * @return bool |
136 | */ |
137 | public function isPassword(): bool |
138 | { |
139 | return in_array(14, $this->flagBits); |
140 | } |
141 | |
142 | /** |
143 | * Get the field stream |
144 | * |
145 | * @param int $i |
146 | * @param int $pageIndex |
147 | * @param ?string $fontReference |
148 | * @param int $x |
149 | * @param int $y |
150 | * @return string |
151 | */ |
152 | public function getStream(int $i, int $pageIndex, ?string $fontReference, int $x, int $y): string |
153 | { |
154 | $color = '0 g'; |
155 | if ($this->fontColor !== null) { |
156 | if ($this->fontColor instanceof Color\Rgb) { |
157 | $color = $this->fontColor->render(Color\Rgb::PERCENT) . " rg"; |
158 | } else if ($this->fontColor instanceof Color\Cmyk) { |
159 | $color = $this->fontColor->render(Color\Cmyk::PERCENT) . " k"; |
160 | } else if ($this->fontColor instanceof Color\Grayscale) { |
161 | $color = $this->fontColor->render(Color\Grayscale::PERCENT) . " g"; |
162 | } |
163 | } |
164 | |
165 | if ($fontReference !== null) { |
166 | $fontReference = substr($fontReference, 0, strpos($fontReference, ' ')); |
167 | $text = ' /DA(' . $fontReference . ' ' . $this->size . ' Tf ' . $color . ')'; |
168 | } else { |
169 | $text = null; |
170 | } |
171 | |
172 | $name = ($this->name !== null) ? ' /T(' . $this->name . ')/TU(' . $this->name . ')/TM(' . $this->name . ')' : ''; |
173 | $flags = (count($this->flagBits) > 0) ? "\n /Ff " . $this->getFlags() . "\n" : null; |
174 | $value = ($this->value !== null) ? "\n /V " . $this->value . "\n" : null; |
175 | $default = ($this->defaultValue !== null) ? "\n /DV " . $this->defaultValue . "\n" : null; |
176 | |
177 | // Return the stream |
178 | return "{$i} 0 obj\n<<\n /Type /Annot\n /Subtype /Widget\n /FT /Tx\n /Rect [{$x} {$y} " . |
179 | ($this->width + $x) . " " . ($this->height + $y) . "]{$value}{$default}\n /P {$pageIndex} 0 R\n{$text}\n{$name}\n{$flags}>>\nendobj\n\n"; |
180 | } |
181 | |
182 | } |