|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NFePHP\DA\Legacy; |
|
4
|
|
|
|
|
5
|
|
|
use NFePHP\DA\Legacy\FPDF\Fpdf as Fpdf; |
|
6
|
|
|
|
|
7
|
|
|
class Pdf extends Fpdf |
|
8
|
|
|
{ |
|
9
|
|
|
private $t128; // tabela de codigos 128 |
|
10
|
|
|
private $abcSet=""; // conjunto de caracteres legiveis em 128 |
|
11
|
|
|
private $aSet=""; // grupo A do conjunto de de caracteres legiveis |
|
12
|
|
|
private $bSet=""; // grupo B do conjunto de caracteres legiveis |
|
13
|
|
|
private $cSet=""; // grupo C do conjunto de caracteres legiveis |
|
14
|
|
|
private $setFrom; // converter de |
|
15
|
|
|
private $setTo; // converter para |
|
16
|
|
|
private $jStart = ["A"=>103, "B"=>104, "C"=>105]; // Caracteres de seleção do grupo 128 |
|
17
|
|
|
private $jSwap = ["A"=>101, "B"=>100, "C"=>99]; // Caracteres de troca de grupo |
|
18
|
|
|
|
|
19
|
|
|
public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4') |
|
20
|
|
|
{ |
|
21
|
|
|
//passar parametros para a classe principal |
|
22
|
|
|
parent::__construct($orientation, $unit, $format); |
|
23
|
|
|
// composição dos caracteres do barcode 128 |
|
24
|
|
|
$this->t128[] = array(2, 1, 2, 2, 2, 2); //0 : [ ] |
|
25
|
|
|
$this->t128[] = array(2, 2, 2, 1, 2, 2); //1 : [!] |
|
26
|
|
|
$this->t128[] = array(2, 2, 2, 2, 2, 1); //2 : ["] |
|
27
|
|
|
$this->t128[] = array(1, 2, 1, 2, 2, 3); //3 : [#] |
|
28
|
|
|
$this->t128[] = array(1, 2, 1, 3, 2, 2); //4 : [$] |
|
29
|
|
|
$this->t128[] = array(1, 3, 1, 2, 2, 2); //5 : [%] |
|
30
|
|
|
$this->t128[] = array(1, 2, 2, 2, 1, 3); //6 : [&] |
|
31
|
|
|
$this->t128[] = array(1, 2, 2, 3, 1, 2); //7 : ['] |
|
32
|
|
|
$this->t128[] = array(1, 3, 2, 2, 1, 2); //8 : [(] |
|
33
|
|
|
$this->t128[] = array(2, 2, 1, 2, 1, 3); //9 : [)] |
|
34
|
|
|
$this->t128[] = array(2, 2, 1, 3, 1, 2); //10 : [*] |
|
35
|
|
|
$this->t128[] = array(2, 3, 1, 2, 1, 2); //11 : [+] |
|
36
|
|
|
$this->t128[] = array(1, 1, 2, 2, 3, 2); //12 : [,] |
|
37
|
|
|
$this->t128[] = array(1, 2, 2, 1, 3, 2); //13 : [-] |
|
38
|
|
|
$this->t128[] = array(1, 2, 2, 2, 3, 1); //14 : [.] |
|
39
|
|
|
$this->t128[] = array(1, 1, 3, 2, 2, 2); //15 : [/] |
|
40
|
|
|
$this->t128[] = array(1, 2, 3, 1, 2, 2); //16 : [0] |
|
41
|
|
|
$this->t128[] = array(1, 2, 3, 2, 2, 1); //17 : [1] |
|
42
|
|
|
$this->t128[] = array(2, 2, 3, 2, 1, 1); //18 : [2] |
|
43
|
|
|
$this->t128[] = array(2, 2, 1, 1, 3, 2); //19 : [3] |
|
44
|
|
|
$this->t128[] = array(2, 2, 1, 2, 3, 1); //20 : [4] |
|
45
|
|
|
$this->t128[] = array(2, 1, 3, 2, 1, 2); //21 : [5] |
|
46
|
|
|
$this->t128[] = array(2, 2, 3, 1, 1, 2); //22 : [6] |
|
47
|
|
|
$this->t128[] = array(3, 1, 2, 1, 3, 1); //23 : [7] |
|
48
|
|
|
$this->t128[] = array(3, 1, 1, 2, 2, 2); //24 : [8] |
|
49
|
|
|
$this->t128[] = array(3, 2, 1, 1, 2, 2); //25 : [9] |
|
50
|
|
|
$this->t128[] = array(3, 2, 1, 2, 2, 1); //26 : [:] |
|
51
|
|
|
$this->t128[] = array(3, 1, 2, 2, 1, 2); //27 : [;] |
|
52
|
|
|
$this->t128[] = array(3, 2, 2, 1, 1, 2); //28 : [<] |
|
53
|
|
|
$this->t128[] = array(3, 2, 2, 2, 1, 1); //29 : [=] |
|
54
|
|
|
$this->t128[] = array(2, 1, 2, 1, 2, 3); //30 : [>] |
|
55
|
|
|
$this->t128[] = array(2, 1, 2, 3, 2, 1); //31 : [?] |
|
56
|
|
|
$this->t128[] = array(2, 3, 2, 1, 2, 1); //32 : [@] |
|
57
|
|
|
$this->t128[] = array(1, 1, 1, 3, 2, 3); //33 : [A] |
|
58
|
|
|
$this->t128[] = array(1, 3, 1, 1, 2, 3); //34 : [B] |
|
59
|
|
|
$this->t128[] = array(1, 3, 1, 3, 2, 1); //35 : [C] |
|
60
|
|
|
$this->t128[] = array(1, 1, 2, 3, 1, 3); //36 : [D] |
|
61
|
|
|
$this->t128[] = array(1, 3, 2, 1, 1, 3); //37 : [E] |
|
62
|
|
|
$this->t128[] = array(1, 3, 2, 3, 1, 1); //38 : [F] |
|
63
|
|
|
$this->t128[] = array(2, 1, 1, 3, 1, 3); //39 : [G] |
|
64
|
|
|
$this->t128[] = array(2, 3, 1, 1, 1, 3); //40 : [H] |
|
65
|
|
|
$this->t128[] = array(2, 3, 1, 3, 1, 1); //41 : [I] |
|
66
|
|
|
$this->t128[] = array(1, 1, 2, 1, 3, 3); //42 : [J] |
|
67
|
|
|
$this->t128[] = array(1, 1, 2, 3, 3, 1); //43 : [K] |
|
68
|
|
|
$this->t128[] = array(1, 3, 2, 1, 3, 1); //44 : [L] |
|
69
|
|
|
$this->t128[] = array(1, 1, 3, 1, 2, 3); //45 : [M] |
|
70
|
|
|
$this->t128[] = array(1, 1, 3, 3, 2, 1); //46 : [N] |
|
71
|
|
|
$this->t128[] = array(1, 3, 3, 1, 2, 1); //47 : [O] |
|
72
|
|
|
$this->t128[] = array(3, 1, 3, 1, 2, 1); //48 : [P] |
|
73
|
|
|
$this->t128[] = array(2, 1, 1, 3, 3, 1); //49 : [Q] |
|
74
|
|
|
$this->t128[] = array(2, 3, 1, 1, 3, 1); //50 : [R] |
|
75
|
|
|
$this->t128[] = array(2, 1, 3, 1, 1, 3); //51 : [S] |
|
76
|
|
|
$this->t128[] = array(2, 1, 3, 3, 1, 1); //52 : [T] |
|
77
|
|
|
$this->t128[] = array(2, 1, 3, 1, 3, 1); //53 : [U] |
|
78
|
|
|
$this->t128[] = array(3, 1, 1, 1, 2, 3); //54 : [V] |
|
79
|
|
|
$this->t128[] = array(3, 1, 1, 3, 2, 1); //55 : [W] |
|
80
|
|
|
$this->t128[] = array(3, 3, 1, 1, 2, 1); //56 : [X] |
|
81
|
|
|
$this->t128[] = array(3, 1, 2, 1, 1, 3); //57 : [Y] |
|
82
|
|
|
$this->t128[] = array(3, 1, 2, 3, 1, 1); //58 : [Z] |
|
83
|
|
|
$this->t128[] = array(3, 3, 2, 1, 1, 1); //59 : [[] |
|
84
|
|
|
$this->t128[] = array(3, 1, 4, 1, 1, 1); //60 : [\] |
|
85
|
|
|
$this->t128[] = array(2, 2, 1, 4, 1, 1); //61 : []] |
|
86
|
|
|
$this->t128[] = array(4, 3, 1, 1, 1, 1); //62 : [^] |
|
87
|
|
|
$this->t128[] = array(1, 1, 1, 2, 2, 4); //63 : [_] |
|
88
|
|
|
$this->t128[] = array(1, 1, 1, 4, 2, 2); //64 : [`] |
|
89
|
|
|
$this->t128[] = array(1, 2, 1, 1, 2, 4); //65 : [a] |
|
90
|
|
|
$this->t128[] = array(1, 2, 1, 4, 2, 1); //66 : [b] |
|
91
|
|
|
$this->t128[] = array(1, 4, 1, 1, 2, 2); //67 : [c] |
|
92
|
|
|
$this->t128[] = array(1, 4, 1, 2, 2, 1); //68 : [d] |
|
93
|
|
|
$this->t128[] = array(1, 1, 2, 2, 1, 4); //69 : [e] |
|
94
|
|
|
$this->t128[] = array(1, 1, 2, 4, 1, 2); //70 : [f] |
|
95
|
|
|
$this->t128[] = array(1, 2, 2, 1, 1, 4); //71 : [g] |
|
96
|
|
|
$this->t128[] = array(1, 2, 2, 4, 1, 1); //72 : [h] |
|
97
|
|
|
$this->t128[] = array(1, 4, 2, 1, 1, 2); //73 : [i] |
|
98
|
|
|
$this->t128[] = array(1, 4, 2, 2, 1, 1); //74 : [j] |
|
99
|
|
|
$this->t128[] = array(2, 4, 1, 2, 1, 1); //75 : [k] |
|
100
|
|
|
$this->t128[] = array(2, 2, 1, 1, 1, 4); //76 : [l] |
|
101
|
|
|
$this->t128[] = array(4, 1, 3, 1, 1, 1); //77 : [m] |
|
102
|
|
|
$this->t128[] = array(2, 4, 1, 1, 1, 2); //78 : [n] |
|
103
|
|
|
$this->t128[] = array(1, 3, 4, 1, 1, 1); //79 : [o] |
|
104
|
|
|
$this->t128[] = array(1, 1, 1, 2, 4, 2); //80 : [p] |
|
105
|
|
|
$this->t128[] = array(1, 2, 1, 1, 4, 2); //81 : [q] |
|
106
|
|
|
$this->t128[] = array(1, 2, 1, 2, 4, 1); //82 : [r] |
|
107
|
|
|
$this->t128[] = array(1, 1, 4, 2, 1, 2); //83 : [s] |
|
108
|
|
|
$this->t128[] = array(1, 2, 4, 1, 1, 2); //84 : [t] |
|
109
|
|
|
$this->t128[] = array(1, 2, 4, 2, 1, 1); //85 : [u] |
|
110
|
|
|
$this->t128[] = array(4, 1, 1, 2, 1, 2); //86 : [v] |
|
111
|
|
|
$this->t128[] = array(4, 2, 1, 1, 1, 2); //87 : [w] |
|
112
|
|
|
$this->t128[] = array(4, 2, 1, 2, 1, 1); //88 : [x] |
|
113
|
|
|
$this->t128[] = array(2, 1, 2, 1, 4, 1); //89 : [y] |
|
114
|
|
|
$this->t128[] = array(2, 1, 4, 1, 2, 1); //90 : [z] |
|
115
|
|
|
$this->t128[] = array(4, 1, 2, 1, 2, 1); //91 : [{] |
|
116
|
|
|
$this->t128[] = array(1, 1, 1, 1, 4, 3); //92 : [|] |
|
117
|
|
|
$this->t128[] = array(1, 1, 1, 3, 4, 1); //93 : [}] |
|
118
|
|
|
$this->t128[] = array(1, 3, 1, 1, 4, 1); //94 : [~] |
|
119
|
|
|
$this->t128[] = array(1, 1, 4, 1, 1, 3); //95 : [DEL] |
|
120
|
|
|
$this->t128[] = array(1, 1, 4, 3, 1, 1); //96 : [FNC3] |
|
121
|
|
|
$this->t128[] = array(4, 1, 1, 1, 1, 3); //97 : [FNC2] |
|
122
|
|
|
$this->t128[] = array(4, 1, 1, 3, 1, 1); //98 : [SHIFT] |
|
123
|
|
|
$this->t128[] = array(1, 1, 3, 1, 4, 1); //99 : [Cswap] |
|
124
|
|
|
$this->t128[] = array(1, 1, 4, 1, 3, 1); //100 : [Bswap] |
|
125
|
|
|
$this->t128[] = array(3, 1, 1, 1, 4, 1); //101 : [Aswap] |
|
126
|
|
|
$this->t128[] = array(4, 1, 1, 1, 3, 1); //102 : [FNC1] |
|
127
|
|
|
$this->t128[] = array(2, 1, 1, 4, 1, 2); //103 : [Astart] |
|
128
|
|
|
$this->t128[] = array(2, 1, 1, 2, 1, 4); //104 : [Bstart] |
|
129
|
|
|
$this->t128[] = array(2, 1, 1, 2, 3, 2); //105 : [Cstart] |
|
130
|
|
|
$this->t128[] = array(2, 3, 3, 1, 1, 1); //106 : [STOP] |
|
131
|
|
|
$this->t128[] = array(2, 1); //107 : [END BAR] |
|
132
|
|
|
for ($i = 32; $i <= 95; $i++) { // conjunto de caracteres |
|
133
|
|
|
$this->abcSet .= chr($i); |
|
134
|
|
|
} |
|
135
|
|
|
$this->aSet = $this->abcSet; |
|
136
|
|
|
$this->bSet = $this->abcSet; |
|
137
|
|
|
for ($i = 0; $i <= 31; $i++) { |
|
138
|
|
|
$this->abcSet .= chr($i); |
|
139
|
|
|
$this->aSet .= chr($i); |
|
140
|
|
|
} |
|
141
|
|
|
for ($i = 96; $i <= 126; $i++) { |
|
142
|
|
|
$this->abcSet .= chr($i); |
|
143
|
|
|
$this->bSet .= chr($i); |
|
144
|
|
|
} |
|
145
|
|
|
$this->cSet="0123456789"; |
|
146
|
|
|
for ($i = 0; $i < 96; $i++) { |
|
147
|
|
|
// convertendo grupos A & B |
|
148
|
|
|
if (isset($this->setFrom["A"])) { |
|
149
|
|
|
$this->setFrom["A"] .= chr($i); |
|
150
|
|
|
} |
|
151
|
|
|
if (isset($this->setFrom["B"])) { |
|
152
|
|
|
$this->setFrom["B"] .= chr($i + 32); |
|
153
|
|
|
} |
|
154
|
|
|
if (isset($this->setTo["A"])) { |
|
155
|
|
|
$this->setTo["A"] .= chr(($i < 32) ? $i+64 : $i-32); |
|
156
|
|
|
} |
|
157
|
|
|
if (isset($this->setTo["A"])) { |
|
158
|
|
|
$this->setTo["B"] .= chr($i); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Imprime barcode 128 |
|
165
|
|
|
*/ |
|
166
|
|
|
public function code128($x, $y, $code, $w, $h) |
|
167
|
|
|
{ |
|
168
|
|
|
$Aguid=""; |
|
169
|
|
|
$Bguid=""; |
|
170
|
|
|
$Cguid=""; |
|
171
|
|
|
for ($i=0; $i < strlen($code); $i++) { |
|
172
|
|
|
$needle=substr($code, $i, 1); |
|
173
|
|
|
$Aguid .= ((strpos($this->aSet, $needle)===false) ? "N" : "O"); |
|
174
|
|
|
$Bguid .= ((strpos($this->bSet, $needle)===false) ? "N" : "O"); |
|
175
|
|
|
$Cguid .= ((strpos($this->cSet, $needle)===false) ? "N" : "O"); |
|
176
|
|
|
} |
|
177
|
|
|
$SminiC = "OOOO"; |
|
178
|
|
|
$IminiC = 4; |
|
179
|
|
|
$crypt = ""; |
|
180
|
|
|
while ($code > "") { |
|
181
|
|
|
$i = strpos($Cguid, $SminiC); |
|
182
|
|
|
if ($i!==false) { |
|
183
|
|
|
$Aguid [$i] = "N"; |
|
184
|
|
|
$Bguid [$i] = "N"; |
|
185
|
|
|
} |
|
186
|
|
|
if (substr($Cguid, 0, $IminiC) == $SminiC) { |
|
187
|
|
|
$crypt .= chr(($crypt > "") ? $this->jSwap["C"] : $this->jStart["C"]); |
|
188
|
|
|
$made = strpos($Cguid, "N"); |
|
189
|
|
|
if ($made === false) { |
|
190
|
|
|
$made = strlen($Cguid); |
|
191
|
|
|
} |
|
192
|
|
|
if (fmod($made, 2)==1) { |
|
193
|
|
|
$made--; |
|
194
|
|
|
} |
|
195
|
|
|
for ($i=0; $i < $made; $i += 2) { |
|
196
|
|
|
$crypt .= chr(strval(substr($code, $i, 2))); |
|
197
|
|
|
} |
|
198
|
|
|
$jeu = "C"; |
|
|
|
|
|
|
199
|
|
|
} else { |
|
200
|
|
|
$madeA = strpos($Aguid, "N"); |
|
201
|
|
|
if ($madeA === false) { |
|
202
|
|
|
$madeA = strlen($Aguid); |
|
203
|
|
|
} |
|
204
|
|
|
$madeB = strpos($Bguid, "N"); |
|
205
|
|
|
if ($madeB === false) { |
|
206
|
|
|
$madeB = strlen($Bguid); |
|
207
|
|
|
} |
|
208
|
|
|
$made = (($madeA < $madeB) ? $madeB : $madeA ); |
|
209
|
|
|
$jeu = (($madeA < $madeB) ? "B" : "A" ); |
|
210
|
|
|
$jeuguid = $jeu . "guid"; |
|
|
|
|
|
|
211
|
|
|
$crypt .= chr(($crypt > "") ? $this->jSwap["$jeu"] : $this->jStart["$jeu"]); |
|
212
|
|
|
$crypt .= strtr(substr($code, 0, $made), $this->setFrom[$jeu], $this->setTo[$jeu]); |
|
213
|
|
|
} |
|
214
|
|
|
$code = substr($code, $made); |
|
215
|
|
|
$Aguid = substr($Aguid, $made); |
|
216
|
|
|
$Bguid = substr($Bguid, $made); |
|
217
|
|
|
$Cguid = substr($Cguid, $made); |
|
218
|
|
|
} |
|
219
|
|
|
$check = ord($crypt[0]); |
|
220
|
|
|
for ($i=0; $i<strlen($crypt); $i++) { |
|
221
|
|
|
$check += (ord($crypt[$i]) * $i); |
|
222
|
|
|
} |
|
223
|
|
|
$check %= 103; |
|
224
|
|
|
$crypt .= chr($check) . chr(106) . chr(107); |
|
225
|
|
|
$i = (strlen($crypt) * 11) - 8; |
|
226
|
|
|
$modul = $w/$i; |
|
227
|
|
|
for ($i=0; $i<strlen($crypt); $i++) { |
|
228
|
|
|
$c = $this->t128[ord($crypt[$i])]; |
|
229
|
|
|
for ($j=0; $j<count($c); $j++) { |
|
|
|
|
|
|
230
|
|
|
$this->Rect($x, $y, $c[$j]*$modul, $h, "F"); |
|
231
|
|
|
$x += ($c[$j++]+$c[$j])*$modul; |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Rotaciona para impressão paisagem (landscape) |
|
238
|
|
|
* @param number $angle |
|
239
|
|
|
* @param number $x |
|
240
|
|
|
* @param number $y |
|
241
|
|
|
*/ |
|
242
|
|
|
public function rotate($angle, $x = -1, $y = -1) |
|
243
|
|
|
{ |
|
244
|
|
|
if ($x == -1) { |
|
245
|
|
|
$x = $this->x; |
|
246
|
|
|
} |
|
247
|
|
|
if ($y == -1) { |
|
248
|
|
|
$y = $this->y; |
|
249
|
|
|
} |
|
250
|
|
|
if (isset($this->angle) && $this->angle != 0) { |
|
|
|
|
|
|
251
|
|
|
$this->out('Q'); |
|
252
|
|
|
} |
|
253
|
|
|
$this->angle = $angle; |
|
254
|
|
|
if ($angle != 0) { |
|
255
|
|
|
$angle *= M_PI/180; |
|
256
|
|
|
$c = cos($angle); |
|
257
|
|
|
$s = sin($angle); |
|
258
|
|
|
$cx =$x*$this->k; |
|
259
|
|
|
$cy = ($this->h-$y)*$this->k; |
|
260
|
|
|
$this->out( |
|
261
|
|
|
sprintf( |
|
262
|
|
|
'q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', |
|
263
|
|
|
$c, |
|
264
|
|
|
$s, |
|
265
|
|
|
-$s, |
|
266
|
|
|
$c, |
|
267
|
|
|
$cx, |
|
268
|
|
|
$cy, |
|
269
|
|
|
-$cx, |
|
270
|
|
|
-$cy |
|
271
|
|
|
) |
|
272
|
|
|
); |
|
273
|
|
|
} |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Desenha um retangulo com cantos arredondados |
|
278
|
|
|
* @param number $x |
|
279
|
|
|
* @param number $y |
|
280
|
|
|
* @param number $w |
|
281
|
|
|
* @param number $h |
|
282
|
|
|
* @param number $r |
|
283
|
|
|
* @param string $corners |
|
284
|
|
|
* @param string $style |
|
285
|
|
|
*/ |
|
286
|
|
|
public function roundedRect($x, $y, $w, $h, $r, $corners = '1234', $style = '') |
|
287
|
|
|
{ |
|
288
|
|
|
$k = $this->k; |
|
289
|
|
|
$hp = $this->h; |
|
290
|
|
|
if ($style == 'F') { |
|
291
|
|
|
$op = 'f'; |
|
292
|
|
|
} elseif ($style == 'FD' || $style == 'DF') { |
|
293
|
|
|
$op = 'B'; |
|
294
|
|
|
} else { |
|
295
|
|
|
$op = 'S'; |
|
296
|
|
|
} |
|
297
|
|
|
$MyArc = 4/3 * (sqrt(2) - 1); |
|
298
|
|
|
$this->out(sprintf('%.2F %.2F m', ($x+$r)*$k, ($hp-$y)*$k)); |
|
299
|
|
|
$xc = $x+$w-$r; |
|
300
|
|
|
$yc = $y+$r; |
|
301
|
|
|
$this->out(sprintf('%.2F %.2F l', $xc*$k, ($hp-$y)*$k)); |
|
302
|
|
|
if (strpos($corners, '2')===false) { |
|
303
|
|
|
$this->out(sprintf('%.2F %.2F l', ($x+$w)*$k, ($hp-$y)*$k)); |
|
304
|
|
|
} else { |
|
305
|
|
|
$this->arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc); |
|
306
|
|
|
} |
|
307
|
|
|
$xc = $x+$w-$r; |
|
308
|
|
|
$yc = $y+$h-$r; |
|
309
|
|
|
$this->out(sprintf('%.2F %.2F l', ($x+$w)*$k, ($hp-$yc)*$k)); |
|
310
|
|
|
if (strpos($corners, '3')===false) { |
|
311
|
|
|
$this->out(sprintf('%.2F %.2F l', ($x+$w)*$k, ($hp-($y+$h))*$k)); |
|
312
|
|
|
} else { |
|
313
|
|
|
$this->arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r); |
|
314
|
|
|
} |
|
315
|
|
|
$xc = $x+$r; |
|
316
|
|
|
$yc = $y+$h-$r; |
|
317
|
|
|
$this->out(sprintf('%.2F %.2F l', $xc*$k, ($hp-($y+$h))*$k)); |
|
318
|
|
|
if (strpos($corners, '4')===false) { |
|
319
|
|
|
$this->out(sprintf('%.2F %.2F l', ($x)*$k, ($hp-($y+$h))*$k)); |
|
320
|
|
|
} else { |
|
321
|
|
|
$this->arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc); |
|
322
|
|
|
} |
|
323
|
|
|
$xc = $x+$r ; |
|
324
|
|
|
$yc = $y+$r; |
|
325
|
|
|
$this->out(sprintf('%.2F %.2F l', ($x)*$k, ($hp-$yc)*$k)); |
|
326
|
|
|
if (strpos($corners, '1')===false) { |
|
327
|
|
|
$this->out(sprintf('%.2F %.2F l', ($x)*$k, ($hp-$y)*$k)); |
|
328
|
|
|
$this->out(sprintf('%.2F %.2F l', ($x+$r)*$k, ($hp-$y)*$k)); |
|
329
|
|
|
} else { |
|
330
|
|
|
$this->arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r); |
|
331
|
|
|
} |
|
332
|
|
|
$this->out($op); |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* Desenha o arco para arredondar o canto do retangulo |
|
337
|
|
|
* @param number $x1 |
|
338
|
|
|
* @param number $y1 |
|
339
|
|
|
* @param number $x2 |
|
340
|
|
|
* @param number $y2 |
|
341
|
|
|
* @param number $x3 |
|
342
|
|
|
* @param number $y3 |
|
343
|
|
|
*/ |
|
344
|
|
|
private function arc($x1, $y1, $x2, $y2, $x3, $y3) |
|
345
|
|
|
{ |
|
346
|
|
|
$h = $this->h; |
|
347
|
|
|
$this->out( |
|
348
|
|
|
sprintf( |
|
349
|
|
|
'%.2F %.2F %.2F %.2F %.2F %.2F c ', |
|
350
|
|
|
$x1*$this->k, |
|
351
|
|
|
($h-$y1)*$this->k, |
|
352
|
|
|
$x2*$this->k, |
|
353
|
|
|
($h-$y2)*$this->k, |
|
354
|
|
|
$x3*$this->k, |
|
355
|
|
|
($h-$y3)*$this->k |
|
356
|
|
|
) |
|
357
|
|
|
); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Desenha um retangulo com linhas tracejadas |
|
362
|
|
|
* @param number $x1 |
|
363
|
|
|
* @param number $y1 |
|
364
|
|
|
* @param number $x2 |
|
365
|
|
|
* @param number $y2 |
|
366
|
|
|
* @param number $width |
|
367
|
|
|
* @param number $nb |
|
368
|
|
|
*/ |
|
369
|
|
|
public function dashedRect($x1, $y1, $x2, $y2, $width = 1, $nb = 15) |
|
370
|
|
|
{ |
|
371
|
|
|
$this->setLineWidth($width); |
|
372
|
|
|
$longueur = abs($x1-$x2); |
|
373
|
|
|
$hauteur = abs($y1-$y2); |
|
374
|
|
|
if ($longueur > $hauteur) { |
|
375
|
|
|
$Pointilles = ($longueur/$nb)/2; |
|
376
|
|
|
} else { |
|
377
|
|
|
$Pointilles = ($hauteur/$nb)/2; |
|
378
|
|
|
} |
|
379
|
|
|
for ($i=$x1; $i<=$x2; $i+=$Pointilles+$Pointilles) { |
|
380
|
|
|
for ($j=$i; $j<=($i+$Pointilles); $j++) { |
|
381
|
|
|
if ($j<=($x2-1)) { |
|
382
|
|
|
$this->line($j, $y1, $j+1, $y1); |
|
383
|
|
|
$this->line($j, $y2, $j+1, $y2); |
|
384
|
|
|
} |
|
385
|
|
|
} |
|
386
|
|
|
} |
|
387
|
|
|
for ($i=$y1; $i<=$y2; $i+=$Pointilles+$Pointilles) { |
|
388
|
|
|
for ($j=$i; $j<=($i+$Pointilles); $j++) { |
|
389
|
|
|
if ($j<=($y2-1)) { |
|
390
|
|
|
$this->line($x1, $j, $x1, $j+1); |
|
391
|
|
|
$this->line($x2, $j, $x2, $j+1); |
|
392
|
|
|
} |
|
393
|
|
|
} |
|
394
|
|
|
} |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
/** |
|
398
|
|
|
* Monta uma caixa de texto |
|
399
|
|
|
* @param string $strText |
|
400
|
|
|
* @param number $w |
|
401
|
|
|
* @param number $h |
|
402
|
|
|
* @param string $align |
|
403
|
|
|
* @param string $valign |
|
404
|
|
|
* @param boolean $border |
|
405
|
|
|
*/ |
|
406
|
|
|
public function drawTextBox($strText, $w, $h, $align = 'L', $valign = 'T', $border = true) |
|
407
|
|
|
{ |
|
408
|
|
|
$xi = $this->getX(); |
|
409
|
|
|
$yi = $this->getY(); |
|
410
|
|
|
$hrow = $this->fontSize; |
|
411
|
|
|
$textrows = $this->drawRows($w, $hrow, $strText, 0, $align, 0, 0, 0); |
|
|
|
|
|
|
412
|
|
|
$maxrows = floor($h/$this->fontSize); |
|
413
|
|
|
$rows = min($textrows, $maxrows); |
|
414
|
|
|
$dy = 0; |
|
415
|
|
|
if (strtoupper($valign) == 'M') { |
|
416
|
|
|
$dy = ($h-$rows*$this->fontSize)/2; |
|
417
|
|
|
} |
|
418
|
|
|
if (strtoupper($valign) == 'B') { |
|
419
|
|
|
$dy = $h-$rows*$this->fontSize; |
|
420
|
|
|
} |
|
421
|
|
|
$this->setY($yi+$dy); |
|
422
|
|
|
$this->setX($xi); |
|
423
|
|
|
$this->drawRows($w, $hrow, $strText, 0, $align, false, $rows, 1); |
|
424
|
|
|
if ($border) { |
|
425
|
|
|
$this->rect($xi, $yi, $w, $h); |
|
426
|
|
|
} |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
/** |
|
430
|
|
|
* Insere linhas de texto na caixa |
|
431
|
|
|
* @param number $w |
|
432
|
|
|
* @param number $h |
|
433
|
|
|
* @param string $txt |
|
434
|
|
|
* @param string $border |
|
435
|
|
|
* @param string $align |
|
436
|
|
|
* @param boolean $fill |
|
437
|
|
|
* @param number $maxline |
|
438
|
|
|
* @param number $prn |
|
439
|
|
|
* @return int |
|
440
|
|
|
*/ |
|
441
|
|
|
private function drawRows($w, $h, $txt, $border = 0, $align = 'J', $fill = false, $maxline = 0, $prn = 0) |
|
442
|
|
|
{ |
|
443
|
|
|
$cw =& $this->currentFont['cw']; |
|
444
|
|
|
if ($w == 0) { |
|
445
|
|
|
$w = $this->w-$this->rMargin-$this->x; |
|
446
|
|
|
} |
|
447
|
|
|
$wmax = ($w-2*$this->cMargin)*1000/$this->fontSize; |
|
448
|
|
|
$s = str_replace("\r", '', $txt); |
|
449
|
|
|
$nb = strlen($s); |
|
450
|
|
|
if ($nb > 0 && $s[$nb-1] == "\n") { |
|
451
|
|
|
$nb--; |
|
452
|
|
|
} |
|
453
|
|
|
$b=0; |
|
454
|
|
|
if ($border) { |
|
455
|
|
|
if ($border == 1) { |
|
456
|
|
|
$border = 'LTRB'; |
|
457
|
|
|
$b = 'LRT'; |
|
458
|
|
|
$b2 = 'LR'; |
|
459
|
|
|
} else { |
|
460
|
|
|
$b2 = ''; |
|
461
|
|
|
if (is_int(strpos($border, 'L'))) { |
|
462
|
|
|
$b2 .= 'L'; |
|
463
|
|
|
} |
|
464
|
|
|
if (is_int(strpos($border, 'R'))) { |
|
465
|
|
|
$b2 .= 'R'; |
|
466
|
|
|
} |
|
467
|
|
|
$b = is_int(strpos($border, 'T')) ? $b2.'T' : $b2; |
|
468
|
|
|
} |
|
469
|
|
|
} |
|
470
|
|
|
$sep = -1; |
|
471
|
|
|
$i = 0; |
|
472
|
|
|
$j = 0; |
|
473
|
|
|
$l = 0; |
|
474
|
|
|
$ns = 0; |
|
475
|
|
|
$nl = 1; |
|
476
|
|
|
while ($i < $nb) { |
|
477
|
|
|
$c = $s[$i]; |
|
478
|
|
|
if ($c == "\n") { |
|
479
|
|
|
if ($this->ws > 0) { |
|
480
|
|
|
$this->ws = 0; |
|
481
|
|
|
if ($prn == 1) { |
|
482
|
|
|
$this->out('0 Tw'); |
|
483
|
|
|
} |
|
484
|
|
|
} |
|
485
|
|
|
if ($prn == 1) { |
|
486
|
|
|
$this->cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill); |
|
487
|
|
|
} |
|
488
|
|
|
$i++; |
|
489
|
|
|
$sep = -1; |
|
490
|
|
|
$j = $i; |
|
491
|
|
|
$l = 0; |
|
492
|
|
|
$ns = 0; |
|
493
|
|
|
$nl++; |
|
494
|
|
|
if ($border && $nl == 2) { |
|
495
|
|
|
$b = $b2; |
|
|
|
|
|
|
496
|
|
|
} |
|
497
|
|
|
if ($maxline && $nl > $maxline) { |
|
498
|
|
|
return substr($s, $i); |
|
499
|
|
|
} |
|
500
|
|
|
continue; |
|
501
|
|
|
} |
|
502
|
|
|
if ($c == ' ') { |
|
503
|
|
|
$sep = $i; |
|
504
|
|
|
$ls = $l; |
|
505
|
|
|
$ns++; |
|
506
|
|
|
} |
|
507
|
|
|
$l += $cw[$c]; |
|
508
|
|
|
if ($l > $wmax) { |
|
509
|
|
|
if ($sep == -1) { |
|
510
|
|
|
if ($i == $j) { |
|
511
|
|
|
$i++; |
|
512
|
|
|
} |
|
513
|
|
|
if ($this->ws > 0) { |
|
514
|
|
|
$this->ws = 0; |
|
515
|
|
|
if ($prn == 1) { |
|
516
|
|
|
$this->out('0 Tw'); |
|
517
|
|
|
} |
|
518
|
|
|
} |
|
519
|
|
|
if ($prn == 1) { |
|
520
|
|
|
$this->cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill); |
|
521
|
|
|
} |
|
522
|
|
|
} else { |
|
523
|
|
|
if ($align == 'J') { |
|
524
|
|
|
$this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
|
|
|
|
|
525
|
|
|
if ($prn == 1) { |
|
526
|
|
|
$this->out(sprintf('%.3F Tw', $this->ws*$this->k)); |
|
527
|
|
|
} |
|
528
|
|
|
} |
|
529
|
|
|
if ($prn == 1) { |
|
530
|
|
|
$this->cell($w, $h, substr($s, $j, $sep-$j), $b, 2, $align, $fill); |
|
531
|
|
|
} |
|
532
|
|
|
$i = $sep+1; |
|
533
|
|
|
} |
|
534
|
|
|
$sep = -1; |
|
535
|
|
|
$j = $i; |
|
536
|
|
|
$l = 0; |
|
537
|
|
|
$ns = 0; |
|
538
|
|
|
$nl++; |
|
539
|
|
|
if ($border && $nl == 2) { |
|
540
|
|
|
$b = $b2; |
|
541
|
|
|
} |
|
542
|
|
|
if ($maxline && $nl > $maxline) { |
|
543
|
|
|
return substr($s, $i); |
|
544
|
|
|
} |
|
545
|
|
|
} else { |
|
546
|
|
|
$i++; |
|
547
|
|
|
} |
|
548
|
|
|
} |
|
549
|
|
|
if ($this->ws > 0) { |
|
550
|
|
|
$this->ws = 0; |
|
551
|
|
|
if ($prn == 1) { |
|
552
|
|
|
$this->out('0 Tw'); |
|
553
|
|
|
} |
|
554
|
|
|
} |
|
555
|
|
|
if ($border && is_int(strpos($border, 'B'))) { |
|
556
|
|
|
$b .= 'B'; |
|
557
|
|
|
} |
|
558
|
|
|
if ($prn == 1) { |
|
559
|
|
|
$this->cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill); |
|
560
|
|
|
} |
|
561
|
|
|
$this->x = $this->lMargin; |
|
562
|
|
|
return $nl; |
|
563
|
|
|
} |
|
564
|
|
|
|
|
565
|
|
|
/** |
|
566
|
|
|
* Quebra o texto para caber na caixa |
|
567
|
|
|
* @param type $text |
|
568
|
|
|
* @param type $maxwidth |
|
569
|
|
|
* @return int |
|
570
|
|
|
*/ |
|
571
|
|
|
public function wordWrap(&$text, $maxwidth) |
|
572
|
|
|
{ |
|
573
|
|
|
$text = trim($text); |
|
574
|
|
|
if ($text === '') { |
|
575
|
|
|
return 0; |
|
576
|
|
|
} |
|
577
|
|
|
$space = $this->getStringWidth(' '); |
|
578
|
|
|
$lines = explode("\n", $text); |
|
579
|
|
|
$text = ''; |
|
580
|
|
|
$count = 0; |
|
581
|
|
|
foreach ($lines as $line) { |
|
582
|
|
|
$words = preg_split('/ +/', $line); |
|
583
|
|
|
$width = 0; |
|
584
|
|
|
foreach ($words as $word) { |
|
585
|
|
|
$wordwidth = $this->getStringWidth($word); |
|
586
|
|
|
if ($wordwidth > $maxwidth) { |
|
587
|
|
|
// Word is too long, we cut it |
|
588
|
|
|
for ($i=0; $i<strlen($word); $i++) { |
|
589
|
|
|
$wordwidth = $this->getStringWidth(substr($word, $i, 1)); |
|
590
|
|
|
if ($width + $wordwidth <= $maxwidth) { |
|
591
|
|
|
$width += $wordwidth; |
|
592
|
|
|
$text .= substr($word, $i, 1); |
|
593
|
|
|
} else { |
|
594
|
|
|
$width = $wordwidth; |
|
595
|
|
|
$text = rtrim($text)."\n".substr($word, $i, 1); |
|
596
|
|
|
$count++; |
|
597
|
|
|
} |
|
598
|
|
|
} |
|
599
|
|
|
} elseif ($width + $wordwidth <= $maxwidth) { |
|
600
|
|
|
$width += $wordwidth + $space; |
|
601
|
|
|
$text .= $word.' '; |
|
602
|
|
|
} else { |
|
603
|
|
|
$width = $wordwidth + $space; |
|
604
|
|
|
$text = rtrim($text)."\n".$word.' '; |
|
605
|
|
|
$count++; |
|
606
|
|
|
} |
|
607
|
|
|
} |
|
608
|
|
|
$text = rtrim($text)."\n"; |
|
609
|
|
|
$count++; |
|
610
|
|
|
} |
|
611
|
|
|
$text = rtrim($text); |
|
612
|
|
|
return $count; |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
/** |
|
616
|
|
|
* Celula com escala horizontal caso o texto seja muito largo |
|
617
|
|
|
* @param number $w |
|
618
|
|
|
* @param number $h |
|
619
|
|
|
* @param string $txt |
|
620
|
|
|
* @param number $border |
|
621
|
|
|
* @param number $ln |
|
622
|
|
|
* @param string $align |
|
623
|
|
|
* @param boolean $fill |
|
624
|
|
|
* @param string $link |
|
625
|
|
|
* @param boolean $scale |
|
626
|
|
|
* @param boolean $force |
|
627
|
|
|
*/ |
|
628
|
|
|
public function cellFit( |
|
629
|
|
|
$w, |
|
630
|
|
|
$h = 0, |
|
631
|
|
|
$txt = '', |
|
632
|
|
|
$border = 0, |
|
633
|
|
|
$ln = 0, |
|
634
|
|
|
$align = '', |
|
635
|
|
|
$fill = false, |
|
636
|
|
|
$link = '', |
|
637
|
|
|
$scale = false, |
|
638
|
|
|
$force = true |
|
639
|
|
|
) { |
|
640
|
|
|
$str_width=$this->getStringWidth($txt); |
|
641
|
|
|
if ($w == 0) { |
|
642
|
|
|
$w = $this->w-$this->rMargin-$this->x; |
|
643
|
|
|
} |
|
644
|
|
|
$ratio = ($w-$this->cMargin*2)/$str_width; |
|
645
|
|
|
$fit = ($ratio < 1 || ($ratio > 1 && $force)); |
|
646
|
|
|
if ($fit) { |
|
647
|
|
|
if ($scale) { |
|
648
|
|
|
//Calcula a escala horizontal |
|
649
|
|
|
$horiz_scale = $ratio*100.0; |
|
650
|
|
|
//Ajusta a escala horizontal |
|
651
|
|
|
$this->out(sprintf('BT %.2F Tz ET', $horiz_scale)); |
|
652
|
|
|
} else { |
|
653
|
|
|
//Calcula o espaçamento de caracteres em pontos |
|
654
|
|
|
$char_space = ($w-$this->cMargin*2-$str_width)/max($this->_MBGetStringLength($txt)-1, 1)*$this->k; |
|
|
|
|
|
|
655
|
|
|
//Ajusta o espaçamento de caracteres |
|
656
|
|
|
$this->out(sprintf('BT %.2F Tc ET', $char_space)); |
|
657
|
|
|
} |
|
658
|
|
|
//Sobrescreve o alinhamento informado (desde que o texto caiba na celula) |
|
659
|
|
|
$align = ''; |
|
660
|
|
|
} |
|
661
|
|
|
//Passa para o método cell |
|
662
|
|
|
$this->cell($w, $h, $txt, $border, $ln, $align, $fill, $link); |
|
663
|
|
|
//Reseta o espaçamento de caracteres e a escala horizontal |
|
664
|
|
|
if ($fit) { |
|
665
|
|
|
$this->out('BT '.($scale ? '100 Tz' : '0 Tc').' ET'); |
|
666
|
|
|
} |
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
/** |
|
670
|
|
|
* Celula com escalamento horizontal somente se necessário |
|
671
|
|
|
* @param number $w |
|
672
|
|
|
* @param number $h |
|
673
|
|
|
* @param string $txt |
|
674
|
|
|
* @param number $border |
|
675
|
|
|
* @param number $ln |
|
676
|
|
|
* @param string $align |
|
677
|
|
|
* @param boolean $fill |
|
678
|
|
|
* @param string $link |
|
679
|
|
|
*/ |
|
680
|
|
|
public function cellFitScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '') |
|
681
|
|
|
{ |
|
682
|
|
|
$this->cellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, true, false); |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
/** |
|
686
|
|
|
* Celula com escalamento forçado |
|
687
|
|
|
* @param number $w |
|
688
|
|
|
* @param number $h |
|
689
|
|
|
* @param string $txt |
|
690
|
|
|
* @param number $border |
|
691
|
|
|
* @param number $ln |
|
692
|
|
|
* @param string $align |
|
693
|
|
|
* @param boolean $fill |
|
694
|
|
|
* @param string $link |
|
695
|
|
|
*/ |
|
696
|
|
|
public function cellFitScaleForce( |
|
697
|
|
|
$w, |
|
698
|
|
|
$h = 0, |
|
699
|
|
|
$txt = '', |
|
700
|
|
|
$border = 0, |
|
701
|
|
|
$ln = 0, |
|
702
|
|
|
$align = '', |
|
703
|
|
|
$fill = false, |
|
704
|
|
|
$link = '' |
|
705
|
|
|
) { |
|
706
|
|
|
$this->cellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, true, true); |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
/** |
|
710
|
|
|
* Celula com espaçamento de caracteres somente se necessário |
|
711
|
|
|
* @param number $w |
|
712
|
|
|
* @param number $h |
|
713
|
|
|
* @param string $txt |
|
714
|
|
|
* @param number $border |
|
715
|
|
|
* @param number $ln |
|
716
|
|
|
* @param string $align |
|
717
|
|
|
* @param boolean $fill |
|
718
|
|
|
* @param string $link |
|
719
|
|
|
*/ |
|
720
|
|
|
public function cellFitSpace($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '') |
|
721
|
|
|
{ |
|
722
|
|
|
$this->cellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, false, false); |
|
723
|
|
|
} |
|
724
|
|
|
|
|
725
|
|
|
/** |
|
726
|
|
|
* Celula com espaçamento de caracteres forçado |
|
727
|
|
|
* @param number $w |
|
728
|
|
|
* @param number $h |
|
729
|
|
|
* @param string $txt |
|
730
|
|
|
* @param number $border |
|
731
|
|
|
* @param number $ln |
|
732
|
|
|
* @param string $align |
|
733
|
|
|
* @param boolean $fill |
|
734
|
|
|
* @param string $link |
|
735
|
|
|
*/ |
|
736
|
|
|
public function cellFitSpaceForce( |
|
737
|
|
|
$w, |
|
738
|
|
|
$h = 0, |
|
739
|
|
|
$txt = '', |
|
740
|
|
|
$border = 0, |
|
741
|
|
|
$ln = 0, |
|
742
|
|
|
$align = '', |
|
743
|
|
|
$fill = false, |
|
744
|
|
|
$link = '' |
|
745
|
|
|
) { |
|
746
|
|
|
$this->cellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, false, true); |
|
747
|
|
|
} |
|
748
|
|
|
|
|
749
|
|
|
/** |
|
750
|
|
|
* Patch para trabalhar com textos de duplo byte CJK |
|
751
|
|
|
* @param string $s |
|
752
|
|
|
* @return int |
|
753
|
|
|
*/ |
|
754
|
|
|
private function mbGetStringLength($s) |
|
755
|
|
|
{ |
|
756
|
|
|
if ($this->currentFont['type'] == 'Type0') { |
|
757
|
|
|
$len = 0; |
|
758
|
|
|
$nbbytes = strlen($s); |
|
759
|
|
|
for ($i = 0; $i < $nbbytes; $i++) { |
|
760
|
|
|
if (ord($s[$i])<128) { |
|
761
|
|
|
$len++; |
|
762
|
|
|
} else { |
|
763
|
|
|
$len++; |
|
764
|
|
|
$i++; |
|
765
|
|
|
} |
|
766
|
|
|
} |
|
767
|
|
|
return $len; |
|
768
|
|
|
} else { |
|
769
|
|
|
return strlen($s); |
|
770
|
|
|
} |
|
771
|
|
|
} |
|
772
|
|
|
|
|
773
|
|
|
/** |
|
774
|
|
|
* Desenha uma linha horizontal tracejada com o FPDF |
|
775
|
|
|
* @param number $x Posição horizontal inicial, em mm |
|
776
|
|
|
* @param number $y Posição vertical inicial, em mm |
|
777
|
|
|
* @param number $w Comprimento da linha, em mm |
|
778
|
|
|
* @param number $h Espessura da linha, em mm |
|
779
|
|
|
* @param number $n Numero de traços na seção da linha com o comprimento $w |
|
780
|
|
|
* @return none |
|
781
|
|
|
*/ |
|
782
|
|
|
public function dashedHLine($x, $y, $w, $h, $n) |
|
783
|
|
|
{ |
|
784
|
|
|
$this->setDrawColor(110); |
|
785
|
|
|
$this->setLineWidth($h); |
|
786
|
|
|
$wDash = ($w/$n)/2; |
|
787
|
|
|
for ($i=$x; $i<=$x+$w; $i += $wDash+$wDash) { |
|
788
|
|
|
for ($j=$i; $j<= ($i+$wDash); $j++) { |
|
789
|
|
|
if ($j <= ($x+$w-1)) { |
|
790
|
|
|
$this->line($j, $y, $j+1, $y); |
|
791
|
|
|
} |
|
792
|
|
|
} |
|
793
|
|
|
} |
|
794
|
|
|
$this->setDrawColor(0); |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
/** |
|
798
|
|
|
* Desenha uma linha vertical tracejada com o FPDF |
|
799
|
|
|
* @param number $x Posição horizontal inicial, em mm |
|
800
|
|
|
* @param number $y Posição vertical inicial, em mm |
|
801
|
|
|
* @param number $w Comprimento da linha, em mm |
|
802
|
|
|
* @param number $yfinal Espessura da linha, em mm |
|
803
|
|
|
* @param number $n Numero de traços na seção da linha com o comprimento $w |
|
804
|
|
|
* @return none |
|
805
|
|
|
*/ |
|
806
|
|
|
public function dashedVLine($x, $y, $w, $yfinal, $n) |
|
807
|
|
|
{ |
|
808
|
|
|
$this->setLineWidth($w); |
|
809
|
|
|
if ($y > $yfinal) { |
|
810
|
|
|
$aux = $yfinal; |
|
811
|
|
|
$yfinal = $y; |
|
812
|
|
|
$y = $aux; |
|
813
|
|
|
} |
|
814
|
|
|
while ($y < $yfinal && $n > 0) { |
|
815
|
|
|
$this->line($x, $y, $x, $y+1); |
|
816
|
|
|
$y += 3; |
|
817
|
|
|
$n--; |
|
818
|
|
|
} |
|
819
|
|
|
} |
|
820
|
|
|
|
|
821
|
|
|
/** |
|
822
|
|
|
* pGetNumLines |
|
823
|
|
|
* Obtem o numero de linhas usadas pelo texto usando a fonte especifidada |
|
824
|
|
|
* @param string $text |
|
825
|
|
|
* @param number $width |
|
826
|
|
|
* @param array $aFont |
|
827
|
|
|
* @return number numero de linhas |
|
828
|
|
|
*/ |
|
829
|
|
|
public function getNumLines($text, $width, $aFont = ['font' => 'Times', 'size' => 8, 'style' => '']) |
|
830
|
|
|
{ |
|
831
|
|
|
$text = trim($text); |
|
832
|
|
|
$this->setFont($aFont['font'], $aFont['style'], $aFont['size']); |
|
833
|
|
|
$n = $this->wordWrap($text, $width - 0.2); |
|
|
|
|
|
|
834
|
|
|
return $n; |
|
835
|
|
|
} |
|
836
|
|
|
|
|
837
|
|
|
/** |
|
838
|
|
|
* pTextBox |
|
839
|
|
|
* Cria uma caixa de texto com ou sem bordas. Esta função perimite o alinhamento horizontal |
|
840
|
|
|
* ou vertical do texto dentro da caixa. |
|
841
|
|
|
* Atenção : Esta função é dependente de outras classes de FPDF |
|
842
|
|
|
* Ex. $this->pTextBox(2,20,34,8,'Texto',array('fonte'=>$this->fontePadrao, |
|
843
|
|
|
* 'size'=>10,'style='B'),'C','L',FALSE,'http://www.nfephp.org') |
|
844
|
|
|
* |
|
845
|
|
|
* @param number $x Posição horizontal da caixa, canto esquerdo superior |
|
846
|
|
|
* @param number $y Posição vertical da caixa, canto esquerdo superior |
|
847
|
|
|
* @param number $w Largura da caixa |
|
848
|
|
|
* @param number $h Altura da caixa |
|
849
|
|
|
* @param string $text Conteúdo da caixa |
|
850
|
|
|
* @param array $aFont Matriz com as informações para formatação do texto com fonte, tamanho e estilo |
|
851
|
|
|
* @param string $vAlign Alinhamento vertical do texto, T-topo C-centro B-base |
|
852
|
|
|
* @param string $hAlign Alinhamento horizontal do texto, L-esquerda, C-centro, R-direita |
|
853
|
|
|
* @param boolean $border TRUE ou 1 desenha a borda, FALSE ou 0 Sem borda |
|
854
|
|
|
* @param string $link Insere um hiperlink |
|
855
|
|
|
* @param boolean $force Se for true força a caixa com uma unica linha e para isso atera o tamanho do |
|
856
|
|
|
* fonte até caber no espaço, se falso mantem o tamanho do fonte e usa quantas linhas forem necessárias |
|
857
|
|
|
* e para isso atera o tamanho do fonte até caber no espaço, |
|
858
|
|
|
* se falso mantem o tamanho do fonte e usa quantas linhas forem necessárias |
|
859
|
|
|
* @param number $hmax |
|
860
|
|
|
* @param number $vOffSet incremento forçado na na posição Y |
|
861
|
|
|
* @return number $height Qual a altura necessária para desenhar esta textBox |
|
862
|
|
|
*/ |
|
863
|
|
|
public function textBox( |
|
864
|
|
|
$x, |
|
865
|
|
|
$y, |
|
866
|
|
|
$w, |
|
867
|
|
|
$h, |
|
868
|
|
|
$text = '', |
|
869
|
|
|
$aFont = array('font' => 'Times', 'size' => 8, 'style' => ''), |
|
870
|
|
|
$vAlign = 'T', |
|
871
|
|
|
$hAlign = 'L', |
|
872
|
|
|
$border = 1, |
|
873
|
|
|
$link = '', |
|
|
|
|
|
|
874
|
|
|
$force = true, |
|
875
|
|
|
$hmax = 0, |
|
876
|
|
|
$vOffSet = 0 |
|
877
|
|
|
) { |
|
878
|
|
|
$oldY = $y; |
|
879
|
|
|
$temObs = false; |
|
|
|
|
|
|
880
|
|
|
$resetou = false; |
|
881
|
|
|
if ($w < 0) { |
|
882
|
|
|
return $y; |
|
883
|
|
|
} |
|
884
|
|
|
if (is_object($text)) { |
|
885
|
|
|
$text = ''; |
|
886
|
|
|
} |
|
887
|
|
|
if (is_string($text)) { |
|
888
|
|
|
//remover espaços desnecessários |
|
889
|
|
|
$text = trim($text); |
|
890
|
|
|
//converter o charset para o fpdf |
|
891
|
|
|
$text = utf8_decode($text); |
|
892
|
|
|
//decodifica os caracteres html no xml |
|
893
|
|
|
$text = html_entity_decode($text); |
|
894
|
|
|
} else { |
|
895
|
|
|
$text = (string) $text; |
|
896
|
|
|
} |
|
897
|
|
|
//desenhar a borda da caixa |
|
898
|
|
|
if ($border) { |
|
899
|
|
|
$this->roundedRect($x, $y, $w, $h, 0.8, '1234', 'D'); |
|
900
|
|
|
} |
|
901
|
|
|
//estabelecer o fonte |
|
902
|
|
|
$this->setFont($aFont['font'], $aFont['style'], $aFont['size']); |
|
903
|
|
|
//calcular o incremento |
|
904
|
|
|
$incY = $this->fontSize; //tamanho da fonte na unidade definida |
|
905
|
|
|
if (!$force) { |
|
906
|
|
|
//verificar se o texto cabe no espaço |
|
907
|
|
|
$n = $this->wordWrap($text, $w); |
|
|
|
|
|
|
908
|
|
|
} else { |
|
909
|
|
|
$n = 1; |
|
910
|
|
|
} |
|
911
|
|
|
//calcular a altura do conjunto de texto |
|
912
|
|
|
$altText = $incY * $n; |
|
913
|
|
|
//separar o texto em linhas |
|
914
|
|
|
$lines = explode("\n", $text); |
|
915
|
|
|
//verificar o alinhamento vertical |
|
916
|
|
|
if ($vAlign == 'T') { |
|
917
|
|
|
//alinhado ao topo |
|
918
|
|
|
$y1 = $y + $incY; |
|
919
|
|
|
} |
|
920
|
|
|
if ($vAlign == 'C') { |
|
921
|
|
|
//alinhado ao centro |
|
922
|
|
|
$y1 = $y + $incY + (($h - $altText) / 2); |
|
923
|
|
|
} |
|
924
|
|
|
if ($vAlign == 'B') { |
|
925
|
|
|
//alinhado a base |
|
926
|
|
|
$y1 = ($y + $h) - 0.5; |
|
927
|
|
|
} |
|
928
|
|
|
//para cada linha |
|
929
|
|
|
foreach ($lines as $line) { |
|
930
|
|
|
//verificar o comprimento da frase |
|
931
|
|
|
$texto = trim($line); |
|
932
|
|
|
$comp = $this->getStringWidth($texto); |
|
933
|
|
|
if ($force) { |
|
934
|
|
|
$newSize = $aFont['size']; |
|
935
|
|
|
while ($comp > $w) { |
|
936
|
|
|
//estabelecer novo fonte |
|
937
|
|
|
$this->setFont($aFont['font'], $aFont['style'], --$newSize); |
|
938
|
|
|
$comp = $this->getStringWidth($texto); |
|
939
|
|
|
} |
|
940
|
|
|
} |
|
941
|
|
|
//ajustar ao alinhamento horizontal |
|
942
|
|
|
if ($hAlign == 'L') { |
|
943
|
|
|
$x1 = $x + 0.5; |
|
944
|
|
|
} |
|
945
|
|
|
if ($hAlign == 'C') { |
|
946
|
|
|
$x1 = $x + (($w - $comp) / 2); |
|
947
|
|
|
} |
|
948
|
|
|
if ($hAlign == 'R') { |
|
949
|
|
|
$x1 = $x + $w - ($comp + 0.5); |
|
950
|
|
|
} |
|
951
|
|
|
//escrever o texto |
|
952
|
|
|
if ($vOffSet > 0) { |
|
953
|
|
|
if ($y1 > ($oldY + $vOffSet)) { |
|
954
|
|
|
if (!$resetou) { |
|
955
|
|
|
$y1 = $oldY; |
|
956
|
|
|
$resetou = true; |
|
957
|
|
|
} |
|
958
|
|
|
$this->text($x1, $y1, $texto); |
|
|
|
|
|
|
959
|
|
|
} |
|
960
|
|
|
} else { |
|
961
|
|
|
$this->text($x1, $y1, $texto); |
|
962
|
|
|
} |
|
963
|
|
|
//incrementar para escrever o proximo |
|
964
|
|
|
$y1 += $incY; |
|
965
|
|
|
if (($hmax > 0) && ($y1 > ($y + ($hmax - 1)))) { |
|
966
|
|
|
$temObs = true; |
|
|
|
|
|
|
967
|
|
|
break; |
|
968
|
|
|
} |
|
969
|
|
|
} |
|
970
|
|
|
return ($y1 - $y) - $incY; |
|
971
|
|
|
} |
|
972
|
|
|
|
|
973
|
|
|
/** |
|
974
|
|
|
* Cria uma caixa de texto com ou sem bordas. Esta função permite o alinhamento horizontal |
|
975
|
|
|
* ou vertical do texto dentro da caixa, rotacionando-o em 90 graus, essa função precisa que |
|
976
|
|
|
* a classe PDF contenha a função Rotate($angle,$x,$y); |
|
977
|
|
|
* Atenção : Esta função é dependente de outras classes de FPDF |
|
978
|
|
|
* Ex. $this->__textBox90(2,20,34,8,'Texto',array('fonte'=>$this->fontePadrao, |
|
979
|
|
|
* 'size'=>10,'style='B'),'C','L',FALSE,'http://www.nfephp.org') |
|
980
|
|
|
* @param number $x Posição horizontal da caixa, canto esquerdo superior |
|
981
|
|
|
* @param number $y Posição vertical da caixa, canto esquerdo superior |
|
982
|
|
|
* @param number $w Largura da caixa |
|
983
|
|
|
* @param number $h Altura da caixa |
|
984
|
|
|
* @param string $text Conteúdo da caixa |
|
985
|
|
|
* @param array $aFont Matriz com as informações para formatação do texto com fonte, tamanho e estilo |
|
986
|
|
|
* @param string $vAlign Alinhamento vertical do texto, T-topo C-centro B-base |
|
987
|
|
|
* @param string $hAlign Alinhamento horizontal do texto, L-esquerda, C-centro, R-direita |
|
988
|
|
|
* @param boolean $border TRUE ou 1 desenha a borda, FALSE ou 0 Sem borda |
|
989
|
|
|
* @param string $link Insere um hiperlink |
|
990
|
|
|
* @param boolean $force Se for true força a caixa com uma unica linha e para isso atera o tamanho do |
|
991
|
|
|
* fonte até caber no espaço, se falso mantem o tamanho do fonte e usa quantas linhas forem necessárias |
|
992
|
|
|
* linha e para isso atera o tamanho do fonte até caber no espaço, |
|
993
|
|
|
* se falso mantem o tamanho do fonte e usa quantas linhas forem necessárias |
|
994
|
|
|
* @param number $hmax |
|
995
|
|
|
* @param number $vOffSet incremento forçado na na posição Y |
|
996
|
|
|
* @return number $height Qual a altura necessária para desenhar esta textBox |
|
997
|
|
|
*/ |
|
998
|
|
|
protected function textBox90( |
|
999
|
|
|
$x, |
|
1000
|
|
|
$y, |
|
1001
|
|
|
$w, |
|
1002
|
|
|
$h, |
|
1003
|
|
|
$text = '', |
|
1004
|
|
|
$aFont = array('font' => 'Times', 'size' => 8, 'style' => ''), |
|
1005
|
|
|
$vAlign = 'T', |
|
1006
|
|
|
$hAlign = 'L', |
|
1007
|
|
|
$border = 1, |
|
1008
|
|
|
$link = '', |
|
|
|
|
|
|
1009
|
|
|
$force = true, |
|
1010
|
|
|
$hmax = 0, |
|
1011
|
|
|
$vOffSet = 0 |
|
1012
|
|
|
) { |
|
1013
|
|
|
$this->rotate(90, $x, $y); |
|
1014
|
|
|
$oldY = $y; |
|
1015
|
|
|
$temObs = false; |
|
|
|
|
|
|
1016
|
|
|
$resetou = false; |
|
1017
|
|
|
if ($w < 0) { |
|
1018
|
|
|
return $y; |
|
1019
|
|
|
} |
|
1020
|
|
|
if (is_object($text)) { |
|
1021
|
|
|
$text = ''; |
|
1022
|
|
|
} |
|
1023
|
|
|
if (is_string($text)) { |
|
1024
|
|
|
//remover espaços desnecessários |
|
1025
|
|
|
$text = trim($text); |
|
1026
|
|
|
//converter o charset para o fpdf |
|
1027
|
|
|
$text = utf8_decode($text); |
|
1028
|
|
|
//decodifica os caracteres html no xml |
|
1029
|
|
|
$text = html_entity_decode($text); |
|
1030
|
|
|
} else { |
|
1031
|
|
|
$text = (string) $text; |
|
1032
|
|
|
} |
|
1033
|
|
|
//desenhar a borda da caixa |
|
1034
|
|
|
if ($border) { |
|
1035
|
|
|
$this->roundedRect($x, $y, $w, $h, 0.8, '1234', 'D'); |
|
1036
|
|
|
} |
|
1037
|
|
|
//estabelecer o fonte |
|
1038
|
|
|
$this->setFont($aFont['font'], $aFont['style'], $aFont['size']); |
|
1039
|
|
|
//calcular o incremento |
|
1040
|
|
|
$incY = $this->fontSize; //tamanho da fonte na unidade definida |
|
1041
|
|
|
if (!$force) { |
|
1042
|
|
|
//verificar se o texto cabe no espaço |
|
1043
|
|
|
$n = $this->wordWrap($text, $w); |
|
|
|
|
|
|
1044
|
|
|
} else { |
|
1045
|
|
|
$n = 1; |
|
1046
|
|
|
} |
|
1047
|
|
|
//calcular a altura do conjunto de texto |
|
1048
|
|
|
$altText = $incY * $n; |
|
1049
|
|
|
//separar o texto em linhas |
|
1050
|
|
|
$lines = explode("\n", $text); |
|
1051
|
|
|
//verificar o alinhamento vertical |
|
1052
|
|
|
if ($vAlign == 'T') { |
|
1053
|
|
|
//alinhado ao topo |
|
1054
|
|
|
$y1 = $y + $incY; |
|
1055
|
|
|
} |
|
1056
|
|
|
if ($vAlign == 'C') { |
|
1057
|
|
|
//alinhado ao centro |
|
1058
|
|
|
$y1 = $y + $incY + (($h - $altText) / 2); |
|
1059
|
|
|
} |
|
1060
|
|
|
if ($vAlign == 'B') { |
|
1061
|
|
|
//alinhado a base |
|
1062
|
|
|
$y1 = ($y + $h) - 0.5; |
|
1063
|
|
|
} |
|
1064
|
|
|
//para cada linha |
|
1065
|
|
|
foreach ($lines as $line) { |
|
1066
|
|
|
//verificar o comprimento da frase |
|
1067
|
|
|
$texto = trim($line); |
|
1068
|
|
|
$comp = $this->getStringWidth($texto); |
|
1069
|
|
|
if ($force) { |
|
1070
|
|
|
$newSize = $aFont['size']; |
|
1071
|
|
|
while ($comp > $w) { |
|
1072
|
|
|
//estabelecer novo fonte |
|
1073
|
|
|
$this->setFont($aFont['font'], $aFont['style'], --$newSize); |
|
1074
|
|
|
$comp = $this->getStringWidth($texto); |
|
1075
|
|
|
} |
|
1076
|
|
|
} |
|
1077
|
|
|
//ajustar ao alinhamento horizontal |
|
1078
|
|
|
if ($hAlign == 'L') { |
|
1079
|
|
|
$x1 = $x + 0.5; |
|
1080
|
|
|
} |
|
1081
|
|
|
if ($hAlign == 'C') { |
|
1082
|
|
|
$x1 = $x + (($w - $comp) / 2); |
|
1083
|
|
|
} |
|
1084
|
|
|
if ($hAlign == 'R') { |
|
1085
|
|
|
$x1 = $x + $w - ($comp + 0.5); |
|
1086
|
|
|
} |
|
1087
|
|
|
//escrever o texto |
|
1088
|
|
|
if ($vOffSet > 0) { |
|
1089
|
|
|
if ($y1 > ($oldY + $vOffSet)) { |
|
1090
|
|
|
if (!$resetou) { |
|
1091
|
|
|
$y1 = $oldY; |
|
1092
|
|
|
$resetou = true; |
|
1093
|
|
|
} |
|
1094
|
|
|
$this->text($x1, $y1, $texto); |
|
|
|
|
|
|
1095
|
|
|
} |
|
1096
|
|
|
} else { |
|
1097
|
|
|
$this->text($x1, $y1, $texto); |
|
1098
|
|
|
} |
|
1099
|
|
|
//incrementar para escrever o proximo |
|
1100
|
|
|
$y1 += $incY; |
|
1101
|
|
|
if (($hmax > 0) && ($y1 > ($y + ($hmax - 1)))) { |
|
1102
|
|
|
$temObs = true; |
|
|
|
|
|
|
1103
|
|
|
break; |
|
1104
|
|
|
} |
|
1105
|
|
|
} |
|
1106
|
|
|
//Zerando rotação |
|
1107
|
|
|
$this->rotate(0, $x, $y); |
|
1108
|
|
|
return ($y1 - $y) - $incY; |
|
1109
|
|
|
} |
|
1110
|
|
|
} |
|
1111
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.