source: trunk/client/inc/hpdf5/spipu/html2pdf/src/MyPdf.php@ 424

Last change on this file since 424 was 347, checked in by roby, 4 years ago

Aggiornamento per compatibilità con php7.4

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