1 | <?php
|
---|
2 | /**
|
---|
3 | * HTML2PDF Librairy - myPdf class
|
---|
4 | *
|
---|
5 | * HTML => PDF convertor
|
---|
6 | * distributed under the LGPL License
|
---|
7 | *
|
---|
8 | * @author Laurent MINGUET <webmaster@html2pdf.fr>
|
---|
9 | * @version 4.03
|
---|
10 | */
|
---|
11 |
|
---|
12 | require_once(dirname(__FILE__).'/tcpdfConfig.php');
|
---|
13 | require_once(dirname(__FILE__).'/../_tcpdf_'.HTML2PDF_USED_TCPDF_VERSION.'/tcpdf.php');
|
---|
14 |
|
---|
15 | class HTML2PDF_myPdf extends TCPDF
|
---|
16 | {
|
---|
17 | protected $_footerParam = array();
|
---|
18 | protected $_transf = array();
|
---|
19 | protected $_myLastPageGroup = null;
|
---|
20 | protected $_myLastPageGroupNb = 0;
|
---|
21 |
|
---|
22 | // used to make a radius with bezier : (4/3 * (sqrt(2) - 1))
|
---|
23 | const MY_ARC = 0.5522847498;
|
---|
24 |
|
---|
25 | // nb of segment to build a arc with bezier curv
|
---|
26 | const ARC_NB_SEGMENT = 8;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * class constructor
|
---|
30 | *
|
---|
31 | * @param string $orientation page orientation, same as TCPDF
|
---|
32 | * @param string $unit User measure unit, same as TCPDF
|
---|
33 | * @param mixed $format The format used for pages, same as TCPDF
|
---|
34 | * @param boolean $unicode TRUE means that the input text is unicode (default = true)
|
---|
35 | * @param String $encoding charset encoding; default is UTF-8
|
---|
36 | * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
|
---|
37 | * @access public
|
---|
38 | */
|
---|
39 | public function __construct(
|
---|
40 | $orientation='P',
|
---|
41 | $unit='mm',
|
---|
42 | $format='A4',
|
---|
43 | $unicode=true,
|
---|
44 | $encoding='UTF-8',
|
---|
45 | $diskcache=false)
|
---|
46 | {
|
---|
47 | // call the parent constructor
|
---|
48 | parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache);
|
---|
49 |
|
---|
50 | // init the specific parameters used by HTML2PDF
|
---|
51 | $this->SetCreator(PDF_CREATOR);
|
---|
52 | $this->SetAutoPageBreak(false, 0);
|
---|
53 | $this->linestyleCap = '2 J';
|
---|
54 | $this->setPrintHeader(false);
|
---|
55 | $this->jpeg_quality = 90;
|
---|
56 |
|
---|
57 | // prepare the automatic footer
|
---|
58 | $this->SetMyFooter();
|
---|
59 |
|
---|
60 | $this->cMargin = 0;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Set the parameters for the automatic footer
|
---|
65 | *
|
---|
66 | * @param boolean $page display the page number
|
---|
67 | * @param boolean $date display the date
|
---|
68 | * @param boolean $hour display the hour
|
---|
69 | * @param boolean $form display a warning abour forms
|
---|
70 | * @access public
|
---|
71 | */
|
---|
72 | public function SetMyFooter($page = false, $date = false, $hour = false, $form = false)
|
---|
73 | {
|
---|
74 | $page = ($page ? true : false);
|
---|
75 | $date = ($date ? true : false);
|
---|
76 | $hour = ($hour ? true : false);
|
---|
77 | $form = ($form ? true : false);
|
---|
78 |
|
---|
79 | $this->_footerParam = array('page' => $page, 'date' => $date, 'hour' => $hour, 'form' => $form);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * This function is call automatically by TCPDF at the end of a page
|
---|
84 | * It takes no parameters
|
---|
85 | *
|
---|
86 | * @access public
|
---|
87 | */
|
---|
88 | public function Footer()
|
---|
89 | {
|
---|
90 | // prepare the text from the tranlated text
|
---|
91 | $txt = '';
|
---|
92 | if ($this->_footerParam['form']) {
|
---|
93 | $txt = (HTML2PDF_locale::get('pdf05'));
|
---|
94 | }
|
---|
95 | if ($this->_footerParam['date'] && $this->_footerParam['hour']) {
|
---|
96 | $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf03'));
|
---|
97 | }
|
---|
98 | if ($this->_footerParam['date'] && !$this->_footerParam['hour']) {
|
---|
99 | $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf01'));
|
---|
100 | }
|
---|
101 | if (!$this->_footerParam['date'] && $this->_footerParam['hour']) {
|
---|
102 | $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf02'));
|
---|
103 | }
|
---|
104 | if ($this->_footerParam['page']) {
|
---|
105 | $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf04'));
|
---|
106 | }
|
---|
107 |
|
---|
108 | if (strlen($txt)>0) {
|
---|
109 | // replace some values
|
---|
110 | $toReplace = array(
|
---|
111 | '[[date_d]]' => date('d'),
|
---|
112 | '[[date_m]]' => date('m'),
|
---|
113 | '[[date_y]]' => date('Y'),
|
---|
114 | '[[date_h]]' => date('H'),
|
---|
115 | '[[date_i]]' => date('i'),
|
---|
116 | '[[date_s]]' => date('s'),
|
---|
117 | '[[page_cu]]' => $this->getMyNumPage(),
|
---|
118 | '[[page_nb]]' => $this->getMyAliasNbPages(),
|
---|
119 | );
|
---|
120 | $txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt);
|
---|
121 |
|
---|
122 | // draw the footer
|
---|
123 | parent::SetY(-11);
|
---|
124 | $this->SetFont('helvetica', 'I', 8);
|
---|
125 | $this->Cell(0, 10, $txt, 0, 0, 'R');
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * after cloning a object, we does not want to clone all the front informations
|
---|
131 | * because it take a lot a time and a lot of memory => we use reference
|
---|
132 | *
|
---|
133 | * @param &HTML2PDF_myPdf object
|
---|
134 | * @access public
|
---|
135 | */
|
---|
136 | public function cloneFontFrom(&$pdf)
|
---|
137 | {
|
---|
138 | $this->fonts = &$pdf->getFonts();
|
---|
139 | $this->FontFiles = &$pdf->getFontFiles();
|
---|
140 | $this->diffs = &$pdf->getDiffs();
|
---|
141 | $this->fontlist = &$pdf->getFontList();
|
---|
142 | $this->numfonts = &$pdf->getNumFonts();
|
---|
143 | $this->fontkeys = &$pdf->getFontKeys();
|
---|
144 | $this->font_obj_ids = &$pdf->getFontObjIds();
|
---|
145 | $this->annotation_fonts = &$pdf->getAnnotFonts();
|
---|
146 | }
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * multiple public accessor for some private attributs
|
---|
150 | * used only by cloneFontFrom
|
---|
151 | *
|
---|
152 | * @return &array
|
---|
153 | * @access public
|
---|
154 | */
|
---|
155 | public function &getFonts()
|
---|
156 | {
|
---|
157 | return $this->fonts;
|
---|
158 | }
|
---|
159 | public function &getFontFiles()
|
---|
160 | {
|
---|
161 | return $this->FontFiles;
|
---|
162 | }
|
---|
163 | public function &getDiffs()
|
---|
164 | {
|
---|
165 | return $this->diffs;
|
---|
166 | }
|
---|
167 | public function &getFontList()
|
---|
168 | {
|
---|
169 | return $this->fontlist;
|
---|
170 | }
|
---|
171 | public function &getNumFonts()
|
---|
172 | {
|
---|
173 | return $this->numfonts;
|
---|
174 | }
|
---|
175 | public function &getFontKeys()
|
---|
176 | {
|
---|
177 | return $this->fontkeys;
|
---|
178 | }
|
---|
179 | public function &getFontObjIds()
|
---|
180 | {
|
---|
181 | return $this->font_obj_ids;
|
---|
182 | }
|
---|
183 | public function &getAnnotFonts()
|
---|
184 | {
|
---|
185 | return $this->annotation_fonts;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Verify that a Font is already loaded
|
---|
190 | *
|
---|
191 | * @param string Font Key
|
---|
192 | * @return boolean
|
---|
193 | * @access public
|
---|
194 | */
|
---|
195 | public function isLoadedFont($fontKey)
|
---|
196 | {
|
---|
197 | if (isset($this->fonts[$fontKey])) {
|
---|
198 | return true;
|
---|
199 | }
|
---|
200 |
|
---|
201 | if (isset($this->CoreFonts[$fontKey])) {
|
---|
202 | return true;
|
---|
203 | }
|
---|
204 |
|
---|
205 | return false;
|
---|
206 | }
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Get the Word Spacing
|
---|
210 | *
|
---|
211 | * @access public
|
---|
212 | * @return float word spacing
|
---|
213 | */
|
---|
214 | public function getWordSpacing()
|
---|
215 | {
|
---|
216 | return $this->ws;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * set the Word Spacing
|
---|
221 | *
|
---|
222 | * @param float word spacing
|
---|
223 | * @access public
|
---|
224 | */
|
---|
225 | public function setWordSpacing($ws=0.)
|
---|
226 | {
|
---|
227 | $this->ws = $ws;
|
---|
228 | $this->_out(sprintf('%.3F Tw', $ws*$this->k));
|
---|
229 | }
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * start to use a rectangular Cliping Path with radius corners
|
---|
233 | *
|
---|
234 | * @param float $x (top left corner)
|
---|
235 | * @param float $y (top left corner)
|
---|
236 | * @param float $w (x+w = botom rigth corner)
|
---|
237 | * @param float $h (y+h = botom rigth corner)
|
---|
238 | * @param array $cornerTL radius of the Top Left corner
|
---|
239 | * @param array $cornerTR radius of the Top Right corner
|
---|
240 | * @param array $cornerBL radius of the Bottom Left corner
|
---|
241 | * @param array $cornerBR radius of the Bottom Right corner
|
---|
242 | * @access public
|
---|
243 | */
|
---|
244 | public function clippingPathStart(
|
---|
245 | $x = null,
|
---|
246 | $y = null,
|
---|
247 | $w = null,
|
---|
248 | $h = null,
|
---|
249 | $cornerTL=null,
|
---|
250 | $cornerTR=null,
|
---|
251 | $cornerBL=null,
|
---|
252 | $cornerBR=null)
|
---|
253 | {
|
---|
254 | // init the path
|
---|
255 | $path = '';
|
---|
256 |
|
---|
257 | // if we have the position and the size of the rectangle, we can proceed
|
---|
258 | if ($x!==null && $y!==null && $w!==null && $h!==null) {
|
---|
259 | // the positions of the rectangle's corners
|
---|
260 | $x1 = $x*$this->k;
|
---|
261 | $y1 = ($this->h-$y)*$this->k;
|
---|
262 |
|
---|
263 | $x2 = ($x+$w)*$this->k;
|
---|
264 | $y2 = ($this->h-$y)*$this->k;
|
---|
265 |
|
---|
266 | $x3 = ($x+$w)*$this->k;
|
---|
267 | $y3 = ($this->h-$y-$h)*$this->k;
|
---|
268 |
|
---|
269 | $x4 = $x*$this->k;
|
---|
270 | $y4 = ($this->h-$y-$h)*$this->k;
|
---|
271 |
|
---|
272 | // if we have at least one radius corner, then we proceed to a specific path, else it is just a rectangle
|
---|
273 | if ($cornerTL || $cornerTR || $cornerBL || $cornerBR) {
|
---|
274 | // prepare the radius values
|
---|
275 | if ($cornerTL) {
|
---|
276 | $cornerTL[0] = $cornerTL[0]*$this->k;
|
---|
277 | $cornerTL[1] =-$cornerTL[1]*$this->k;
|
---|
278 | }
|
---|
279 | if ($cornerTR) {
|
---|
280 | $cornerTR[0] = $cornerTR[0]*$this->k;
|
---|
281 | $cornerTR[1] =-$cornerTR[1]*$this->k;
|
---|
282 | }
|
---|
283 | if ($cornerBL) {
|
---|
284 | $cornerBL[0] = $cornerBL[0]*$this->k;
|
---|
285 | $cornerBL[1] =-$cornerBL[1]*$this->k;
|
---|
286 | }
|
---|
287 | if ($cornerBR) {
|
---|
288 | $cornerBR[0] = $cornerBR[0]*$this->k;
|
---|
289 | $cornerBR[1] =-$cornerBR[1]*$this->k;
|
---|
290 | }
|
---|
291 |
|
---|
292 | // if TL radius then specific start else (X1,Y1)
|
---|
293 | if ($cornerTL) {
|
---|
294 | $path.= sprintf('%.2F %.2F m ', $x1+$cornerTL[0], $y1);
|
---|
295 | } else {
|
---|
296 | $path.= sprintf('%.2F %.2F m ', $x1, $y1);
|
---|
297 | }
|
---|
298 |
|
---|
299 | // if TR radius then line + arc, else line to (X2,Y2)
|
---|
300 | if ($cornerTR) {
|
---|
301 | $xt1 = ($x2-$cornerTR[0])+$cornerTR[0]*self::MY_ARC;
|
---|
302 | $yt1 = ($y2+$cornerTR[1])-$cornerTR[1];
|
---|
303 | $xt2 = ($x2-$cornerTR[0])+$cornerTR[0];
|
---|
304 | $yt2 = ($y2+$cornerTR[1])-$cornerTR[1]*self::MY_ARC;
|
---|
305 |
|
---|
306 | $path.= sprintf('%.2F %.2F l ', $x2-$cornerTR[0], $y2);
|
---|
307 | $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x2, $y2+$cornerTR[1]);
|
---|
308 | } else {
|
---|
309 | $path.= sprintf('%.2F %.2F l ', $x2, $y2);
|
---|
310 | }
|
---|
311 |
|
---|
312 | // if BR radius then line + arc, else line to (X3, Y3)
|
---|
313 | if ($cornerBR) {
|
---|
314 | $xt1 = ($x3-$cornerBR[0])+$cornerBR[0];
|
---|
315 | $yt1 = ($y3-$cornerBR[1])+$cornerBR[1]*self::MY_ARC;
|
---|
316 | $xt2 = ($x3-$cornerBR[0])+$cornerBR[0]*self::MY_ARC;
|
---|
317 | $yt2 = ($y3-$cornerBR[1])+$cornerBR[1];
|
---|
318 |
|
---|
319 | $path.= sprintf('%.2F %.2F l ', $x3, $y3-$cornerBR[1]);
|
---|
320 | $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x3-$cornerBR[0], $y3);
|
---|
321 | } else {
|
---|
322 | $path.= sprintf('%.2F %.2F l ', $x3, $y3);
|
---|
323 | }
|
---|
324 |
|
---|
325 | // if BL radius then line + arc, else line to (X4, Y4)
|
---|
326 | if ($cornerBL) {
|
---|
327 | $xt1 = ($x4+$cornerBL[0])-$cornerBL[0]*self::MY_ARC;
|
---|
328 | $yt1 = ($y4-$cornerBL[1])+$cornerBL[1];
|
---|
329 | $xt2 = ($x4+$cornerBL[0])-$cornerBL[0];
|
---|
330 | $yt2 = ($y4-$cornerBL[1])+$cornerBL[1]*self::MY_ARC;
|
---|
331 |
|
---|
332 | $path.= sprintf('%.2F %.2F l ', $x4+$cornerBL[0], $y4);
|
---|
333 | $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x4, $y4-$cornerBL[1]);
|
---|
334 | } else {
|
---|
335 | $path.= sprintf('%.2F %.2F l ', $x4, $y4);
|
---|
336 | }
|
---|
337 |
|
---|
338 | // if RL radius then line + arc
|
---|
339 | if ($cornerTL) {
|
---|
340 | $xt1 = ($x1+$cornerTL[0])-$cornerTL[0];
|
---|
341 | $yt1 = ($y1+$cornerTL[1])-$cornerTL[1]*self::MY_ARC;
|
---|
342 | $xt2 = ($x1+$cornerTL[0])-$cornerTL[0]*self::MY_ARC;
|
---|
343 | $yt2 = ($y1+$cornerTL[1])-$cornerTL[1];
|
---|
344 |
|
---|
345 | $path.= sprintf('%.2F %.2F l ', $x1, $y1+$cornerTL[1]);
|
---|
346 | $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x1+$cornerTL[0], $y1);
|
---|
347 | }
|
---|
348 | } else {
|
---|
349 | $path.= sprintf('%.2F %.2F m ', $x1, $y1);
|
---|
350 | $path.= sprintf('%.2F %.2F l ', $x2, $y2);
|
---|
351 | $path.= sprintf('%.2F %.2F l ', $x3, $y3);
|
---|
352 | $path.= sprintf('%.2F %.2F l ', $x4, $y4);
|
---|
353 | }
|
---|
354 |
|
---|
355 | // close the path
|
---|
356 | $path.= ' h W n';
|
---|
357 | }
|
---|
358 |
|
---|
359 | // using the path as a clipping path
|
---|
360 | $this->_out('q '.$path.' ');
|
---|
361 | }
|
---|
362 |
|
---|
363 | /**
|
---|
364 | * stop to use the Cliping Path
|
---|
365 | *
|
---|
366 | * @access public
|
---|
367 | */
|
---|
368 | public function clippingPathStop()
|
---|
369 | {
|
---|
370 | $this->_out(' Q');
|
---|
371 | }
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * draw a filled corner of a border with a external and a internal radius
|
---|
375 | * /--------+ ext2
|
---|
376 | * / |
|
---|
377 | * / /-------+ int2
|
---|
378 | * / /
|
---|
379 | * | /
|
---|
380 | * | |
|
---|
381 | * | |
|
---|
382 | * ext1 +-+ int1 + cen
|
---|
383 | *
|
---|
384 | * @param float $ext1X
|
---|
385 | * @param float $ext1Y
|
---|
386 | * @param float $ext2X
|
---|
387 | * @param float $ext2Y
|
---|
388 | * @param float $int1X
|
---|
389 | * @param float $int1Y
|
---|
390 | * @param float $int2X
|
---|
391 | * @param float $int2Y
|
---|
392 | * @param float $cenX
|
---|
393 | * @param float $cenY
|
---|
394 | * @access public
|
---|
395 | */
|
---|
396 | public function drawCurve($ext1X, $ext1Y, $ext2X, $ext2Y, $int1X, $int1Y, $int2X, $int2Y, $cenX, $cenY)
|
---|
397 | {
|
---|
398 | // prepare the coordinates
|
---|
399 | $ext1X = $ext1X*$this->k;
|
---|
400 | $ext2X = $ext2X*$this->k;
|
---|
401 | $int1X = $int1X*$this->k;
|
---|
402 | $int2X = $int2X*$this->k;
|
---|
403 | $cenX = $cenX*$this->k;
|
---|
404 |
|
---|
405 | $ext1Y = ($this->h-$ext1Y)*$this->k;
|
---|
406 | $ext2Y = ($this->h-$ext2Y)*$this->k;
|
---|
407 | $int1Y = ($this->h-$int1Y)*$this->k;
|
---|
408 | $int2Y = ($this->h-$int2Y)*$this->k;
|
---|
409 | $cenY = ($this->h-$cenY) *$this->k;
|
---|
410 |
|
---|
411 | // init the curve
|
---|
412 | $path = '';
|
---|
413 |
|
---|
414 | if ($ext1X-$cenX!=0) {
|
---|
415 | $xt1 = $cenX+($ext1X-$cenX);
|
---|
416 | $yt1 = $cenY+($ext2Y-$cenY)*self::MY_ARC;
|
---|
417 | $xt2 = $cenX+($ext1X-$cenX)*self::MY_ARC;
|
---|
418 | $yt2 = $cenY+($ext2Y-$cenY);
|
---|
419 | } else {
|
---|
420 | $xt1 = $cenX+($ext2X-$cenX)*self::MY_ARC;
|
---|
421 | $yt1 = $cenY+($ext1Y-$cenY);
|
---|
422 | $xt2 = $cenX+($ext2X-$cenX);
|
---|
423 | $yt2 = $cenY+($ext1Y-$cenY)*self::MY_ARC;
|
---|
424 | }
|
---|
425 | $path.= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
|
---|
426 | $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
|
---|
427 |
|
---|
428 | if ($int1X-$cenX!=0) {
|
---|
429 | $xt1 = $cenX+($int1X-$cenX)*self::MY_ARC;
|
---|
430 | $yt1 = $cenY+($int2Y-$cenY);
|
---|
431 | $xt2 = $cenX+($int1X-$cenX);
|
---|
432 | $yt2 = $cenY+($int2Y-$cenY)*self::MY_ARC;
|
---|
433 | } else {
|
---|
434 | $xt1 = $cenX+($int2X-$cenX);
|
---|
435 | $yt1 = $cenY+($int1Y-$cenY)*self::MY_ARC;
|
---|
436 | $xt2 = $cenX+($int2X-$cenX)*self::MY_ARC;
|
---|
437 | $yt2 = $cenY+($int1Y-$cenY);
|
---|
438 | }
|
---|
439 | $path.= sprintf('%.2F %.2F l ', $int2X, $int2Y);
|
---|
440 | $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $int1X, $int1Y);
|
---|
441 |
|
---|
442 | // draw the curve
|
---|
443 | $this->_out($path . 'f');
|
---|
444 | }
|
---|
445 |
|
---|
446 | /**
|
---|
447 | * draw a filled corner of a border with only a external radius
|
---|
448 | * /--+ ext2
|
---|
449 | * / |
|
---|
450 | * / |
|
---|
451 | * / |
|
---|
452 | * | |
|
---|
453 | * | |
|
---|
454 | * | |
|
---|
455 | * ext1 +-----+ int + cen
|
---|
456 | *
|
---|
457 | * @param float $ext1X
|
---|
458 | * @param float $ext1Y
|
---|
459 | * @param float $ext2X
|
---|
460 | * @param float $ext2Y
|
---|
461 | * @param float $intX
|
---|
462 | * @param float $intY
|
---|
463 | * @param float $cenX
|
---|
464 | * @param float $cenY
|
---|
465 | * @access public
|
---|
466 | */
|
---|
467 | public function drawCorner($ext1X, $ext1Y, $ext2X, $ext2Y, $intX, $intY, $cenX, $cenY)
|
---|
468 | {
|
---|
469 | // prepare the coordinates
|
---|
470 | $ext1X = $ext1X*$this->k;
|
---|
471 | $ext2X = $ext2X*$this->k;
|
---|
472 | $intX = $intX*$this->k;
|
---|
473 | $cenX = $cenX*$this->k;
|
---|
474 |
|
---|
475 | $ext1Y = ($this->h-$ext1Y)*$this->k;
|
---|
476 | $ext2Y = ($this->h-$ext2Y)*$this->k;
|
---|
477 | $intY = ($this->h-$intY)*$this->k;
|
---|
478 | $cenY = ($this->h-$cenY)*$this->k;
|
---|
479 |
|
---|
480 | // init the curve
|
---|
481 | $path = '';
|
---|
482 |
|
---|
483 | if ($ext1X-$cenX!=0) {
|
---|
484 | $xt1 = $cenX+($ext1X-$cenX);
|
---|
485 | $yt1 = $cenY+($ext2Y-$cenY)*self::MY_ARC;
|
---|
486 | $xt2 = $cenX+($ext1X-$cenX)*self::MY_ARC;
|
---|
487 | $yt2 = $cenY+($ext2Y-$cenY);
|
---|
488 | } else {
|
---|
489 | $xt1 = $cenX+($ext2X-$cenX)*self::MY_ARC;
|
---|
490 | $yt1 = $cenY+($ext1Y-$cenY);
|
---|
491 | $xt2 = $cenX+($ext2X-$cenX);
|
---|
492 | $yt2 = $cenY+($ext1Y-$cenY)*self::MY_ARC;
|
---|
493 | }
|
---|
494 | $path.= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
|
---|
495 | $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
|
---|
496 | $path.= sprintf('%.2F %.2F l ', $intX, $intY);
|
---|
497 | $path.= sprintf('%.2F %.2F l ', $ext1X, $ext1Y);
|
---|
498 |
|
---|
499 | // draw the curve
|
---|
500 | $this->_out($path . 'f');
|
---|
501 | }
|
---|
502 |
|
---|
503 | /**
|
---|
504 | * Start a transformation
|
---|
505 | *
|
---|
506 | * @access public
|
---|
507 | */
|
---|
508 | public function startTransform()
|
---|
509 | {
|
---|
510 | $this->_out('q');
|
---|
511 | }
|
---|
512 |
|
---|
513 | /**
|
---|
514 | * Stop a transformation
|
---|
515 | *
|
---|
516 | * @access public
|
---|
517 | */
|
---|
518 | public function stopTransform()
|
---|
519 | {
|
---|
520 | $this->_out('Q');
|
---|
521 | }
|
---|
522 |
|
---|
523 | /**
|
---|
524 | * add a Translate transformation
|
---|
525 | *
|
---|
526 | * @param float $Tx
|
---|
527 | * @param float $Ty
|
---|
528 | * @access public
|
---|
529 | */
|
---|
530 | public function setTranslate($xT, $yT)
|
---|
531 | {
|
---|
532 | // Matrix for Translate
|
---|
533 | $tm[0]=1;
|
---|
534 | $tm[1]=0;
|
---|
535 | $tm[2]=0;
|
---|
536 | $tm[3]=1;
|
---|
537 | $tm[4]=$xT*$this->k;
|
---|
538 | $tm[5]=-$yT*$this->k;
|
---|
539 |
|
---|
540 | // apply the Transform Matric
|
---|
541 | $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
|
---|
542 | }
|
---|
543 |
|
---|
544 | /**
|
---|
545 | * add a Rotate transformation
|
---|
546 | *
|
---|
547 | * @param float $angle
|
---|
548 | * @param float $Cx
|
---|
549 | * @param float $Cy
|
---|
550 | * @access public
|
---|
551 | */
|
---|
552 | public function setRotation($angle, $xC=null, $yC=null)
|
---|
553 | {
|
---|
554 | // if no center, rotate around the current posiition
|
---|
555 | if($xC === null) $xC=$this->x;
|
---|
556 | if($yC === null) $yC=$this->y;
|
---|
557 |
|
---|
558 | // prepare the coordinate
|
---|
559 | $yC=($this->h-$yC)*$this->k;
|
---|
560 | $xC*=$this->k;
|
---|
561 |
|
---|
562 | // Matrix for Rotate
|
---|
563 | $tm[0]=cos(deg2rad($angle));
|
---|
564 | $tm[1]=sin(deg2rad($angle));
|
---|
565 | $tm[2]=-$tm[1];
|
---|
566 | $tm[3]=$tm[0];
|
---|
567 | $tm[4]=$xC+$tm[1]*$yC-$tm[0]*$xC;
|
---|
568 | $tm[5]=$yC-$tm[0]*$yC-$tm[1]*$xC;
|
---|
569 |
|
---|
570 | // apply the Transform Matric
|
---|
571 | $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
|
---|
572 | }
|
---|
573 |
|
---|
574 | /**
|
---|
575 | * we redifine the original SetX method, because we don't want the automatic treatment.
|
---|
576 | * It is HTML2PDF that make the treatment
|
---|
577 | *
|
---|
578 | * @param float $x
|
---|
579 | * @param boolean $rtloff NOT USED
|
---|
580 | * @access public
|
---|
581 | */
|
---|
582 | public function SetX($x, $rtloff=false)
|
---|
583 | {
|
---|
584 | $this->x=$x;
|
---|
585 | }
|
---|
586 |
|
---|
587 | /**
|
---|
588 | * we redifine the original SetY method, because we don't want the automatic treatment.
|
---|
589 | * It is HTML2PDF that make the treatment
|
---|
590 | *
|
---|
591 | * @param float $y
|
---|
592 | * @param boolean $resetx Reset the X position
|
---|
593 | * @param boolean $rtloff NOT USED
|
---|
594 | * @access public
|
---|
595 | */
|
---|
596 | public function SetY($y, $resetx=true, $rtloff=false)
|
---|
597 | {
|
---|
598 | if ($resetx)
|
---|
599 | $this->x=$this->lMargin;
|
---|
600 |
|
---|
601 | $this->y=$y;
|
---|
602 | }
|
---|
603 |
|
---|
604 | /**
|
---|
605 | * we redifine the original SetXY method, because we don't want the automatic treatment.
|
---|
606 | * It is HTML2PDF that make the treatment
|
---|
607 | *
|
---|
608 | * @param integer $x
|
---|
609 | * @param integer $y
|
---|
610 | * @param boolean $rtloff NOT USED
|
---|
611 | * @access public
|
---|
612 | */
|
---|
613 | public function SetXY($x, $y, $rtloff=false)
|
---|
614 | {
|
---|
615 | $this->x=$x;
|
---|
616 | $this->y=$y;
|
---|
617 | }
|
---|
618 |
|
---|
619 | /**
|
---|
620 | * multiple public accessor because HTML2PDF need to use TCPDF without being a extend of it
|
---|
621 | *
|
---|
622 | * @param mixed
|
---|
623 | * @return mixed
|
---|
624 | * @access public
|
---|
625 | */
|
---|
626 | public function getK()
|
---|
627 | {
|
---|
628 | return $this->k;
|
---|
629 | }
|
---|
630 | public function getW()
|
---|
631 | {
|
---|
632 | return $this->w;
|
---|
633 | }
|
---|
634 | public function getH()
|
---|
635 | {
|
---|
636 | return $this->h;
|
---|
637 | }
|
---|
638 | public function getlMargin()
|
---|
639 | {
|
---|
640 | return $this->lMargin;
|
---|
641 | }
|
---|
642 | public function getrMargin()
|
---|
643 | {
|
---|
644 | return $this->rMargin;
|
---|
645 | }
|
---|
646 | public function gettMargin()
|
---|
647 | {
|
---|
648 | return $this->tMargin;
|
---|
649 | }
|
---|
650 | public function getbMargin()
|
---|
651 | {
|
---|
652 | return $this->bMargin;
|
---|
653 | }
|
---|
654 | public function setbMargin($v)
|
---|
655 | {
|
---|
656 | $this->bMargin=$v;
|
---|
657 | }
|
---|
658 |
|
---|
659 | /**
|
---|
660 | * SVG - Convert a SVG Style in PDF Style
|
---|
661 | *
|
---|
662 | * @param array $styles SVG Style
|
---|
663 | * @return string PDF style
|
---|
664 | * @access public
|
---|
665 | */
|
---|
666 | public function svgSetStyle($styles)
|
---|
667 | {
|
---|
668 | // init the PDF style
|
---|
669 | $style = '';
|
---|
670 |
|
---|
671 | // Style : fill
|
---|
672 | if ($styles['fill']) {
|
---|
673 | $this->setFillColorArray($styles['fill']);
|
---|
674 | $style.= 'F';
|
---|
675 | }
|
---|
676 |
|
---|
677 | // Style : stroke
|
---|
678 | if ($styles['stroke'] && $styles['stroke-width']) {
|
---|
679 | $this->SetDrawColorArray($styles['stroke']);
|
---|
680 | $this->SetLineWidth($styles['stroke-width']);
|
---|
681 | $style.= 'D';
|
---|
682 | }
|
---|
683 |
|
---|
684 | // Style : opacity
|
---|
685 | if ($styles['fill-opacity']) {
|
---|
686 | $this->SetAlpha($styles['fill-opacity']);
|
---|
687 | }
|
---|
688 |
|
---|
689 | return $style;
|
---|
690 | }
|
---|
691 |
|
---|
692 | /**
|
---|
693 | * SVG - make a Rectangle
|
---|
694 | *
|
---|
695 | * @param float $x
|
---|
696 | * @param float $y
|
---|
697 | * @param float $w
|
---|
698 | * @param float $h
|
---|
699 | * @param string $style PDF Style
|
---|
700 | * @access public
|
---|
701 | */
|
---|
702 | public function svgRect($x, $y, $w, $h, $style)
|
---|
703 | {
|
---|
704 | // prepare the 4 corners
|
---|
705 | $x1=$x;
|
---|
706 | $x2=$x+$w;
|
---|
707 | $x3=$x+$w;
|
---|
708 | $x4=$x;
|
---|
709 |
|
---|
710 | $y1=$y;
|
---|
711 | $y2=$y;
|
---|
712 | $y3=$y+$h;
|
---|
713 | $y4=$y+$h;
|
---|
714 |
|
---|
715 | // get the Closing operator from the PDF Style
|
---|
716 | if($style=='F') $op='f';
|
---|
717 | elseif($style=='FD' || $style=='DF') $op='B';
|
---|
718 | else $op='S';
|
---|
719 |
|
---|
720 | // drawing
|
---|
721 | $this->_Point($x1, $y1, true);
|
---|
722 | $this->_Line($x2, $y2, true);
|
---|
723 | $this->_Line($x3, $y3, true);
|
---|
724 | $this->_Line($x4, $y4, true);
|
---|
725 | $this->_Line($x1, $y1, true);
|
---|
726 | $this->_out($op);
|
---|
727 | }
|
---|
728 |
|
---|
729 | /**
|
---|
730 | * SVG - make a Line
|
---|
731 | *
|
---|
732 | * @param float $x1
|
---|
733 | * @param float $y1
|
---|
734 | * @param float $x2
|
---|
735 | * @param float $y2
|
---|
736 | * @access public
|
---|
737 | */
|
---|
738 | public function svgLine($x1, $y1, $x2, $y2)
|
---|
739 | {
|
---|
740 | // get the Closing operator
|
---|
741 | $op='S';
|
---|
742 |
|
---|
743 | // drawing
|
---|
744 | $this->_Point($x1, $y1, true);
|
---|
745 | $this->_Line($x2, $y2, true);
|
---|
746 | $this->_out($op);
|
---|
747 | }
|
---|
748 |
|
---|
749 | /**
|
---|
750 | * SVG - make a Ellipse
|
---|
751 | *
|
---|
752 | * @param float $x0 x Center
|
---|
753 | * @param float $y0 y Center
|
---|
754 | * @param float $rx x radius
|
---|
755 | * @param float $ry y radius
|
---|
756 | * @param string $style PDF Style
|
---|
757 | * @access public
|
---|
758 | */
|
---|
759 | public function svgEllipse($x0, $y0, $rx, $ry, $style)
|
---|
760 | {
|
---|
761 | // get the Closing operator from the PDF Style
|
---|
762 | if($style=='F') $op='f';
|
---|
763 | elseif($style=='FD' || $style=='DF') $op='B';
|
---|
764 | else $op='S';
|
---|
765 |
|
---|
766 | // drawing
|
---|
767 | $this->_Arc($x0, $y0, $rx, $ry, 0, 2*M_PI, true, true, true);
|
---|
768 | $this->_out($op);
|
---|
769 | }
|
---|
770 |
|
---|
771 | /**
|
---|
772 | * SVG - make a Advanced Polygone
|
---|
773 | *
|
---|
774 | * @param array $actions list of actions
|
---|
775 | * @param string $style PDF Style
|
---|
776 | * @access public
|
---|
777 | */
|
---|
778 | public function svgPolygone($actions, $style)
|
---|
779 | {
|
---|
780 | // get the Closing operator from the PDF Style
|
---|
781 | if($style=='F') $op='f';
|
---|
782 | elseif($style=='FD' || $style=='DF') $op='B';
|
---|
783 | else $op='S';
|
---|
784 |
|
---|
785 | // To save the First action and the last point
|
---|
786 | $first = array('', 0, 0);
|
---|
787 | $last = array(0, 0, 0, 0);
|
---|
788 |
|
---|
789 | foreach ($actions as $action) {
|
---|
790 | switch($action[0])
|
---|
791 | {
|
---|
792 | // Start the Path
|
---|
793 | case 'M':
|
---|
794 | case 'm':
|
---|
795 | $first = $action;
|
---|
796 | $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
|
---|
797 | $this->_Point($x, $y, true);
|
---|
798 | break;
|
---|
799 |
|
---|
800 | // Close the Path
|
---|
801 | case 'Z':
|
---|
802 | case 'z':
|
---|
803 | $x = $first[1]; $y = $first[2]; $xc = $x; $yc = $y;
|
---|
804 | $this->_Line($x, $y, true);
|
---|
805 | break;
|
---|
806 |
|
---|
807 | // Make a Line (new point)
|
---|
808 | case 'L':
|
---|
809 | $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
|
---|
810 | $this->_Line($x, $y, true);
|
---|
811 | break;
|
---|
812 |
|
---|
813 | // Make a Line (vector from last point)
|
---|
814 | case 'l':
|
---|
815 | $x = $last[0]+$action[1]; $y = $last[1]+$action[2]; $xc = $x; $yc = $y;
|
---|
816 | $this->_Line($x, $y, true);
|
---|
817 | break;
|
---|
818 |
|
---|
819 | // Make a Horizontal Line (new point)
|
---|
820 | case 'H':
|
---|
821 | $x = $action[1]; $y = $last[1]; $xc = $x; $yc = $y;
|
---|
822 | $this->_Line($x, $y, true);
|
---|
823 | break;
|
---|
824 |
|
---|
825 | // Make a Horisontal Line (vector from last point)
|
---|
826 | case 'h':
|
---|
827 | $x = $last[0]+$action[1]; $y = $last[1]; $xc = $x; $yc = $y;
|
---|
828 | $this->_Line($x, $y, true);
|
---|
829 | break;
|
---|
830 |
|
---|
831 | // Make a Vertical Line (new point)
|
---|
832 | case 'V':
|
---|
833 | $x = $last[0]; $y = $action[1]; $xc = $x; $yc = $y;
|
---|
834 | $this->_Line($x, $y, true);
|
---|
835 | break;
|
---|
836 |
|
---|
837 | // Make a Vertical Line (vector from last point)
|
---|
838 | case 'v':
|
---|
839 | $x = $last[0]; $y = $last[1]+$action[1]; $xc = $x; $yc = $y;
|
---|
840 | $this->_Line($x, $y, true);
|
---|
841 | break;
|
---|
842 |
|
---|
843 | // Make a Arc (new point)
|
---|
844 | case 'A':
|
---|
845 | $rx = $action[1]; // rx
|
---|
846 | $ry = $action[2]; // ry
|
---|
847 | $a = $action[3]; // deviation angle of the axis X
|
---|
848 | $l = $action[4]; // large-arc-flag
|
---|
849 | $s = $action[5]; // sweep-flag
|
---|
850 | $x1 = $last[0]; // begin x
|
---|
851 | $y1 = $last[1]; // begin y
|
---|
852 | $x2 = $action[6]; // final x
|
---|
853 | $y2 = $action[7]; // final y
|
---|
854 |
|
---|
855 | $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
|
---|
856 | $x = $x2; $y = $y2; $xc = $x; $yc = $y;
|
---|
857 | break;
|
---|
858 |
|
---|
859 | // Make a Arc (vector from last point)
|
---|
860 | case 'a':
|
---|
861 | $rx = $action[1]; // rx
|
---|
862 | $ry = $action[2]; // ry
|
---|
863 | $a = $action[3]; // deviation angle of the axis X
|
---|
864 | $l = $action[4]; // large-arc-flag
|
---|
865 | $s = $action[5]; // sweep-flag
|
---|
866 | $x1 = $last[0]; // begin x
|
---|
867 | $y1 = $last[1]; // begin y
|
---|
868 | $x2 = $last[0]+$action[6]; // final x
|
---|
869 | $y2 = $last[1]+$action[7]; // final y
|
---|
870 |
|
---|
871 | $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
|
---|
872 | $x = $x2; $y = $y2; $xc = $x; $yc = $y;
|
---|
873 | break;
|
---|
874 |
|
---|
875 | // Make a Bezier Curve (new point)
|
---|
876 | case 'C':
|
---|
877 | $x1 = $action[1];
|
---|
878 | $y1 = $action[2];
|
---|
879 | $x2 = $action[3];
|
---|
880 | $y2 = $action[4];
|
---|
881 | $xf = $action[5];
|
---|
882 | $yf = $action[6];
|
---|
883 | $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
|
---|
884 | $x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
|
---|
885 | break;
|
---|
886 |
|
---|
887 | // Make a Bezier Curve (vector from last point)
|
---|
888 | case 'c':
|
---|
889 | $x1 = $last[0]+$action[1];
|
---|
890 | $y1 = $last[1]+$action[2];
|
---|
891 | $x2 = $last[0]+$action[3];
|
---|
892 | $y2 = $last[1]+$action[4];
|
---|
893 | $xf = $last[0]+$action[5];
|
---|
894 | $yf = $last[1]+$action[6];
|
---|
895 | $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
|
---|
896 | $x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
|
---|
897 | break;
|
---|
898 |
|
---|
899 | // Unknown Path
|
---|
900 | default:
|
---|
901 | throw new HTML2PDF_exception(0, 'SVG Path Error : ['.$action[0].'] unkown');
|
---|
902 | }
|
---|
903 |
|
---|
904 | // save the last point
|
---|
905 | $last = array($x, $y, $xc, $yc);
|
---|
906 | }
|
---|
907 |
|
---|
908 | // finish the path
|
---|
909 | $this->_out($op);
|
---|
910 | }
|
---|
911 |
|
---|
912 | /**
|
---|
913 | * SVG - go to a point
|
---|
914 | *
|
---|
915 | * @param float $x
|
---|
916 | * @param float $y
|
---|
917 | * @param boolean $trans apply transformation
|
---|
918 | * @access protected
|
---|
919 | */
|
---|
920 | protected function _Point($x, $y, $trans = false)
|
---|
921 | {
|
---|
922 | if ($trans) $this->ptTransform($x, $y);
|
---|
923 |
|
---|
924 | $this->_out(sprintf('%.2F %.2F m', $x, $y));
|
---|
925 | }
|
---|
926 |
|
---|
927 | /**
|
---|
928 | * SVG - make a line from the last point to (x,y)
|
---|
929 | *
|
---|
930 | * @param float $x
|
---|
931 | * @param float $y
|
---|
932 | * @param boolean $trans apply transformation
|
---|
933 | * @access protected
|
---|
934 | */
|
---|
935 | protected function _Line($x, $y, $trans = false)
|
---|
936 | {
|
---|
937 | if ($trans) $this->ptTransform($x, $y);
|
---|
938 |
|
---|
939 | $this->_out(sprintf('%.2F %.2F l', $x, $y));
|
---|
940 | }
|
---|
941 |
|
---|
942 | /**
|
---|
943 | * SVG - make a bezier curve from the last point to (xf,yf), with the 2 direction points (x1,y1) and (x2,y2)
|
---|
944 | *
|
---|
945 | * @param float $x1
|
---|
946 | * @param float $y1
|
---|
947 | * @param float $x2
|
---|
948 | * @param float $y2
|
---|
949 | * @param float $xf
|
---|
950 | * @param float $yf
|
---|
951 | * @param boolean $trans apply transformation
|
---|
952 | * @access protected
|
---|
953 | */
|
---|
954 | protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false)
|
---|
955 | {
|
---|
956 | if ($trans) {
|
---|
957 | $this->ptTransform($x1, $y1);
|
---|
958 | $this->ptTransform($x2, $y2);
|
---|
959 | $this->ptTransform($xf, $yf);
|
---|
960 | }
|
---|
961 | $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1, $y1, $x2, $y2, $xf, $yf));
|
---|
962 | }
|
---|
963 |
|
---|
964 | /**
|
---|
965 | * SVG - make a arc with Center, Radius, from angleBegin to angleEnd
|
---|
966 | *
|
---|
967 | * @param float $xc
|
---|
968 | * @param float $yc
|
---|
969 | * @param float $rx
|
---|
970 | * @param float $ry
|
---|
971 | * @param float $angleBegin in radians
|
---|
972 | * @param float $angleEng in radians
|
---|
973 | * @param boolean $direction
|
---|
974 | * @param boolean $drawFirst, true => add the first point
|
---|
975 | * @param boolean $trans apply transformation
|
---|
976 | * @access protected
|
---|
977 | */
|
---|
978 | protected function _Arc(
|
---|
979 | $xc,
|
---|
980 | $yc,
|
---|
981 | $rx,
|
---|
982 | $ry,
|
---|
983 | $angleBegin,
|
---|
984 | $angleEnd,
|
---|
985 | $direction = true,
|
---|
986 | $drawFirst = true,
|
---|
987 | $trans=false)
|
---|
988 | {
|
---|
989 | // if we want the no trigo direction : add 2PI to the begin angle, to invert the direction
|
---|
990 | if (!$direction) $angleBegin+= M_PI*2.;
|
---|
991 |
|
---|
992 | // cut in segment to convert in berize curv
|
---|
993 | $dt = ($angleEnd - $angleBegin)/self::ARC_NB_SEGMENT;
|
---|
994 | $dtm = $dt/3;
|
---|
995 |
|
---|
996 | // center of the arc
|
---|
997 | $x0 = $xc; $y0 = $yc;
|
---|
998 |
|
---|
999 | // calculing the first point
|
---|
1000 | $t1 = $angleBegin;
|
---|
1001 | $a0 = $x0 + ($rx * cos($t1));
|
---|
1002 | $b0 = $y0 + ($ry * sin($t1));
|
---|
1003 | $c0 = -$rx * sin($t1);
|
---|
1004 | $d0 = $ry * cos($t1);
|
---|
1005 |
|
---|
1006 | // if drawFirst => draw the first point
|
---|
1007 | if ($drawFirst) $this->_Point($a0, $b0, $trans);
|
---|
1008 |
|
---|
1009 | // foreach segment
|
---|
1010 | for ($i = 1; $i <= self::ARC_NB_SEGMENT; $i++) {
|
---|
1011 | // calculing the next point
|
---|
1012 | $t1 = ($i * $dt)+$angleBegin;
|
---|
1013 | $a1 = $x0 + ($rx * cos($t1));
|
---|
1014 | $b1 = $y0 + ($ry * sin($t1));
|
---|
1015 | $c1 = -$rx * sin($t1);
|
---|
1016 | $d1 = $ry * cos($t1);
|
---|
1017 |
|
---|
1018 | // make the bezier curv
|
---|
1019 | $this->_Curve(
|
---|
1020 | $a0 + ($c0 * $dtm), $b0 + ($d0 * $dtm),
|
---|
1021 | $a1 - ($c1 * $dtm), $b1 - ($d1 * $dtm),
|
---|
1022 | $a1, $b1,
|
---|
1023 | $trans
|
---|
1024 | );
|
---|
1025 |
|
---|
1026 | // save the point
|
---|
1027 | $a0 = $a1;
|
---|
1028 | $b0 = $b1;
|
---|
1029 | $c0 = $c1;
|
---|
1030 | $d0 = $d1;
|
---|
1031 | }
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | /**
|
---|
1035 | * SVG - make a arc from Pt1 to Pt2, with Radius
|
---|
1036 | *
|
---|
1037 | * @param float $x1
|
---|
1038 | * @param float $y1
|
---|
1039 | * @param float $x2
|
---|
1040 | * @param float $y2
|
---|
1041 | * @param float $rx
|
---|
1042 | * @param float $ry
|
---|
1043 | * @param float $angle deviation angle of the axis X
|
---|
1044 | * @param boolean $l large-arc-flag
|
---|
1045 | * @param boolean $s sweep-flag
|
---|
1046 | * @param boolean $trans apply transformation
|
---|
1047 | * @access protected
|
---|
1048 | */
|
---|
1049 | protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle=0., $l=0, $s=0, $trans = false)
|
---|
1050 | {
|
---|
1051 | // array to stock the parameters
|
---|
1052 | $v = array();
|
---|
1053 |
|
---|
1054 | // the original values
|
---|
1055 | $v['x1'] = $x1;
|
---|
1056 | $v['y1'] = $y1;
|
---|
1057 | $v['x2'] = $x2;
|
---|
1058 | $v['y2'] = $y2;
|
---|
1059 | $v['rx'] = $rx;
|
---|
1060 | $v['ry'] = $ry;
|
---|
1061 |
|
---|
1062 | // rotate with the deviation angle of the axis X
|
---|
1063 | $v['xr1'] = $v['x1']*cos($angle) - $v['y1']*sin($angle);
|
---|
1064 | $v['yr1'] = $v['x1']*sin($angle) + $v['y1']*cos($angle);
|
---|
1065 | $v['xr2'] = $v['x2']*cos($angle) - $v['y2']*sin($angle);
|
---|
1066 | $v['yr2'] = $v['x2']*sin($angle) + $v['y2']*cos($angle);
|
---|
1067 |
|
---|
1068 | // the normalized vector
|
---|
1069 | $v['Xr1'] = $v['xr1']/$v['rx'];
|
---|
1070 | $v['Yr1'] = $v['yr1']/$v['ry'];
|
---|
1071 | $v['Xr2'] = $v['xr2']/$v['rx'];
|
---|
1072 | $v['Yr2'] = $v['yr2']/$v['ry'];
|
---|
1073 | $v['dXr'] = $v['Xr2']-$v['Xr1'];
|
---|
1074 | $v['dYr'] = $v['Yr2']-$v['Yr1'];
|
---|
1075 | $v['D'] = $v['dXr']*$v['dXr'] + $v['dYr']*$v['dYr'];
|
---|
1076 |
|
---|
1077 | // if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line
|
---|
1078 | if ($v['D']==0 || $v['D']>4) {
|
---|
1079 | $this->_Line($x2, $y2, $trans);
|
---|
1080 | return false;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | // convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd
|
---|
1084 | $v['s1'] = array();
|
---|
1085 | $v['s1']['t'] = sqrt((4.-$v['D'])/$v['D']);
|
---|
1086 | $v['s1']['Xr'] = ($v['Xr1']+$v['Xr2'])/2. + $v['s1']['t']*($v['Yr2']-$v['Yr1'])/2.;
|
---|
1087 | $v['s1']['Yr'] = ($v['Yr1']+$v['Yr2'])/2. + $v['s1']['t']*($v['Xr1']-$v['Xr2'])/2.;
|
---|
1088 | $v['s1']['xr'] = $v['s1']['Xr']*$v['rx'];
|
---|
1089 | $v['s1']['yr'] = $v['s1']['Yr']*$v['ry'];
|
---|
1090 | $v['s1']['x'] = $v['s1']['xr']*cos($angle)+$v['s1']['yr']*sin($angle);
|
---|
1091 | $v['s1']['y'] =-$v['s1']['xr']*sin($angle)+$v['s1']['yr']*cos($angle);
|
---|
1092 | $v['s1']['a1'] = atan2($v['y1']-$v['s1']['y'], $v['x1']-$v['s1']['x']);
|
---|
1093 | $v['s1']['a2'] = atan2($v['y2']-$v['s1']['y'], $v['x2']-$v['s1']['x']);
|
---|
1094 | if ($v['s1']['a1']>$v['s1']['a2']) $v['s1']['a1']-=2*M_PI;
|
---|
1095 |
|
---|
1096 | $v['s2'] = array();
|
---|
1097 | $v['s2']['t'] = -$v['s1']['t'];
|
---|
1098 | $v['s2']['Xr'] = ($v['Xr1']+$v['Xr2'])/2. + $v['s2']['t']*($v['Yr2']-$v['Yr1'])/2.;
|
---|
1099 | $v['s2']['Yr'] = ($v['Yr1']+$v['Yr2'])/2. + $v['s2']['t']*($v['Xr1']-$v['Xr2'])/2.;
|
---|
1100 | $v['s2']['xr'] = $v['s2']['Xr']*$v['rx'];
|
---|
1101 | $v['s2']['yr'] = $v['s2']['Yr']*$v['ry'];
|
---|
1102 | $v['s2']['x'] = $v['s2']['xr']*cos($angle)+$v['s2']['yr']*sin($angle);
|
---|
1103 | $v['s2']['y'] =-$v['s2']['xr']*sin($angle)+$v['s2']['yr']*cos($angle);
|
---|
1104 | $v['s2']['a1'] = atan2($v['y1']-$v['s2']['y'], $v['x1']-$v['s2']['x']);
|
---|
1105 | $v['s2']['a2'] = atan2($v['y2']-$v['s2']['y'], $v['x2']-$v['s2']['x']);
|
---|
1106 | if ($v['s2']['a1']>$v['s2']['a2']) $v['s2']['a1']-=2*M_PI;
|
---|
1107 |
|
---|
1108 | if (!$l) {
|
---|
1109 | if ($s) {
|
---|
1110 | $xc = $v['s2']['x'];
|
---|
1111 | $yc = $v['s2']['y'];
|
---|
1112 | $a1 = $v['s2']['a1'];
|
---|
1113 | $a2 = $v['s2']['a2'];
|
---|
1114 | $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
|
---|
1115 | } else {
|
---|
1116 | $xc = $v['s1']['x'];
|
---|
1117 | $yc = $v['s1']['y'];
|
---|
1118 | $a1 = $v['s1']['a1'];
|
---|
1119 | $a2 = $v['s1']['a2'];
|
---|
1120 | $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
|
---|
1121 | }
|
---|
1122 | } else {
|
---|
1123 | if ($s) {
|
---|
1124 | $xc = $v['s1']['x'];
|
---|
1125 | $yc = $v['s1']['y'];
|
---|
1126 | $a1 = $v['s1']['a1'];
|
---|
1127 | $a2 = $v['s1']['a2'];
|
---|
1128 | $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
|
---|
1129 | } else {
|
---|
1130 | $xc = $v['s2']['x'];
|
---|
1131 | $yc = $v['s2']['y'];
|
---|
1132 | $a1 = $v['s2']['a1'];
|
---|
1133 | $a2 = $v['s2']['a2'];
|
---|
1134 | $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
|
---|
1135 | }
|
---|
1136 | }
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | /**
|
---|
1140 | * SVG - transform the point (reference)
|
---|
1141 | *
|
---|
1142 | * @param float &$x
|
---|
1143 | * @param float &$y
|
---|
1144 | * @param boolean $trans true => convert into PDF unit
|
---|
1145 | * @return boolean
|
---|
1146 | * @access public
|
---|
1147 | */
|
---|
1148 | public function ptTransform(&$x, &$y, $trans=true)
|
---|
1149 | {
|
---|
1150 | // load the last Transfomation Matrix
|
---|
1151 | $nb = count($this->_transf);
|
---|
1152 | if ($nb) $m = $this->_transf[$nb-1];
|
---|
1153 | else $m = array(1,0,0,1,0,0);
|
---|
1154 |
|
---|
1155 | // apply the Transformation Matrix
|
---|
1156 | list($x,$y) = array(($x*$m[0]+$y*$m[2]+$m[4]),($x*$m[1]+$y*$m[3]+$m[5]));
|
---|
1157 |
|
---|
1158 | // if true => convert into PDF unit
|
---|
1159 | if ($trans) {
|
---|
1160 | $x = $x*$this->k;
|
---|
1161 | $y = ($this->h-$y)*$this->k;
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | return true;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | /**
|
---|
1168 | * SVG - add a transformation Matric
|
---|
1169 | *
|
---|
1170 | * @param array $n matrix
|
---|
1171 | * @access public
|
---|
1172 | */
|
---|
1173 | public function doTransform($n = null)
|
---|
1174 | {
|
---|
1175 | // get the last Transformation Matrix
|
---|
1176 | $nb = count($this->_transf);
|
---|
1177 | if ($nb) $m = $this->_transf[$nb-1];
|
---|
1178 | else $m = array(1,0,0,1,0,0);
|
---|
1179 |
|
---|
1180 | // if no transform, get the Identity Matrix
|
---|
1181 | if (!$n) $n = array(1,0,0,1,0,0);
|
---|
1182 |
|
---|
1183 | // create the new Transformation Matrix
|
---|
1184 | $this->_transf[] = array(
|
---|
1185 | $m[0]*$n[0]+$m[2]*$n[1],
|
---|
1186 | $m[1]*$n[0]+$m[3]*$n[1],
|
---|
1187 | $m[0]*$n[2]+$m[2]*$n[3],
|
---|
1188 | $m[1]*$n[2]+$m[3]*$n[3],
|
---|
1189 | $m[0]*$n[4]+$m[2]*$n[5]+$m[4],
|
---|
1190 | $m[1]*$n[4]+$m[3]*$n[5]+$m[5]
|
---|
1191 | );
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | /**
|
---|
1195 | * SVG - remove a transformation Matric
|
---|
1196 | *
|
---|
1197 | * @access public
|
---|
1198 | */
|
---|
1199 | public function undoTransform()
|
---|
1200 | {
|
---|
1201 | array_pop($this->_transf);
|
---|
1202 | }
|
---|
1203 |
|
---|
1204 | /**
|
---|
1205 | * Convert a HTML2PDF barcode in a TCPDF barcode
|
---|
1206 | *
|
---|
1207 | * @param string $code code to print
|
---|
1208 | * @param string $type type of barcode (see tcpdf/barcodes.php for supported formats)
|
---|
1209 | * @param int $x x position in user units
|
---|
1210 | * @param int $y y position in user units
|
---|
1211 | * @param int $w width in user units
|
---|
1212 | * @param int $h height in user units
|
---|
1213 | * @param int $labelFontsize of the Test Label. If false : no Label
|
---|
1214 | * @param array $color color of the foreground
|
---|
1215 | * @access public
|
---|
1216 | */
|
---|
1217 | public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color)
|
---|
1218 | {
|
---|
1219 | // the style of the barcode
|
---|
1220 | $style = array(
|
---|
1221 | 'position' => 'S',
|
---|
1222 | 'text' => ($labelFontsize ? true : false),
|
---|
1223 | 'fgcolor' => $color,
|
---|
1224 | 'bgcolor' => false,
|
---|
1225 | );
|
---|
1226 |
|
---|
1227 | // build the barcode
|
---|
1228 | $this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
|
---|
1229 |
|
---|
1230 | // it Label => add the FontSize to the height
|
---|
1231 | if ($labelFontsize) $h+= ($labelFontsize);
|
---|
1232 |
|
---|
1233 | // return the size of the barcode
|
---|
1234 | return array($w, $h);
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | /**
|
---|
1238 | * create a automatic Index on a page
|
---|
1239 | *
|
---|
1240 | * @param html2pdf $obj parent object
|
---|
1241 | * @param string $titre Title of the Index Page
|
---|
1242 | * @param integer $sizeTitle Font size for hthe Title
|
---|
1243 | * @param integer $sizeBookmark Font size for the bookmarks
|
---|
1244 | * @param boolean $bookmarkTitle Bookmark the Title
|
---|
1245 | * @param boolean $displayPage Display the page number for each bookmark
|
---|
1246 | * @param integer $page draw the automatic Index on a specific Page. if null => add a page at the end
|
---|
1247 | * @param string $fontName FontName to use
|
---|
1248 | * @access public
|
---|
1249 | */
|
---|
1250 | public function createIndex(
|
---|
1251 | &$obj,
|
---|
1252 | $titre = 'Index',
|
---|
1253 | $sizeTitle = 20,
|
---|
1254 | $sizeBookmark = 15,
|
---|
1255 | $bookmarkTitle = true,
|
---|
1256 | $displayPage = true,
|
---|
1257 | $page = null,
|
---|
1258 | $fontName = 'helvetica')
|
---|
1259 | {
|
---|
1260 | // bookmark the Title if wanted
|
---|
1261 | if ($bookmarkTitle) $this->Bookmark($titre, 0, -1);
|
---|
1262 |
|
---|
1263 | // display the Title with the good Font size
|
---|
1264 | $this->SetFont($fontName, '', $sizeTitle);
|
---|
1265 | $this->Cell(0, 5, $titre, 0, 1, 'C');
|
---|
1266 |
|
---|
1267 | // set the good Font size for the bookmarks
|
---|
1268 | $this->SetFont($fontName, '', $sizeBookmark);
|
---|
1269 | $this->Ln(10);
|
---|
1270 |
|
---|
1271 | // get the number of bookmarks
|
---|
1272 | $size=sizeof($this->outlines);
|
---|
1273 |
|
---|
1274 | // get the size of the "P. xx" cell
|
---|
1275 | $pageCellSize=$this->GetStringWidth('p. '.$this->outlines[$size-1]['p'])+2;
|
---|
1276 |
|
---|
1277 | // Foreach bookmark
|
---|
1278 | for ($i=0;$i<$size;$i++) {
|
---|
1279 | // if we need a new page => add a new page
|
---|
1280 | if ($this->getY()+$this->FontSize>=($this->h - $this->bMargin)) {
|
---|
1281 | $obj->_INDEX_NewPage($page);
|
---|
1282 | $this->SetFont($fontName, '', $sizeBookmark);
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 | // Offset of the current level
|
---|
1286 | $level=$this->outlines[$i]['l'];
|
---|
1287 | if($level>0) $this->Cell($level*8);
|
---|
1288 |
|
---|
1289 | // Caption (cut to fit on the width page)
|
---|
1290 | $str=$this->outlines[$i]['t'];
|
---|
1291 | $strsize=$this->GetStringWidth($str);
|
---|
1292 | $availableSize=$this->w-$this->lMargin-$this->rMargin-$pageCellSize-($level*8)-4;
|
---|
1293 | while ($strsize>=$availableSize) {
|
---|
1294 | $str=substr($str, 0, -1);
|
---|
1295 | $strsize=$this->GetStringWidth($str);
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | // if we want to display the page nmber
|
---|
1299 | if ($displayPage) {
|
---|
1300 | // display the Bookmark Caption
|
---|
1301 | $this->Cell($strsize+2, $this->FontSize+2, $str);
|
---|
1302 |
|
---|
1303 | //Filling dots
|
---|
1304 | $w=$this->w-$this->lMargin-$this->rMargin-$pageCellSize-($level*8)-($strsize+2);
|
---|
1305 | $nb=$w/$this->GetStringWidth('.');
|
---|
1306 | $dots=str_repeat('.', $nb);
|
---|
1307 | $this->Cell($w, $this->FontSize+2, $dots, 0, 0, 'R');
|
---|
1308 |
|
---|
1309 | //Page number
|
---|
1310 | $this->Cell($pageCellSize, $this->FontSize+2, 'p. '.$this->outlines[$i]['p'], 0, 1, 'R');
|
---|
1311 | } else {
|
---|
1312 | // display the Bookmark Caption
|
---|
1313 | $this->Cell($strsize+2, $this->FontSize+2, $str, 0, 1);
|
---|
1314 | }
|
---|
1315 | }
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | /**
|
---|
1319 | * Returns the string alias used for the total number of pages.
|
---|
1320 | *
|
---|
1321 | * @access public
|
---|
1322 | * @return string;
|
---|
1323 | * @see TCPDF::getAliasNbPages(), TCPDF::getPageGroupAlias()
|
---|
1324 | */
|
---|
1325 | public function getMyAliasNbPages()
|
---|
1326 | {
|
---|
1327 | if ($this->_myLastPageGroupNb==0) {
|
---|
1328 | return $this->getAliasNbPages();
|
---|
1329 | } else {
|
---|
1330 | $old = $this->currpagegroup;
|
---|
1331 | $this->currpagegroup = '{nb'.$this->_myLastPageGroupNb.'}';
|
---|
1332 | $new = $this->getPageGroupAlias();
|
---|
1333 | $this->currpagegroup = $old;
|
---|
1334 |
|
---|
1335 | return $new;
|
---|
1336 | }
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | /**
|
---|
1340 | * Returns the current page number.
|
---|
1341 | *
|
---|
1342 | * @access public
|
---|
1343 | * @param integer $page
|
---|
1344 | * @return integer;
|
---|
1345 | */
|
---|
1346 | public function getMyNumPage($page=null)
|
---|
1347 | {
|
---|
1348 | if ($page===null) {
|
---|
1349 | $page = $this->page;
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | if ($this->_myLastPageGroupNb==0) {
|
---|
1353 | return $page;
|
---|
1354 | } else {
|
---|
1355 | return $page-$this->_myLastPageGroup;
|
---|
1356 | }
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | /**
|
---|
1360 | * Start a new group of pages
|
---|
1361 | *
|
---|
1362 | * @access public
|
---|
1363 | * @return integer;
|
---|
1364 | * @see tcpdf::startPageGroup
|
---|
1365 | */
|
---|
1366 | public function myStartPageGroup()
|
---|
1367 | {
|
---|
1368 | $this->_myLastPageGroup = $this->page-1;
|
---|
1369 | $this->_myLastPageGroupNb++;
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 | /**
|
---|
1373 | * get $_myLastPageGroup;
|
---|
1374 | *
|
---|
1375 | * @access public
|
---|
1376 | * @return integer $_myLastPageGroup;
|
---|
1377 | */
|
---|
1378 | public function getMyLastPageGroup()
|
---|
1379 | {
|
---|
1380 | return $this->_myLastPageGroup;
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 | /**
|
---|
1384 | * set $_myLastPageGroup;
|
---|
1385 | *
|
---|
1386 | * @access public
|
---|
1387 | * @param integer $myLastPageGroup;
|
---|
1388 | */
|
---|
1389 | public function setMyLastPageGroup($myLastPageGroup)
|
---|
1390 | {
|
---|
1391 | $this->_myLastPageGroup = $myLastPageGroup;
|
---|
1392 | }
|
---|
1393 |
|
---|
1394 | /**
|
---|
1395 | * get $_myLastPageGroupNb;
|
---|
1396 | *
|
---|
1397 | * @access public
|
---|
1398 | * @return integer $_myLastPageGroupNb;
|
---|
1399 | */
|
---|
1400 | public function getMyLastPageGroupNb()
|
---|
1401 | {
|
---|
1402 | return $this->_myLastPageGroupNb;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | /**
|
---|
1406 | * set $_myLastPageGroupNb;
|
---|
1407 | *
|
---|
1408 | * @access public
|
---|
1409 | * @param integer $myLastPageGroupNb;
|
---|
1410 | */
|
---|
1411 | public function setMyLastPageGroupNb($myLastPageGroupNb)
|
---|
1412 | {
|
---|
1413 | $this->_myLastPageGroupNb = $myLastPageGroupNb;
|
---|
1414 | }
|
---|
1415 | }
|
---|