Some assorted fixes for html2pdf (converted line endings) and the patient report.
[openemr.git] / library / html2pdf / html2pdf.class.php
blob30e256e33c86bca14424573310cd47307670066e
1 <?php
2 /**
3 * Logiciel : HTML2PDF
4 *
5 * Convertisseur HTML => PDF, utilise FPDF
6 * Distribué sous la licence LGPL.
8 * @author Laurent MINGUET <webmaster@html2pdf.fr>
9 * @version 3.31
12 if (!defined('__CLASS_HTML2PDF__'))
14 define('__CLASS_HTML2PDF__', '3.31');
16 require_once(dirname(__FILE__).'/_mypdf/mypdf.class.php'); // classe mypdf
17 require_once(dirname(__FILE__).'/fpdi/fpdi.php'); // Added by Rod
18 require_once(dirname(__FILE__).'/parsingHTML.class.php'); // classe de parsing HTML
19 require_once(dirname(__FILE__).'/styleHTML.class.php'); // classe de gestion des styles
21 global $HTML2PDF_TABLEAU; $HTML2PDF_TABLEAU = array(); // tableau global necessaire à la gestion des tables imbriquées
22 global $HTML2PDF_TEXTES; $HTML2PDF_TEXTES = array(); // tableau comprennant le fichier de langue
24 class HTML2PDF
26 var $pdf = null; // objet PDF
27 var $style = null; // objet de style
28 var $parsing = null; // objet de parsing
30 var $langue = 'fr'; // langue des messages
31 var $sens = 'P'; // sens d'affichage Portrait ou Landscape
32 var $format = 'A4'; // format de la page : A4, A3, ...
33 var $encoding = ''; // charset encoding
35 var $background = array(); // informations sur le background
36 var $testTDin1page = true; // activer le test de TD ne devant pas depasser une page
37 var $testIsImage = true; // test si les images existes ou non
38 var $testIsDeprecated = false; // test si certaines fonctions sont deprecated
39 var $isSubPart = false; // indique que le convertisseur courant est un sous html
41 var $parse_pos = 0; // position du parsing
42 var $temp_pos = 0; // position temporaire pour multi tableau
43 var $page = 0; // numero de la page courante
45 var $sub_html = null; // sous html
46 var $sub_part = false; // indicateur de sous html
48 var $maxX = 0; // zone maxi X
49 var $maxY = 0; // zone maxi Y
50 var $maxE = 0; // nomre d'elements dans la zone
51 var $maxH = 0; // plus grande hauteur dans la ligne, pour saut de ligne à corriger
52 var $maxSave = array(); // tableau de sauvegarde des maximaux
53 var $currentH = 0; // hauteur de la ligne courante
55 var $firstPage = true; // premier page
57 var $defaultLeft = 0; // marges par default de la page
58 var $defaultTop = 0;
59 var $defaultRight = 0;
60 var $defaultBottom = 0;
62 var $margeLeft = 0; //marges réelles de la page
63 var $margeTop = 0;
64 var $margeRight = 0;
65 var $margeBottom = 0;
66 var $marges = array(); // tableau de sauvegarde des differents etats des marges de la page courante
68 var $inLink = ''; // indique si on est à l'interieur d'un lien
69 var $lstAncre = array(); // liste des ancres détectées ou créées
70 var $subHEADER = array(); // tableau des sous commandes pour faire l'HEADER
71 var $subFOOTER = array(); // tableau des sous commandes pour faire le FOOTER
72 var $subSTATES = array(); // tableau de sauvegarde de certains paramètres
73 var $defLIST = array(); // tableau de sauvegarde de l'etat des UL et OL
75 var $lstChamps = array(); // liste des champs
76 var $lstSelect = array(); // options du select en cours
77 var $previousCall = null; // dernier appel
78 var $pageMarges = array(); // marges spécifiques dues aux floats
79 var $isInThead = false; // indique si on est dans un thead
80 var $isInTfoot = false; // indique si on est dans un tfoot
81 var $isInOverflow = false; // indique si on est dans une div overflow
82 var $isInFooter = false; // indique si on est dans un footer ou non
83 var $isInDraw = null; // indique si on est en mode dessin
84 var $isAfterFloat = false; // indique si on est apres un float
85 var $forOneLine = false; // indique si on est dans un sous HTML ne servant qu'a calculer la taille de la prochaine ligne
86 var $isInForm = false; // indique si on est dans un formulaire. Contient dans ce cas là l'action de celui-ci
88 var $DEBUG_actif = false; // indique si on est en mode debug
89 var $DEBUG_ok_usage = false; // indique l'existance de la fonction memory_get_usage
90 var $DEBUG_ok_peak = false; // indique l'existance de la fonction memory_get_peak_usage
91 var $DEBUG_level = 0; // niveau du debug
92 var $DEBUG_start_time = 0; //
93 var $DEBUG_last_time = 0; //
94 var $defaultFont = null; // fonte par défaut si la fonte demandée n'existe pas
96 /**
97 * Constructeur
99 * @param string sens portrait ou landscape
100 * @param string format A4, A5, ...
101 * @param string langue : fr, en, it...
102 * @param array marges par defaut, dans l'ordre (left, top, right, bottom)
103 * @return null
105 function HTML2PDF($sens = 'P', $format = 'A4', $langue='fr', $marges = array(5, 5, 5, 8))
107 // sauvegarde des paramètres
108 $this->page = 0;
109 $this->sens = $sens;
110 $this->format = $format;
111 $this->encoding = 'ISO-8859-15';
113 $this->firstPage = true;
114 $this->langue = strtolower($langue);
116 // chargement du fichier de langue
117 HTML2PDF::textLOAD($this->langue);
119 // création de l' objet PDF
120 $this->pdf = new FPDI($sens, 'mm', $format);
122 // initialisation des styles
123 $this->style = new styleHTML($this->pdf);
124 $this->style->FontSet();
125 $this->defLIST = array();
127 // initialisations diverses
128 $this->setTestTdInOnePage(true);
129 $this->setTestIsImage(true);
130 $this->setTestIsDeprecated(true);
131 $this->setDefaultFont(null);
133 // initialisation du parsing
134 $this->parsing = new parsingHTML($this->encoding);
135 $this->sub_html = null;
136 $this->sub_part = false;
138 // initialisation des marges
139 if (!is_array($marges)) $marges = array($marges, $marges, $marges, $marges);
140 $this->setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]);
141 $this->setMargins();
142 $this->marges = array();
144 // initialisation des champs de formulaire
145 $this->lstChamps = array();
149 * activer le debug mode
151 * @return null
153 function setModeDebug()
155 list($usec, $sec) = explode(' ', microtime());
157 $this->DEBUG_actif = true;
158 $this->DEBUG_ok_usage = function_exists('memory_get_usage');
159 $this->DEBUG_ok_peak = function_exists('memory_get_peak_usage');
160 $this->DEBUG_start_time = (float)$sec + (float)$usec;
161 $this->DEBUG_last_time = (float)$sec + (float)$usec;
163 $this->DEBUG_stepline('step', 'time', 'delta', 'memory', 'peak');
164 $this->DEBUG_add('Init debug');
168 * rajouter une ligne de debug
170 * @param string nom de l'etape
171 * @param boolean true=monter d'un niveau, false=descendre d'un niveau, null : ne rien faire
172 * @return null
174 function DEBUG_add($nom, $level=null)
176 list($usec, $sec) = explode(' ', microtime());
177 if ($level===true) $this->DEBUG_level++;
179 $nom = str_repeat(' ',$this->DEBUG_level). $nom.($level===true ? ' Begin' : ($level===false ? ' End' : ''));
180 $time = (float)$sec + (float)$usec;
181 $usage = ($this->DEBUG_ok_usage ? memory_get_usage() : 0);
182 $peak = ($this->DEBUG_ok_peak ? memory_get_peak_usage() : 0);
184 $this->DEBUG_stepline(
185 $nom,
186 number_format(($time - $this->DEBUG_start_time)*1000, 1, '.', ' ').' ms',
187 number_format(($time - $this->DEBUG_last_time)*1000, 1, '.', ' ').' ms',
188 number_format($usage/1024, 1, '.', ' ').' Ko',
189 number_format($peak/1024, 1, '.', ' ').' Ko');
191 $this->DEBUG_last_time = $time;
192 if ($level===false) $this->DEBUG_level--;
193 return true;
197 * affiche une ligne de debug
199 * @param string nom de l'etape
200 * @param string valeur 1
201 * @param string valeur 2
202 * @param string valeur 3
203 * @param string valeur 4
204 * @return null
206 function DEBUG_stepline($nom, $val1, $val2, $val3, $val4)
208 $txt = str_pad($nom, 30, ' ', STR_PAD_RIGHT).
209 str_pad($val1, 12, ' ', STR_PAD_LEFT).
210 str_pad($val2, 12, ' ', STR_PAD_LEFT).
211 str_pad($val3, 15, ' ', STR_PAD_LEFT).
212 str_pad($val4, 15, ' ', STR_PAD_LEFT);
214 echo '<pre style="padding:0; margin:0">'.$txt.'</pre>';
218 * renseigner l'encoding à utiliser
221 * @param string nouvel encoding
222 * @return string ancien encoding
224 function setEncoding($encoding = 'ISO-8859-15')
226 $old = $this->encoding;
227 $this->encoding = $encoding;
228 $this->parsing->setEncoding($this->encoding);
229 return $old;
233 * activer ou desactiver le test de TD ne devant pas depasser une page
235 * @param boolean nouvel etat
236 * @return boolean ancien etat
238 function setTestTdInOnePage($mode = true)
240 $old = $this->testTDin1page;
241 $this->testTDin1page = $mode ? true : false;
242 return $old;
246 * activer ou desactiver le test sur la présence des images
248 * @param boolean nouvel etat
249 * @return boolean ancien etat
251 function setTestIsImage($mode = true)
253 $old = $this->testIsImage;
254 $this->testIsImage = $mode ? true : false;
255 return $old;
259 * activer ou desactiver le test sur les fonctions deprecated
261 * @param boolean nouvel etat
262 * @return boolean ancien etat
264 function setTestIsDeprecated($mode = true)
266 $old = $this->testIsDeprecated;
267 $this->testIsDeprecated = $mode ? true : false;
268 return $old;
272 * définit la fonte par défaut si aucun fonte n'est spécifiée, ou si la fonte demandée n'existe pas
274 * @param string nom de la fonte par defaut. si null : Arial pour fonte non spécifiée, et erreur pour fonte non existante
275 * @return string nom de l'ancienne fonte par defaut
277 function setDefaultFont($default = null)
279 $old = $this->defaultFont;
280 $this->defaultFont = $default;
281 $this->style->setDefaultFont($default);
282 return $old;
286 * définir les marges par défault
288 * @param int en mm, marge left
289 * @param int en mm, marge top
290 * @param int en mm, marge right. si null, left=right
291 * @param int en mm, marge bottom. si null, bottom=8
292 * @return null
294 function setDefaultMargins($left, $top, $right = null, $bottom = null)
296 if ($right===null) $right = $left;
297 if ($bottom===null) $bottom = 8;
299 $this->defaultLeft = $this->style->ConvertToMM($left.'mm');
300 $this->defaultTop = $this->style->ConvertToMM($top.'mm');
301 $this->defaultRight = $this->style->ConvertToMM($right.'mm');
302 $this->defaultBottom = $this->style->ConvertToMM($bottom.'mm');
306 * définir les marges réelles, fonctions de la balise page
308 * @return null
310 function setMargins()
312 $this->margeLeft = $this->defaultLeft + (isset($this->background['left']) ? $this->background['left'] : 0);
313 $this->margeRight = $this->defaultRight + (isset($this->background['right']) ? $this->background['right'] : 0);
314 $this->margeTop = $this->defaultTop + (isset($this->background['top']) ? $this->background['top'] : 0);
315 $this->margeBottom = $this->defaultBottom + (isset($this->background['bottom']) ? $this->background['bottom'] : 0);
317 $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
318 $this->pdf->setcMargin(0);
319 $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
321 $this->pageMarges = array();
322 $this->pageMarges[floor($this->margeTop*100)] = array($this->margeLeft, $this->pdf->getW()-$this->margeRight);
326 * recuperer les positions x minimales et maximales en fonction d'une hauteur
328 * @param float y
329 * @return array(float, float)
331 function getMargins($y)
333 $y = floor($y*100);
334 $x = array($this->pdf->getlMargin(), $this->pdf->getW()-$this->pdf->getrMargin());
336 foreach($this->pageMarges as $m_y => $m_x)
337 if ($m_y<=$y) $x = $m_x;
339 return $x;
343 * ajouter une marge suite a un float
345 * @param string left ou right
346 * @param float x1
347 * @param float y1
348 * @param float x2
349 * @param float y2
350 * @return null
352 function addMargins($float, $x1, $y1, $x2, $y2)
354 $old1 = $this->getMargins($y1);
355 $old2 = $this->getMargins($y2);
356 if ($float=='left') $old1[0] = $x2;
357 if ($float=='right') $old1[1] = $x1;
359 $y1 = floor($y1*100);
360 $y2 = floor($y2*100);
362 foreach($this->pageMarges as $m_y => $m_x)
364 if ($m_y<$y1) continue;
365 if ($m_y>$y2) break;
366 if ($float=='left' && $this->pageMarges[$m_y][0]<$x2) unset($this->pageMarges[$m_y]);
367 if ($float=='right' && $this->pageMarges[$m_y][1]>$x1) unset($this->pageMarges[$m_y]);
370 $this->pageMarges[$y1] = $old1;
371 $this->pageMarges[$y2] = $old2;
373 ksort($this->pageMarges);
375 $this->isAfterFloat = true;
379 * définir des nouvelles marges et sauvegarder les anciennes
381 * @param float marge left
382 * @param float marge top
383 * @param float marge right
384 * @return null
386 function saveMargin($ml, $mt, $mr)
388 $this->marges[] = array('l' => $this->pdf->getlMargin(), 't' => $this->pdf->gettMargin(), 'r' => $this->pdf->getrMargin(), 'page' => $this->pageMarges);
389 $this->pdf->SetMargins($ml, $mt, $mr);
391 $this->pageMarges = array();
392 $this->pageMarges[floor($mt*100)] = array($ml, $this->pdf->getW()-$mr);
396 * récuperer les dernières marches sauvées
398 * @return null
400 function loadMargin()
402 $old = array_pop($this->marges);
403 if ($old)
405 $ml = $old['l'];
406 $mt = $old['t'];
407 $mr = $old['r'];
408 $mP = $old['page'];
410 else
412 $ml = $this->margeLeft;
413 $mt = 0;
414 $mr = $this->margeRight;
415 $mP = array($mt => array($ml, $this->pdf->getW()-$mr));
418 $this->pdf->SetMargins($ml, $mt, $mr);
419 $this->pageMarges = $mP;
423 * permet d'ajouter une fonte.
425 * @param string nom de la fonte
426 * @param string style de la fonte
427 * @param string fichier de la fonte
428 * @return null
430 function addFont($family, $style='', $file='')
432 $this->pdf->AddFont($family, $style, $file);
436 * sauvegarder l'état actuelle des maximums
438 * @return null
440 function saveMax()
442 $this->maxSave[] = array($this->maxX, $this->maxY, $this->maxH, $this->maxE);
446 * charger le dernier état sauvé des maximums
448 * @return null
450 function loadMax()
452 $old = array_pop($this->maxSave);
454 if ($old)
456 $this->maxX = $old[0];
457 $this->maxY = $old[1];
458 $this->maxH = $old[2];
459 $this->maxE = $old[3];
461 else
463 $this->maxX = 0;
464 $this->maxY = 0;
465 $this->maxH = 0;
466 $this->maxE = 0;
471 * afficher l'header contenu dans page_header
473 * @return null
475 function setPageHeader()
477 if (!count($this->subHEADER)) return false;
479 $OLD_parse_pos = $this->parse_pos;
480 $OLD_parse_code = $this->parsing->code;
482 $this->parse_pos = 0;
483 $this->parsing->code = $this->subHEADER;
484 $this->makeHTMLcode();
486 $this->parse_pos = $OLD_parse_pos;
487 $this->parsing->code = $OLD_parse_code;
491 * afficher le footer contenu dans page_footer
493 * @return null
495 function setPageFooter()
497 if (!count($this->subFOOTER)) return false;
499 $OLD_parse_pos = $this->parse_pos;
500 $OLD_parse_code = $this->parsing->code;
502 $this->parse_pos = 0;
503 $this->parsing->code = $this->subFOOTER;
504 $this->isInFooter = true;
505 $this->makeHTMLcode();
506 $this->isInFooter = false;
508 $this->parse_pos = $OLD_parse_pos;
509 $this->parsing->code = $OLD_parse_code;
513 * saut de ligne avec une hauteur spécifique
515 * @param float hauteur de la ligne
516 * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
517 * @return null
519 function setNewLine($h, $curr = null)
521 $this->pdf->Ln($h);
523 $this->setNewPositionForNewLine($curr);
527 * création d'une nouvelle page avec le format et l'orientation spécifies
529 * @param mixed format de la page : A5, A4, array(width, height)
530 * @param string sens P=portrait ou L=landscape
531 * @param array tableau des propriétés du fond de la page
532 * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
533 * @return null
535 function setNewPage($format = null, $orientation = '', $background = null, $curr = null)
537 $this->firstPage = false;
539 $this->format = $format ? $format : $this->format;
540 $this->sens = $orientation ? $orientation : $this->sens;
541 $this->background = $background!==null ? $background : $this->background;
542 $this->maxY = 0;
543 $this->maxX = 0;
544 $this->maxH = 0;
546 $this->pdf->SetMargins($this->defaultLeft, $this->defaultTop, $this->defaultRight);
547 $this->pdf->AddPage($this->sens, $this->format);
548 $this->page++;
550 if (!$this->sub_part && !$this->isSubPart)
552 if (is_array($this->background))
554 if (isset($this->background['color']) && $this->background['color'])
556 $this->pdf->setMyFillColor($this->background['color']);
557 $this->pdf->Rect(0, 0, $this->pdf->getW(), $this->pdf->getH(), 'F');
560 if (isset($this->background['img']) && $this->background['img'])
561 $this->pdf->Image($this->background['img'], $this->background['posX'], $this->background['posY'], $this->background['width']);
564 $this->setPageHeader();
565 $this->setPageFooter();
568 $this->setMargins();
569 $this->pdf->setY($this->margeTop);
571 $this->setNewPositionForNewLine($curr);
572 $this->maxH = 0;
576 * calcul de la position de debut de la prochaine ligne en fonction de l'alignement voulu
578 * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
579 * @return null
581 function setNewPositionForNewLine($curr = null)
583 list($lx, $rx) = $this->getMargins($this->pdf->getY());
584 $this->pdf->setX($lx);
585 $wMax = $rx-$lx;
586 $this->currentH = 0;
588 if ($this->sub_part || $this->isSubPart || $this->forOneLine)
590 // $this->pdf->setWordSpacing(0);
591 return null;
594 if (
595 $this->style->value['text-align']!='right' &&
596 $this->style->value['text-align']!='center' &&
597 $this->style->value['text-align']!='justify'
600 // $this->pdf->setWordSpacing(0);
601 return null;
604 $sub = null;
605 $this->createSubHTML($sub);
606 $sub->saveMargin(0, 0, $sub->pdf->getW()-$wMax);
607 $sub->forOneLine = true;
608 $sub->parse_pos = $this->parse_pos;
609 $sub->parsing->code = $this->parsing->code;
611 if ($curr!==null && $sub->parsing->code[$this->parse_pos]['name']=='write')
613 $txt = $sub->parsing->code[$this->parse_pos]['param']['txt'];
614 $txt = str_replace('[[page_cu]]', $sub->page, $txt);
615 $sub->parsing->code[$this->parse_pos]['param']['txt'] = substr($txt, $curr);
617 else
618 $sub->parse_pos++;
620 // pour chaque element identifié par le parsing
621 $res = null;
622 for($sub->parse_pos; $sub->parse_pos<count($sub->parsing->code); $sub->parse_pos++)
624 $todo = $sub->parsing->code[$sub->parse_pos];
625 $res = $sub->loadAction($todo);
626 if (!$res) break;
629 $w = $sub->maxX; // largeur maximale
630 $h = $sub->maxH; // hauteur maximale
631 $e = ($res===null ? $sub->maxE : 0); // nombre d'éléments maximal
632 $this->destroySubHTML($sub);
634 if ($this->style->value['text-align']=='center')
635 $this->pdf->setX(($rx+$this->pdf->getX()-$w)*0.5-0.01);
636 elseif ($this->style->value['text-align']=='right')
637 $this->pdf->setX($rx-$w-0.01);
638 else
639 $this->pdf->setX($lx);
641 $this->currentH = $h;
643 if ($this->style->value['text-align']=='justify' && $e>1)
644 $this->pdf->setWordSpacing(($wMax-$w)/($e-1));
645 else
646 $this->pdf->setWordSpacing(0);
650 /**
651 * récupération du PDF
653 * @param string nom du fichier PDF
654 * @param boolean destination
655 * @return string contenu éventuel du pdf
658 * Destination où envoyer le document. Le paramètre peut prendre les valeurs suivantes :
659 * true : equivalent à I
660 * false : equivalent à S
661 * I : envoyer en inline au navigateur. Le plug-in est utilisé s'il est installé. Le nom indiqué dans name est utilisé lorsque l'on sélectionne "Enregistrer sous" sur le lien générant le PDF.
662 * D : envoyer au navigateur en forçant le téléchargement, avec le nom indiqué dans name.
663 * F : sauver dans un fichier local, avec le nom indiqué dans name (peut inclure un répertoire).
664 * S : renvoyer le document sous forme de chaîne. name est ignoré.
666 function Output($name = '', $dest = false)
668 // nettoyage
669 global $HTML2PDF_TABLEAU; $HTML2PDF_TABLEAU = array();
671 if ($this->DEBUG_actif)
673 $this->DEBUG_add('Before output');
674 $this->pdf->Close();
675 exit;
678 // interpretation des paramètres
679 if ($dest===false) $dest = 'I';
680 if ($dest===true) $dest = 'S';
681 if ($dest==='') $dest = 'I';
682 if ($name=='') $name='document.pdf';
684 // verification de la destination
685 $dest = strtoupper($dest);
686 if (!in_array($dest, array('I', 'D', 'F', 'S'))) $dest = 'I';
688 // verification du nom
689 if (strtolower(substr($name, -4))!='.pdf')
691 echo 'ERROR : The output document name "'.$name.'" is not a PDF name';
692 exit;
695 return $this->pdf->Output($name, $dest);
699 * création d'un sous HTML2PDF pour la gestion des tableaux imbriqués
701 * @param HTML2PDF futur sous HTML2PDF passé en référence pour création
702 * @param integer marge eventuelle de l'objet si simulation d'un TD
703 * @return null
705 function createSubHTML(&$sub_html, $cellmargin=0)
707 // calcul de la largueur
708 if ($this->style->value['width'])
710 $marge = $cellmargin*2;
711 $marge+= $this->style->value['padding']['l'] + $this->style->value['padding']['r'];
712 $marge+= $this->style->value['border']['l']['width'] + $this->style->value['border']['r']['width'];
713 $marge = $this->pdf->getW() - $this->style->value['width'] + $marge;
715 else
716 $marge = $this->margeLeft+$this->margeRight;
718 //clonage
719 $sub_html = new HTML2PDF(
720 $this->sens,
721 $this->format,
722 $this->langue,
723 array($this->defaultLeft,$this->defaultTop,$this->defaultRight,$this->defaultBottom)
725 $sub_html->setIsSubPart();
726 $sub_html->setEncoding($this->encoding);
727 $sub_html->setTestTdInOnePage($this->testTDin1page);
728 $sub_html->setTestIsImage($this->testIsImage);
729 $sub_html->setTestIsDeprecated($this->testIsDeprecated);
730 $sub_html->setDefaultFont($this->defaultFont);
731 $sub_html->style->css = $this->style->css;
732 $sub_html->style->css_keys = $this->style->css_keys;
733 $sub_html->pdf->cloneFontFrom($this->pdf);
735 $sub_html->style->table = $this->style->table;
736 $sub_html->style->value = $this->style->value;
737 $sub_html->style->setOnlyLeft();
738 $sub_html->setNewPage($this->format, $this->sens);
739 $sub_html->initSubHtml($marge, $this->page, $this->defLIST);
741 // initialisation des positions et autre
742 $sub_html->maxX = 0;
743 $sub_html->maxY = 0;
744 $sub_html->maxH = 0;
745 $sub_html->pdf->setXY(0, 0);
749 * initialise le sous HTML2PDF. Ne pas utiliser directement. seul la fonction createSubHTML doit l'utiliser
751 * @return null
753 function initSubHtml($marge, $page, $defLIST)
755 $this->saveMargin(0, 0, $marge);
756 $this->defLIST = $defLIST;
758 $this->page = $page;
759 $this->pdf->setXY(0, 0);
760 $this->style->FontSet();
763 function setIsSubPart()
765 $this->isSubPart = true;
769 * destruction d'un sous HTML2PDF pour la gestion des tableaux imbriqués
771 * @return null
773 function destroySubHTML(&$sub_html)
775 unset($sub_html);
776 $sub_html = null;
780 * Convertir un nombre arabe en nombre romain
782 * @param integer nombre à convertir
783 * @return string nombre converti
785 function listeArab2Rom($nb_ar)
787 $nb_b10 = array('I','X','C','M');
788 $nb_b5 = array('V','L','D');
789 $nb_ro = '';
791 if ($nb_ar<1) return $nb_ar;
792 if ($nb_ar>3999) return $nb_ar;
794 for($i=3; $i>=0 ; $i--)
796 $chiffre=floor($nb_ar/pow(10,$i));
797 if($chiffre>=1)
799 $nb_ar=$nb_ar-$chiffre*pow(10,$i);
800 if($chiffre<=3)
802 for($j=$chiffre; $j>=1; $j--)
804 $nb_ro=$nb_ro.$nb_b10[$i];
807 else if($chiffre==9)
809 $nb_ro=$nb_ro.$nb_b10[$i].$nb_b10[$i+1];
811 elseif($chiffre==4)
813 $nb_ro=$nb_ro.$nb_b10[$i].$nb_b5[$i];
815 else
817 $nb_ro=$nb_ro.$nb_b5[$i];
818 for($j=$chiffre-5; $j>=1; $j--)
820 $nb_ro=$nb_ro.$nb_b10[$i];
825 return $nb_ro;
829 * Ajouter un LI au niveau actuel
831 * @return null
833 function listeAddLi()
835 $this->defLIST[count($this->defLIST)-1]['nb']++;
838 function listeGetWidth() { return '7mm'; }
839 function listeGetPadding() { return '1mm'; }
842 * Recuperer le LI du niveau actuel
844 * @return string chaine à afficher
846 function listeGetLi()
848 $im = $this->defLIST[count($this->defLIST)-1]['img'];
849 $st = $this->defLIST[count($this->defLIST)-1]['style'];
850 $nb = $this->defLIST[count($this->defLIST)-1]['nb'];
851 $up = (substr($st, 0, 6)=='upper-');
853 if ($im) return array(false, false, $im);
855 switch($st)
857 case 'none':
858 return array('helvetica', true, ' ');
860 case 'upper-alpha':
861 case 'lower-alpha':
862 $str = '';
863 while($nb>26)
865 $str = chr(96+$nb%26).$str;
866 $nb = floor($nb/26);
868 $str = chr(96+$nb).$str;
870 return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
872 case 'upper-roman':
873 case 'lower-roman':
874 $str = $this->listeArab2Rom($nb);
876 return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
878 case 'decimal':
879 return array('helvetica', false, $nb.'.');
881 case 'square':
882 return array('zapfdingbats', true, chr(110));
884 case 'circle':
885 return array('zapfdingbats', true, chr(109));
887 case 'disc':
888 default:
889 return array('zapfdingbats', true, chr(108));
894 * Ajouter un niveau de liste
896 * @param string type de liste : ul, ol
897 * @param string style de la liste
898 * @return null
900 function listeAddLevel($type = 'ul', $style = '', $img = null)
902 if ($img)
904 if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match))
905 $img = $match[1];
906 else
907 $img = null;
909 else
910 $img = null;
912 if (!in_array($type, array('ul', 'ol'))) $type = 'ul';
913 if (!in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = '';
915 if (!$style)
917 if ($type=='ul') $style = 'disc';
918 else $style = 'decimal';
920 $this->defLIST[count($this->defLIST)] = array('style' => $style, 'nb' => 0, 'img' => $img);
924 * Supprimer un niveau de liste
926 * @return null
928 function listeDelLevel()
930 if (count($this->defLIST))
932 unset($this->defLIST[count($this->defLIST)-1]);
933 $this->defLIST = array_values($this->defLIST);
938 * traitement d'un code HTML fait pour HTML2PDF
940 * @param string code HTML à convertir
941 * @param boolean afficher en pdf (false) ou en html adapté (true)
942 * @return null
944 function writeHTML($html, $vue = false)
946 // si c'est une vrai page HTML, une conversion s'impose
947 if (preg_match('/<body/isU', $html))
948 $html = $this->getHtmlFromPage($html);
950 $html = str_replace('[[page_nb]]', '{nb}', $html);
952 $html = str_replace('[[date_y]]', date('Y'), $html);
953 $html = str_replace('[[date_m]]', date('m'), $html);
954 $html = str_replace('[[date_d]]', date('d'), $html);
956 $html = str_replace('[[date_h]]', date('H'), $html);
957 $html = str_replace('[[date_i]]', date('i'), $html);
958 $html = str_replace('[[date_s]]', date('s'), $html);
960 // si on veut voir le résultat en HTML => on appelle la fonction
961 if ($vue) $this->vueHTML($html);
963 // sinon, traitement pour conversion en PDF :
964 // parsing
965 $this->sub_pdf = false;
966 $this->style->readStyle($html);
967 $this->parsing->setHTML($html);
968 $this->parsing->parse();
969 $this->makeHTMLcode();
973 * traitement du code d'une vrai page HTML pour l'adapter à HTML2PDF
975 * @param string code HTML à adapter
976 * @return string code HTML adapté
978 function getHtmlFromPage($html)
980 $html = str_replace('<BODY', '<body', $html);
981 $html = str_replace('</BODY', '</body', $html);
983 // extraction du contenu
984 $res = explode('<body', $html);
985 if (count($res)<2) return $html;
986 $content = '<page'.$res[1];
987 $content = explode('</body', $content);
988 $content = $content[0].'</page>';
990 // extraction des balises link
991 preg_match_all('/<link([^>]*)>/isU', $html, $match);
992 foreach($match[0] as $src)
993 $content = $src.'</link>'.$content;
995 // extraction des balises style
996 preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
997 foreach($match[0] as $src)
998 $content = $src.$content;
1000 return $content;
1004 * execute les différentes actions du code HTML
1006 * @return null
1008 function makeHTMLcode()
1010 // pour chaque element identifié par le parsing
1011 for($this->parse_pos=0; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
1013 // récupération de l'élément
1014 $todo = $this->parsing->code[$this->parse_pos];
1016 // si c'est une ouverture de tableau
1017 if (in_array($todo['name'], array('table', 'ul', 'ol')) && !$todo['close'])
1019 // on va créer un sous HTML, et on va travailler sur une position temporaire
1020 $tag_open = $todo['name'];
1022 $this->sub_part = true;
1023 $this->temp_pos = $this->parse_pos;
1025 // pour tous les éléments jusqu'à la fermeture de la table afin de préparer les dimensions
1026 while(isset($this->parsing->code[$this->temp_pos]) && !($this->parsing->code[$this->temp_pos]['name']==$tag_open && $this->parsing->code[$this->temp_pos]['close']))
1028 $this->loadAction($this->parsing->code[$this->temp_pos]);
1029 $this->temp_pos++;
1031 if (isset($this->parsing->code[$this->temp_pos])) $this->loadAction($this->parsing->code[$this->temp_pos]);
1032 $this->sub_part = false;
1035 // chargement de l'action correspondant à l'élément
1036 $this->loadAction($todo);
1043 * affichage en mode HTML du contenu
1045 * @param string contenu
1046 * @return null
1048 function vueHTML($content)
1050 $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue01').' : $1<hr><div$1>', $content);
1051 $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue02').' : $1<hr><div$1>', $content);
1052 $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue03').' : $1<hr><div$1>', $content);
1053 $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content);
1054 $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content);
1055 $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content);
1056 $content = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $content);
1057 $content = preg_replace('/<\/barcode([^>]*)>/isU', '', $content);
1058 $content = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $content);
1059 $content = preg_replace('/<\/qrcode([^>]*)>/isU', '', $content);
1061 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
1062 <html>
1063 <head>
1064 <title>'.HTML2PDF::textGET('vue04').' HTML</title>
1065 <meta http-equiv="Content-Type" content="text/html; charset='.$this->encoding.'" >
1066 </head>
1067 <body style="padding: 10px; font-size: 10pt;font-family: Verdana;">
1068 '.$content.'
1069 </body>
1070 </html>';
1071 exit;
1075 * chargement de l'action correspondante à un element de parsing
1077 * @param array élément de parsing
1078 * @return null
1080 function loadAction($row)
1082 // nom de l'action
1083 $fnc = ($row['close'] ? 'c_' : 'o_').strtoupper($row['name']);
1085 // parametres de l'action
1086 $param = $row['param'];
1088 // si aucune page n'est créé, on la créé
1089 if ($fnc!='o_PAGE' && $this->firstPage)
1091 $this->setNewPage();
1094 // lancement de l'action
1095 if (is_callable(array(&$this, $fnc)))
1097 $res = $this->{$fnc}($param);
1098 $this->previousCall = $fnc;
1099 return $res;
1101 else
1103 HTML2PDF::makeError(1, __FILE__, __LINE__, strtoupper($row['name']), $this->parsing->getHtmlErrorCode($row['html_pos']));
1104 return false;
1109 * balise : PAGE
1110 * mode : OUVERTURE
1112 * @param array paramètres de l'élément de parsing
1113 * @return null
1115 function o_PAGE($param)
1117 if ($this->forOneLine) return false;
1118 if ($this->DEBUG_actif) $this->DEBUG_add('PAGE n°'.($this->page+1), true);
1120 $newPageSet= (!isset($param['pageset']) || $param['pageset']!='old');
1122 $this->maxH = 0;
1123 if ($newPageSet)
1125 $this->subHEADER = array();
1126 $this->subFOOTER = array();
1128 // identification de l'orientation demandée
1129 $orientation = '';
1130 if (isset($param['orientation']))
1132 $param['orientation'] = strtolower($param['orientation']);
1133 if ($param['orientation']=='p') $orientation = 'P';
1134 if ($param['orientation']=='portrait') $orientation = 'P';
1136 if ($param['orientation']=='l') $orientation = 'L';
1137 if ($param['orientation']=='paysage') $orientation = 'L';
1138 if ($param['orientation']=='landscape') $orientation = 'L';
1141 // identification de l'orientation demandée
1142 $format = null;
1143 if (isset($param['format']))
1145 $format = strtolower($param['format']);
1146 if (preg_match('/^([0-9]+)x([0-9]+)$/isU', $format, $match))
1148 $format = array(intval($match[1]), intval($match[2]));
1152 // identification des propriétés du background
1153 $background = array();
1154 if (isset($param['backimg']))
1156 $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // nom de l'image
1157 $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // position horizontale de l'image
1158 $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // position verticale de l'image
1159 $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // taille de l'image (100% = largueur de la feuille)
1161 // conversion du nom de l'image, en cas de paramètres en _GET
1162 $background['img'] = str_replace('&amp;', '&', $background['img']);
1163 // conversion des positions
1164 if ($background['posX']=='left') $background['posX'] = '0%';
1165 if ($background['posX']=='center') $background['posX'] = '50%';
1166 if ($background['posX']=='right') $background['posX'] = '100%';
1167 if ($background['posY']=='top') $background['posY'] = '0%';
1168 if ($background['posY']=='middle') $background['posY'] = '50%';
1169 if ($background['posY']=='bottom') $background['posY'] = '100%';
1172 // si il y a une image de précisé
1173 if ($background['img'])
1175 // est-ce que c'est une image ?
1176 $infos=@GetImageSize($background['img']);
1177 if (count($infos)>1)
1179 // taille de l'image, en fonction de la taille spécifiée.
1180 $Wi = $this->style->ConvertToMM($background['width'], $this->pdf->getW());
1181 $Hi = $Wi*$infos[1]/$infos[0];
1183 // récupération des dimensions et positions de l'image
1184 $background['width'] = $Wi;
1185 $background['posX'] = $this->style->ConvertToMM($background['posX'], $this->pdf->getW() - $Wi);
1186 $background['posY'] = $this->style->ConvertToMM($background['posY'], $this->pdf->getH() - $Hi);
1188 else
1189 $background = array();
1191 else
1192 $background = array();
1195 // marges TOP et BOTTOM pour le texte.
1196 $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0';
1197 $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0';
1198 $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0';
1199 $background['right'] = isset($param['backright']) ? $param['backright'] : '0';
1201 if (preg_match('/^([0-9]*)$/isU', $background['top'])) $background['top'] .= 'mm';
1202 if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) $background['bottom'] .= 'mm';
1203 if (preg_match('/^([0-9]*)$/isU', $background['left'])) $background['left'] .= 'mm';
1204 if (preg_match('/^([0-9]*)$/isU', $background['right'])) $background['right'] .= 'mm';
1206 $background['top'] = $this->style->ConvertToMM($background['top'], $this->pdf->getH());
1207 $background['bottom'] = $this->style->ConvertToMM($background['bottom'], $this->pdf->getH());
1208 $background['left'] = $this->style->ConvertToMM($background['left'], $this->pdf->getW());
1209 $background['right'] = $this->style->ConvertToMM($background['right'], $this->pdf->getW());
1211 $res = false;
1212 $background['color'] = isset($param['backcolor']) ? $this->style->ConvertToColor($param['backcolor'], $res) : null;
1213 if (!$res) $background['color'] = null;
1215 $this->style->save();
1216 $this->style->analyse('PAGE', $param);
1217 $this->style->setPosition();
1218 $this->style->FontSet();
1220 // nouvelle page
1221 $this->setNewPage($format, $orientation, $background);
1223 // footer automatique
1224 if (isset($param['footer']))
1226 $lst = explode(';', $param['footer']);
1227 foreach($lst as $key => $val) $lst[$key] = trim(strtolower($val));
1228 $page = in_array('page', $lst);
1229 $date = in_array('date', $lst);
1230 $heure = in_array('heure', $lst);
1231 $form = in_array('form', $lst);
1233 else
1235 $page = null;
1236 $date = null;
1237 $heure = null;
1238 $form = null;
1240 $this->pdf->SetMyFooter($page, $date, $heure, $form);
1242 else
1244 $this->style->save();
1245 $this->style->analyse('PAGE', $param);
1246 $this->style->setPosition();
1247 $this->style->FontSet();
1249 $this->setNewPage();
1252 return true;
1256 * balise : PAGE
1257 * mode : FERMETURE
1259 * @param array paramètres de l'élément de parsing
1260 * @return null
1262 function c_PAGE($param)
1264 if ($this->forOneLine) return false;
1266 $this->maxH = 0;
1268 $this->style->load();
1269 $this->style->FontSet();
1271 if ($this->DEBUG_actif) $this->DEBUG_add('PAGE n°'.$this->page, false);
1273 return true;
1277 function o_PAGE_HEADER($param)
1279 if ($this->forOneLine) return false;
1281 $this->subHEADER = array();
1282 for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
1284 $todo = $this->parsing->code[$this->parse_pos];
1285 if ($todo['name']=='page_header') $todo['name']='page_header_sub';
1286 $this->subHEADER[] = $todo;
1287 if (strtolower($todo['name'])=='page_header_sub' && $todo['close']) break;
1290 $this->setPageHeader();
1292 return true;
1295 function o_PAGE_FOOTER($param)
1297 if ($this->forOneLine) return false;
1299 $this->subFOOTER = array();
1300 for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
1302 $todo = $this->parsing->code[$this->parse_pos];
1303 if ($todo['name']=='page_footer') $todo['name']='page_footer_sub';
1304 $this->subFOOTER[] = $todo;
1305 if (strtolower($todo['name'])=='page_footer_sub' && $todo['close']) break;
1308 $this->setPageFooter();
1310 return true;
1313 function o_PAGE_HEADER_SUB($param)
1315 if ($this->forOneLine) return false;
1317 // sauvegarde de l'état
1318 $this->subSTATES = array();
1319 $this->subSTATES['x'] = $this->pdf->getX();
1320 $this->subSTATES['y'] = $this->pdf->getY();
1321 $this->subSTATES['s'] = $this->style->value;
1322 $this->subSTATES['t'] = $this->style->table;
1323 $this->subSTATES['ml'] = $this->margeLeft;
1324 $this->subSTATES['mr'] = $this->margeRight;
1325 $this->subSTATES['mt'] = $this->margeTop;
1326 $this->subSTATES['mb'] = $this->margeBottom;
1327 $this->subSTATES['mp'] = $this->pageMarges;
1329 // nouvel etat pour le footer
1330 $this->pageMarges = array();
1331 $this->margeLeft = $this->defaultLeft;
1332 $this->margeRight = $this->defaultRight;
1333 $this->margeTop = $this->defaultTop;
1334 $this->margeBottom = $this->defaultBottom;
1335 $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
1336 $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
1337 $this->pdf->setXY($this->defaultLeft, $this->defaultTop);
1339 $this->style->initStyle();
1340 $this->style->resetStyle();
1341 $this->style->value['width'] = $this->pdf->getW() - $this->defaultLeft - $this->defaultRight;
1342 $this->style->table = array();
1344 $this->style->save();
1345 $this->style->analyse('page_header_sub', $param);
1346 $this->style->setPosition();
1347 $this->style->FontSet();
1348 $this->setNewPositionForNewLine();
1349 return true;
1352 function c_PAGE_HEADER_SUB($param)
1354 if ($this->forOneLine) return false;
1356 $this->style->load();
1358 // retablissement de l'etat
1359 $this->style->value = $this->subSTATES['s'];
1360 $this->style->table = $this->subSTATES['t'];
1361 $this->pageMarges = $this->subSTATES['mp'];
1362 $this->margeLeft = $this->subSTATES['ml'];
1363 $this->margeRight = $this->subSTATES['mr'];
1364 $this->margeTop = $this->subSTATES['mt'];
1365 $this->margeBottom = $this->subSTATES['mb'];
1366 $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
1367 $this->pdf->setbMargin($this->margeBottom);
1368 $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
1369 $this->pdf->setXY($this->subSTATES['x'], $this->subSTATES['y']);
1371 $this->style->FontSet();
1372 $this->maxH = 0;
1374 return true;
1377 function o_PAGE_FOOTER_SUB($param)
1379 if ($this->forOneLine) return false;
1381 $this->subSTATES = array();
1382 $this->subSTATES['x'] = $this->pdf->getX();
1383 $this->subSTATES['y'] = $this->pdf->getY();
1384 $this->subSTATES['s'] = $this->style->value;
1385 $this->subSTATES['t'] = $this->style->table;
1386 $this->subSTATES['ml'] = $this->margeLeft;
1387 $this->subSTATES['mr'] = $this->margeRight;
1388 $this->subSTATES['mt'] = $this->margeTop;
1389 $this->subSTATES['mb'] = $this->margeBottom;
1390 $this->subSTATES['mp'] = $this->pageMarges;
1392 // nouvel etat pour le footer
1393 $this->pageMarges = array();
1394 $this->margeLeft = $this->defaultLeft;
1395 $this->margeRight = $this->defaultRight;
1396 $this->margeTop = $this->defaultTop;
1397 $this->margeBottom = $this->defaultBottom;
1398 $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
1399 $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
1400 $this->pdf->setXY($this->defaultLeft, $this->defaultTop);
1403 $this->style->initStyle();
1404 $this->style->resetStyle();
1405 $this->style->value['width'] = $this->pdf->getW() - $this->defaultLeft - $this->defaultRight;
1406 $this->style->table = array();
1408 // on en créé un sous HTML que l'on transforme en PDF
1409 // pour récupérer la hauteur
1410 // on extrait tout ce qui est contenu dans le FOOTER
1411 $sub = null;
1412 $this->CreateSubHTML($sub);
1413 $sub->parsing->code = $this->parsing->getLevel($this->parse_pos);
1414 $sub->MakeHTMLcode();
1415 $this->pdf->setY($this->pdf->getH() - $sub->maxY - $this->defaultBottom - 0.01);
1416 $this->destroySubHTML($sub);
1418 $this->style->save();
1419 $this->style->analyse('page_footer_sub', $param);
1420 $this->style->setPosition();
1421 $this->style->FontSet();
1422 $this->setNewPositionForNewLine();
1424 return true;
1427 function c_PAGE_FOOTER_SUB($param)
1429 if ($this->forOneLine) return false;
1431 $this->style->load();
1433 $this->style->value = $this->subSTATES['s'];
1434 $this->style->table = $this->subSTATES['t'];
1435 $this->pageMarges = $this->subSTATES['mp'];
1436 $this->margeLeft = $this->subSTATES['ml'];
1437 $this->margeRight = $this->subSTATES['mr'];
1438 $this->margeTop = $this->subSTATES['mt'];
1439 $this->margeBottom = $this->subSTATES['mb'];
1440 $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
1441 $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
1442 $this->pdf->setXY($this->subSTATES['x'], $this->subSTATES['y']);
1444 $this->style->FontSet();
1445 $this->maxH = 0;
1447 return true;
1451 * balise : NOBREAK
1452 * mode : OUVERTURE
1454 * @param array paramètres de l'élément de parsing
1455 * @return null
1457 function o_NOBREAK($param)
1459 if ($this->forOneLine) return false;
1461 $this->maxH = 0;
1463 // on en créé un sous HTML que l'on transforme en PDF
1464 // pour analyse les dimensions
1465 // et voir si ca rentre
1466 $sub = null;
1467 $this->CreateSubHTML($sub);
1468 $sub->parsing->code = $this->parsing->getLevel($this->parse_pos);
1469 $sub->MakeHTMLcode();
1471 $y = $this->pdf->getY();
1472 if (
1473 $sub->maxY < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin()) &&
1474 $y + $sub->maxY>=($this->pdf->getH() - $this->pdf->getbMargin())
1476 $this->setNewPage();
1477 $this->destroySubHTML($sub);
1479 return true;
1484 * balise : NOBREAK
1485 * mode : FERMETURE
1487 * @param array paramètres de l'élément de parsing
1488 * @return null
1490 function c_NOBREAK($param)
1492 if ($this->forOneLine) return false;
1494 $this->maxH = 0;
1496 return true;
1500 * balise : DIV
1501 * mode : OUVERTURE
1503 * @param array paramètres de l'élément de parsing
1504 * @return null
1506 function o_DIV($param, $other = 'div')
1508 if ($this->forOneLine) return false;
1509 if ($this->DEBUG_actif) $this->DEBUG_add(strtoupper($other), true);
1511 $this->style->save();
1512 $this->style->analyse($other, $param);
1513 $this->style->FontSet();
1515 // gestion specifique a la balise legend pour l'afficher au bon endroit
1516 if (in_array($other, array('fieldset', 'legend')))
1518 if (isset($param['moveTop'])) $this->style->value['margin']['t'] += $param['moveTop'];
1519 if (isset($param['moveLeft'])) $this->style->value['margin']['l'] += $param['moveLeft'];
1520 if (isset($param['moveDown'])) $this->style->value['margin']['b'] += $param['moveDown'];
1523 $align_object = null;
1524 if ($this->style->value['margin-auto']) $align_object = 'center';
1526 $marge = array();
1527 $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
1528 $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
1529 $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
1530 $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
1532 // on extrait tout ce qui est contenu dans la DIV
1533 $level = $this->parsing->getLevel($this->parse_pos);
1535 // on en créé un sous HTML que l'on transforme en PDF
1536 // pour analyse les dimensions
1537 $w = 0; $h = 0;
1538 if (count($level))
1540 $sub = null;
1541 $this->CreateSubHTML($sub);
1542 $sub->parsing->code = $level;
1543 $sub->MakeHTMLcode();
1544 $w = $sub->maxX;
1545 $h = $sub->maxY;
1546 $this->destroySubHTML($sub);
1548 $w_reel = $w;
1549 $h_reel = $h;
1551 // if (($w==0 && $this->style->value['width']==0) || ($w>$this->style->value['width']) || $this->style->value['position']=='absolute')
1552 $w+= $marge['l']+$marge['r']+0.001;
1554 $h+= $marge['t']+$marge['b']+0.001;
1556 if ($this->style->value['overflow']=='hidden')
1558 $over_w = max($w, $this->style->value['width']);
1559 $over_h = max($h, $this->style->value['height']);
1560 $overflow = true;
1561 $this->style->value['old_maxX'] = $this->maxX;
1562 $this->style->value['old_maxY'] = $this->maxY;
1563 $this->style->value['old_maxH'] = $this->maxH;
1564 $this->style->value['old_overflow'] = $this->isInOverflow;
1565 $this->isInOverflow = true;
1567 else
1569 $over_w = null;
1570 $over_h = null;
1571 $overflow = false;
1572 $this->style->value['width'] = max($w, $this->style->value['width']);
1573 $this->style->value['height'] = max($h, $this->style->value['height']);
1576 switch($this->style->value['rotate'])
1578 case 90:
1579 $tmp = $over_h; $over_h = $over_w; $over_w = $tmp;
1580 $tmp = $h_reel; $h_reel = $w_reel; $w_reel = $tmp;
1581 unset($tmp);
1582 $w = $this->style->value['height'];
1583 $h = $this->style->value['width'];
1584 $t_x =-$h;
1585 $t_y = 0;
1586 break;
1588 case 180:
1589 $w = $this->style->value['width'];
1590 $h = $this->style->value['height'];
1591 $t_x = -$w;
1592 $t_y = -$h;
1593 break;
1595 case 270:
1596 $tmp = $over_h; $over_h = $over_w; $over_w = $tmp;
1597 $tmp = $h_reel; $h_reel = $w_reel; $w_reel = $tmp;
1598 unset($tmp);
1599 $w = $this->style->value['height'];
1600 $h = $this->style->value['width'];
1601 $t_x = 0;
1602 $t_y =-$w;
1603 break;
1605 default:
1606 $w = $this->style->value['width'];
1607 $h = $this->style->value['height'];
1608 $t_x = 0;
1609 $t_y = 0;
1610 break;
1613 if (!$this->style->value['position'])
1615 if (
1616 $w < ($this->pdf->getW() - $this->pdf->getlMargin()-$this->pdf->getrMargin()) &&
1617 $this->pdf->getX() + $w>=($this->pdf->getW() - $this->pdf->getrMargin())
1619 $this->o_BR(array());
1621 if (
1622 ($h < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin())) &&
1623 ($this->pdf->getY() + $h>=($this->pdf->getH() - $this->pdf->getbMargin())) &&
1624 !$this->isInOverflow
1626 $this->setNewPage();
1628 // en cas d'alignement => correction
1629 $old = $this->style->getOldValues();
1630 $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
1632 if ($parent_w>$w)
1634 if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
1635 else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
1638 $this->style->setPosition();
1640 else
1642 // en cas d'alignement => correction
1643 $old = $this->style->getOldValues();
1644 $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
1646 if ($parent_w>$w)
1648 if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
1649 else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
1652 $this->style->setPosition();
1653 $this->saveMax();
1654 $this->maxX = 0;
1655 $this->maxY = 0;
1656 $this->maxH = 0;
1657 $this->maxE = 0;
1660 if ($this->style->value['rotate'])
1662 $this->pdf->startTransform();
1663 $this->pdf->setRotation($this->style->value['rotate']);
1664 $this->pdf->setTranslate($t_x, $t_y);
1667 // initialisation du style des bordures de la div
1668 $this->drawRectangle(
1669 $this->style->value['x'],
1670 $this->style->value['y'],
1671 $this->style->value['width'],
1672 $this->style->value['height'],
1673 $this->style->value['border'],
1674 $this->style->value['padding'],
1676 $this->style->value['background']
1679 $marge = array();
1680 $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
1681 $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
1682 $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
1683 $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
1685 $this->style->value['width'] -= $marge['l']+$marge['r'];
1686 $this->style->value['height']-= $marge['t']+$marge['b'];
1688 // positionnement en fonction des alignements
1689 $x_corr = 0;
1690 $y_corr = 0;
1691 if (!$this->sub_part && !$this->isSubPart)
1693 switch($this->style->value['text-align'])
1695 case 'right': $x_corr = ($this->style->value['width']-$w_reel); break;
1696 case 'center': $x_corr = ($this->style->value['width']-$w_reel)*0.5; break;
1698 if ($x_corr>0) $x_corr=0;
1699 switch($this->style->value['vertical-align'])
1701 case 'bottom': $y_corr = ($this->style->value['height']-$h_reel); break;
1702 case 'middle': $y_corr = ($this->style->value['height']-$h_reel)*0.5; break;
1706 if ($overflow)
1708 $over_w-= $marge['l']+$marge['r'];
1709 $over_h-= $marge['t']+$marge['b'];
1710 $this->pdf->clippingPathOpen(
1711 $this->style->value['x']+$marge['l'],
1712 $this->style->value['y']+$marge['t'],
1713 $this->style->value['width'],
1714 $this->style->value['height']
1717 $this->style->value['x']+= $x_corr;
1718 // limitation des marges aux dimensions du contenu
1719 $mL = $this->style->value['x']+$marge['l'];
1720 $mR = $this->pdf->getW() - $mL - $over_w;
1722 else
1724 // limitation des marges aux dimensions de la div
1725 $mL = $this->style->value['x']+$marge['l'];
1726 $mR = $this->pdf->getW() - $mL - $this->style->value['width'];
1729 $x = $this->style->value['x']+$marge['l'];
1730 $y = $this->style->value['y']+$marge['t']+$y_corr;
1731 $this->saveMargin($mL, 0, $mR);
1732 $this->pdf->setXY($x, $y);
1734 $this->setNewPositionForNewLine();
1736 return true;
1738 function o_BLOCKQUOTE($param) { return $this->o_DIV($param, 'blockquote'); }
1739 function o_LEGEND($param) { return $this->o_DIV($param, 'legend'); }
1742 * balise : FIELDSET
1743 * mode : OUVERTURE
1744 * ecrite par Pavel Kochman
1746 * @param array paramètres de l'élément de parsing
1747 * @return null
1749 function o_FIELDSET($param)
1752 $this->style->save();
1753 $this->style->analyse('fieldset', $param);
1755 // get height of LEGEND element and make fieldset corrections
1756 for($temp_pos = $this->parse_pos + 1; $temp_pos<count($this->parsing->code); $temp_pos++)
1758 $todo = $this->parsing->code[$temp_pos];
1759 if($todo['name'] == 'fieldset') break;
1760 if($todo['name'] == 'legend' && !$todo['close'])
1762 $legend_open_pos = $temp_pos;
1764 $sub = null;
1765 $this->CreateSubHTML($sub);
1766 $sub->parsing->code = $this->parsing->getLevel($temp_pos - 1);
1768 // pour chaque element identifié par le parsing
1769 $res = null;
1770 for($sub->parse_pos = 0; $sub->parse_pos<count($sub->parsing->code); $sub->parse_pos++)
1772 $todo = $sub->parsing->code[$sub->parse_pos];
1773 $sub->loadAction($todo);
1775 if ($todo['name'] == 'legend' && $todo['close'])
1776 break;
1779 $legendH = $sub->maxY;
1780 $this->destroySubHTML($sub);
1782 $move = $this->style->value['padding']['t'] + $this->style->value['border']['t']['width'] + 0.03;
1784 $param['moveTop'] = $legendH / 2;
1786 $this->parsing->code[$legend_open_pos]['param']['moveTop'] = - ($legendH / 2 + $move);
1787 $this->parsing->code[$legend_open_pos]['param']['moveLeft'] = 2 - $this->style->value['border']['l']['width'] - $this->style->value['padding']['l'];
1788 $this->parsing->code[$legend_open_pos]['param']['moveDown'] = $move;
1789 break;
1792 $this->style->load();
1794 return $this->o_DIV($param, 'fieldset');
1798 * balise : DIV
1799 * mode : FERMETURE
1801 * @param array paramètres de l'élément de parsing
1802 * @return null
1804 function c_DIV($param, $other='div')
1806 if ($this->forOneLine) return false;
1808 if ($this->style->value['overflow']=='hidden')
1810 $this->maxX = $this->style->value['old_maxX'];
1811 $this->maxY = $this->style->value['old_maxY'];
1812 $this->maxH = $this->style->value['old_maxH'];
1813 $this->isInOverflow = $this->style->value['old_overflow'];
1814 $this->pdf->clippingPathClose();
1817 if ($this->style->value['rotate'])
1818 $this->pdf->stopTransform();
1820 $marge = array();
1821 $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
1822 $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
1823 $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
1824 $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
1826 $x = $this->style->value['x'];
1827 $y = $this->style->value['y'];
1828 $w = $this->style->value['width']+$marge['l']+$marge['r']+$this->style->value['margin']['r'];
1829 $h = $this->style->value['height']+$marge['t']+$marge['b']+$this->style->value['margin']['b'];
1831 switch($this->style->value['rotate'])
1833 case 90:
1834 $t = $w; $w = $h; $h = $t;
1835 break;
1837 case 270:
1838 $t = $w; $w = $h; $h = $t;
1839 break;
1841 default:
1842 break;
1846 if ($this->style->value['position']!='absolute')
1848 // position
1849 $this->pdf->setXY($x+$w, $y);
1851 // position MAX
1852 $this->maxX = max($this->maxX, $x+$w);
1853 $this->maxY = max($this->maxY, $y+$h);
1854 $this->maxH = max($this->maxH, $h);
1856 else
1858 // position
1859 $this->pdf->setXY($this->style->value['xc'], $this->style->value['yc']);
1861 $this->loadMax();
1864 $block = ($this->style->value['display']!='inline' && $this->style->value['position']!='absolute');
1866 $this->style->load();
1867 $this->style->FontSet();
1868 $this->loadMargin();
1870 if ($block) $this->o_BR(array());
1871 if ($this->DEBUG_actif) $this->DEBUG_add(strtoupper($other), false);
1873 return true;
1875 function c_BLOCKQUOTE($param) { return $this->c_DIV($param, 'blockquote'); }
1876 function c_FIELDSET($param) { return $this->c_DIV($param, 'fieldset'); }
1877 function c_LEGEND($param) { return $this->c_DIV($param, 'legend'); }
1880 * balise : BARCODE
1881 * mode : OUVERTURE
1883 * @param array paramètres de l'élément de parsing
1884 * @return null
1886 function o_BARCODE($param)
1888 if (!isset($param['type'])) $param['type'] = '';
1889 if (!isset($param['value'])) $param['value'] = 0;
1890 if (!isset($param['label'])) $param['label'] = 'label';
1892 if ($this->testIsDeprecated && (isset($param['bar_h']) || isset($param['bar_w'])))
1893 HTML2PDF::makeError(9, __FILE__, __LINE__, array('BARCODE', 'bar_h, bar_w'));
1895 // les différents types de barcode
1896 $lst_barcode = array();
1897 $lst_barcode['EAN13'] = 'EAN13';
1898 $lst_barcode['UPCA'] = 'UPC_A';
1899 $lst_barcode['C39'] = 'CODE39';
1901 // pour compatibilité < 3.29
1902 $lst_barcode['UPC_A'] = 'UPC_A';
1903 $lst_barcode['CODE39'] = 'CODE39';
1905 $param['type'] = strtoupper($param['type']);
1906 if (!isset($lst_barcode[$param['type']])) $param['type']=='C39';
1907 $param['type'] = $lst_barcode[$param['type']];
1909 if (!isset($param['style']['color'])) $param['style']['color'] = '#000000';
1910 $param['style']['background-color'] = $param['style']['color'];
1912 $this->style->save();
1913 $this->style->analyse('barcode', $param);
1914 $this->style->setPosition();
1915 $this->style->FontSet();
1917 $x = $this->pdf->getX();
1918 $y = $this->pdf->getY();
1919 $w = $this->style->value['width']; if (!$w) $w = $this->style->ConvertToMM('50mm');
1920 $h = $this->style->value['height']; if (!$h) $h = $this->style->ConvertToMM('10mm');
1921 $txt = ($param['label']!=='none');
1922 $infos = $this->pdf->{'BARCODE_'.$param['type']}($x, $y, $w, $h, $param['value'], $txt);
1924 // position maximale globale
1925 $this->maxX = max($this->maxX, $x+$infos[0]);
1926 $this->maxY = max($this->maxY, $y+$infos[1]);
1927 $this->maxH = max($this->maxH, $infos[1]);
1928 $this->maxE++;
1930 $this->pdf->setXY($x+$infos[0], $y);
1932 $this->style->load();
1933 $this->style->FontSet();
1935 return true;
1939 * balise : BARCODE
1940 * mode : FERMETURE
1942 * @param array paramètres de l'élément de parsing
1943 * @return null
1945 function c_BARCODE($param)
1947 // completement inutile
1949 return true;
1954 * balise : QRCODE
1955 * mode : OUVERTURE
1957 * @param array paramètres de l'élément de parsing
1958 * @return null
1960 function o_QRCODE($param)
1962 if ($this->testIsDeprecated && (isset($param['size']) || isset($param['noborder'])))
1963 HTML2PDF::makeError(9, __FILE__, __LINE__, array('QRCODE', 'size, noborder'));
1965 $msg = '
1966 <h1>QRCODE Tag</h1>
1967 <pre>
1968 <b>ATTENTION :</b>
1969 Vous devez télécharger la librairie "QR-code generator >=0.99" (sous licence LGPL)
1970 a cette adresse : <a href="http://prgm.spipu.net/php_qrcode" target="_blank">http://prgm.spipu.net/php_qrcode</a>
1971 et mettre tout son contenu dans ce repertoire : '.str_replace('\\', '/', dirname(__FILE__)).'/qrcode
1973 <b>WARNING:</b>
1974 You have to download the librairy "QR-code generator >=0.99" (under LGPL licence)
1975 at this url : <a href="http://prgm.spipu.net/php_qrcode" target="_blank">http://prgm.spipu.net/php_qrcode</a>
1976 and to put all his contents in this folder '.str_replace('\\', '/', dirname(__FILE__)).'/qrcode
1977 </pre>';
1979 $file_class = dirname(__FILE__).'/qrcode/qrcode.class.php';
1980 if (!is_file($file_class)) { echo $msg; exit; }
1981 require_once($file_class);
1982 if (__CLASS_QRCODE__<'0.99') { echo $msg; exit; }
1984 if ($this->DEBUG_actif) $this->DEBUG_add('QRCODE', true);
1985 if (!isset($param['value'])) $param['value'] = '';
1986 if (!isset($param['ec'])) $param['ec'] = 'H';
1987 if (!isset($param['style']['color'])) $param['style']['color'] = '#000000';
1988 if (!isset($param['style']['background-color'])) $param['style']['background-color'] = '#FFFFFF';
1989 if (isset($param['style']['border']))
1991 $borders = $param['style']['border']!='none';
1992 unset($param['style']['border']);
1994 else
1995 $borders = true;
1997 if ($param['value']==='') return true;
1998 if (!in_array($param['ec'], array('L', 'M', 'Q', 'H'))) $param['ec'] = 'H';
2000 $this->style->save();
2001 $this->style->analyse('qrcode', $param);
2002 $this->style->setPosition();
2003 $this->style->FontSet();
2005 $x = $this->pdf->getX();
2006 $y = $this->pdf->getY();
2007 $w = $this->style->value['width'];
2008 $h = $this->style->value['height'];
2009 $size = max($w, $h); if (!$size) $size = $this->style->ConvertToMM('50mm');
2011 $color = $this->style->value['color'];
2012 if (count($color)==4) $color = array(0, 0, 0);
2013 $color[0] = floor($color[0]*255.);
2014 $color[1] = floor($color[1]*255.);
2015 $color[2] = floor($color[2]*255.);
2017 $background = $this->style->value['background']['color'];
2018 if (count($background)==4) $background = array(0, 0, 0);
2019 $background[0] = floor($background[0]*255.);
2020 $background[1] = floor($background[1]*255.);
2021 $background[2] = floor($background[2]*255.);
2023 if (!$this->sub_part && !$this->isSubPart)
2025 $qrcode = new QRcode($param['value'], $param['ec']);
2026 if (!$borders) $qrcode->disableBorder();
2027 $qrcode->displayFPDF($this->pdf, $x, $y, $size, $background, $color);
2028 unset($qrcode);
2031 // position maximale globale
2032 $this->maxX = max($this->maxX, $x+$size);
2033 $this->maxY = max($this->maxY, $y+$size);
2034 $this->maxH = max($this->maxH, $size);
2036 $this->pdf->setX($x+$size);
2038 $this->style->load();
2039 $this->style->FontSet();
2041 return true;
2045 * balise : QRCODE
2046 * mode : FERMETURE
2048 * @param array paramètres de l'élément de parsing
2049 * @return null
2051 function c_QRCODE($param)
2053 if ($this->DEBUG_actif) $this->DEBUG_add('QRCODE', false);
2054 // completement inutile
2055 return true;
2059 * balise : BOOKMARK
2060 * mode : OUVERTURE
2062 * @param array paramètres de l'élément de parsing
2063 * @return null
2065 function o_BOOKMARK($param)
2067 $titre = isset($param['title']) ? trim($param['title']) : '';
2068 $level = isset($param['level']) ? floor($param['level']) : 0;
2070 if ($level<0) $level = 0;
2071 if ($titre) $this->pdf->Bookmark($titre, $level, -1);
2073 return true;
2077 * balise : BOOKMARK
2078 * mode : FERMETURE
2080 * @param array paramètres de l'élément de parsing
2081 * @return null
2083 function c_BOOKMARK($param)
2085 // completement inutile
2087 return true;
2090 function getElementY($h)
2092 if ($this->sub_part || $this->isSubPart || !$this->currentH || $this->currentH<$h)
2093 return 0;
2095 return ($this->currentH-$h)*0.8;
2099 * balise : WRITE
2100 * mode : OUVERTURE
2102 * @param array paramètres de l'élément de parsing
2103 * @return null
2105 function o_WRITE($param)
2107 $fill = ($this->style->value['background']['color']!==null && $this->style->value['background']['image']===null);
2108 if (in_array($this->style->value['id_balise'], array('fieldset', 'legend', 'div', 'table', 'tr', 'td', 'th')))
2109 $fill = false;
2111 // récupération du texte à écrire, et conversion
2112 $txt = $param['txt'];
2114 if ($this->isAfterFloat)
2116 $txt = ltrim($txt);
2117 $this->isAfterFloat = false;
2120 $txt = str_replace('[[page_cu]]', $this->page, $txt);
2122 if ($this->style->value['text-transform']!='none')
2124 if ($this->style->value['text-transform']=='capitalize')
2125 $txt = ucwords($txt);
2126 else if ($this->style->value['text-transform']=='uppercase')
2127 $txt = strtoupper($txt);
2128 else if ($this->style->value['text-transform']=='lowercase')
2129 $txt = strtolower($txt);
2132 // tailles du texte
2133 $h = 1.08*$this->style->value['font-size'];
2134 $dh = $h*$this->style->value['mini-decal'];
2135 $lh = $this->style->getLineHeight();
2137 // identification de l'alignement
2138 $align = 'L';
2139 if ($this->style->value['text-align']=='li_right')
2141 $w = $this->style->value['width'];
2142 $align = 'R';
2145 // pré calcul de la taille de chaque mot et de la phrase complete
2146 $w = 0;
2147 $words = explode(' ', $txt);
2148 foreach($words as $k => $word)
2150 $words[$k] = array($word, $this->pdf->GetStringWidth($word));
2151 $w+= $words[$k][1];
2153 $space = $this->pdf->GetStringWidth(' ');
2154 $w+= $space*(count($words)-1);
2156 $curr_pos = 0; // position dans le texte
2157 $curr_max = strlen($txt); // taille maxi du texte
2158 $maxX = 0; // plus grande largeur du texte apres retour à la ligne
2159 $x = $this->pdf->getX(); // position du texte
2160 $y = $this->pdf->getY();
2161 $dy = $this->getElementY($lh);
2163 list($left, $right) = $this->getMargins($y); // marges autorisees
2164 $nb = 0; // nbr de lignes découpées
2166 // tant que ca ne rentre pas sur la ligne et qu'on a du texte => on découpe
2167 while($x+$w>$right && $x<$right && count($words))
2169 // trouver une phrase qui rentre dans la largeur, en ajoutant les mots 1 à 1
2170 $i=0;
2171 $old = array('', 0);
2172 $str = $words[0];
2173 $add = false;
2174 while(($x+$str[1])<$right)
2176 $i++;
2177 $add = true;
2179 array_shift($words);
2180 $old = $str;
2182 if (!count($words)) break;
2183 $str[0].= ' '.$words[0][0];
2184 $str[1]+= $space+$words[0][1];
2186 $str = $old;
2188 // si rien de rentre, et que le premier mot ne rentre de toute facon pas dans une ligne, on le force...
2189 if ($i==0 && (($left+$words[0][1])>=$right))
2191 $str = $words[0];
2192 array_shift($words);
2193 $i++;
2194 $add = true;
2196 $curr_pos+= ($curr_pos ? 1 : 0)+strlen($str[0]);
2198 // ecriture du bout de phrase extrait et qui rentre
2199 $wc = ($align=='L' ? $str[1] : $this->style->value['width']);
2200 if ($right - $left<$wc) $wc = $right - $left;
2202 if ($this->pdf->ws)
2204 $oldSpace = $this->pdf->CurrentFont['cw'][' '];
2205 $this->pdf->CurrentFont['cw'][' ']*=(1.+$this->pdf->ws);
2206 $wc = $str[1];
2207 $this->pdf->CurrentFont['cw'][' '] = $oldSpace;
2210 if (strlen($str[0]))
2212 $this->pdf->setXY($this->pdf->getX(), $y+$dh+$dy);
2213 $this->pdf->Cell($wc, $h, $str[0], 0, 0, $align, $fill, $this->inLink);
2214 $this->pdf->setXY($this->pdf->getX(), $y);
2216 $this->maxH = max($this->maxH, $lh);
2218 // détermination de la largeur max
2219 $maxX = max($maxX, $this->pdf->getX());
2221 // nouvelle position et nouvelle largeur pour la boucle
2222 $w-= $str[1];
2223 $y = $this->pdf->getY();
2224 $x = $this->pdf->getX();
2225 $dy = $this->getElementY($lh);
2227 // si il reste du text à afficher
2228 if (count($words))
2230 if ($add) $w-= $space;
2231 if ($this->forOneLine)
2233 $this->maxE+= $i+1;
2234 $this->maxX = max($this->maxX, $maxX);
2235 return null;
2238 // retour à la ligne
2239 $this->o_BR(array('style' => ''), $curr_pos);
2241 $y = $this->pdf->getY();
2242 $x = $this->pdf->getX();
2243 $dy = $this->getElementY($lh);
2245 // si la prochaine ligne ne rentre pas dans la page => nouvelle page
2246 if ($y + $h>=$this->pdf->getH() - $this->pdf->getbMargin())
2248 if (!$this->isInOverflow && !$this->isInFooter)
2250 $this->setNewPage(null, '', null, $curr_pos);
2251 $y = $this->pdf->getY();
2252 $x = $this->pdf->getX();
2253 $dy = $this->getElementY($lh);
2257 // ligne suplémentaire. au bout de 1000 : trop long => erreur
2258 $nb++;
2259 if ($nb>1000)
2261 $txt = ''; foreach($words as $k => $word) $txt.= ($k ? ' ' : '').$word[0];
2262 HTML2PDF::makeError(2, __FILE__, __LINE__, array($txt, $right-$left, $w));
2265 list($left, $right) = $this->getMargins($y); // marges autorisees
2269 // si il reste du text apres découpe, c'est qu'il rentre direct => on l'affiche
2270 if (count($words))
2272 $txt = ''; foreach($words as $k => $word) $txt.= ($k ? ' ' : '').$word[0];
2274 if ($this->pdf->ws)
2276 $oldSpace = $this->pdf->CurrentFont['cw'][' '];
2277 $this->pdf->CurrentFont['cw'][' ']*=(1.+$this->pdf->ws);
2278 $w = $this->pdf->GetStringWidth($txt);
2279 $this->pdf->CurrentFont['cw'][' '] = $oldSpace;
2282 $this->pdf->setXY($this->pdf->getX(), $y+$dh+$dy);
2283 $this->pdf->Cell(($align=='L' ? $w : $this->style->value['width']), $h, $txt, 0, 0, $align, $fill, $this->inLink);
2284 $this->pdf->setXY($this->pdf->getX(), $y);
2285 $this->maxH = max($this->maxH, $lh);
2286 $this->maxE+= count($words);
2289 // détermination des positions MAX
2290 $maxX = max($maxX, $this->pdf->getX());
2291 $maxY = $this->pdf->getY()+$h;
2293 // position maximale globale
2294 $this->maxX = max($this->maxX, $maxX);
2295 $this->maxY = max($this->maxY, $maxY);
2297 return true;
2301 * tracer une image
2303 * @param string nom du fichier source
2304 * @return null
2306 function Image($src, $sub_li=false)
2308 // est-ce que c'est une image ?
2309 $infos=@GetImageSize($src);
2311 if (count($infos)<2)
2313 if ($this->testIsImage)
2315 HTML2PDF::makeError(6, __FILE__, __LINE__, $src);
2316 return false;
2318 $src = null;
2319 $infos = array(16, 16);
2322 // récupération des dimensions dans l'unité du PDF
2323 $wi = $infos[0]/$this->pdf->getK();
2324 $hi = $infos[1]/$this->pdf->getK();
2326 // détermination des dimensions d'affichage en fonction du style
2327 if ($this->style->value['width'] && $this->style->value['height'])
2329 $w = $this->style->value['width'];
2330 $h = $this->style->value['height'];
2332 else if ($this->style->value['width'])
2334 $w = $this->style->value['width'];
2335 $h = $hi*$w/$wi;
2338 else if ($this->style->value['height'])
2340 $h = $this->style->value['height'];
2341 $w = $wi*$h/$hi;
2343 else
2345 $w = 72./96.*$wi;
2346 $h = 72./96.*$hi;
2349 // detection du float
2350 $float = $this->style->getFloat();
2351 if ($float && $this->maxH)
2352 if (!$this->o_BR(array()))
2353 return false;
2355 // position d'affichage
2356 $x = $this->pdf->getX();
2357 $y = $this->pdf->getY();
2359 // si l'image ne rentre pas dans la ligne => nouvelle ligne
2360 if (!$float && ($x + $w>$this->pdf->getW() - $this->pdf->getrMargin()) && $this->maxH)
2362 if ($this->forOneLine) return null;
2364 $hnl = max($this->maxH, $this->style->getLineHeight());
2365 $this->setNewLine($hnl);
2366 $x = $this->pdf->getX();
2367 $y = $this->pdf->getY();
2370 // si l'image ne rentre pas dans la page => nouvelle page
2371 if (
2372 ($y + $h>$this->pdf->getH() - $this->pdf->getbMargin()) &&
2373 !$this->isInOverflow
2376 $this->setNewPage();
2377 $x = $this->pdf->getX();
2378 $y = $this->pdf->getY();
2381 // correction pour l'affichage d'une puce image
2382 $hT = 0.80*$this->style->value['font-size'];
2383 if ($sub_li && $h<$hT)
2385 $y+=($hT-$h);
2388 $yc = $y-$this->style->value['margin']['t'];
2390 // détermination de la position réelle d'affichage en fonction du text-align du parent
2391 $old = $this->style->getOldValues();
2393 if ( $old['width'])
2395 $parent_w = $old['width'];
2396 $parent_x = $x;
2398 else
2400 $parent_w = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
2401 $parent_x = $this->pdf->getlMargin();
2404 if ($float)
2406 list($lx, $rx) = $this->getMargins($yc);
2407 $parent_x = $lx;
2408 $parent_w = $rx-$lx;
2411 if ($parent_w>$w && $float!='left')
2413 if ($float=='right' || $this->style->value['text-align']=='li_right') $x = $parent_x + $parent_w - $w-$this->style->value['margin']['r']-$this->style->value['margin']['l'];
2416 // affichage de l'image, et positionnement à la suite
2417 if (!$this->sub_part && !$this->isSubPart)
2419 if ($src) $this->pdf->Image($src, $x, $y, $w, $h, '', $this->inLink);
2420 else
2422 $this->pdf->setMyFillColor(array(0.94, 0.86, 0.86));
2423 $this->pdf->Rect($x, $y, $w, $h, 'F');
2427 $x-= $this->style->value['margin']['l'];
2428 $y-= $this->style->value['margin']['t'];
2429 $w+= $this->style->value['margin']['l'] + $this->style->value['margin']['r'];
2430 $h+= $this->style->value['margin']['t'] + $this->style->value['margin']['b'];
2432 if ($float=='left')
2434 $this->maxX = max($this->maxX, $x+$w);
2435 $this->maxY = max($this->maxY, $y+$h);
2437 $this->addMargins($float, $x, $y, $x+$w, $y+$h);
2439 list($lx, $rx) = $this->getMargins($yc);
2440 $this->pdf->setXY($lx, $yc);
2442 else if ($float=='right')
2444 // $this->maxX = max($this->maxX, $x+$w);
2445 $this->maxY = max($this->maxY, $y+$h);
2447 $this->addMargins($float, $x, $y, $x+$w, $y+$h);
2449 list($lx, $rx) = $this->getMargins($yc);
2450 $this->pdf->setXY($lx, $yc);
2452 else
2454 $this->pdf->setX($x+$w);
2455 $this->maxX = max($this->maxX, $x+$w);
2456 $this->maxY = max($this->maxY, $y+$h);
2457 $this->maxH = max($this->maxH, $h);
2459 return true;
2463 * Tracer un rectanble
2465 * @param float position X
2466 * @param float position Y
2467 * @param float Largeur
2468 * @param float Hauteur
2469 * @param array Tableau de style de définition des borders
2470 * @param float padding - marge intérieur au rectangle => non utile mais on le passe en paramètre
2471 * @param float margin - marge exterieur au rectangle
2472 * @param array Tableau de style de définition du background
2473 * @return null
2475 function drawRectangle($x, $y, $w, $h, $border, $padding, $margin, $background)
2477 if ($this->sub_part || $this->isSubPart) return false;
2478 if ($h===null) return false;
2480 $x+= $margin;
2481 $y+= $margin;
2482 $w-= $margin*2;
2483 $h-= $margin*2;
2485 // récupération des radius
2486 $out_TL = $border['radius']['tl'];
2487 $out_TR = $border['radius']['tr'];
2488 $out_BR = $border['radius']['br'];
2489 $out_BL = $border['radius']['bl'];
2491 // verification des coins en radius
2492 $out_TL = ($out_TL[0] && $out_TL[1]) ? $out_TL : null;
2493 $out_TR = ($out_TR[0] && $out_TR[1]) ? $out_TR : null;
2494 $out_BR = ($out_BR[0] && $out_BR[1]) ? $out_BR : null;
2495 $out_BL = ($out_BL[0] && $out_BL[1]) ? $out_BL : null;
2498 $in_TL = $out_TL;
2499 $in_TR = $out_TR;
2500 $in_BR = $out_BR;
2501 $in_BL = $out_BL;
2503 if (is_array($in_TL)) { $in_TL[0]-= $border['l']['width']; $in_TL[1]-= $border['t']['width']; }
2504 if (is_array($in_TR)) { $in_TR[0]-= $border['r']['width']; $in_TR[1]-= $border['t']['width']; }
2505 if (is_array($in_BR)) { $in_BR[0]-= $border['r']['width']; $in_BR[1]-= $border['b']['width']; }
2506 if (is_array($in_BL)) { $in_BL[0]-= $border['l']['width']; $in_BL[1]-= $border['b']['width']; }
2508 if ($in_TL[0]<=0 || $in_TL[1]<=0) $in_TL = null;
2509 if ($in_TR[0]<=0 || $in_TR[1]<=0) $in_TR = null;
2510 if ($in_BR[0]<=0 || $in_BR[1]<=0) $in_BR = null;
2511 if ($in_BL[0]<=0 || $in_BL[1]<=0) $in_BL = null;
2513 // traitement de la couleur de fond
2514 $STYLE = '';
2515 if ($background['color'])
2517 $this->pdf->setMyFillColor($background['color']);
2518 $STYLE.= 'F';
2521 if ($STYLE)
2523 $this->pdf->clippingPathOpen($x, $y, $w, $h, $out_TL,$out_TR, $out_BL, $out_BR);
2524 $this->pdf->Rect($x, $y, $w, $h, $STYLE);
2525 $this->pdf->clippingPathClose();
2528 // traitement de l'image de fond
2529 if ($background['image'])
2531 $i_name = $background['image'];
2532 $i_position = $background['position']!==null ? $background['position'] : array(0, 0);
2533 $i_repeat = $background['repeat']!==null ? $background['repeat'] : array(true, true);
2535 // taile du fond (il faut retirer les borders
2536 $b_x = $x;
2537 $b_y = $y;
2538 $b_w = $w;
2539 $b_h = $h;
2541 if ($border['b']['width']) { $b_h-= $border['b']['width']; }
2542 if ($border['l']['width']) { $b_w-= $border['l']['width']; $b_x+= $border['l']['width']; }
2543 if ($border['t']['width']) { $b_h-= $border['t']['width']; $b_y+= $border['t']['width']; }
2544 if ($border['r']['width']) { $b_w-= $border['r']['width']; }
2546 // est-ce que c'est une image ?
2547 $i_infos=@GetImageSize($i_name);
2549 if (count($i_infos)<2)
2551 if ($this->testIsImage)
2553 HTML2PDF::makeError(6, __FILE__, __LINE__, $i_name);
2554 return false;
2557 else
2559 // récupération des dimensions dans l'unité du PDF
2560 $i_width = 72./96.*$i_infos[0]/$this->pdf->getK();
2561 $i_height = 72./96.*$i_infos[1]/$this->pdf->getK();
2563 if ($i_repeat[0]) $i_position[0] = $b_x;
2564 else if(preg_match('/^([-]?[0-9\.]+)%/isU', $i_position[0], $match)) $i_position[0] = $b_x + $match[1]*($b_w-$i_width)/100;
2565 else $i_position[0] = $b_x+$i_position[0];
2567 if ($i_repeat[1]) $i_position[1] = $b_y;
2568 else if(preg_match('/^([-]?[0-9\.]+)%/isU', $i_position[1], $match)) $i_position[1] = $b_y + $match[1]*($b_h-$i_height)/100;
2569 else $i_position[1] = $b_y+$i_position[1];
2571 $i_x_min = $b_x;
2572 $i_x_max = $b_x+$b_w;
2573 $i_y_min = $b_y;
2574 $i_y_max = $b_y+$b_h;
2576 if (!$i_repeat[0] && !$i_repeat[1])
2578 $i_x_min = $i_position[0]; $i_x_max = $i_position[0]+$i_width;
2579 $i_y_min = $i_position[1]; $i_y_max = $i_position[1]+$i_height;
2581 else if ($i_repeat[0] && !$i_repeat[1])
2583 $i_y_min = $i_position[1]; $i_y_max = $i_position[1]+$i_height;
2585 elseif (!$i_repeat[0] && $i_repeat[1])
2587 $i_x_min = $i_position[0]; $i_x_max = $i_position[0]+$i_width;
2590 $this->pdf->clippingPathOpen($b_x, $b_y, $b_w, $b_h, $in_TL, $in_TR, $in_BL, $in_BR);
2591 for ($i_y=$i_y_min; $i_y<$i_y_max; $i_y+=$i_height)
2593 for ($i_x=$i_x_min; $i_x<$i_x_max; $i_x+=$i_width)
2595 $c_x = null;
2596 $c_y = null;
2597 $c_w = $i_width;
2598 $c_h = $i_height;
2599 if ($i_y_max-$i_y<$i_height)
2601 $c_x = $i_x;
2602 $c_y = $i_y;
2603 $c_h = $i_y_max-$i_y;
2605 if ($i_x_max-$i_x<$i_width)
2607 $c_x = $i_x;
2608 $c_y = $i_y;
2609 $c_w = $i_x_max-$i_x;
2612 $this->pdf->Image($i_name, $i_x, $i_y, $i_width, $i_height, '', '');
2615 $this->pdf->clippingPathClose();
2619 $x-= 0.01;
2620 $y-= 0.01;
2621 $w+= 0.02;
2622 $h+= 0.02;
2623 if ($border['l']['width']) $border['l']['width']+= 0.02;
2624 if ($border['t']['width']) $border['t']['width']+= 0.02;
2625 if ($border['r']['width']) $border['r']['width']+= 0.02;
2626 if ($border['b']['width']) $border['b']['width']+= 0.02;
2628 $Bl = ($border['l']['width'] && $border['l']['color'][0]!==null);
2629 $Bt = ($border['t']['width'] && $border['t']['color'][0]!==null);
2630 $Br = ($border['r']['width'] && $border['r']['color'][0]!==null);
2631 $Bb = ($border['b']['width'] && $border['b']['color'][0]!==null);
2633 if (is_array($out_BL) && ($Bb || $Bl))
2635 if ($in_BL)
2637 $courbe = array();
2638 $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h;
2639 $courbe[] = $x; $courbe[] = $y+$h-$out_BL[1];
2640 $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h-$border['b']['width'];
2641 $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$h-$out_BL[1];
2642 $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h-$out_BL[1];
2644 else
2646 $courbe = array();
2647 $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h;
2648 $courbe[] = $x; $courbe[] = $y+$h-$out_BL[1];
2649 $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$h-$border['b']['width'];
2650 $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h-$out_BL[1];
2652 $this->drawCourbe($courbe, $border['l']['color']);
2656 if (is_array($out_TL) && ($Bt || $Bl))
2658 if ($in_TL)
2660 $courbe = array();
2661 $courbe[] = $x; $courbe[] = $y+$out_TL[1];
2662 $courbe[] = $x+$out_TL[0]; $courbe[] = $y;
2663 $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$out_TL[1];
2664 $courbe[] = $x+$out_TL[0]; $courbe[] = $y+$border['t']['width'];
2665 $courbe[] = $x+$out_TL[0]; $courbe[] = $y+$out_TL[1];
2667 else
2669 $courbe = array();
2670 $courbe[] = $x; $courbe[] = $y+$out_TL[1];
2671 $courbe[] = $x+$out_TL[0]; $courbe[] = $y;
2672 $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$border['t']['width'];
2673 $courbe[] = $x+$out_TL[0]; $courbe[] = $y+$out_TL[1];
2675 $this->drawCourbe($courbe, $border['t']['color']);
2678 if (is_array($out_TR) && ($Bt || $Br))
2680 if ($in_TR)
2682 $courbe = array();
2683 $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y;
2684 $courbe[] = $x+$w; $courbe[] = $y+$out_TR[1];
2685 $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y+$border['t']['width'];
2686 $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$out_TR[1];
2687 $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y+$out_TR[1];
2689 else
2691 $courbe = array();
2692 $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y;
2693 $courbe[] = $x+$w; $courbe[] = $y+$out_TR[1];
2694 $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$border['t']['width'];
2695 $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y+$out_TR[1];
2697 $this->drawCourbe($courbe, $border['r']['color']);
2700 if (is_array($out_BR) && ($Bb || $Br))
2702 if ($in_BR)
2704 $courbe = array();
2705 $courbe[] = $x+$w; $courbe[] = $y+$h-$out_BR[1];
2706 $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h;
2707 $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$h-$out_BR[1];
2708 $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h-$border['b']['width'];
2709 $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h-$out_BR[1];
2711 else
2713 $courbe = array();
2714 $courbe[] = $x+$w; $courbe[] = $y+$h-$out_BR[1];
2715 $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h;
2716 $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$h-$border['b']['width'];
2717 $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h-$out_BR[1];
2719 $this->drawCourbe($courbe, $border['b']['color']);
2722 if ($Bl)
2724 $pt = array();
2725 $pt[] = $x; $pt[] = $y+$h;
2726 $pt[] = $x; $pt[] = $y+$h-$border['b']['width'];
2727 $pt[] = $x; $pt[] = $y+$border['t']['width'];
2728 $pt[] = $x; $pt[] = $y;
2729 $pt[] = $x+$border['l']['width']; $pt[] = $y+$border['t']['width'];
2730 $pt[] = $x+$border['l']['width']; $pt[] = $y+$h-$border['b']['width'];
2732 $bord = 3;
2733 if (is_array($out_BL))
2735 $bord-=1;
2736 $pt[3] -= $out_BL[1] - $border['b']['width'];
2737 if ($in_BL) $pt[11]-= $in_BL[1];
2738 unset($pt[0]);unset($pt[1]);
2740 if (is_array($out_TL))
2742 $bord-=2;
2743 $pt[5] += $out_TL[1]-$border['t']['width'];
2744 if ($in_TL) $pt[9] += $in_TL[1];
2745 unset($pt[6]);unset($pt[7]);
2748 $pt = array_values($pt);
2749 $this->drawLine($pt, $border['l']['color'], $border['l']['type'], $border['l']['width'], $bord);
2752 if ($Bt)
2754 $pt = array();
2755 $pt[] = $x; $pt[] = $y;
2756 $pt[] = $x+$border['l']['width']; $pt[] = $y;
2757 $pt[] = $x+$w-$border['r']['width']; $pt[] = $y;
2758 $pt[] = $x+$w; $pt[] = $y;
2759 $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$border['t']['width'];
2760 $pt[] = $x+$border['l']['width']; $pt[] = $y+$border['t']['width'];
2762 $bord = 3;
2763 if (is_array($out_TL))
2765 $bord-=1;
2766 $pt[2] += $out_TL[0] - $border['l']['width'];
2767 if ($in_TL) $pt[10]+= $in_TL[0];
2768 unset($pt[0]);unset($pt[1]);
2770 if (is_array($out_TR))
2772 $bord-=2;
2773 $pt[4] -= $out_TR[0] - $border['r']['width'];
2774 if ($in_TR) $pt[8] -= $in_TR[0];
2775 unset($pt[6]);unset($pt[7]);
2778 $pt = array_values($pt);
2779 $this->drawLine($pt, $border['t']['color'], $border['t']['type'], $border['t']['width'], $bord);
2782 if ($Br)
2784 $pt = array();
2785 $pt[] = $x+$w; $pt[] = $y;
2786 $pt[] = $x+$w; $pt[] = $y+$border['t']['width'];
2787 $pt[] = $x+$w; $pt[] = $y+$h-$border['b']['width'];
2788 $pt[] = $x+$w; $pt[] = $y+$h;
2789 $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h-$border['b']['width'];
2790 $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$border['t']['width'];
2792 $bord = 3;
2793 if (is_array($out_TR))
2795 $bord-=1;
2796 $pt[3] += $out_TR[1] - $border['t']['width'];
2797 if ($in_TR) $pt[11]+= $in_TR[1];
2798 unset($pt[0]);unset($pt[1]);
2800 if (is_array($out_BR))
2802 $bord-=2;
2803 $pt[5] -= $out_BR[1] - $border['b']['width'];
2804 if ($in_BR) $pt[9] -= $in_BR[1];
2805 unset($pt[6]);unset($pt[7]);
2808 $pt = array_values($pt);
2809 $this->drawLine($pt, $border['r']['color'], $border['r']['type'], $border['r']['width'], $bord);
2812 if ($Bb)
2814 $pt = array();
2815 $pt[] = $x+$w; $pt[] = $y+$h;
2816 $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h;
2817 $pt[] = $x+$border['l']['width']; $pt[] = $y+$h;
2818 $pt[] = $x; $pt[] = $y+$h;
2819 $pt[] = $x+$border['l']['width']; $pt[] = $y+$h-$border['b']['width'];
2820 $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h-$border['b']['width'];
2822 $bord = 3;
2823 if (is_array($out_BL))
2825 $bord-=2;
2826 $pt[4] += $out_BL[0] - $border['l']['width'];
2827 if ($in_BL) $pt[8] += $in_BL[0];
2828 unset($pt[6]);unset($pt[7]);
2830 if (is_array($out_BR))
2832 $bord-=1;
2833 $pt[2] -= $out_BR[0] - $border['r']['width'];
2834 if ($in_BR) $pt[10]-= $in_BR[0];
2835 unset($pt[0]);unset($pt[1]);
2839 $pt = array_values($pt);
2840 $this->drawLine($pt, $border['b']['color'], $border['b']['type'], $border['b']['width'], $bord);
2843 if ($background['color'])
2845 $this->pdf->setMyFillColor($background['color']);
2849 function drawCourbe($pt, $color)
2851 $this->pdf->setMyFillColor($color);
2853 if (count($pt)==10)
2854 $this->pdf->drawCourbe($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7], $pt[8], $pt[9]);
2855 else
2856 $this->pdf->drawCoin($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7]);
2860 * Tracer une ligne epaisse défini par ses points avec des extreminites en biseau
2862 * @param array liste des points definissant le tour de la ligne
2863 * @param float couleur RVB
2864 * @param string type de ligne
2865 * @param float largeur de la ligne
2866 * @return null
2868 function drawLine($pt, $color, $type, $width, $bord=3)
2870 $this->pdf->setMyFillColor($color);
2871 if ($type=='dashed' || $type=='dotted')
2873 if ($bord==1)
2875 $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
2876 $this->pdf->Polygon($tmp, 'F');
2878 $tmp = array(); $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
2879 $pt = $tmp;
2881 else if ($bord==2)
2883 $tmp = array(); $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7];
2884 $this->pdf->Polygon($tmp, 'F');
2886 $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[6]; $tmp[]=$pt[7]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
2887 $pt = $tmp;
2889 else if ($bord==3)
2891 $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[10]; $tmp[]=$pt[11];
2892 $this->pdf->Polygon($tmp, 'F');
2894 $tmp = array(); $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
2895 $this->pdf->Polygon($tmp, 'F');
2897 $tmp = array(); $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[8]; $tmp[]=$pt[9]; $tmp[]=$pt[10]; $tmp[]=$pt[11];
2898 $pt = $tmp;
2901 if ($pt[2]==$pt[0])
2903 $l = abs(($pt[3]-$pt[1])*0.5);
2904 $px = 0;
2905 $py = $width;
2906 $x1 = $pt[0]; $y1 = ($pt[3]+$pt[1])*0.5;
2907 $x2 = $pt[6]; $y2 = ($pt[7]+$pt[5])*0.5;
2909 else
2911 $l = abs(($pt[2]-$pt[0])*0.5);
2912 $px = $width;
2913 $py = 0;
2914 $x1 = ($pt[2]+$pt[0])*0.5; $y1 = $pt[1];
2915 $x2 = ($pt[6]+$pt[4])*0.5; $y2 = $pt[7];
2917 if ($type=='dashed')
2919 $px = $px*3.;
2920 $py = $py*3.;
2922 $mode = ($l/($px+$py)<.5);
2924 for($i=0; $l-($px+$py)*($i-0.5)>0; $i++)
2926 if (($i%2)==$mode)
2928 $j = $i-0.5;
2929 $lx1 = $px*($j); if ($lx1<-$l) $lx1 =-$l;
2930 $ly1 = $py*($j); if ($ly1<-$l) $ly1 =-$l;
2931 $lx2 = $px*($j+1); if ($lx2>$l) $lx2 = $l;
2932 $ly2 = $py*($j+1); if ($ly2>$l) $ly2 = $l;
2934 $tmp = array();
2935 $tmp[] = $x1+$lx1; $tmp[] = $y1+$ly1;
2936 $tmp[] = $x1+$lx2; $tmp[] = $y1+$ly2;
2937 $tmp[] = $x2+$lx2; $tmp[] = $y2+$ly2;
2938 $tmp[] = $x2+$lx1; $tmp[] = $y2+$ly1;
2939 $this->pdf->Polygon($tmp, 'F');
2941 if ($j>0)
2943 $tmp = array();
2944 $tmp[] = $x1-$lx1; $tmp[] = $y1-$ly1;
2945 $tmp[] = $x1-$lx2; $tmp[] = $y1-$ly2;
2946 $tmp[] = $x2-$lx2; $tmp[] = $y2-$ly2;
2947 $tmp[] = $x2-$lx1; $tmp[] = $y2-$ly1;
2948 $this->pdf->Polygon($tmp, 'F');
2953 else if ($type=='double')
2955 $pt1 = $pt;
2956 $pt2 = $pt;
2958 if (count($pt)==12)
2960 $pt1[0] = ($pt[0]-$pt[10])*0.33 + $pt[10];
2961 $pt1[1] = ($pt[1]-$pt[11])*0.33 + $pt[11];
2962 $pt1[2] = ($pt[2]-$pt[10])*0.33 + $pt[10];
2963 $pt1[3] = ($pt[3]-$pt[11])*0.33 + $pt[11];
2964 $pt1[4] = ($pt[4]-$pt[8])*0.33 + $pt[8];
2965 $pt1[5] = ($pt[5]-$pt[9])*0.33 + $pt[9];
2966 $pt1[6] = ($pt[6]-$pt[8])*0.33 + $pt[8];
2967 $pt1[7] = ($pt[7]-$pt[9])*0.33 + $pt[9];
2968 $pt2[10]= ($pt[10]-$pt[0])*0.33 + $pt[0];
2969 $pt2[11]= ($pt[11]-$pt[1])*0.33 + $pt[1];
2970 $pt2[2] = ($pt[2] -$pt[0])*0.33 + $pt[0];
2971 $pt2[3] = ($pt[3] -$pt[1])*0.33 + $pt[1];
2972 $pt2[4] = ($pt[4] -$pt[6])*0.33 + $pt[6];
2973 $pt2[5] = ($pt[5] -$pt[7])*0.33 + $pt[7];
2974 $pt2[8] = ($pt[8] -$pt[6])*0.33 + $pt[6];
2975 $pt2[9] = ($pt[9] -$pt[7])*0.33 + $pt[7];
2977 else
2979 $pt1[0] = ($pt[0]-$pt[6])*0.33 + $pt[6];
2980 $pt1[1] = ($pt[1]-$pt[7])*0.33 + $pt[7];
2981 $pt1[2] = ($pt[2]-$pt[4])*0.33 + $pt[4];
2982 $pt1[3] = ($pt[3]-$pt[5])*0.33 + $pt[5];
2983 $pt2[6] = ($pt[6]-$pt[0])*0.33 + $pt[0];
2984 $pt2[7] = ($pt[7]-$pt[1])*0.33 + $pt[1];
2985 $pt2[4] = ($pt[4]-$pt[2])*0.33 + $pt[2];
2986 $pt2[5] = ($pt[5]-$pt[3])*0.33 + $pt[3];
2988 $this->pdf->Polygon($pt1, 'F');
2989 $this->pdf->Polygon($pt2, 'F');
2991 else if ($type=='solid')
2993 $this->pdf->Polygon($pt, 'F');
2998 * balise : BR
2999 * mode : OUVERTURE
3001 * @param array paramètres de l'élément de parsing
3002 * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
3003 * @return null
3005 function o_BR($param, $curr = null)
3007 if ($this->forOneLine) return false;
3009 $h = max($this->maxH, $this->style->getLineHeight());
3011 // si la ligne est vide, la position maximale n'a pas été mise à jour => on la met à jour
3012 if ($this->maxH==0) $this->maxY = max($this->maxY, $this->pdf->getY()+$h);
3014 $this->makeBR($h, $curr);
3016 $this->maxH = 0;
3018 return true;
3021 function makeBR($h, $curr = null)
3023 // si le saut de ligne rentre => on le prend en compte, sinon nouvelle page
3024 if ($h)
3026 if (($this->pdf->getY()+$h<$this->pdf->getH() - $this->pdf->getbMargin()) || $this->isInOverflow || $this->isInFooter)
3027 $this->setNewLine($h, $curr);
3028 else
3029 $this->setNewPage(null, '', null, $curr);
3031 else
3033 $this->setNewPositionForNewLine($curr);
3036 $this->maxH = 0;
3040 * balise : HR
3041 * mode : OUVERTURE
3043 * @param array paramètres de l'élément de parsing
3044 * @return null
3046 function o_HR($param)
3048 if ($this->forOneLine) return false;
3049 $old_align = $this->style->value['text-align'];
3050 $this->style->value['text-align'] = 'left';
3052 if ($this->maxH) $this->o_BR($param);
3054 $f_size = $this->style->value['font-size'];
3055 $this->style->value['font-size']=$f_size*0.5; $this->o_BR($param);
3056 $this->style->value['font-size']=0;
3058 $param['style']['width'] = '100%';
3060 $this->style->save();
3061 $this->style->value['height']=$this->style->ConvertToMM('1mm');
3063 $this->style->analyse('hr', $param);
3064 $this->style->setPosition();
3065 $this->style->FontSet();
3067 $h = $this->style->value['height'];
3068 if ($h) $h-= $this->style->value['border']['t']['width']+$this->style->value['border']['b']['width'];
3069 if ($h<=0) $h = $this->style->value['border']['t']['width']+$this->style->value['border']['b']['width'];
3071 $this->drawRectangle($this->pdf->getX(), $this->pdf->getY(), $this->style->value['width'], $h, $this->style->value['border'], 0, 0, $this->style->value['background']);
3072 $this->maxH = $h;
3074 $this->style->load();
3075 $this->style->FontSet();
3077 $this->o_BR($param);
3079 $this->style->value['font-size']=$f_size*0.5; $this->o_BR($param);
3080 $this->style->value['font-size']=$f_size;
3082 $this->style->value['text-align'] = $old_align;
3083 $this->setNewPositionForNewLine();
3085 return true;
3089 * balise : B
3090 * mode : OUVERTURE
3092 * @param array paramètres de l'élément de parsing
3093 * @return null
3095 function o_B($param, $other = 'b')
3097 $this->style->save();
3098 $this->style->value['font-bold'] = true;
3099 $this->style->analyse($other, $param);
3100 $this->style->setPosition();
3101 $this->style->FontSet();
3103 return true;
3105 function o_STRONG($param) { return $this->o_B($param, 'strong'); }
3108 * balise : B
3109 * mode : FERMETURE
3111 * @param array paramètres de l'élément de parsing
3112 * @return null
3114 function c_B($param)
3116 $this->style->load();
3117 $this->style->FontSet();
3119 return true;
3121 function c_STRONG($param) { return $this->c_B($param); }
3124 * balise : I
3125 * mode : OUVERTURE
3127 * @param array paramètres de l'élément de parsing
3128 * @return null
3130 function o_I($param, $other = 'i')
3132 $this->style->save();
3133 $this->style->value['font-italic'] = true;
3134 $this->style->analyse($other, $param);
3135 $this->style->setPosition();
3136 $this->style->FontSet();
3138 return true;
3140 function o_ADDRESS($param) { return $this->o_I($param, 'address'); }
3141 function o_CITE($param) { return $this->o_I($param, 'cite'); }
3142 function o_EM($param) { return $this->o_I($param, 'em'); }
3143 function o_SAMP($param) { return $this->o_I($param, 'samp'); }
3146 * balise : I
3147 * mode : FERMETURE
3149 * @param array paramètres de l'élément de parsing
3150 * @return null
3152 function c_I($param)
3154 $this->style->load();
3155 $this->style->FontSet();
3157 return true;
3159 function c_ADDRESS($param) { return $this->c_I($param); }
3160 function c_CITE($param) { return $this->c_I($param); }
3161 function c_EM($param) { return $this->c_I($param); }
3162 function c_SAMP($param) { return $this->c_I($param); }
3165 * balise : S
3166 * mode : OUVERTURE
3168 * @param array paramètres de l'élément de parsing
3169 * @return null
3171 function o_S($param, $other = 's')
3173 $this->style->save();
3174 $this->style->value['font-linethrough'] = true;
3175 $this->style->analyse($other, $param);
3176 $this->style->setPosition();
3177 $this->style->FontSet();
3179 return true;
3181 function o_DEL($param) { return $this->o_S($param, 'del'); }
3184 * balise : S
3185 * mode : FERMETURE
3187 * @param array paramètres de l'élément de parsing
3188 * @return null
3190 function c_S($param)
3192 $this->style->load();
3193 $this->style->FontSet();
3195 return true;
3197 function c_DEL($param) { return $this->c_S($param); }
3200 * balise : U
3201 * mode : OUVERTURE
3203 * @param array paramètres de l'élément de parsing
3204 * @return null
3206 function o_U($param, $other='u')
3208 $this->style->save();
3209 $this->style->value['font-underline'] = true;
3210 $this->style->analyse($other, $param);
3211 $this->style->setPosition();
3212 $this->style->FontSet();
3214 return true;
3216 function o_INS($param) { return $this->o_U($param, 'ins'); }
3219 * balise : U
3220 * mode : FERMETURE
3222 * @param array paramètres de l'élément de parsing
3223 * @return null
3225 function c_U($param)
3227 $this->style->load();
3228 $this->style->FontSet();
3230 return true;
3232 function c_INS($param) { return $this->c_U($param); }
3235 * balise : A
3236 * mode : OUVERTURE
3238 * @param array paramètres de l'élément de parsing
3239 * @return null
3241 function o_A($param)
3243 $this->inLink = str_replace('&amp;', '&', isset($param['href']) ? $param['href'] : '');
3245 if (isset($param['name']))
3247 $nom = $param['name'];
3248 if (!isset($this->lstAncre[$nom])) $this->lstAncre[$nom] = array($this->pdf->AddLink(), false);
3250 if (!$this->lstAncre[$nom][1])
3252 $this->lstAncre[$nom][1] = true;
3253 $this->pdf->SetLink($this->lstAncre[$nom][0], -1, -1);
3257 if (preg_match('/^#([^#]+)$/isU', $this->inLink, $match))
3259 $nom = $match[1];
3260 if (!isset($this->lstAncre[$nom])) $this->lstAncre[$nom] = array($this->pdf->AddLink(), false);
3262 $this->inLink = $this->lstAncre[$nom][0];
3265 $this->style->save();
3266 $this->style->value['font-underline'] = true;
3267 $this->style->value['color'] = array(0.08, 0.08, 0.98);
3268 $this->style->analyse('a', $param);
3269 $this->style->setPosition();
3270 $this->style->FontSet();
3272 return true;
3276 * balise : A
3277 * mode : FERMETURE
3279 * @param array paramètres de l'élément de parsing
3280 * @return null
3282 function c_A($param)
3284 $this->inLink = '';
3285 $this->style->load();
3286 $this->style->FontSet();
3288 return true;
3292 * balise : H1
3293 * mode : OUVERTURE
3295 * @param array paramètres de l'élément de parsing
3296 * @return null
3298 function o_H1($param, $other = 'h1')
3300 if ($this->forOneLine) return false;
3302 if ($this->maxH) $this->o_BR(array());
3303 $this->style->save();
3304 $this->style->value['font-bold'] = true;
3306 $size = array('h1' => '28px', 'h2' => '24px', 'h3' => '20px', 'h4' => '16px', 'h5' => '12px', 'h6' => '9px');
3307 $this->style->value['margin']['l'] = 0;
3308 $this->style->value['margin']['r'] = 0;
3309 $this->style->value['margin']['t'] = $this->style->ConvertToMM('16px');
3310 $this->style->value['margin']['b'] = $this->style->ConvertToMM('16px');
3311 $this->style->value['font-size'] = $this->style->ConvertToMM($size[$other]);
3313 $this->style->analyse($other, $param);
3314 $this->style->setPosition();
3315 $this->style->FontSet();
3316 $this->setNewPositionForNewLine();
3318 return true;
3320 function o_H2($param) { return $this->o_H1($param, 'h2'); }
3321 function o_H3($param) { return $this->o_H1($param, 'h3'); }
3322 function o_H4($param) { return $this->o_H1($param, 'h4'); }
3323 function o_H5($param) { return $this->o_H1($param, 'h5'); }
3324 function o_H6($param) { return $this->o_H1($param, 'h6'); }
3328 * balise : H1
3329 * mode : FERMETURE
3331 * @param array paramètres de l'élément de parsing
3332 * @return null
3334 function c_H1($param)
3336 if ($this->forOneLine) return false;
3338 // hauteur du H1
3339 $this->maxH+= $this->style->value['margin']['b'];
3340 $h = max($this->maxH, $this->style->getLineHeight());
3342 $this->style->load();
3343 $this->style->FontSet();
3345 // saut de ligne et initialisation de la hauteur
3346 $this->makeBR($h);
3347 $this->maxH = 0;
3349 return true;
3351 function c_H2($param) { return $this->c_H1($param); }
3352 function c_H3($param) { return $this->c_H1($param); }
3353 function c_H4($param) { return $this->c_H1($param); }
3354 function c_H5($param) { return $this->c_H1($param); }
3355 function c_H6($param) { return $this->c_H1($param); }
3358 * balise : SPAN
3359 * mode : OUVERTURE
3361 * @param array paramètres de l'élément de parsing
3362 * @return null
3364 function o_SPAN($param, $other = 'span')
3366 $this->style->save();
3367 $this->style->analyse($other, $param);
3368 $this->style->setPosition();
3369 $this->style->FontSet();
3371 return true;
3373 function o_FONT($param) { return $this->o_SPAN($param, 'font'); }
3374 function o_LABEL($param) { return $this->o_SPAN($param, 'label');}
3377 * balise : SPAN
3378 * mode : FERMETURE
3380 * @param array paramètres de l'élément de parsing
3381 * @return null
3383 function c_SPAN($param)
3385 $this->style->restorePosition();
3386 $this->style->load();
3387 $this->style->FontSet();
3389 return true;
3391 function c_FONT($param) { return $this->c_SPAN($param); }
3392 function c_LABEL($param) { return $this->c_SPAN($param); }
3396 * balise : P
3397 * mode : OUVERTURE
3399 * @param array paramètres de l'élément de parsing
3400 * @return null
3402 function o_P($param)
3404 if ($this->forOneLine) return false;
3406 if (!in_array($this->previousCall, array('c_P', 'c_UL')))
3408 if ($this->maxH) $this->o_BR(array());
3411 $this->style->save();
3412 $this->style->analyse('p', $param);
3413 $this->style->setPosition();
3414 $this->style->FontSet();
3415 // annule les effets du setposition
3416 $this->pdf->setXY($this->pdf->getX()-$this->style->value['margin']['l'], $this->pdf->getY()-$this->style->value['margin']['t']);
3418 list($mL, $mR) = $this->getMargins($this->pdf->getY());
3419 $mR = $this->pdf->getW()-$mR;
3420 $mL+= $this->style->value['margin']['l']+$this->style->value['padding']['l'];
3421 $mR+= $this->style->value['margin']['r']+$this->style->value['padding']['r'];
3422 $this->saveMargin($mL,0,$mR);
3424 if ($this->style->value['text-indent']>0)
3426 $y = $this->pdf->getY()+$this->style->value['margin']['t']+$this->style->value['padding']['t'];
3427 $this->pageMarges[floor($y*100)] = array($mL+$this->style->value['text-indent'], $this->pdf->getW()-$mR);
3428 $y+= $this->style->getLineHeight()*0.1;
3429 $this->pageMarges[floor($y*100)] = array($mL, $this->pdf->getW()-$mR);
3431 $this->makeBR($this->style->value['margin']['t']+$this->style->value['padding']['t']);
3432 return true;
3436 * balise : P
3437 * mode : FERMETURE
3439 * @param array paramètres de l'élément de parsing
3440 * @return null
3442 function c_P($param)
3444 if ($this->forOneLine) return false;
3446 if ($this->maxH) $this->o_BR(array());
3447 $this->loadMargin();
3448 $h = $this->style->value['margin']['b']+$this->style->value['padding']['b'];
3450 $this->style->load();
3451 $this->style->FontSet();
3452 $this->makeBR($h);
3454 return true;
3458 * balise : PRE
3459 * mode : OUVERTURE
3461 * @param array paramètres de l'élément de parsing
3462 * @return null
3464 function o_PRE($param, $other = 'pre')
3466 if ($other=='pre' && $this->maxH) $this->o_BR(array());
3468 $this->style->save();
3469 $this->style->value['font-family'] = 'courier';
3470 $this->style->analyse($other, $param);
3471 $this->style->setPosition();
3472 $this->style->FontSet();
3474 if ($other=='pre') return $this->o_DIV($param, $other);
3476 return true;
3478 function o_CODE($param) { return $this->o_PRE($param, 'code'); }
3481 * balise : PRE
3482 * mode : FERMETURE
3484 * @param array paramètres de l'élément de parsing
3485 * @return null
3487 function c_PRE($param, $other = 'pre')
3489 if ($other=='pre')
3491 if ($this->forOneLine) return false;
3493 $this->c_DIV($param);
3494 $this->o_BR(array());
3496 $this->style->load();
3497 $this->style->FontSet();
3499 return true;
3501 function c_CODE($param) { return $this->c_PRE($param, 'code'); }
3504 * balise : BIG
3505 * mode : OUVERTURE
3507 * @param array paramètres de l'élément de parsing
3508 * @return null
3510 function o_BIG($param)
3512 $this->style->save();
3513 $this->style->value['mini-decal']-= $this->style->value['mini-size']*0.05;
3514 $this->style->value['mini-size'] *= 1.2;
3515 $this->style->analyse('big', $param);
3516 $this->style->setPosition();
3517 $this->style->FontSet();
3518 return true;
3522 * balise : BIG
3523 * mode : FERMETURE
3525 * @param array paramètres de l'élément de parsing
3526 * @return null
3528 function c_BIG($param)
3530 $this->style->load();
3531 $this->style->FontSet();
3533 return true;
3537 * balise : SMALL
3538 * mode : OUVERTURE
3540 * @param array paramètres de l'élément de parsing
3541 * @return null
3543 function o_SMALL($param)
3545 $this->style->save();
3546 $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.05;
3547 $this->style->value['mini-size'] *= 0.82;
3548 $this->style->analyse('small', $param);
3549 $this->style->setPosition();
3550 $this->style->FontSet();
3551 return true;
3555 * balise : SMALL
3556 * mode : FERMETURE
3558 * @param array paramètres de l'élément de parsing
3559 * @return null
3561 function c_SMALL($param)
3563 $this->style->load();
3564 $this->style->FontSet();
3566 return true;
3571 * balise : SUP
3572 * mode : OUVERTURE
3574 * @param array paramètres de l'élément de parsing
3575 * @return null
3577 function o_SUP($param)
3579 $this->style->save();
3580 $this->style->value['mini-decal']-= $this->style->value['mini-size']*0.15;
3581 $this->style->value['mini-size'] *= 0.75;
3582 $this->style->analyse('sup', $param);
3583 $this->style->setPosition();
3584 $this->style->FontSet();
3586 return true;
3590 * balise : SUP
3591 * mode : FERMETURE
3593 * @param array paramètres de l'élément de parsing
3594 * @return null
3596 function c_SUP($param)
3598 $this->style->load();
3599 $this->style->FontSet();
3601 return true;
3605 * balise : SUB
3606 * mode : OUVERTURE
3608 * @param array paramètres de l'élément de parsing
3609 * @return null
3611 function o_SUB($param)
3613 $this->style->save();
3614 $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.15;
3615 $this->style->value['mini-size'] *= 0.75;
3616 $this->style->analyse('sub', $param);
3617 $this->style->setPosition();
3618 $this->style->FontSet();
3619 return true;
3623 * balise : SUB
3624 * mode : FERMETURE
3626 * @param array paramètres de l'élément de parsing
3627 * @return null
3629 function c_SUB($param)
3631 $this->style->load();
3632 $this->style->FontSet();
3634 return true;
3638 * balise : UL
3639 * mode : OUVERTURE
3641 * @param array paramètres de l'élément de parsing
3642 * @return null
3644 function o_UL($param, $other = 'ul')
3646 if ($this->forOneLine) return false;
3648 if (!in_array($this->previousCall, array('c_P', 'c_UL')))
3650 if ($this->maxH) $this->o_BR(array());
3651 if (!count($this->defLIST)) $this->o_BR(array());
3654 if (!isset($param['style']['width'])) $param['allwidth'] = true;
3655 $param['cellspacing'] = 0;
3657 // une liste est traitée comme un tableau
3658 $this->o_TABLE($param, $other);
3660 // ajouter un niveau de liste
3661 $this->listeAddLevel($other, $this->style->value['list-style-type'], $this->style->value['list-style-image']);
3663 return true;
3665 function o_OL($param) { return $this->o_UL($param, 'ol'); }
3668 * balise : UL
3669 * mode : FERMETURE
3671 * @param array paramètres de l'élément de parsing
3672 * @return null
3674 function c_UL($param)
3676 if ($this->forOneLine) return false;
3678 // fin du tableau
3679 $this->c_TABLE($param);
3681 // enlever un niveau de liste
3682 $this->listeDelLevel();
3684 if (!$this->sub_part)
3686 if (!count($this->defLIST)) $this->o_BR(array());
3689 return true;
3691 function c_OL($param) { return $this->c_UL($param); }
3694 * balise : LI
3695 * mode : OUVERTURE
3697 * @param array paramètres de l'élément de parsing
3698 * @return null
3700 function o_LI($param)
3702 if ($this->forOneLine) return false;
3704 // ajouter une puce au niveau actuel
3705 $this->listeAddLi();
3707 if (!isset($param['style']['width'])) $param['style']['width'] = '100%';
3709 // preparation du style de la puce
3710 $paramPUCE = $param;
3712 $inf = $this->listeGetLi();
3713 if ($inf[0])
3715 $paramPUCE['style']['font-family'] = $inf[0];
3716 $paramPUCE['style']['text-align'] = 'li_right';
3717 $paramPUCE['style']['vertical-align'] = 'top';
3718 $paramPUCE['style']['width'] = $this->listeGetWidth();
3719 $paramPUCE['style']['padding-right'] = $this->listeGetPadding();
3720 $paramPUCE['txt'] = $inf[2];
3722 else
3724 $paramPUCE['style']['text-align'] = 'li_right';
3725 $paramPUCE['style']['vertical-align'] = 'top';
3726 $paramPUCE['style']['width'] = $this->listeGetWidth();
3727 $paramPUCE['style']['padding-right'] = $this->listeGetPadding();
3728 $paramPUCE['src'] = $inf[2];
3729 $paramPUCE['sub_li'] = true;
3732 // nouvelle ligne
3733 $this->o_TR($param, 'li');
3735 $this->style->save();
3737 if ($inf[1]) // small
3739 $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.045;
3740 $this->style->value['mini-size'] *= 0.75;
3743 // si on est dans un sub_html => preparation, sinon affichage classique
3744 if ($this->sub_part)
3746 // TD pour la puce
3747 $tmp_pos = $this->temp_pos;
3748 $tmp_lst1 = $this->parsing->code[$tmp_pos+1];
3749 $tmp_lst2 = $this->parsing->code[$tmp_pos+2];
3750 $this->parsing->code[$tmp_pos+1] = array();
3751 $this->parsing->code[$tmp_pos+1]['name'] = (isset($paramPUCE['src'])) ? 'img' : 'write';
3752 $this->parsing->code[$tmp_pos+1]['param'] = $paramPUCE; unset($this->parsing->code[$tmp_pos+1]['param']['style']['width']);
3753 $this->parsing->code[$tmp_pos+1]['close'] = 0;
3754 $this->parsing->code[$tmp_pos+2] = array();
3755 $this->parsing->code[$tmp_pos+2]['name'] = 'li';
3756 $this->parsing->code[$tmp_pos+2]['param'] = $paramPUCE;
3757 $this->parsing->code[$tmp_pos+2]['close'] = 1;
3758 $this->o_TD($paramPUCE, 'li_sub');
3759 $this->c_TD($param);
3760 $this->temp_pos = $tmp_pos;
3761 $this->parsing->code[$tmp_pos+1] = $tmp_lst1;
3762 $this->parsing->code[$tmp_pos+2] = $tmp_lst2;
3764 else
3766 // TD pour la puce
3767 $this->o_TD($paramPUCE, 'li_sub');
3768 unset($paramPUCE['style']['width']);
3769 if (isset($paramPUCE['src'])) $this->o_IMG($paramPUCE);
3770 else $this->o_WRITE($paramPUCE);
3771 $this->c_TD($paramPUCE);
3773 $this->style->load();
3776 // td pour le contenu
3777 $this->o_TD($param, 'li');
3779 return true;
3783 * balise : LI
3784 * mode : FERMETURE
3786 * @param array paramètres de l'élément de parsing
3787 * @return null
3789 function c_LI($param)
3791 if ($this->forOneLine) return false;
3793 // fin du contenu
3794 $this->c_TD($param);
3796 // fin de la ligne
3797 $this->c_TR($param);
3799 return true;
3803 * balise : TBODY
3804 * mode : OUVERTURE
3806 * @param array paramètres de l'élément de parsing
3807 * @return null
3809 function o_TBODY($param)
3811 if ($this->forOneLine) return false;
3813 $this->style->save();
3814 $this->style->analyse('tbody', $param);
3815 $this->style->setPosition();
3816 $this->style->FontSet();
3818 return true;
3822 * balise : TBODY
3823 * mode : FERMETURE
3825 * @param array paramètres de l'élément de parsing
3826 * @return null
3828 function c_TBODY($param)
3830 if ($this->forOneLine) return false;
3832 $this->style->load();
3833 $this->style->FontSet();
3835 return true;
3839 * balise : THEAD
3840 * mode : OUVERTURE
3842 * @param array paramètres de l'élément de parsing
3843 * @return null
3845 function o_THEAD($param)
3847 if ($this->forOneLine) return false;
3849 global $HTML2PDF_TABLEAU;
3851 $this->style->save();
3852 $this->style->analyse('thead', $param);
3853 $this->style->setPosition();
3854 $this->style->FontSet();
3856 // si on est en mode sub_html : sauvegarde du numéro du TR
3857 if ($this->sub_part)
3859 $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'][0] = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
3860 $HTML2PDF_TABLEAU[$param['num']]['thead']['code'] = array();
3861 for($pos=$this->temp_pos; $pos<count($this->parsing->code); $pos++)
3863 $todo = $this->parsing->code[$pos];
3864 if (strtolower($todo['name'])=='thead') $todo['name'] = 'thead_sub';
3865 $HTML2PDF_TABLEAU[$param['num']]['thead']['code'][] = $todo;
3866 if (strtolower($todo['name'])=='thead_sub' && $todo['close']) break;
3869 else
3871 $level = $this->parsing->getLevel($this->parse_pos);
3872 $this->parse_pos+= count($level);
3873 $HTML2PDF_TABLEAU[$param['num']]['tr_curr']+= count($HTML2PDF_TABLEAU[$param['num']]['thead']['tr']);
3876 return true;
3880 * balise : THEAD
3881 * mode : FERMETURE
3883 * @param array paramètres de l'élément de parsing
3884 * @return null
3886 function c_THEAD($param)
3888 if ($this->forOneLine) return false;
3890 $this->style->load();
3891 $this->style->FontSet();
3893 // si on est en mode sub_html : sauvegarde du numéro du TR
3894 if ($this->sub_part)
3896 global $HTML2PDF_TABLEAU;
3897 $min = $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'][0];
3898 $max = $HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1;
3899 $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'] = range($min, $max);
3902 return true;
3906 * balise : TFOOT
3907 * mode : OUVERTURE
3909 * @param array paramètres de l'élément de parsing
3910 * @return null
3912 function o_TFOOT($param)
3914 if ($this->forOneLine) return false;
3916 global $HTML2PDF_TABLEAU;
3918 $this->style->save();
3919 $this->style->analyse('tfoot', $param);
3920 $this->style->setPosition();
3921 $this->style->FontSet();
3923 // si on est en mode sub_html : sauvegarde du numéro du TR
3924 if ($this->sub_part)
3926 $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0] = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
3927 $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'] = array();
3928 for($pos=$this->temp_pos; $pos<count($this->parsing->code); $pos++)
3930 $todo = $this->parsing->code[$pos];
3931 if (strtolower($todo['name'])=='tfoot') $todo['name'] = 'tfoot_sub';
3932 $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'][] = $todo;
3933 if (strtolower($todo['name'])=='tfoot_sub' && $todo['close']) break;
3936 else
3938 $level = $this->parsing->getLevel($this->parse_pos);
3939 $this->parse_pos+= count($level);
3940 $HTML2PDF_TABLEAU[$param['num']]['tr_curr']+= count($HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr']);
3943 return true;
3947 * balise : TFOOT
3948 * mode : FERMETURE
3950 * @param array paramètres de l'élément de parsing
3951 * @return null
3953 function c_TFOOT($param)
3955 if ($this->forOneLine) return false;
3957 $this->style->load();
3958 $this->style->FontSet();
3960 // si on est en mode sub_html : sauvegarde du numéro du TR
3961 if ($this->sub_part)
3963 global $HTML2PDF_TABLEAU;
3965 $min = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0];
3966 $max = $HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1;
3967 $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'] = range($min, $max);
3970 return true;
3974 * balise : THEAD_SUB
3975 * mode : OUVERTURE
3977 * @param array paramètres de l'élément de parsing
3978 * @return null
3980 function o_THEAD_SUB($param)
3982 if ($this->forOneLine) return false;
3984 $this->style->save();
3985 $this->style->analyse('thead', $param);
3986 $this->style->setPosition();
3987 $this->style->FontSet();
3989 return true;
3993 * balise : THEAD_SUB
3994 * mode : FERMETURE
3996 * @param array paramètres de l'élément de parsing
3997 * @return null
3999 function c_THEAD_SUB($param)
4001 if ($this->forOneLine) return false;
4003 $this->style->load();
4004 $this->style->FontSet();
4006 return true;
4010 * balise : TFOOT_SUB
4011 * mode : OUVERTURE
4013 * @param array paramètres de l'élément de parsing
4014 * @return null
4016 function o_TFOOT_SUB($param)
4018 if ($this->forOneLine) return false;
4020 $this->style->save();
4021 $this->style->analyse('tfoot', $param);
4022 $this->style->setPosition();
4023 $this->style->FontSet();
4025 return true;
4029 * balise : TFOOT_SUB
4030 * mode : FERMETURE
4032 * @param array paramètres de l'élément de parsing
4033 * @return null
4035 function c_TFOOT_SUB($param)
4037 if ($this->forOneLine) return false;
4039 $this->style->load();
4040 $this->style->FontSet();
4042 return true;
4046 * balise : FORM
4047 * mode : OUVERTURE
4049 * @param array paramètres de l'élément de parsing
4050 * @return null
4052 function o_FORM($param)
4054 $this->style->save();
4055 $this->style->analyse('form', $param);
4056 $this->style->setPosition();
4057 $this->style->FontSet();
4059 $this->isInForm = isset($param['action']) ? $param['action'] : '';
4061 return true;
4065 * balise : FORM
4066 * mode : FERMETURE
4068 * @param array paramètres de l'élément de parsing
4069 * @return null
4071 function c_FORM($param)
4073 $this->isInForm = false;
4074 $this->style->load();
4075 $this->style->FontSet();
4077 return true;
4081 * balise : TABLE
4082 * mode : OUVERTURE
4084 * @param array paramètres de l'élément de parsing
4085 * @return null
4087 function o_TABLE($param, $other = 'table')
4089 if ($this->maxH)
4091 if ($this->forOneLine) return false;
4092 $this->o_BR(array());
4095 if ($this->forOneLine)
4097 $this->maxE++;
4098 $this->maxX = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
4099 return false;
4102 $this->maxH = 0;
4103 // utilisation du tableau des paramétres des tables
4104 global $HTML2PDF_TABLEAU;
4106 $align_object = isset($param['align']) ? strtolower($param['align']) : 'left';
4107 if (isset($param['align'])) unset($param['align']);
4108 if (!in_array($align_object, array('left', 'center', 'right'))) $align_object = 'left';
4110 // lecture et initialisation du style
4111 $this->style->save();
4112 $this->style->analyse($other, $param);
4113 $this->style->setPosition();
4114 $this->style->FontSet();
4116 if ($this->style->value['margin-auto']) $align_object = 'center';
4118 // est-on en collapse
4119 $collapse = false;
4120 if ($other=='table')
4121 $collapse = isset($this->style->value['border']['collapse']) ? $this->style->value['border']['collapse'] : false;
4123 // si oui il faut adapté les borders
4124 if ($collapse)
4126 $param['style']['border'] = 'none';
4127 $param['cellspacing'] = 0;
4128 $none = $this->style->readBorder('none');
4129 $this->style->value['border']['t'] = $none;
4130 $this->style->value['border']['r'] = $none;
4131 $this->style->value['border']['b'] = $none;
4132 $this->style->value['border']['l'] = $none;
4135 // si on est en mode sub_html : initialisation des dimensions et autres
4136 if ($this->sub_part)
4138 if ($this->DEBUG_actif) $this->DEBUG_add('Table n°'.$param['num'], true);
4139 $HTML2PDF_TABLEAU[$param['num']] = array();
4140 $HTML2PDF_TABLEAU[$param['num']]['border'] = isset($param['border']) ? $this->style->readBorder($param['border']) : null; // border spécifique si border precisé en paramètre
4141 $HTML2PDF_TABLEAU[$param['num']]['cellpadding'] = $this->style->ConvertToMM(isset($param['cellpadding']) ? $param['cellpadding'] : '1px'); // cellpadding du tableau
4142 $HTML2PDF_TABLEAU[$param['num']]['cellspacing'] = $this->style->ConvertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); // cellspacing du tableau
4143 $HTML2PDF_TABLEAU[$param['num']]['cases'] = array(); // liste des propriétés des cases
4144 $HTML2PDF_TABLEAU[$param['num']]['corr'] = array(); // tableau de correlation pour les colspan et rowspan
4145 $HTML2PDF_TABLEAU[$param['num']]['corr_x'] = 0; // position dans le tableau de correlation
4146 $HTML2PDF_TABLEAU[$param['num']]['corr_y'] = 0; // position dans le tableau de correlation
4147 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0; // colonne courante
4148 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = 0; // ligne courante
4149 $HTML2PDF_TABLEAU[$param['num']]['curr_x'] = $this->pdf->getX(); // position courante X
4150 $HTML2PDF_TABLEAU[$param['num']]['curr_y'] = $this->pdf->getY(); // position courante Y
4151 $HTML2PDF_TABLEAU[$param['num']]['width'] = 0; // largeur globale
4152 $HTML2PDF_TABLEAU[$param['num']]['height'] = 0; // hauteur globale
4153 $HTML2PDF_TABLEAU[$param['num']]['align'] = $align_object;
4154 $HTML2PDF_TABLEAU[$param['num']]['marge'] = array();
4155 $HTML2PDF_TABLEAU[$param['num']]['marge']['t'] = $this->style->value['padding']['t']+$this->style->value['border']['t']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
4156 $HTML2PDF_TABLEAU[$param['num']]['marge']['r'] = $this->style->value['padding']['r']+$this->style->value['border']['r']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
4157 $HTML2PDF_TABLEAU[$param['num']]['marge']['b'] = $this->style->value['padding']['b']+$this->style->value['border']['b']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
4158 $HTML2PDF_TABLEAU[$param['num']]['marge']['l'] = $this->style->value['padding']['l']+$this->style->value['border']['l']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
4159 $HTML2PDF_TABLEAU[$param['num']]['page'] = 0; // nombre de pages
4160 $HTML2PDF_TABLEAU[$param['num']]['new_page'] = true; // nouvelle page pour le TR courant
4161 $HTML2PDF_TABLEAU[$param['num']]['style_value'] = null; // style du tableau
4162 $HTML2PDF_TABLEAU[$param['num']]['thead'] = array(); // infos sur le thead
4163 $HTML2PDF_TABLEAU[$param['num']]['tfoot'] = array(); // infos sur le tfoot
4164 $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'] = array(); // tr du thead
4165 $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'] = array(); // tr du tfoot
4166 $HTML2PDF_TABLEAU[$param['num']]['thead']['height'] = 0; // hauteur du thead
4167 $HTML2PDF_TABLEAU[$param['num']]['tfoot']['height'] = 0; // hauteur du tfoot
4168 $HTML2PDF_TABLEAU[$param['num']]['thead']['code'] = array(); // contenu HTML du thead
4169 $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'] = array(); // contenu HTML du tfoot
4170 $HTML2PDF_TABLEAU[$param['num']]['cols'] = array(); // definition via les balises col
4171 $this->saveMargin($this->pdf->getlMargin(), $this->pdf->gettMargin(), $this->pdf->getrMargin());
4173 // adaptation de la largeur en fonction des marges du tableau
4174 $this->style->value['width']-= $HTML2PDF_TABLEAU[$param['num']]['marge']['l'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['r'];
4176 else
4178 // on repart à la premiere page du tableau et à la premiere case
4179 $HTML2PDF_TABLEAU[$param['num']]['page'] = 0;
4180 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
4181 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = 0;
4182 $HTML2PDF_TABLEAU[$param['num']]['td_x'] = $HTML2PDF_TABLEAU[$param['num']]['marge']['l']+$HTML2PDF_TABLEAU[$param['num']]['curr_x'];
4183 $HTML2PDF_TABLEAU[$param['num']]['td_y'] = $HTML2PDF_TABLEAU[$param['num']]['marge']['t']+$HTML2PDF_TABLEAU[$param['num']]['curr_y'];
4185 // initialisation du style des bordures de la premiere partie de tableau
4186 $this->drawRectangle(
4187 $HTML2PDF_TABLEAU[$param['num']]['curr_x'],
4188 $HTML2PDF_TABLEAU[$param['num']]['curr_y'],
4189 $HTML2PDF_TABLEAU[$param['num']]['width'],
4190 isset($HTML2PDF_TABLEAU[$param['num']]['height'][0]) ? $HTML2PDF_TABLEAU[$param['num']]['height'][0] : null,
4191 $this->style->value['border'],
4192 $this->style->value['padding'],
4194 $this->style->value['background']
4197 $HTML2PDF_TABLEAU[$param['num']]['style_value'] = $this->style->value;
4200 return true;
4204 * balise : TABLE
4205 * mode : FERMETURE
4207 * @param array paramètres de l'élément de parsing
4208 * @return null
4210 function c_TABLE($param)
4212 if ($this->forOneLine) return false;
4214 $this->maxH = 0;
4215 global $HTML2PDF_TABLEAU;
4217 // restauration du style
4218 $this->style->load();
4219 $this->style->FontSet();
4221 // si on est en mode sub_html : initialisation des dimensions et autres
4222 if ($this->sub_part)
4224 // ajustement de la taille des cases
4225 $this->calculTailleCases($HTML2PDF_TABLEAU[$param['num']]['cases'], $HTML2PDF_TABLEAU[$param['num']]['corr']);
4227 // calcul de la hauteur du THEAD et du TFOOT
4228 $lst = array('thead', 'tfoot');
4229 foreach($lst as $mode)
4231 $HTML2PDF_TABLEAU[$param['num']][$mode]['height'] = 0;
4232 foreach($HTML2PDF_TABLEAU[$param['num']][$mode]['tr'] as $tr)
4234 // hauteur de la ligne tr
4235 $h = 0;
4236 for($i=0; $i<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$tr]); $i++)
4237 if ($HTML2PDF_TABLEAU[$param['num']]['cases'][$tr][$i]['rowspan']==1)
4238 $h = max($h, $HTML2PDF_TABLEAU[$param['num']]['cases'][$tr][$i]['h']);
4239 $HTML2PDF_TABLEAU[$param['num']][$mode]['height']+= $h;
4243 // calcul des dimensions du tableau - Largeur
4244 $HTML2PDF_TABLEAU[$param['num']]['width'] = $HTML2PDF_TABLEAU[$param['num']]['marge']['l'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['r'];
4245 if (isset($HTML2PDF_TABLEAU[$param['num']]['cases'][0]))
4246 foreach($HTML2PDF_TABLEAU[$param['num']]['cases'][0] as $case)
4247 $HTML2PDF_TABLEAU[$param['num']]['width']+= $case['w'];
4249 // positionnement du tableau horizontalement;
4250 $old = $this->style->getOldValues();
4251 $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
4252 $x = $HTML2PDF_TABLEAU[$param['num']]['curr_x'];
4253 $w = $HTML2PDF_TABLEAU[$param['num']]['width'];
4254 if ($parent_w>$w)
4256 if ($HTML2PDF_TABLEAU[$param['num']]['align']=='center')
4257 $x = $x + ($parent_w-$w)*0.5;
4258 else if ($HTML2PDF_TABLEAU[$param['num']]['align']=='right')
4259 $x = $x + $parent_w-$w;
4261 $HTML2PDF_TABLEAU[$param['num']]['curr_x'] = $x;
4265 // calcul des dimensions du tableau - hauteur du tableau sur chaque page
4266 $HTML2PDF_TABLEAU[$param['num']]['height'] = array();
4268 $h0 = $HTML2PDF_TABLEAU[$param['num']]['marge']['t'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['b']; // minimum de hauteur à cause des marges
4269 $h0+= $HTML2PDF_TABLEAU[$param['num']]['thead']['height'] + $HTML2PDF_TABLEAU[$param['num']]['tfoot']['height']; // et du tfoot et thead
4270 $max = $this->pdf->getH() - $this->pdf->getbMargin(); // max de hauteur par page
4271 $y = $HTML2PDF_TABLEAU[$param['num']]['curr_y']; // position Y actuelle
4272 $height = $h0;
4274 // on va lire les hauteurs de chaque ligne, une à une, et voir si ca rentre sur la page.
4275 for($k=0; $k<count($HTML2PDF_TABLEAU[$param['num']]['cases']); $k++)
4277 // si c'est des lignes du thead ou du tfoot : on passe
4278 if (in_array($k, $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'])) continue;
4279 if (in_array($k, $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'])) continue;
4281 // hauteur de la ligne $k
4282 $th = 0;
4283 $h = 0;
4284 for($i=0; $i<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$k]); $i++)
4286 $h = max($h, $HTML2PDF_TABLEAU[$param['num']]['cases'][$k][$i]['h']);
4288 if ($HTML2PDF_TABLEAU[$param['num']]['cases'][$k][$i]['rowspan']==1)
4289 $th = max($th, $HTML2PDF_TABLEAU[$param['num']]['cases'][$k][$i]['h']);
4292 // si la ligne ne rentre pas dans la page
4293 // => la hauteur sur cette page est trouvée, et on passe à la page d'apres
4294 if ($y+$h+$height>$max)
4296 if ($height==$h0) $height = null;
4297 $HTML2PDF_TABLEAU[$param['num']]['height'][] = $height;
4298 $height = $h0;
4299 $y = $this->margeTop;
4301 $height+= $th;
4303 // rajout du reste de tableau (si il existe) à la derniere page
4304 if ($height!=$h0 || $k==0) $HTML2PDF_TABLEAU[$param['num']]['height'][] = $height;
4306 else
4308 if (count($HTML2PDF_TABLEAU[$param['num']]['tfoot']['code']))
4310 $tmp_tr = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
4311 $tmp_td = $HTML2PDF_TABLEAU[$param['num']]['td_curr'];
4312 $OLD_parse_pos = $this->parse_pos;
4313 $OLD_parse_code = $this->parsing->code;
4315 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0];
4316 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
4317 $this->parse_pos = 0;
4318 $this->parsing->code = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'];
4319 $this->makeHTMLcode();
4321 $this->parse_pos = $OLD_parse_pos;
4322 $this->parsing->code = $OLD_parse_code;
4323 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $tmp_tr;
4324 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = $tmp_td;
4327 // determination des coordonnées de sortie du tableau
4328 $x = $HTML2PDF_TABLEAU[$param['num']]['curr_x'] + $HTML2PDF_TABLEAU[$param['num']]['width'];
4329 if (count($HTML2PDF_TABLEAU[$param['num']]['height'])>1)
4330 $y = $this->margeTop+$HTML2PDF_TABLEAU[$param['num']]['height'][count($HTML2PDF_TABLEAU[$param['num']]['height'])-1];
4331 else if (count($HTML2PDF_TABLEAU[$param['num']]['height'])==1)
4332 $y = $HTML2PDF_TABLEAU[$param['num']]['curr_y']+$HTML2PDF_TABLEAU[$param['num']]['height'][count($HTML2PDF_TABLEAU[$param['num']]['height'])-1];
4333 else
4334 $y = $HTML2PDF_TABLEAU[$param['num']]['curr_y'];
4336 // taille du tableau
4337 $this->maxX = max($this->maxX, $x);
4338 $this->maxY = max($this->maxY, $y);
4341 // nouvelle position apres le tableau
4342 $this->pdf->setXY($this->pdf->getlMargin(), $y);
4344 // restauration des marges
4345 $this->loadMargin();
4347 if ($this->DEBUG_actif) $this->DEBUG_add('Table n°'.$param['num'], false);
4350 return true;
4355 * balise : COL
4356 * mode : OUVERTURE (pas de fermeture)
4358 * @param array paramètres de l'élément de parsing
4359 * @return null
4361 function o_COL($param)
4363 global $HTML2PDF_TABLEAU;
4364 $span = isset($param['span']) ? $param['span'] : 1;
4365 for($k=0; $k<$span; $k++)
4366 $HTML2PDF_TABLEAU[$param['num']]['cols'][] = $param;
4370 * balise : TR
4371 * mode : OUVERTURE
4373 * @param array paramètres de l'élément de parsing
4374 * @return null
4376 function o_TR($param, $other = 'tr')
4378 if ($this->forOneLine) return false;
4380 $this->maxH = 0;
4381 global $HTML2PDF_TABLEAU;
4383 // analyse du style
4384 $this->style->save();
4385 $this->style->analyse($other, $param);
4386 $this->style->setPosition();
4387 $this->style->FontSet();
4389 // positionnement dans le tableau
4390 $HTML2PDF_TABLEAU[$param['num']]['tr_curr']++;
4391 $HTML2PDF_TABLEAU[$param['num']]['td_curr']= 0;
4393 // si on est pas dans un sub_html
4394 if (!$this->sub_part)
4396 // Y courant apres la ligne
4397 $ty=null;
4398 for($ii=0; $ii<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1]); $ii++)
4399 $ty = max($ty, $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$ii]['h']);
4401 $hfoot = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['height'];
4403 // si la ligne ne rentre pas dans la page => nouvelle page
4404 if (!$this->isInTfoot && $HTML2PDF_TABLEAU[$param['num']]['td_y'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['b'] + $ty +$hfoot> $this->pdf->getH() - $this->pdf->getbMargin())
4406 if (count($HTML2PDF_TABLEAU[$param['num']]['tfoot']['code']))
4408 $tmp_tr = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
4409 $tmp_td = $HTML2PDF_TABLEAU[$param['num']]['td_curr'];
4410 $OLD_parse_pos = $this->parse_pos;
4411 $OLD_parse_code = $this->parsing->code;
4413 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0];
4414 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
4415 $this->parse_pos = 0;
4416 $this->parsing->code = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'];
4417 $this->isInTfoot = true;
4418 $this->makeHTMLcode();
4419 $this->isInTfoot = false;
4421 $this->parse_pos = $OLD_parse_pos;
4422 $this->parsing->code = $OLD_parse_code;
4423 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $tmp_tr;
4424 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = $tmp_td;
4427 $HTML2PDF_TABLEAU[$param['num']]['new_page'] = true;
4428 $this->setNewPage();
4430 $HTML2PDF_TABLEAU[$param['num']]['page']++;
4431 $HTML2PDF_TABLEAU[$param['num']]['curr_y'] = $this->pdf->getY();
4432 $HTML2PDF_TABLEAU[$param['num']]['td_y'] = $HTML2PDF_TABLEAU[$param['num']]['curr_y']+$HTML2PDF_TABLEAU[$param['num']]['marge']['t'];
4434 // si la hauteur de cette partie a bien été calculée, on trace le cadre
4435 if (isset($HTML2PDF_TABLEAU[$param['num']]['height'][$HTML2PDF_TABLEAU[$param['num']]['page']]))
4437 $old = $this->style->value;
4438 $this->style->value = $HTML2PDF_TABLEAU[$param['num']]['style_value'];
4440 // initialisation du style des bordures de la premiere partie de tableau
4441 $this->drawRectangle(
4442 $HTML2PDF_TABLEAU[$param['num']]['curr_x'],
4443 $HTML2PDF_TABLEAU[$param['num']]['curr_y'],
4444 $HTML2PDF_TABLEAU[$param['num']]['width'],
4445 $HTML2PDF_TABLEAU[$param['num']]['height'][$HTML2PDF_TABLEAU[$param['num']]['page']],
4446 $this->style->value['border'],
4447 $this->style->value['padding'],
4448 $HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5,
4449 $this->style->value['background']
4452 $this->style->value = $old;
4456 if ($HTML2PDF_TABLEAU[$param['num']]['new_page'] && count($HTML2PDF_TABLEAU[$param['num']]['thead']['code']))
4458 $HTML2PDF_TABLEAU[$param['num']]['new_page'] = false;
4459 $tmp_tr = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
4460 $tmp_td = $HTML2PDF_TABLEAU[$param['num']]['td_curr'];
4461 $OLD_parse_pos = $this->parse_pos;
4462 $OLD_parse_code = $this->parsing->code;
4464 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'][0];
4465 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
4466 $this->parse_pos = 0;
4467 $this->parsing->code = $HTML2PDF_TABLEAU[$param['num']]['thead']['code'];
4468 $this->isInThead = true;
4469 $this->makeHTMLcode();
4470 $this->isInThead = false;
4472 $this->parse_pos = $OLD_parse_pos;
4473 $this->parsing->code = $OLD_parse_code;
4474 $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $tmp_tr;
4475 $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = $tmp_td;
4476 $HTML2PDF_TABLEAU[$param['num']]['new_page'] = true;
4479 else
4481 $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1] = array();
4482 if (!isset($HTML2PDF_TABLEAU[$param['num']]['corr'][$HTML2PDF_TABLEAU[$param['num']]['corr_y']]))
4483 $HTML2PDF_TABLEAU[$param['num']]['corr'][$HTML2PDF_TABLEAU[$param['num']]['corr_y']] = array();
4485 $HTML2PDF_TABLEAU[$param['num']]['corr_x']=0;
4486 while(isset($HTML2PDF_TABLEAU[$param['num']]['corr'][$HTML2PDF_TABLEAU[$param['num']]['corr_y']][$HTML2PDF_TABLEAU[$param['num']]['corr_x']]))
4487 $HTML2PDF_TABLEAU[$param['num']]['corr_x']++;
4490 return true;
4494 * balise : TR
4495 * mode : FERMETURE
4497 * @param array paramètres de l'élément de parsing
4498 * @return null
4500 function c_TR($param)
4502 if ($this->forOneLine) return false;
4504 $this->maxH = 0;
4505 global $HTML2PDF_TABLEAU;
4507 // restauration du style
4508 $this->style->load();
4509 $this->style->FontSet();
4511 // si on est pas dans un sub_html
4512 if (!$this->sub_part)
4514 // Y courant apres la ligne
4515 $ty=null;
4516 for($ii=0; $ii<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1]); $ii++)
4517 if ($HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$ii]['rowspan']==1)
4518 $ty = $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$ii]['h'];
4520 // mise à jour des coordonnées courantes
4521 $HTML2PDF_TABLEAU[$param['num']]['td_x'] = $HTML2PDF_TABLEAU[$param['num']]['curr_x']+$HTML2PDF_TABLEAU[$param['num']]['marge']['l'];
4522 $HTML2PDF_TABLEAU[$param['num']]['td_y']+= $ty;
4523 $HTML2PDF_TABLEAU[$param['num']]['new_page'] = false;
4525 else
4527 $HTML2PDF_TABLEAU[$param['num']]['corr_y']++;
4530 return true;
4534 * balise : TD
4535 * mode : OUVERTURE
4537 * @param array paramètres de l'élément de parsing
4538 * @return null
4540 function o_TD($param, $other = 'td')
4542 if ($this->forOneLine) return false;
4544 $this->maxH = 0;
4545 global $HTML2PDF_TABLEAU;
4547 $param['cellpadding'] = $HTML2PDF_TABLEAU[$param['num']]['cellpadding'].'mm';
4548 $param['cellspacing'] = $HTML2PDF_TABLEAU[$param['num']]['cellspacing'].'mm';
4550 if ($other=='li')
4552 $special_li = true;
4554 else
4556 $special_li = false;
4557 if ($other=='li_sub')
4559 $param['style']['border'] = 'none';
4560 $param['style']['background-color'] = 'transparent';
4561 $param['style']['background-image'] = 'none';
4562 $param['style']['background-position'] = '';
4563 $param['style']['background-repeat'] = '';
4564 $other = 'li';
4568 // est-on en collapse, et egalement y-a-t'il des definitions de colonne
4569 $x = $HTML2PDF_TABLEAU[$param['num']]['td_curr'];
4570 $y = $HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1;
4571 $colspan = isset($param['colspan']) ? $param['colspan'] : 1;
4572 $rowspan = isset($param['rowspan']) ? $param['rowspan'] : 1;
4573 $collapse = false;
4574 if (in_array($other, array('td', 'th')))
4576 $num_col = isset($HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['Xr']) ? $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['Xr'] : $HTML2PDF_TABLEAU[$param['num']]['corr_x'];
4578 // si une definition de colonne est presente
4579 if (isset($HTML2PDF_TABLEAU[$param['num']]['cols'][$num_col]))
4581 // on la recupere
4582 $col_param = $HTML2PDF_TABLEAU[$param['num']]['cols'][$num_col];
4584 // pour les colspan, on recupere toutes les largeurs
4585 $col_param['style']['width'] = array();
4586 for($k=0; $k<$colspan; $k++)
4588 if (isset($HTML2PDF_TABLEAU[$param['num']]['cols'][$num_col+$k]['style']['width']))
4589 $col_param['style']['width'][] = $HTML2PDF_TABLEAU[$param['num']]['cols'][$num_col+$k]['style']['width'];
4592 // on les somme
4593 $total = '';
4594 $last = $this->style->getLastWidth();
4595 if (count($col_param['style']['width']))
4597 $total = $col_param['style']['width'][0]; unset($col_param['style']['width'][0]);
4598 foreach($col_param['style']['width'] as $width)
4600 if (substr($total, -1)=='%' && substr($width, -1)=='%')
4601 $total = (str_replace('%', '', $total)+str_replace('%', '', $width)).'%';
4602 else
4603 $total = ($this->style->ConvertToMM($total, $last) + $this->style->ConvertToMM($width, $last)).'mm';
4607 // et on recupere la largeur finale
4608 if ($total)
4609 $col_param['style']['width'] = $total;
4610 else
4611 unset($col_param['style']['width']);
4614 // on merge les 2 styles (col + td)
4615 $param['style'] = array_merge($col_param['style'], $param['style']);
4617 // si une classe est définie, on la merge egalement
4618 if (isset($col_param['class']))
4619 $param['class'] = $col_param['class'].(isset($param['class']) ? ' '.$param['class'] : '');
4622 $collapse = isset($this->style->value['border']['collapse']) ? $this->style->value['border']['collapse'] : false;
4626 // analyse du style
4627 $this->style->save();
4628 $heritage = null;
4629 if (in_array($other, array('td', 'th')))
4631 $heritage = array();
4633 $old = $this->style->getLastValue('background');
4634 if ($old && ($old['color'] || $old['image']))
4635 $heritage['background'] = $old;
4637 if ($HTML2PDF_TABLEAU[$param['num']]['border'])
4639 $heritage['border'] = array();
4640 $heritage['border']['l'] = $HTML2PDF_TABLEAU[$param['num']]['border'];
4641 $heritage['border']['t'] = $HTML2PDF_TABLEAU[$param['num']]['border'];
4642 $heritage['border']['r'] = $HTML2PDF_TABLEAU[$param['num']]['border'];
4643 $heritage['border']['b'] = $HTML2PDF_TABLEAU[$param['num']]['border'];
4646 $return = $this->style->analyse($other, $param, $heritage);
4648 if ($special_li)
4650 $this->style->value['width']-= $this->style->ConvertToMM($this->listeGetWidth());
4651 $this->style->value['width']-= $this->style->ConvertToMM($this->listeGetPadding());
4653 $this->style->setPosition();
4654 $this->style->FontSet();
4656 // si on est en collapse : modification du style
4657 if ($collapse)
4659 if (!$this->sub_part)
4661 if (
4662 ($HTML2PDF_TABLEAU[$param['num']]['tr_curr']>1 && !$HTML2PDF_TABLEAU[$param['num']]['new_page']) ||
4663 (!$this->isInThead && count($HTML2PDF_TABLEAU[$param['num']]['thead']['code']))
4666 $this->style->value['border']['t'] = $this->style->readBorder('none');
4670 if ($HTML2PDF_TABLEAU[$param['num']]['td_curr']>0)
4672 if (!$return) $this->style->value['width']+= $this->style->value['border']['l']['width'];
4673 $this->style->value['border']['l'] = $this->style->readBorder('none');
4677 $marge = array();
4678 $marge['t'] = $this->style->value['padding']['t']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['t']['width'];
4679 $marge['r'] = $this->style->value['padding']['r']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['r']['width'];
4680 $marge['b'] = $this->style->value['padding']['b']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['b']['width'];
4681 $marge['l'] = $this->style->value['padding']['l']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['l']['width'];
4683 // si on est dans un sub_html
4684 if ($this->sub_part)
4686 // on se positionne dans le tableau
4687 $HTML2PDF_TABLEAU[$param['num']]['td_curr']++;
4688 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x] = array();
4689 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['w'] = 0;
4690 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['h'] = 0;
4691 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['dw'] = 0;
4692 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['colspan'] = $colspan;
4693 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['rowspan'] = $rowspan;
4694 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['Xr'] = $HTML2PDF_TABLEAU[$param['num']]['corr_x'];
4695 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['Yr'] = $HTML2PDF_TABLEAU[$param['num']]['corr_y'];
4697 for($j=0; $j<$rowspan; $j++)
4699 for($i=0; $i<$colspan; $i++)
4701 $HTML2PDF_TABLEAU[$param['num']]['corr']
4702 [$HTML2PDF_TABLEAU[$param['num']]['corr_y']+$j]
4703 [$HTML2PDF_TABLEAU[$param['num']]['corr_x']+$i] = ($i+$j>0) ? '' : array($x,$y,$colspan,$rowspan);
4707 $HTML2PDF_TABLEAU[$param['num']]['corr_x']+= $colspan;
4708 while(isset($HTML2PDF_TABLEAU[$param['num']]['corr'][$HTML2PDF_TABLEAU[$param['num']]['corr_y']][$HTML2PDF_TABLEAU[$param['num']]['corr_x']]))
4709 $HTML2PDF_TABLEAU[$param['num']]['corr_x']++;
4711 // on extrait tout ce qui est contenu dans le TD
4712 // on en créé un sous HTML que l'on transforme en PDF
4713 // pour analyse les dimensions
4714 // et les récupérer dans le tableau global.
4715 $level = $this->parsing->getLevel($this->temp_pos);
4716 $this->CreateSubHTML($this->sub_html);
4717 $this->sub_html->parsing->code = $level;
4718 $this->sub_html->MakeHTMLcode();
4719 $this->temp_pos+= count($level);
4721 else
4723 // on se positionne dans le tableau
4724 $HTML2PDF_TABLEAU[$param['num']]['td_curr']++;
4725 $HTML2PDF_TABLEAU[$param['num']]['td_x']+= $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['dw'];
4727 // initialisation du style des bordures de la premiere partie de tableau
4728 $this->drawRectangle(
4729 $HTML2PDF_TABLEAU[$param['num']]['td_x'],
4730 $HTML2PDF_TABLEAU[$param['num']]['td_y'],
4731 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['w'],
4732 $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['h'],
4733 $this->style->value['border'],
4734 $this->style->value['padding'],
4735 $HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5,
4736 $this->style->value['background']
4740 $this->style->value['width'] = $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['w'] - $marge['l'] - $marge['r'];
4742 // limitation des marges aux dimensions de la case
4743 $mL = $HTML2PDF_TABLEAU[$param['num']]['td_x']+$marge['l'];
4744 $mR = $this->pdf->getW() - $mL - $this->style->value['width'];
4745 $this->saveMargin($mL, 0, $mR);
4747 // positionnement en fonction
4748 $h_corr = $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['h'];
4749 $h_reel = $HTML2PDF_TABLEAU[$param['num']]['cases'][$y][$x]['real_h'];
4750 switch($this->style->value['vertical-align'])
4752 case 'bottom':
4753 $y_corr = $h_corr-$h_reel;
4754 break;
4756 case 'middle':
4757 $y_corr = ($h_corr-$h_reel)*0.5;
4758 break;
4760 case 'top':
4761 default:
4762 $y_corr = 0;
4763 break;
4766 $x = $HTML2PDF_TABLEAU[$param['num']]['td_x']+$marge['l'];
4767 $y = $HTML2PDF_TABLEAU[$param['num']]['td_y']+$marge['t']+$y_corr;
4768 $this->pdf->setXY($x, $y);
4769 $this->setNewPositionForNewLine();
4772 return true;
4776 * balise : TD
4777 * mode : FERMETURE
4779 * @param array paramètres de l'élément de parsing
4780 * @return null
4782 function c_TD($param)
4784 if ($this->forOneLine) return false;
4786 $this->maxH = 0;
4787 global $HTML2PDF_TABLEAU;
4789 // récupération de la marge
4790 $marge = array();
4791 $marge['t'] = $this->style->value['padding']['t']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['t']['width'];
4792 $marge['r'] = $this->style->value['padding']['r']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['r']['width'];
4793 $marge['b'] = $this->style->value['padding']['b']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['b']['width'];
4794 $marge['l'] = $this->style->value['padding']['l']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['l']['width'];
4795 $marge['t']+= 0.001;
4796 $marge['r']+= 0.001;
4797 $marge['b']+= 0.001;
4798 $marge['l']+= 0.001;
4800 // si on est dans un sub_html
4801 if ($this->sub_part)
4803 if ($this->testTDin1page && $this->sub_html->pdf->getPage()>1) HTML2PDF::makeError(7, __FILE__, __LINE__);
4805 // dimentions de cette case
4806 $w0 = $this->sub_html->maxX + $marge['l'] + $marge['r'];
4807 $h0 = $this->sub_html->maxY + $marge['t'] + $marge['b'];
4809 // dimensions imposées par le style
4810 $w2 = $this->style->value['width'] + $marge['l'] + $marge['r'];
4811 $h2 = $this->style->value['height'] + $marge['t'] + $marge['b'];
4813 // dimension finale de la case = max des 2 ci-dessus
4814 $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['w'] = max(array($w0, $w2));
4815 $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['h'] = max(array($h0, $h2));
4817 $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['real_w'] = $w0;
4818 $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['real_h'] = $h0;
4820 // suppresion du sous_html
4821 $this->destroySubHTML($this->sub_html);
4823 else
4825 $this->loadMargin();
4826 //positionnement
4827 $HTML2PDF_TABLEAU[$param['num']]['td_x']+= $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['w'];
4830 // restauration du style
4831 $this->style->load();
4832 $this->style->FontSet();
4834 return true;
4837 function calculTailleCases(&$cases, &$corr)
4839 /* // construction d'un tableau de correlation
4840 $corr = array();
4842 // on fait correspondre chaque case d'un tableau normé aux cases réelles, en prennant en compte les colspan et rowspan
4843 $Yr=0;
4844 for($y=0; $y<count($cases); $y++)
4846 $Xr=0; while(isset($corr[$Yr][$Xr])) $Xr++;
4848 for($x=0; $x<count($cases[$y]); $x++)
4850 for($j=0; $j<$cases[$y][$x]['rowspan']; $j++)
4852 for($i=0; $i<$cases[$y][$x]['colspan']; $i++)
4854 $corr[$Yr+$j][$Xr+$i] = ($i+$j>0) ? '' : array($x, $y, $cases[$y][$x]['colspan'], $cases[$y][$x]['rowspan']);
4857 $Xr+= $cases[$y][$x]['colspan'];
4858 while(isset($corr[$Yr][$Xr])) $Xr++;
4860 $Yr++;
4863 if (!isset($corr[0])) return true;
4865 // on détermine, pour les cases sans colspan, la largeur maximale de chaque colone
4866 $sw = array();
4867 for($x=0; $x<count($corr[0]); $x++)
4869 $m=0;
4870 for($y=0; $y<count($corr); $y++)
4871 if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2]==1)
4872 $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']);
4873 $sw[$x] = $m;
4876 // on vérifie que cette taille est valide avec les colones en colspan
4877 for($x=0; $x<count($corr[0]); $x++)
4879 for($y=0; $y<count($corr); $y++)
4881 if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2]>1)
4883 // somme des colonnes correspondant au colspan
4884 $s = 0; for($i=0; $i<$corr[$y][$x][2]; $i++) $s+= $sw[$x+$i];
4886 // si la somme est inférieure à la taille necessaire => règle de 3 pour adapter
4887 if ($s>0 && $s<$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'])
4888 for($i=0; $i<$corr[$y][$x][2]; $i++)
4889 $sw[$x+$i] = $sw[$x+$i]/$s*$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'];
4894 // on applique les nouvelles largeurs
4895 for($x=0; $x<count($corr[0]); $x++)
4897 for($y=0; $y<count($corr); $y++)
4899 if (isset($corr[$y][$x]) && is_array($corr[$y][$x]))
4901 if ($corr[$y][$x][2]==1)
4903 $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $sw[$x];
4905 else
4907 // somme des colonnes correspondant au colspan
4908 $s = 0; for($i=0; $i<$corr[$y][$x][2]; $i++) $s+= $sw[$x+$i];
4909 $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $s;
4915 // on détermine, pour les cases sans rowspan, la hauteur maximale de chaque colone
4916 $sh = array();
4917 for($y=0; $y<count($corr); $y++)
4919 $m=0;
4920 for($x=0; $x<count($corr[0]); $x++)
4921 if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3]==1)
4922 $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']);
4923 $sh[$y] = $m;
4927 // on vérifie que cette taille est valide avec les lignes en rowspan
4928 for($y=0; $y<count($corr); $y++)
4930 for($x=0; $x<count($corr[0]); $x++)
4932 if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3]>1)
4934 // somme des colonnes correspondant au colspan
4935 $s = 0; for($i=0; $i<$corr[$y][$x][3]; $i++) $s+= $sh[$y+$i];
4937 // si la somme est inférieure à la taille necessaire => règle de 3 pour adapter
4938 if ($s>0 && $s<$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'])
4939 for($i=0; $i<$corr[$y][$x][3]; $i++)
4940 $sh[$y+$i] = $sh[$y+$i]/$s*$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'];
4946 // on applique les nouvelles hauteurs
4947 for($y=0; $y<count($corr); $y++)
4949 for($x=0; $x<count($corr[0]); $x++)
4951 if (isset($corr[$y][$x]) && is_array($corr[$y][$x]))
4953 if ($corr[$y][$x][3]==1)
4955 $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $sh[$y];
4957 else
4959 // somme des lignes correspondant au rowspan
4960 $s = 0; for($i=0; $i<$corr[$y][$x][3]; $i++) $s+= $sh[$y+$i];
4961 $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $s;
4963 for($j=1; $j<$corr[$y][$x][3]; $j++)
4965 $tx = $x+1;
4966 $ty = $y+$j;
4967 for(true; isset($corr[$ty][$tx]) && !is_array($corr[$ty][$tx]); $tx++);
4968 if (isset($corr[$ty][$tx])) $cases[$corr[$ty][$tx][1]][$corr[$ty][$tx][0]]['dw']+= $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'];
4978 * balise : TH
4979 * mode : OUVERTURE
4981 * @param array paramètres de l'élément de parsing
4982 * @return null
4984 function o_TH($param)
4986 if ($this->forOneLine) return false;
4988 $this->maxH = 0;
4989 // identique à TD mais en gras
4990 if (!isset($param['style']['font-weight'])) $param['style']['font-weight'] = 'bold';
4991 $this->o_TD($param, 'th');
4993 return true;
4997 * balise : TH
4998 * mode : FERMETURE
5000 * @param array paramètres de l'élément de parsing
5001 * @return null
5003 function c_TH($param)
5005 if ($this->forOneLine) return false;
5007 $this->maxH = 0;
5008 // identique à TD
5009 $this->c_TD($param);
5011 return true;
5015 * balise : IMG
5016 * mode : OUVERTURE
5018 * @param array paramètres de l'élément de parsing
5019 * @return null
5021 function o_IMG($param)
5023 // analyse du style
5024 $src = str_replace('&amp;', '&', $param['src']);
5026 $this->style->save();
5027 $this->style->value['width'] = 0;
5028 $this->style->value['height'] = 0;
5029 $this->style->value['border'] = array(
5030 'type' => 'none',
5031 'width' => 0,
5032 'color' => array(0, 0, 0),
5034 $this->style->value['background'] = array(
5035 'color' => null,
5036 'image' => null,
5037 'position' => null,
5038 'repeat' => null
5040 $this->style->analyse('img', $param);
5041 $this->style->setPosition();
5042 $this->style->FontSet();
5044 // affichage de l'image
5045 $res = $this->Image($src, isset($param['sub_li']));
5046 if (!$res) return $res;
5048 // restauration du style
5049 $this->style->load();
5050 $this->style->FontSet();
5051 $this->maxE++;
5053 return true;
5057 * balise : SELECT
5058 * mode : OUVERTURE
5060 * @param array paramètres de l'élément de parsing
5061 * @return null
5063 function o_SELECT($param)
5065 // preparation du champs
5066 if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
5068 $param['name'] = strtolower($param['name']);
5070 if (isset($this->lstChamps[$param['name']]))
5071 $this->lstChamps[$param['name']]++;
5072 else
5073 $this->lstChamps[$param['name']] = 1;
5075 $this->style->save();
5076 $this->style->analyse('select', $param);
5077 $this->style->setPosition();
5078 $this->style->FontSet();
5080 $this->lstSelect = array();
5081 $this->lstSelect['name'] = $param['name'];
5082 $this->lstSelect['multi'] = isset($param['multiple']) ? true : false;
5083 $this->lstSelect['size'] = isset($param['size']) ? $param['size'] : 1;
5084 $this->lstSelect['options'] = array();
5086 if ($this->lstSelect['multi'] && $this->lstSelect['size']<3) $this->lstSelect['size'] = 3;
5088 return true;
5092 * balise : OPTION
5093 * mode : OUVERTURE
5095 * @param array paramètres de l'élément de parsing
5096 * @return null
5098 function o_OPTION($param)
5100 // on extrait tout ce qui est contenu dans l'option
5101 $level = $this->parsing->getLevel($this->parse_pos);
5102 $this->parse_pos+= count($level);
5103 $value = isset($param['value']) ? $param['value'] : 'auto_opt_'.(count($this->lstSelect)+1);
5105 $this->lstSelect['options'][$value] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : '';
5107 return true;
5111 * balise : OPTION
5112 * mode : FERMETURE
5114 * @param array paramètres de l'élément de parsing
5115 * @return null
5117 function c_OPTION($param) { return true; }
5120 * balise : SELECT
5121 * mode : FERMETURE
5123 * @param array paramètres de l'élément de parsing
5124 * @return null
5126 function c_SELECT()
5128 // position d'affichage
5129 $x = $this->pdf->getX();
5130 $y = $this->pdf->getY();
5131 $f = 1.08*$this->style->value['font-size'];
5133 $w = $this->style->value['width']; if (!$w) $w = 50;
5134 $h = ($f*1.07*$this->lstSelect['size'] + 1);
5135 $prop = array();
5136 if ($this->lstSelect['multi']) $prop['multipleSelection'] = true;
5137 $this->pdf->form_Select($this->lstSelect['name'], $x, $y, $w, $h, $this->lstSelect['options'], $this->lstSelect['size']>1, $prop);
5139 $this->maxX = max($this->maxX, $x+$w);
5140 $this->maxY = max($this->maxY, $y+$h);
5141 $this->maxH = max($this->maxH, $h);
5142 $this->pdf->setX($x+$w);
5144 $this->style->load();
5145 $this->style->FontSet();
5147 $this->lstSelect = array();
5149 return true;
5153 * balise : TEXTAREA
5154 * mode : OUVERTURE
5156 * @param array paramètres de l'élément de parsing
5157 * @return null
5159 function o_TEXTAREA($param)
5161 // preparation du champs
5162 if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
5164 $param['name'] = strtolower($param['name']);
5166 if (isset($this->lstChamps[$param['name']]))
5167 $this->lstChamps[$param['name']]++;
5168 else
5169 $this->lstChamps[$param['name']] = 1;
5171 $this->style->save();
5172 $this->style->analyse('textarea', $param);
5173 $this->style->setPosition();
5174 $this->style->FontSet();
5176 // position d'affichage
5177 $x = $this->pdf->getX();
5178 $y = $this->pdf->getY();
5179 $fx = 0.65*$this->style->value['font-size'];
5180 $fy = 1.08*$this->style->value['font-size'];
5182 // on extrait tout ce qui est contenu dans le textarea
5183 $level = $this->parsing->getLevel($this->parse_pos);
5184 $this->parse_pos+= count($level);
5186 $w = $fx*(isset($param['cols']) ? $param['cols'] : 22)+1;
5187 $h = $fy*1.07*(isset($param['rows']) ? $param['rows'] : 3)+3;
5189 // if ($this->style->value['width']) $w = $this->style->value['width'];
5190 // if ($this->style->value['height']) $h = $this->style->value['height'];
5192 $prop = array();
5193 $prop['multiline'] = true;
5194 $prop['value'] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : '';
5196 $this->pdf->form_InputText($param['name'], $x, $y, $w, $h, $prop);
5198 $this->maxX = max($this->maxX, $x+$w);
5199 $this->maxY = max($this->maxY, $y+$h);
5200 $this->maxH = max($this->maxH, $h);
5201 $this->pdf->setX($x+$w);
5203 return true;
5207 * balise : TEXTAREA
5208 * mode : FERMETURE
5210 * @param array paramètres de l'élément de parsing
5211 * @return null
5213 function c_TEXTAREA()
5215 $this->style->load();
5216 $this->style->FontSet();
5218 return true;
5222 * balise : INPUT
5223 * mode : OUVERTURE
5225 * @param array paramètres de l'élément de parsing
5226 * @return null
5228 function o_INPUT($param)
5230 // preparation du champs
5231 if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
5232 if (!isset($param['value'])) $param['value'] = '';
5233 if (!isset($param['type'])) $param['type'] = 'text';
5235 $param['name'] = strtolower($param['name']);
5236 $param['type'] = strtolower($param['type']);
5238 if (!in_array($param['type'], array('text', 'checkbox', 'radio', 'hidden', 'submit', 'reset', 'button'))) $param['type'] = 'text';
5240 if (isset($this->lstChamps[$param['name']]))
5241 $this->lstChamps[$param['name']]++;
5242 else
5243 $this->lstChamps[$param['name']] = 1;
5245 $this->style->save();
5246 $this->style->analyse('input', $param);
5247 $this->style->setPosition();
5248 $this->style->FontSet();
5250 $name = $param['name'];
5252 // position d'affichage
5253 $x = $this->pdf->getX();
5254 $y = $this->pdf->getY();
5255 $f = 1.08*$this->style->value['font-size'];
5257 switch($param['type'])
5259 case 'checkbox':
5260 $w = 3;
5261 $h = $w;
5262 if ($h<$f) $y+= ($f-$h)*0.5;
5263 $this->pdf->form_InputCheckBox($name, $x, $y, $w, isset($param['checked']));
5264 break;
5266 case 'radio':
5267 $w = 3;
5268 $h = $w;
5269 if ($h<$f) $y+= ($f-$h)*0.5;
5270 $this->pdf->form_InputRadio($name, $x, $y, $w);
5271 break;
5273 case 'hidden':
5274 $w = 0;
5275 $h = 0;
5276 $this->pdf->form_InputHidden($name, $param['value']);
5277 break;
5279 case 'text':
5280 $w = $this->style->value['width']; if (!$w) $w = 40;
5281 $h = $f*1.3;
5282 $prop = array();
5283 $prop['value'] = $param['value'];
5284 $this->pdf->form_InputText($name, $x, $y, $w, $h, $prop);
5285 break;
5287 case 'submit':
5288 $w = $this->style->value['width']; if (!$w) $w = 40;
5289 $h = $this->style->value['height']; if (!$h) $h = $f*1.3;
5290 $action = 'this.submitForm("'.$this->isInForm.'", false);';
5291 $this->pdf->form_InputButton($name, $x, $y, $w, $h, $param['value'], $action, array());
5292 break;
5294 case 'reset':
5295 $w = $this->style->value['width']; if (!$w) $w = 40;
5296 $h = $this->style->value['height']; if (!$h) $h = $f*1.3;
5297 $action = 'this.resetForm();';
5298 $this->pdf->form_InputButton($name, $x, $y, $w, $h, $param['value'], $action, array());
5299 break;
5301 case 'button':
5302 $w = $this->style->value['width']; if (!$w) $w = 40;
5303 $h = $this->style->value['height']; if (!$h) $h = $f*1.3;
5304 $action = isset($param['onclick']) ? $param['onclick'] : '';
5305 $this->pdf->form_InputButton($name, $x, $y, $w, $h, $param['value'], $action, array());
5306 break;
5308 default:
5309 $w = 0;
5310 $h = 0;
5311 break;
5314 $this->maxX = max($this->maxX, $x+$w);
5315 $this->maxY = max($this->maxY, $y+$h);
5316 $this->maxH = max($this->maxH, $h);
5317 $this->pdf->setX($x+$w);
5319 $this->style->load();
5320 $this->style->FontSet();
5322 return true;
5326 * balise : DRAW
5327 * mode : OUVERTURE
5329 * @param array paramètres de l'élément de parsing
5330 * @return null
5332 function o_DRAW($param)
5334 if ($this->forOneLine) return false;
5335 if ($this->DEBUG_actif) $this->DEBUG_add('DRAW', true);
5337 $this->style->save();
5338 $this->style->analyse('draw', $param);
5339 $this->style->FontSet();
5341 $align_object = null;
5342 if ($this->style->value['margin-auto']) $align_object = 'center';
5344 $over_w = $this->style->value['width'];
5345 $over_h = $this->style->value['height'];
5346 $this->style->value['old_maxX'] = $this->maxX;
5347 $this->style->value['old_maxY'] = $this->maxY;
5348 $this->style->value['old_maxH'] = $this->maxH;
5350 $w = $this->style->value['width'];
5351 $h = $this->style->value['height'];
5353 if (!$this->style->value['position'])
5355 if (
5356 $w < ($this->pdf->getW() - $this->pdf->getlMargin()-$this->pdf->getrMargin()) &&
5357 $this->pdf->getX() + $w>=($this->pdf->getW() - $this->pdf->getrMargin())
5359 $this->o_BR(array());
5361 if (
5362 ($h < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin())) &&
5363 ($this->pdf->getY() + $h>=($this->pdf->getH() - $this->pdf->getbMargin())) &&
5364 !$this->isInOverflow
5366 $this->setNewPage();
5368 // en cas d'alignement => correction
5369 $old = $this->style->getOldValues();
5370 $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
5372 if ($parent_w>$w)
5374 if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
5375 else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
5378 $this->style->setPosition();
5380 else
5382 // en cas d'alignement => correction
5383 $old = $this->style->getOldValues();
5384 $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
5386 if ($parent_w>$w)
5388 if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
5389 else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
5392 $this->style->setPosition();
5393 $this->saveMax();
5394 $this->maxX = 0;
5395 $this->maxY = 0;
5396 $this->maxH = 0;
5397 $this->maxE = 0;
5400 // initialisation du style des bordures de la div
5401 $this->drawRectangle(
5402 $this->style->value['x'],
5403 $this->style->value['y'],
5404 $this->style->value['width'],
5405 $this->style->value['height'],
5406 $this->style->value['border'],
5407 $this->style->value['padding'],
5409 $this->style->value['background']
5412 $marge = array();
5413 $marge['l'] = $this->style->value['border']['l']['width'];
5414 $marge['r'] = $this->style->value['border']['r']['width'];
5415 $marge['t'] = $this->style->value['border']['t']['width'];
5416 $marge['b'] = $this->style->value['border']['b']['width'];
5418 $this->style->value['width'] -= $marge['l']+$marge['r'];
5419 $this->style->value['height']-= $marge['t']+$marge['b'];
5421 $over_w-= $marge['l']+$marge['r'];
5422 $over_h-= $marge['t']+$marge['b'];
5423 $this->pdf->clippingPathOpen(
5424 $this->style->value['x']+$marge['l'],
5425 $this->style->value['y']+$marge['t'],
5426 $this->style->value['width'],
5427 $this->style->value['height']
5430 // limitation des marges aux dimensions du contenu
5431 $mL = $this->style->value['x']+$marge['l'];
5432 $mR = $this->pdf->getW() - $mL - $over_w;
5434 $x = $this->style->value['x']+$marge['l'];
5435 $y = $this->style->value['y']+$marge['t'];
5436 $this->saveMargin($mL, 0, $mR);
5437 $this->pdf->setXY($x, $y);
5439 $this->isInDraw = array(
5440 'x' => $x,
5441 'y' => $y,
5442 'w' => $over_w,
5443 'h' => $over_h,
5445 $this->pdf->doTransform(array(1,0,0,1,$x,$y));
5446 return true;
5450 * balise : DRAW
5451 * mode : FERMETURE
5453 * @param array paramètres de l'élément de parsing
5454 * @return null
5456 function c_DRAW($param)
5458 if ($this->forOneLine) return false;
5460 $this->pdf->undoTransform();
5461 $this->pdf->clippingPathClose();
5463 $this->maxX = $this->style->value['old_maxX'];
5464 $this->maxY = $this->style->value['old_maxY'];
5465 $this->maxH = $this->style->value['old_maxH'];
5467 $marge = array();
5468 $marge['l'] = $this->style->value['border']['l']['width'];
5469 $marge['r'] = $this->style->value['border']['r']['width'];
5470 $marge['t'] = $this->style->value['border']['t']['width'];
5471 $marge['b'] = $this->style->value['border']['b']['width'];
5473 $x = $this->style->value['x'];
5474 $y = $this->style->value['y'];
5475 $w = $this->style->value['width']+$marge['l']+$marge['r'];
5476 $h = $this->style->value['height']+$marge['t']+$marge['b'];
5478 if ($this->style->value['position']!='absolute')
5480 // position
5481 $this->pdf->setXY($x+$w, $y);
5483 // position MAX
5484 $this->maxX = max($this->maxX, $x+$w);
5485 $this->maxY = max($this->maxY, $y+$h);
5486 $this->maxH = max($this->maxH, $h);
5488 else
5490 // position
5491 $this->pdf->setXY($this->style->value['xc'], $this->style->value['yc']);
5493 $this->loadMax();
5496 $block = ($this->style->value['display']!='inline' && $this->style->value['position']!='absolute');
5498 $this->style->load();
5499 $this->style->FontSet();
5500 $this->loadMargin();
5502 if ($block) $this->o_BR(array());
5503 if ($this->DEBUG_actif) $this->DEBUG_add('DRAW', false);
5505 $this->isInDraw = null;
5507 return true;
5511 * balise : LINE
5512 * mode : OUVERTURE
5514 * @param array paramètres de l'élément de parsing
5515 * @return null
5517 function o_LINE($param)
5519 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'LINE');
5520 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5521 $this->style->save();
5522 $styles = $this->style->getSvgStyle('path', $param);
5523 $styles['fill'] = null;
5524 $style = $this->pdf->svgSetStyle($styles);
5526 $x1 = isset($param['x1']) ? $this->style->ConvertToMM($param['x1'], $this->isInDraw['w']) : 0.;
5527 $y1 = isset($param['y1']) ? $this->style->ConvertToMM($param['y1'], $this->isInDraw['h']) : 0.;
5528 $x2 = isset($param['x2']) ? $this->style->ConvertToMM($param['x2'], $this->isInDraw['w']) : 0.;
5529 $y2 = isset($param['y2']) ? $this->style->ConvertToMM($param['y2'], $this->isInDraw['h']) : 0.;
5530 $this->pdf->svgLine($x1, $y1, $x2, $y2);
5532 $this->pdf->undoTransform();
5533 $this->style->load();
5537 * balise : RECT
5538 * mode : OUVERTURE
5540 * @param array paramètres de l'élément de parsing
5541 * @return null
5543 function o_RECT($param)
5545 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'RECT');
5546 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5547 $this->style->save();
5548 $styles = $this->style->getSvgStyle('path', $param);
5549 $style = $this->pdf->svgSetStyle($styles);
5551 $x = isset($param['x']) ? $this->style->ConvertToMM($param['x'], $this->isInDraw['w']) : 0.;
5552 $y = isset($param['y']) ? $this->style->ConvertToMM($param['y'], $this->isInDraw['h']) : 0.;
5553 $w = isset($param['w']) ? $this->style->ConvertToMM($param['w'], $this->isInDraw['w']) : 0.;
5554 $h = isset($param['h']) ? $this->style->ConvertToMM($param['h'], $this->isInDraw['h']) : 0.;
5556 $this->pdf->svgRect($x, $y, $w, $h, $style);
5558 $this->pdf->undoTransform();
5559 $this->style->load();
5563 * balise : CIRCLE
5564 * mode : OUVERTURE
5566 * @param array paramètres de l'élément de parsing
5567 * @return null
5569 function o_CIRCLE($param)
5571 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'CIRCLE');
5572 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5573 $this->style->save();
5574 $styles = $this->style->getSvgStyle('path', $param);
5575 $style = $this->pdf->svgSetStyle($styles);
5577 $cx = isset($param['cx']) ? $this->style->ConvertToMM($param['cx'], $this->isInDraw['w']) : 0.;
5578 $cy = isset($param['cy']) ? $this->style->ConvertToMM($param['cy'], $this->isInDraw['h']) : 0.;
5579 $r = isset($param['r']) ? $this->style->ConvertToMM($param['r'], $this->isInDraw['w']) : 0.;
5580 $this->pdf->svgEllipse($cx, $cy, $r, $r, $style);
5582 $this->pdf->undoTransform();
5583 $this->style->load();
5587 * balise : ELLIPSE
5588 * mode : OUVERTURE
5590 * @param array paramètres de l'élément de parsing
5591 * @return null
5593 function o_ELLIPSE($param)
5595 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'ELLIPSE');
5596 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5597 $this->style->save();
5598 $styles = $this->style->getSvgStyle('path', $param);
5599 $style = $this->pdf->svgSetStyle($styles);
5601 $cx = isset($param['cx']) ? $this->style->ConvertToMM($param['cx'], $this->isInDraw['w']) : 0.;
5602 $cy = isset($param['cy']) ? $this->style->ConvertToMM($param['cy'], $this->isInDraw['h']) : 0.;
5603 $rx = isset($param['ry']) ? $this->style->ConvertToMM($param['rx'], $this->isInDraw['w']) : 0.;
5604 $ry = isset($param['rx']) ? $this->style->ConvertToMM($param['ry'], $this->isInDraw['h']) : 0.;
5605 $this->pdf->svgEllipse($cx, $cy, $rx, $ry, $style);
5607 $this->pdf->undoTransform();
5608 $this->style->load();
5613 * balise : POLYLINE
5614 * mode : OUVERTURE
5616 * @param array paramètres de l'élément de parsing
5617 * @return null
5619 function o_POLYLINE($param)
5621 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'POLYGON');
5622 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5623 $this->style->save();
5624 $styles = $this->style->getSvgStyle('path', $param);
5625 $style = $this->pdf->svgSetStyle($styles);
5627 $path = isset($param['points']) ? $param['points'] : null;
5628 if ($path)
5630 $path = str_replace(',', ' ', $path);
5631 $path = preg_replace('/[\s]+/', ' ', trim($path));
5633 // decoupage et nettoyage
5634 $path = explode(' ', $path);
5635 foreach($path as $k => $v)
5637 $path[$k] = trim($v);
5638 if ($path[$k]==='') unset($path[$k]);
5640 $path = array_values($path);
5642 $actions = array();
5643 for($k=0; $k<count($path); $k+=2)
5645 $actions[] = array(($k ? 'L' : 'M') ,
5646 $this->style->ConvertToMM($path[$k+0], $this->isInDraw['w']),
5647 $this->style->ConvertToMM($path[$k+1], $this->isInDraw['h']));
5650 // on trace
5651 $this->pdf->svgPolygone($actions, $style);
5654 $this->pdf->undoTransform();
5655 $this->style->load();
5659 * balise : POLYGON
5660 * mode : OUVERTURE
5662 * @param array paramètres de l'élément de parsing
5663 * @return null
5665 function o_POLYGON($param)
5667 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'POLYGON');
5668 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5669 $this->style->save();
5670 $styles = $this->style->getSvgStyle('path', $param);
5671 $style = $this->pdf->svgSetStyle($styles);
5673 $path = isset($param['points']) ? $param['points'] : null;
5674 if ($path)
5676 $path = str_replace(',', ' ', $path);
5677 $path = preg_replace('/[\s]+/', ' ', trim($path));
5679 // decoupage et nettoyage
5680 $path = explode(' ', $path);
5681 foreach($path as $k => $v)
5683 $path[$k] = trim($v);
5684 if ($path[$k]==='') unset($path[$k]);
5686 $path = array_values($path);
5688 $actions = array();
5689 for($k=0; $k<count($path); $k+=2)
5691 $actions[] = array(($k ? 'L' : 'M') ,
5692 $this->style->ConvertToMM($path[$k+0], $this->isInDraw['w']),
5693 $this->style->ConvertToMM($path[$k+1], $this->isInDraw['h']));
5695 $actions[] = array('z');
5696 // on trace
5697 $this->pdf->svgPolygone($actions, $style);
5700 $this->pdf->undoTransform();
5701 $this->style->load();
5705 * balise : PATH
5706 * mode : OUVERTURE
5708 * @param array paramètres de l'élément de parsing
5709 * @return null
5711 function o_PATH($param)
5713 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'PATH');
5714 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5715 $this->style->save();
5716 $styles = $this->style->getSvgStyle('path', $param);
5717 $style = $this->pdf->svgSetStyle($styles);
5719 $path = isset($param['d']) ? $param['d'] : null;
5720 if ($path)
5722 // preparation
5723 $path = str_replace(',', ' ', $path);
5724 $path = preg_replace('/([a-zA-Z])([0-9\.\-])/', '$1 $2', $path);
5725 $path = preg_replace('/([0-9\.])([a-zA-Z])/', '$1 $2', $path);
5726 $path = preg_replace('/[\s]+/', ' ', trim($path));
5727 $path = preg_replace('/ ([a-z]{2})/', '$1', $path);
5729 // decoupage et nettoyage
5730 $path = explode(' ', $path);
5731 foreach($path as $k => $v)
5733 $path[$k] = trim($v);
5734 if ($path[$k]==='') unset($path[$k]);
5736 $path = array_values($path);
5738 // conversion des unites
5739 $actions = array();
5740 $action = array();
5741 for($k=0; $k<count($path); $k+=count($action))
5743 $action = array();
5744 $action[] = $path[$k];
5745 switch($path[$k])
5747 case 'C':
5748 case 'c':
5749 $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x1
5750 $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // y1
5751 $action[] = $this->style->ConvertToMM($path[$k+3], $this->isInDraw['w']); // x2
5752 $action[] = $this->style->ConvertToMM($path[$k+4], $this->isInDraw['h']); // y2
5753 $action[] = $this->style->ConvertToMM($path[$k+5], $this->isInDraw['w']); // x
5754 $action[] = $this->style->ConvertToMM($path[$k+6], $this->isInDraw['h']); // y
5755 break;
5757 case 'Q':
5758 case 'S':
5759 case 'q':
5760 case 's':
5761 $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x2
5762 $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // y2
5763 $action[] = $this->style->ConvertToMM($path[$k+3], $this->isInDraw['w']); // x
5764 $action[] = $this->style->ConvertToMM($path[$k+4], $this->isInDraw['h']); // y
5765 break;
5767 case 'A':
5768 case 'a':
5769 $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // rx
5770 $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // ry
5771 $action[] = 1.*$path[$k+3]; // angle de deviation de l'axe X
5772 $action[] = ($path[$k+4]=='1') ? 1 : 0; // large-arc-flag
5773 $action[] = ($path[$k+5]=='1') ? 1 : 0; // sweep-flag
5774 $action[] = $this->style->ConvertToMM($path[$k+6], $this->isInDraw['w']); // x
5775 $action[] = $this->style->ConvertToMM($path[$k+7], $this->isInDraw['h']); // y
5776 break;
5778 case 'M':
5779 case 'L':
5780 case 'T':
5781 case 'm':
5782 case 'l':
5783 case 't':
5784 $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x
5785 $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // y
5786 break;
5788 case 'H':
5789 case 'h':
5790 $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x
5791 break;
5793 case 'V':
5794 case 'v':
5795 $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['h']); // y
5796 break;
5798 case 'z':
5799 case 'Z':
5800 default:
5801 break;
5803 $actions[] = $action;
5806 // on trace
5807 $this->pdf->svgPolygone($actions, $style);
5810 $this->pdf->undoTransform();
5811 $this->style->load();
5815 * balise : G
5816 * mode : OUVERTURE
5818 * @param array paramètres de l'élément de parsing
5819 * @return null
5821 function o_G($param)
5823 if (!$this->isInDraw) HTML2PDF::makeError(8, __FILE__, __LINE__, 'LINE');
5824 $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
5825 $this->style->save();
5826 $styles = $this->style->getSvgStyle('path', $param);
5827 $style = $this->pdf->svgSetStyle($styles);
5831 * balise : G
5832 * mode : FERMETURE
5834 * @param array paramètres de l'élément de parsing
5835 * @return null
5837 function c_G($param)
5839 $this->pdf->undoTransform();
5840 $this->style->load();
5843 function _prepareTransform($transform)
5845 if (!$transform) return null;
5846 $actions = array();
5847 if (!preg_match_all('/([a-z]+)\(([^\)]*)\)/isU', $transform, $match)) return null;
5849 for($k=0; $k<count($match[0]); $k++)
5851 $nom = strtolower($match[1][$k]);
5852 $val = explode(',', trim($match[2][$k]));
5853 foreach($val as $i => $j)
5854 $val[$i] = trim($j);
5856 switch($nom)
5858 case 'scale':
5859 if (!isset($val[0])) $val[0] = 1.; else $val[0] = 1.*$val[0];
5860 if (!isset($val[1])) $val[1] = $val[0]; else $val[1] = 1.*$val[1];
5861 $actions[] = array($val[0],0,0,$val[1],0,0);
5862 break;
5864 case 'translate':
5865 if (!isset($val[0])) $val[0] = 0.; else $val[0] = $this->style->ConvertToMM($val[0], $this->isInDraw['w']);
5866 if (!isset($val[1])) $val[1] = 0.; else $val[1] = $this->style->ConvertToMM($val[1], $this->isInDraw['h']);
5867 $actions[] = array(1,0,0,1,$val[0],$val[1]);
5868 break;
5870 case 'rotate':
5871 if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*M_PI/180.;
5872 if (!isset($val[1])) $val[1] = 0.; else $val[1] = $this->style->ConvertToMM($val[1], $this->isInDraw['w']);
5873 if (!isset($val[2])) $val[2] = 0.; else $val[2] = $this->style->ConvertToMM($val[2], $this->isInDraw['h']);
5874 if ($val[1] || $val[2]) $actions[] = array(1,0,0,1,-$val[1],-$val[2]);
5875 $actions[] = array(cos($val[0]),sin($val[0]),-sin($val[0]),cos($val[0]),0,0);
5876 if ($val[1] || $val[2]) $actions[] = array(1,0,0,1,$val[1],$val[2]);
5877 break;
5879 case 'skewx':
5880 if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*M_PI/180.;
5881 $actions[] = array(1,0,tan($val[0]),1,0,0);
5882 break;
5884 case 'skewy':
5885 if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*M_PI/180.;
5886 $actions[] = array(1,tan($val[0]),0,1,0,0);
5887 break;
5888 case 'matrix':
5889 if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*1.;
5890 if (!isset($val[1])) $val[1] = 0.; else $val[1] = $val[1]*1.;
5891 if (!isset($val[2])) $val[2] = 0.; else $val[2] = $val[2]*1.;
5892 if (!isset($val[3])) $val[3] = 0.; else $val[3] = $val[3]*1.;
5893 if (!isset($val[4])) $val[4] = 0.; else $val[4] = $this->style->ConvertToMM($val[4], $this->isInDraw['w']);
5894 if (!isset($val[5])) $val[5] = 0.; else $val[5] = $this->style->ConvertToMM($val[5], $this->isInDraw['h']);
5895 $actions[] =$val;
5896 break;
5900 if (!$actions) return null;
5901 $m = $actions[0]; unset($actions[0]);
5902 foreach($actions as $n)
5904 $m = array(
5905 $m[0]*$n[0]+$m[2]*$n[1],
5906 $m[1]*$n[0]+$m[3]*$n[1],
5907 $m[0]*$n[2]+$m[2]*$n[3],
5908 $m[1]*$n[2]+$m[3]*$n[3],
5909 $m[0]*$n[4]+$m[2]*$n[5]+$m[4],
5910 $m[1]*$n[4]+$m[3]*$n[5]+$m[5]
5914 return $m;
5917 function _getDrawNumber(&$lst, $key, $n=1, $correct=false)
5919 $res = array_fill(0, $n, 0);
5920 $tmp = isset($lst[$key]) ? $lst[$key] : null;
5921 if (!$tmp) return $res;
5922 $tmp = explode(' ', trim(preg_replace('/[\s]+/', ' ', $tmp)));
5923 foreach($tmp as $k => $v)
5925 $v = trim($v);
5926 if (!$correct)
5928 $res[$k] = $this->style->ConvertToMM($v);
5930 else
5932 $res[$k] = $this->style->ConvertToMM($v, ($k%2) ? $this->isInDraw['h'] : $this->isInDraw['w']);
5935 return $res;
5939 * permet d'afficher un index automatique utilisant les bookmark
5941 * @param string titre du sommaire
5942 * @param int taille en mm de la fonte du titre du sommaire
5943 * @param int taille en mm de la fonte du texte du sommaire
5944 * @param boolean ajouter un bookmark spécifique pour l'index, juste avant le début de celui-ci
5945 * @param boolean afficher les numéros de page associés à chaque bookmark
5946 * @param int si présent : page où afficher le sommaire. sinon : nouvelle page
5947 * @param string nom de la fonte à utiliser
5948 * @return null
5950 function createIndex($titre = 'Index', $size_title = 20, $size_bookmark = 15, $bookmark_title = true, $display_page = true, $on_page = null, $font_name = 'helvetica')
5952 $old_page = $this->INDEX_NewPage($on_page);
5953 $this->pdf->createIndex($this, $titre, $size_title, $size_bookmark, $bookmark_title, $display_page, $on_page, $font_name);
5954 if ($old_page) $this->pdf->setPage($old_page);
5958 * nouvelle page pour l'index. ne pas utiliser directement. seul MyPDF doit l'utiliser !!!!
5960 * @param int page courante
5961 * @return null
5963 function INDEX_NewPage(&$page)
5965 if ($page)
5967 $old_page = $this->pdf->getPage();
5968 $this->pdf->setPage($page);
5969 $this->pdf->setXY($this->margeLeft, $this->margeTop);
5970 $this->maxH = 0;
5971 $page++;
5972 return $old_page;
5974 else
5976 $this->setNewPage();
5978 return null;
5983 * chargement du fichier de langue
5985 * @param string langue
5986 * @return null
5988 function textLOAD($langue)
5990 global $HTML2PDF_TEXTES;
5991 if (count($HTML2PDF_TEXTES)) return true;
5993 if (!preg_match('/^([a-z0-9]+)$/isU', $langue))
5995 echo 'ERROR : language code <b>'.$langue.'</b> incorrect.';
5996 exit;
5999 $file = dirname(__FILE__).'/langues/'.strtolower($langue).'.txt';
6000 if (!is_file($file))
6002 echo 'ERROR : language code <b>'.$langue.'</b> unknown.<br>';
6003 echo 'You can create the translation file <b>'.$file.'</b> and send it to me in order to integrate it into a future version.';
6004 exit;
6007 $texte = array();
6008 $infos = file($file);
6009 foreach($infos as $val)
6011 $val = trim($val);
6012 $val = explode("\t", $val);
6013 if (count($val)<2) continue;
6015 $t_k = trim($val[0]); unset($val[0]);
6016 $t_v = trim(implode(' ', $val));
6017 if ($t_k && $t_v) $texte[$t_k] = $t_v;
6019 $HTML2PDF_TEXTES = $texte;
6021 return true;
6025 * recuperer un texte precis
6027 * @param string code du texte
6028 * @return null
6030 function textGET($key)
6032 global $HTML2PDF_TEXTES;
6033 if (!isset($HTML2PDF_TEXTES[$key])) return '######';
6035 return $HTML2PDF_TEXTES[$key];
6039 * generer une erreur HTML2PDF
6041 * @param int numero de l'erreur
6042 * @param string nom du fichier ou c'est produit l'erreur
6043 * @param int numero de la ligne ou c'est produit l'erreur
6044 * @param mixed indications suplementaires sur l'erreur
6045 * @return string code HTML eventuel associé à l'erreur
6047 function makeError($err, $file, $line, $other = null, $html = '')
6049 $msg = '';
6050 switch($err)
6052 case 1:
6053 $msg = (HTML2PDF::textGET('err01'));
6054 $msg = str_replace('[[OTHER]]', $other, $msg);
6055 break;
6057 case 2:
6058 $msg = (HTML2PDF::textGET('err02'));
6059 $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
6060 $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
6061 $msg = str_replace('[[OTHER_2]]', $other[2], $msg);
6062 break;
6064 case 3:
6065 $msg = (HTML2PDF::textGET('err03'));
6066 $msg = str_replace('[[OTHER]]', $other, $msg);
6067 break;
6069 case 4:
6070 $msg = (HTML2PDF::textGET('err04'));
6071 $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
6072 break;
6074 case 5:
6075 $msg = (HTML2PDF::textGET('err05'));
6076 $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
6077 break;
6079 case 6:
6080 $msg = (HTML2PDF::textGET('err06'));
6081 $msg = str_replace('[[OTHER]]', $other, $msg);
6082 break;
6084 case 7:
6085 $msg = (HTML2PDF::textGET('err07'));
6086 break;
6088 case 8:
6089 $msg = (HTML2PDF::textGET('err08'));
6090 $msg = str_replace('[[OTHER]]', $other, $msg);
6091 break;
6093 case 9:
6094 $msg = (HTML2PDF::textGET('err09'));
6095 $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
6096 $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
6097 break;
6099 echo '<span style="color: #AA0000; font-weight: bold;">'.(HTML2PDF::textGET('txt01')).$err.'</span><br>';
6100 echo (HTML2PDF::textGET('txt02')).' '.$file.'<br>';
6101 echo (HTML2PDF::textGET('txt03')).' '.$line.'<br>';
6102 echo '<br>';
6103 echo $msg;
6104 echo '<br>';
6105 if ($html) echo '<br>HTML : ...'.htmlentities($html).'...';
6106 exit;