/common/libraries/plugin/html2pdf/html2pdf.class.php
PHP | 2115 lines | 1344 code | 309 blank | 462 comment | 188 complexity | ca913e667e1afd5ef9c8573b8103cda4 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Logiciel : HTML2PDF
- *
- * Convertisseur HTML => PDF, utilise TCPDF
- * Distribu? sous la licence LGPL.
- *
- * @author Laurent MINGUET <webmaster@html2pdf.fr>
- * @version 4.00
- */
-
- if (!defined('__CLASS_HTML2PDF__'))
- {
- define('__CLASS_HTML2PDF__', '4.00');
-
- require_once(dirname(__FILE__).'/_mypdf/mypdf.class.php'); // classe mypdf
- require_once(dirname(__FILE__).'/parsingHTML.class.php'); // classe de parsing HTML
- require_once(dirname(__FILE__).'/styleHTML.class.php'); // classe de gestion des styles
-
- class HTML2PDF
- {
- public $pdf = null; // objet PDF
- public $style = null; // objet de style
- public $parsing = null; // objet de parsing
-
- protected $langue = 'fr'; // langue des messages
- protected $sens = 'P'; // sens d'affichage Portrait ou Landscape
- protected $format = 'A4'; // format de la page : A4, A3, ...
- protected $encoding = ''; // charset encoding
- protected $unicode = true; // means that the input text is unicode (default = true)
-
- protected $background = array(); // informations sur le background
- protected $testTDin1page = true; // activer le test de TD ne devant pas depasser une page
- protected $testIsImage = true; // test si les images existes ou non
- protected $isSubPart = false; // indique que le convertisseur courant est un sous html
-
- protected $parse_pos = 0; // position du parsing
- protected $temp_pos = 0; // position temporaire pour multi tableau
- protected $page = 0; // numero de la page courante
-
- protected $sub_html = null; // sous html
- protected $sub_part = false; // indicateur de sous html
-
- protected $maxX = 0; // zone maxi X
- protected $maxY = 0; // zone maxi Y
- protected $maxE = 0; // nomre d'elements dans la zone
- protected $maxH = 0; // plus grande hauteur dans la ligne, pour saut de ligne ? corriger
- protected $maxSave = array(); // tableau de sauvegarde des maximaux
- protected $currentH = 0; // hauteur de la ligne courante
-
- protected $firstPage = true; // premier page
-
- protected $defaultLeft = 0; // marges par default de la page
- protected $defaultTop = 0;
- protected $defaultRight = 0;
- protected $defaultBottom = 0;
-
- protected $margeLeft = 0; //marges r?elles de la page
- protected $margeTop = 0;
- protected $margeRight = 0;
- protected $margeBottom = 0;
- protected $marges = array(); // tableau de sauvegarde des differents etats des marges de la page courante
-
- protected $inLink = ''; // indique si on est ? l'interieur d'un lien
- protected $lstAncre = array(); // liste des ancres d?tect?es ou cr??es
- protected $subHEADER = array(); // tableau des sous commandes pour faire l'HEADER
- protected $subFOOTER = array(); // tableau des sous commandes pour faire le FOOTER
- protected $subSTATES = array(); // tableau de sauvegarde de certains param?tres
- protected $defLIST = array(); // tableau de sauvegarde de l'etat des UL et OL
-
- protected $lstChamps = array(); // liste des champs
- protected $lstSelect = array(); // options du select en cours
- protected $previousCall = null; // dernier appel
- protected $pageMarges = array(); // marges sp?cifiques dues aux floats
- protected $isInThead = false; // indique si on est dans un thead
- protected $isInTfoot = false; // indique si on est dans un tfoot
- protected $isInOverflow = false; // indique si on est dans une div overflow
- protected $isInFooter = false; // indique si on est dans un footer ou non
- protected $isInDraw = null; // indique si on est en mode dessin
- protected $isAfterFloat = false; // indique si on est apres un float
- protected $forOneLine = false; // indique si on est dans un sous HTML ne servant qu'a calculer la taille de la prochaine ligne
- protected $isInForm = false; // indique si on est dans un formulaire. Contient dans ce cas l? l'action de celui-ci
-
- protected $DEBUG_actif = false; // indique si on est en mode debug
- protected $DEBUG_ok_usage = false; // indique l'existance de la fonction memory_get_usage
- protected $DEBUG_ok_peak = false; // indique l'existance de la fonction memory_get_peak_usage
- protected $DEBUG_level = 0; // niveau du debug
- protected $DEBUG_start_time = 0; //
- protected $DEBUG_last_time = 0; //
- protected $defaultFont = null; // fonte par d?faut si la fonte demand?e n'existe pas
-
- static protected $SUBOBJ = null; // sous objet HTML2PDF pr?par? en cas de besoin
- static protected $TABLES = array(); // tableau global necessaire ? la gestion des tables imbriqu?es
- static protected $TEXTES = array(); // tableau comprennant le fichier de langue
-
- /**
- * Constructeur
- *
- * @param string sens portrait ou landscape
- * @param string format A4, A5, ...
- * @param string langue : fr, en, it...
- * @param boolean $unicode TRUE means that the input text is unicode (default = true)
- * @param String $encoding charset encoding; default is UTF-8
- * @param array marges par defaut, dans l'ordre (left, top, right, bottom)
- * @return null
- */
- public function __construct($sens = 'P', $format = 'A4', $langue='fr', $unicode=true, $encoding='UTF-8', $marges = array(5, 5, 5, 8))
- {
- // sauvegarde des param?tres
- $this->page = 0;
- $this->sens = $sens;
- $this->format = $format;
- $this->unicode = $unicode;
- $this->encoding = $encoding;
-
- $this->firstPage = true;
- $this->langue = strtolower($langue);
-
- // chargement du fichier de langue
- HTML2PDF::textLOAD($this->langue);
-
- // cr?ation de l' objet PDF
- $this->pdf = new MyPDF($sens, 'mm', $format, $unicode, $encoding);
-
- // initialisation des styles
- $this->style = new styleHTML($this->pdf);
- $this->style->FontSet();
- $this->defLIST = array();
-
- // initialisations diverses
- $this->setTestTdInOnePage(true);
- $this->setTestIsImage(true);
- $this->setDefaultFont(null);
-
- // initialisation du parsing
- $this->parsing = new parsingHTML($this->encoding);
- $this->sub_html = null;
- $this->sub_part = false;
-
- // initialisation des marges
- if (!is_array($marges)) $marges = array($marges, $marges, $marges, $marges);
- $this->setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]);
- $this->setMargins();
- $this->marges = array();
-
- // initialisation des champs de formulaire
- $this->lstChamps = array();
- }
-
- /**
- * Destructeur
- *
- * @return null
- */
- public function __destruct()
- {
-
- }
-
- /**
- * activer le debug mode
- *
- * @return null
- */
- public function setModeDebug()
- {
- list($usec, $sec) = explode(' ', microtime());
-
- $this->DEBUG_actif = true;
- $this->DEBUG_ok_usage = function_exists('memory_get_usage');
- $this->DEBUG_ok_peak = function_exists('memory_get_peak_usage');
- $this->DEBUG_start_time = (float)$sec + (float)$usec;
- $this->DEBUG_last_time = (float)$sec + (float)$usec;
-
- $this->DEBUG_stepline('step', 'time', 'delta', 'memory', 'peak');
- $this->DEBUG_add('Init debug');
- }
-
- /**
- * rajouter une ligne de debug
- *
- * @param string nom de l'etape
- * @param boolean true=monter d'un niveau, false=descendre d'un niveau, null : ne rien faire
- * @return null
- */
- protected function DEBUG_add($nom, $level=null)
- {
- list($usec, $sec) = explode(' ', microtime());
- if ($level===true) $this->DEBUG_level++;
-
- $nom = str_repeat(' ',$this->DEBUG_level). $nom.($level===true ? ' Begin' : ($level===false ? ' End' : ''));
- $time = (float)$sec + (float)$usec;
- $usage = ($this->DEBUG_ok_usage ? memory_get_usage() : 0);
- $peak = ($this->DEBUG_ok_peak ? memory_get_peak_usage() : 0);
-
- $this->DEBUG_stepline(
- $nom,
- number_format(($time - $this->DEBUG_start_time)*1000, 1, '.', ' ').' ms',
- number_format(($time - $this->DEBUG_last_time)*1000, 1, '.', ' ').' ms',
- number_format($usage/1024, 1, '.', ' ').' Ko',
- number_format($peak/1024, 1, '.', ' ').' Ko');
-
- $this->DEBUG_last_time = $time;
- if ($level===false) $this->DEBUG_level--;
- return true;
- }
-
- /**
- * affiche une ligne de debug
- *
- * @param string nom de l'etape
- * @param string valeur 1
- * @param string valeur 2
- * @param string valeur 3
- * @param string valeur 4
- * @return null
- */
- protected function DEBUG_stepline($nom, $val1, $val2, $val3, $val4)
- {
- $txt = str_pad($nom, 30, ' ', STR_PAD_RIGHT).
- str_pad($val1, 12, ' ', STR_PAD_LEFT).
- str_pad($val2, 12, ' ', STR_PAD_LEFT).
- str_pad($val3, 15, ' ', STR_PAD_LEFT).
- str_pad($val4, 15, ' ', STR_PAD_LEFT);
-
- echo '<pre style="padding:0; margin:0">'.$txt.'</pre>';
- }
-
- /**
- * activer ou desactiver le test de TD ne devant pas depasser une page
- *
- * @param boolean nouvel etat
- * @return boolean ancien etat
- */
- public function setTestTdInOnePage($mode = true)
- {
- $old = $this->testTDin1page;
- $this->testTDin1page = $mode ? true : false;
- return $old;
- }
-
- /**
- * activer ou desactiver le test sur la pr?sence des images
- *
- * @param boolean nouvel etat
- * @return boolean ancien etat
- */
- public function setTestIsImage($mode = true)
- {
- $old = $this->testIsImage;
- $this->testIsImage = $mode ? true : false;
- return $old;
- }
-
- /**
- * d?finit la fonte par d?faut si aucun fonte n'est sp?cifi?e, ou si la fonte demand?e n'existe pas
- *
- * @param string nom de la fonte par defaut. si null : Arial pour fonte non sp?cifi?e, et erreur pour fonte non existante
- * @return string nom de l'ancienne fonte par defaut
- */
- public function setDefaultFont($default = null)
- {
- $old = $this->defaultFont;
- $this->defaultFont = $default;
- $this->style->setDefaultFont($default);
- return $old;
- }
-
- /**
- * d?finir les marges par d?fault
- *
- * @param int en mm, marge left
- * @param int en mm, marge top
- * @param int en mm, marge right. si null, left=right
- * @param int en mm, marge bottom. si null, bottom=8
- * @return null
- */
- protected function setDefaultMargins($left, $top, $right = null, $bottom = null)
- {
- if ($right===null) $right = $left;
- if ($bottom===null) $bottom = 8;
-
- $this->defaultLeft = $this->style->ConvertToMM($left.'mm');
- $this->defaultTop = $this->style->ConvertToMM($top.'mm');
- $this->defaultRight = $this->style->ConvertToMM($right.'mm');
- $this->defaultBottom = $this->style->ConvertToMM($bottom.'mm');
- }
-
- /**
- * d?finir les marges r?elles, fonctions de la balise page
- *
- * @return null
- */
- protected function setMargins()
- {
- $this->margeLeft = $this->defaultLeft + (isset($this->background['left']) ? $this->background['left'] : 0);
- $this->margeRight = $this->defaultRight + (isset($this->background['right']) ? $this->background['right'] : 0);
- $this->margeTop = $this->defaultTop + (isset($this->background['top']) ? $this->background['top'] : 0);
- $this->margeBottom = $this->defaultBottom + (isset($this->background['bottom']) ? $this->background['bottom'] : 0);
-
- $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
- $this->pdf->setcMargin(0);
- $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
-
- $this->pageMarges = array();
- $this->pageMarges[floor($this->margeTop*100)] = array($this->margeLeft, $this->pdf->getW()-$this->margeRight);
- }
-
- /**
- * recuperer les positions x minimales et maximales en fonction d'une hauteur
- *
- * @param float y
- * @return array(float, float)
- */
- protected function getMargins($y)
- {
- $y = floor($y*100);
- $x = array($this->pdf->getlMargin(), $this->pdf->getW()-$this->pdf->getrMargin());
-
- foreach($this->pageMarges as $m_y => $m_x)
- if ($m_y<=$y) $x = $m_x;
-
- return $x;
- }
-
- /**
- * ajouter une marge suite a un float
- *
- * @param string left ou right
- * @param float x1
- * @param float y1
- * @param float x2
- * @param float y2
- * @return null
- */
- protected function addMargins($float, $x1, $y1, $x2, $y2)
- {
- $old1 = $this->getMargins($y1);
- $old2 = $this->getMargins($y2);
- if ($float=='left') $old1[0] = $x2;
- if ($float=='right') $old1[1] = $x1;
-
- $y1 = floor($y1*100);
- $y2 = floor($y2*100);
-
- foreach($this->pageMarges as $m_y => $m_x)
- {
- if ($m_y<$y1) continue;
- if ($m_y>$y2) break;
- if ($float=='left' && $this->pageMarges[$m_y][0]<$x2) unset($this->pageMarges[$m_y]);
- if ($float=='right' && $this->pageMarges[$m_y][1]>$x1) unset($this->pageMarges[$m_y]);
- }
-
- $this->pageMarges[$y1] = $old1;
- $this->pageMarges[$y2] = $old2;
-
- ksort($this->pageMarges);
-
- $this->isAfterFloat = true;
- }
-
- /**
- * d?finir des nouvelles marges et sauvegarder les anciennes
- *
- * @param float marge left
- * @param float marge top
- * @param float marge right
- * @return null
- */
- protected function saveMargin($ml, $mt, $mr)
- {
- $this->marges[] = array('l' => $this->pdf->getlMargin(), 't' => $this->pdf->gettMargin(), 'r' => $this->pdf->getrMargin(), 'page' => $this->pageMarges);
- $this->pdf->SetMargins($ml, $mt, $mr);
-
- $this->pageMarges = array();
- $this->pageMarges[floor($mt*100)] = array($ml, $this->pdf->getW()-$mr);
- }
-
- /**
- * r?cuperer les derni?res marches sauv?es
- *
- * @return null
- */
- protected function loadMargin()
- {
- $old = array_pop($this->marges);
- if ($old)
- {
- $ml = $old['l'];
- $mt = $old['t'];
- $mr = $old['r'];
- $mP = $old['page'];
- }
- else
- {
- $ml = $this->margeLeft;
- $mt = 0;
- $mr = $this->margeRight;
- $mP = array($mt => array($ml, $this->pdf->getW()-$mr));
- }
-
- $this->pdf->SetMargins($ml, $mt, $mr);
- $this->pageMarges = $mP;
- }
-
- /**
- * permet d'ajouter une fonte.
- *
- * @param string nom de la fonte
- * @param string style de la fonte
- * @param string fichier de la fonte
- * @return null
- */
- public function addFont($family, $style='', $file='')
- {
- $this->pdf->AddFont($family, $style, $file);
- }
-
- /**
- * sauvegarder l'?tat actuelle des maximums
- *
- * @return null
- */
- protected function saveMax()
- {
- $this->maxSave[] = array($this->maxX, $this->maxY, $this->maxH, $this->maxE);
- }
-
- /**
- * charger le dernier ?tat sauv? des maximums
- *
- * @return null
- */
- protected function loadMax()
- {
- $old = array_pop($this->maxSave);
-
- if ($old)
- {
- $this->maxX = $old[0];
- $this->maxY = $old[1];
- $this->maxH = $old[2];
- $this->maxE = $old[3];
- }
- else
- {
- $this->maxX = 0;
- $this->maxY = 0;
- $this->maxH = 0;
- $this->maxE = 0;
- }
- }
-
- /**
- * afficher l'header contenu dans page_header
- *
- * @return null
- */
- protected function setPageHeader()
- {
- if (!count($this->subHEADER)) return false;
-
- $OLD_parse_pos = $this->parse_pos;
- $OLD_parse_code = $this->parsing->code;
-
- $this->parse_pos = 0;
- $this->parsing->code = $this->subHEADER;
- $this->makeHTMLcode();
-
- $this->parse_pos = $OLD_parse_pos;
- $this->parsing->code = $OLD_parse_code;
- }
-
- /**
- * afficher le footer contenu dans page_footer
- *
- * @return null
- */
- protected function setPageFooter()
- {
- if (!count($this->subFOOTER)) return false;
-
- $OLD_parse_pos = $this->parse_pos;
- $OLD_parse_code = $this->parsing->code;
-
- $this->parse_pos = 0;
- $this->parsing->code = $this->subFOOTER;
- $this->isInFooter = true;
- $this->makeHTMLcode();
- $this->isInFooter = false;
-
- $this->parse_pos = $OLD_parse_pos;
- $this->parsing->code = $OLD_parse_code;
- }
-
- /**
- * saut de ligne avec une hauteur sp?cifique
- *
- * @param float hauteur de la ligne
- * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
- * @return null
- */
- protected function setNewLine($h, $curr = null)
- {
- $this->pdf->Ln($h);
-
- $this->setNewPositionForNewLine($curr);
- }
-
- /**
- * cr?ation d'une nouvelle page avec le format et l'orientation sp?cifies
- *
- * @param mixed format de la page : A5, A4, array(width, height)
- * @param string sens P=portrait ou L=landscape
- * @param array tableau des propri?t?s du fond de la page
- * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
- * @return null
- */
- public function setNewPage($format = null, $orientation = '', $background = null, $curr = null)
- {
- $this->firstPage = false;
-
- $this->format = $format ? $format : $this->format;
- $this->sens = $orientation ? $orientation : $this->sens;
- $this->background = $background!==null ? $background : $this->background;
- $this->maxY = 0;
- $this->maxX = 0;
- $this->maxH = 0;
-
- $this->pdf->SetMargins($this->defaultLeft, $this->defaultTop, $this->defaultRight);
- $this->pdf->AddPage($this->sens, $this->format);
- $this->page++;
-
- if (!$this->sub_part && !$this->isSubPart)
- {
- if (is_array($this->background))
- {
- if (isset($this->background['color']) && $this->background['color'])
- {
- $this->pdf->setFillColorArray($this->background['color']);
- $this->pdf->Rect(0, 0, $this->pdf->getW(), $this->pdf->getH(), 'F');
- }
-
- if (isset($this->background['img']) && $this->background['img'])
- $this->pdf->Image($this->background['img'], $this->background['posX'], $this->background['posY'], $this->background['width']);
- }
-
- $this->setPageHeader();
- $this->setPageFooter();
- }
-
- $this->setMargins();
- $this->pdf->setY($this->margeTop);
-
- $this->setNewPositionForNewLine($curr);
- $this->maxH = 0;
- }
-
- /**
- * calcul de la position de debut de la prochaine ligne en fonction de l'alignement voulu
- *
- * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
- * @return null
- */
- protected function setNewPositionForNewLine($curr = null)
- {
- list($lx, $rx) = $this->getMargins($this->pdf->getY());
- $this->pdf->setX($lx);
- $wMax = $rx-$lx;
- $this->currentH = 0;
-
- if ($this->sub_part || $this->isSubPart || $this->forOneLine)
- {
- // $this->pdf->setWordSpacing(0);
- return null;
- }
- /*
- if (
- $this->style->value['text-align']!='right' &&
- $this->style->value['text-align']!='center' &&
- $this->style->value['text-align']!='justify'
- )
- {
- // $this->pdf->setWordSpacing(0);
- return null;
- }
- */
- $sub = null;
- $this->createSubHTML($sub);
- $sub->saveMargin(0, 0, $sub->pdf->getW()-$wMax);
- $sub->forOneLine = true;
- $sub->parse_pos = $this->parse_pos;
- $sub->parsing->code = $this->parsing->code;
-
- if ($curr!==null && $sub->parsing->code[$this->parse_pos]['name']=='write')
- {
- $txt = $sub->parsing->code[$this->parse_pos]['param']['txt'];
- $txt = str_replace('[[page_cu]]', $sub->page, $txt);
- $sub->parsing->code[$this->parse_pos]['param']['txt'] = substr($txt, $curr);
- }
- else
- $sub->parse_pos++;
-
- // pour chaque element identifi? par le parsing
- $res = null;
- for($sub->parse_pos; $sub->parse_pos<count($sub->parsing->code); $sub->parse_pos++)
- {
- $todo = $sub->parsing->code[$sub->parse_pos];
- $res = $sub->loadAction($todo);
- if (!$res) break;
- }
-
- $w = $sub->maxX; // largeur maximale
- $h = $sub->maxH; // hauteur maximale
- $e = ($res===null ? $sub->maxE : 0); // nombre d'?l?ments maximal
- $this->destroySubHTML($sub);
-
- if ($this->style->value['text-align']=='center')
- $this->pdf->setX(($rx+$this->pdf->getX()-$w)*0.5-0.01);
- elseif ($this->style->value['text-align']=='right')
- $this->pdf->setX($rx-$w-0.01);
- else
- $this->pdf->setX($lx);
-
- $this->currentH = $h;
- /*
- if ($this->style->value['text-align']=='justify' && $e>1)
- $this->pdf->setWordSpacing(($wMax-$w)/($e-1));
- else
- $this->pdf->setWordSpacing(0);
- */
- }
-
- /**
- * r?cup?ration du PDF
- *
- * @param string nom du fichier PDF
- * @param boolean destination
- * @return string contenu ?ventuel du pdf
- *
- *
- * Destination o? envoyer le document. Le param?tre peut prendre les valeurs suivantes :
- * true : equivalent ? I
- * false : equivalent ? S
- * 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.
- * D : envoyer au navigateur en for?ant le t?l?chargement, avec le nom indiqu? dans name.
- * F : sauver dans un fichier local, avec le nom indiqu? dans name (peut inclure un r?pertoire).
- * S : renvoyer le document sous forme de cha?ne. name est ignor?.
- */
- public function Output($name = '', $dest = false)
- {
- // nettoyage
- HTML2PDF::$TABLES = array();
-
- if ($this->DEBUG_actif)
- {
- $this->DEBUG_add('Before output');
- $this->pdf->Close();
- exit;
- }
-
- // interpretation des param?tres
- if ($dest===false) $dest = 'I';
- if ($dest===true) $dest = 'S';
- if ($dest==='') $dest = 'I';
- if ($name=='') $name='document.pdf';
-
- // verification de la destination
- $dest = strtoupper($dest);
- if (!in_array($dest, array('I', 'D', 'F', 'S'))) $dest = 'I';
-
- // verification du nom
- if (strtolower(substr($name, -4))!='.pdf')
- {
- echo 'ERROR : The output document name "'.$name.'" is not a PDF name';
- exit;
- }
-
-
- return $this->pdf->Output($name, $dest);
- }
-
- /**
- * preparation de HTML2PDF::$SUBOBJ utilis? pour la cr?ation des sous HTML2PDF
- *
- * @return null
- */
- protected function prepareSubObj()
- {
- $pdf = null;
-
- HTML2PDF::$SUBOBJ = new HTML2PDF(
- $this->sens,
- $this->format,
- $this->langue,
- $this->unicode,
- $this->encoding,
- array($this->defaultLeft,$this->defaultTop,$this->defaultRight,$this->defaultBottom)
- );
-
- // initialisation
- HTML2PDF::$SUBOBJ->setIsSubPart();
- HTML2PDF::$SUBOBJ->setTestTdInOnePage($this->testTDin1page);
- HTML2PDF::$SUBOBJ->setTestIsImage($this->testIsImage);
- HTML2PDF::$SUBOBJ->setDefaultFont($this->defaultFont);
- HTML2PDF::$SUBOBJ->style->css = &$this->style->css;
- HTML2PDF::$SUBOBJ->style->css_keys = &$this->style->css_keys;
- HTML2PDF::$SUBOBJ->pdf->cloneFontFrom($this->pdf);
- HTML2PDF::$SUBOBJ->style->setPdfParent($pdf);
- }
-
- /**
- * fonction de clonage pour la creation d'un sous HTML2PDF ? partir de HTML2PDF::$SUBOBJ
- *
- * @return null
- */
- public function __clone()
- {
- $this->pdf = clone $this->pdf;
- $this->parsing = clone $this->parsing;
- $this->style = clone $this->style;
- $this->style->setPdfParent($this->pdf);
- }
-
- /**
- * cr?ation d'un sous HTML2PDF pour la gestion des tableaux imbriqu?s
- *
- * @param HTML2PDF futur sous HTML2PDF pass? en r?f?rence pour cr?ation
- * @param integer marge eventuelle de l'objet si simulation d'un TD
- * @return null
- */
- protected function createSubHTML(&$sub_html, $cellmargin=0)
- {
- if (!HTML2PDF::$SUBOBJ) $this->prepareSubObj();
-
- // calcul de la largueur
- if ($this->style->value['width'])
- {
- $marge = $cellmargin*2;
- $marge+= $this->style->value['padding']['l'] + $this->style->value['padding']['r'];
- $marge+= $this->style->value['border']['l']['width'] + $this->style->value['border']['r']['width'];
- $marge = $this->pdf->getW() - $this->style->value['width'] + $marge;
- }
- else
- $marge = $this->margeLeft+$this->margeRight;
-
- //clonage
- $sub_html = clone HTML2PDF::$SUBOBJ;
- $sub_html->style->table = $this->style->table;
- $sub_html->style->value = $this->style->value;
- $sub_html->style->setOnlyLeft();
- $sub_html->setNewPage($this->format, $this->sens);
- $sub_html->initSubHtml($marge, $this->page, $this->defLIST);
- }
-
- /**
- * initialise le sous HTML2PDF. Ne pas utiliser directement. seul la fonction createSubHTML doit l'utiliser
- *
- * @return null
- */
- public function initSubHtml($marge, $page, $defLIST)
- {
- $this->saveMargin(0, 0, $marge);
- $this->defLIST = $defLIST;
-
- $this->page = $page;
- $this->pdf->setXY(0, 0);
- $this->style->FontSet();
- }
-
- public function setIsSubPart()
- {
- $this->isSubPart = true;
- }
-
- /**
- * destruction d'un sous HTML2PDF pour la gestion des tableaux imbriqu?s
- *
- * @return null
- */
- protected function destroySubHTML(&$sub_html)
- {
- unset($sub_html);
- $sub_html = null;
- }
-
- /**
- * Convertir un nombre arabe en nombre romain
- *
- * @param integer nombre ? convertir
- * @return string nombre converti
- */
- protected function listeArab2Rom($nb_ar)
- {
- $nb_b10 = array('I','X','C','M');
- $nb_b5 = array('V','L','D');
- $nb_ro = '';
-
- if ($nb_ar<1) return $nb_ar;
- if ($nb_ar>3999) return $nb_ar;
-
- for($i=3; $i>=0 ; $i--)
- {
- $chiffre=floor($nb_ar/pow(10,$i));
- if($chiffre>=1)
- {
- $nb_ar=$nb_ar-$chiffre*pow(10,$i);
- if($chiffre<=3)
- {
- for($j=$chiffre; $j>=1; $j--)
- {
- $nb_ro=$nb_ro.$nb_b10[$i];
- }
- }
- else if($chiffre==9)
- {
- $nb_ro=$nb_ro.$nb_b10[$i].$nb_b10[$i+1];
- }
- elseif($chiffre==4)
- {
- $nb_ro=$nb_ro.$nb_b10[$i].$nb_b5[$i];
- }
- else
- {
- $nb_ro=$nb_ro.$nb_b5[$i];
- for($j=$chiffre-5; $j>=1; $j--)
- {
- $nb_ro=$nb_ro.$nb_b10[$i];
- }
- }
- }
- }
- return $nb_ro;
- }
-
- /**
- * Ajouter un LI au niveau actuel
- *
- * @return null
- */
- protected function listeAddLi()
- {
- $this->defLIST[count($this->defLIST)-1]['nb']++;
- }
-
- protected function listeGetWidth() { return '7mm'; }
- protected function listeGetPadding() { return '1mm'; }
-
- /**
- * Recuperer le LI du niveau actuel
- *
- * @return string chaine ? afficher
- */
- protected function listeGetLi()
- {
- $im = $this->defLIST[count($this->defLIST)-1]['img'];
- $st = $this->defLIST[count($this->defLIST)-1]['style'];
- $nb = $this->defLIST[count($this->defLIST)-1]['nb'];
- $up = (substr($st, 0, 6)=='upper-');
-
- if ($im) return array(false, false, $im);
-
- switch($st)
- {
- case 'none':
- return array('helvetica', true, ' ');
-
- case 'upper-alpha':
- case 'lower-alpha':
- $str = '';
- while($nb>26)
- {
- $str = chr(96+$nb%26).$str;
- $nb = floor($nb/26);
- }
- $str = chr(96+$nb).$str;
-
- return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
-
- case 'upper-roman':
- case 'lower-roman':
- $str = $this->listeArab2Rom($nb);
-
- return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
-
- case 'decimal':
- return array('helvetica', false, $nb.'.');
-
- case 'square':
- return array('zapfdingbats', true, chr(110));
-
- case 'circle':
- return array('zapfdingbats', true, chr(109));
-
- case 'disc':
- default:
- return array('zapfdingbats', true, chr(108));
- }
- }
-
- /**
- * Ajouter un niveau de liste
- *
- * @param string type de liste : ul, ol
- * @param string style de la liste
- * @return null
- */
- protected function listeAddLevel($type = 'ul', $style = '', $img = null)
- {
- if ($img)
- {
- if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match))
- $img = $match[1];
- else
- $img = null;
- }
- else
- $img = null;
-
- if (!in_array($type, array('ul', 'ol'))) $type = 'ul';
- if (!in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = '';
-
- if (!$style)
- {
- if ($type=='ul') $style = 'disc';
- else $style = 'decimal';
- }
- $this->defLIST[count($this->defLIST)] = array('style' => $style, 'nb' => 0, 'img' => $img);
- }
-
- /**
- * Supprimer un niveau de liste
- *
- * @return null
- */
- protected function listeDelLevel()
- {
- if (count($this->defLIST))
- {
- unset($this->defLIST[count($this->defLIST)-1]);
- $this->defLIST = array_values($this->defLIST);
- }
- }
-
- /**
- * traitement d'un code HTML fait pour HTML2PDF
- *
- * @param string code HTML ? convertir
- * @param boolean afficher en pdf (false) ou en html adapt? (true)
- * @return null
- */
- public function writeHTML($html, $vue = false)
- {
- // si c'est une vrai page HTML, une conversion s'impose
- if (preg_match('/<body/isU', $html))
- $html = $this->getHtmlFromPage($html);
-
- $html = str_replace('[[page_nb]]', '{nb}', $html);
-
- $html = str_replace('[[date_y]]', date('Y'), $html);
- $html = str_replace('[[date_m]]', date('m'), $html);
- $html = str_replace('[[date_d]]', date('d'), $html);
-
- $html = str_replace('[[date_h]]', date('H'), $html);
- $html = str_replace('[[date_i]]', date('i'), $html);
- $html = str_replace('[[date_s]]', date('s'), $html);
-
- // si on veut voir le r?sultat en HTML => on appelle la fonction
- if ($vue) $this->vueHTML($html);
-
- // sinon, traitement pour conversion en PDF :
- // parsing
- $this->sub_pdf = false;
- $this->style->readStyle($html);
- $this->parsing->setHTML($html);
- $this->parsing->parse();
- $this->makeHTMLcode();
- }
-
- /**
- * traitement du code d'une vrai page HTML pour l'adapter ? HTML2PDF
- *
- * @param string code HTML ? adapter
- * @return string code HTML adapt?
- */
- public function getHtmlFromPage($html)
- {
- $html = str_replace('<BODY', '<body', $html);
- $html = str_replace('</BODY', '</body', $html);
-
- // extraction du contenu
- $res = explode('<body', $html);
- if (count($res)<2) return $html;
- $content = '<page'.$res[1];
- $content = explode('</body', $content);
- $content = $content[0].'</page>';
-
- // extraction des balises link
- preg_match_all('/<link([^>]*)>/isU', $html, $match);
- foreach($match[0] as $src)
- $content = $src.'</link>'.$content;
-
- // extraction des balises style
- preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
- foreach($match[0] as $src)
- $content = $src.$content;
-
- return $content;
- }
-
- /**
- * execute les diff?rentes actions du code HTML
- *
- * @return null
- */
- protected function makeHTMLcode()
- {
- // pour chaque element identifi? par le parsing
- for($this->parse_pos=0; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
- {
- // r?cup?ration de l'?l?ment
- $todo = $this->parsing->code[$this->parse_pos];
-
- // si c'est une ouverture de tableau
- if (in_array($todo['name'], array('table', 'ul', 'ol')) && !$todo['close'])
- {
- // on va cr?er un sous HTML, et on va travailler sur une position temporaire
- $tag_open = $todo['name'];
-
- $this->sub_part = true;
- $this->temp_pos = $this->parse_pos;
-
- // pour tous les ?l?ments jusqu'? la fermeture de la table afin de pr?parer les dimensions
- while(isset($this->parsing->code[$this->temp_pos]) && !($this->parsing->code[$this->temp_pos]['name']==$tag_open && $this->parsing->code[$this->temp_pos]['close']))
- {
- $this->loadAction($this->parsing->code[$this->temp_pos]);
- $this->temp_pos++;
- }
- if (isset($this->parsing->code[$this->temp_pos])) $this->loadAction($this->parsing->code[$this->temp_pos]);
- $this->sub_part = false;
- }
-
- // chargement de l'action correspondant ? l'?l?ment
- $this->loadAction($todo);
- }
- }
-
-
-
- /**
- * affichage en mode HTML du contenu
- *
- * @param string contenu
- * @return null
- */
- protected function vueHTML($content)
- {
- $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue01').' : $1<hr><div$1>', $content);
- $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue02').' : $1<hr><div$1>', $content);
- $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue03').' : $1<hr><div$1>', $content);
- $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content);
- $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content);
- $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content);
- $content = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $content);
- $content = preg_replace('/<\/barcode([^>]*)>/isU', '', $content);
- $content = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $content);
- $content = preg_replace('/<\/qrcode([^>]*)>/isU', '', $content);
-
- echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>'.HTML2PDF::textGET('vue04').' HTML</title>
- <meta http-equiv="Content-Type" content="text/html; charset='.$this->encoding.'" >
- </head>
- <body style="padding: 10px; font-size: 10pt;font-family: Verdana;">
- '.$content.'
- </body>
- </html>';
- exit;
- }
-
- /**
- * chargement de l'action correspondante ? un element de parsing
- *
- * @param array ?l?ment de parsing
- * @return null
- */
- protected function loadAction($row)
- {
- // nom de l'action
- $fnc = ($row['close'] ? 'c_' : 'o_').strtoupper($row['name']);
-
- // parametres de l'action
- $param = $row['param'];
-
- // si aucune page n'est cr??, on la cr??
- if ($fnc!='o_PAGE' && $this->firstPage)
- {
- $this->setNewPage();
- }
-
- // lancement de l'action
- if (is_callable(array(&$this, $fnc)))
- {
- $res = $this->{$fnc}($param);
- $this->previousCall = $fnc;
- return $res;
- }
- else
- {
- HTML2PDF::makeError(1, __FILE__, __LINE__, strtoupper($row['name']), $this->parsing->getHtmlErrorCode($row['html_pos']));
- return false;
- }
- }
-
- /**
- * balise : PAGE
- * mode : OUVERTURE
- *
- * @param array param?tres de l'?l?ment de parsing
- * @return null
- */
- protected function o_PAGE($param)
- {
- if ($this->forOneLine) return false;
- if ($this->DEBUG_actif) $this->DEBUG_add('PAGE n?'.($this->page+1), true);
-
- $newPageSet= (!isset($param['pageset']) || $param['pageset']!='old');
-
- $this->maxH = 0;
- if ($newPageSet)
- {
- $this->subHEADER = array();
- $this->subFOOTER = array();
-
- // identification de l'orientation demand?e
- $orientation = '';
- if (isset($param['orientation']))
- {
- $param['orientation'] = strtolower($param['orientation']);
- if ($param['orientation']=='p') $orientation = 'P';
- if ($param['orientation']=='portrait') $orientation = 'P';
-
- if ($param['orientation']=='l') $orientation = 'L';
- if ($param['orientation']=='paysage') $orientation = 'L';
- if ($param['orientation']=='landscape') $orientation = 'L';
- }
-
- // identification de l'orientation demand?e
- $format = null;
- if (isset($param['format']))
- {
- $format = strtolower($param['format']);
- if (preg_match('/^([0-9]+)x([0-9]+)$/isU', $format, $match))
- {
- $format = array(intval($match[1]), intval($match[2]));
- }
- }
-
- // identification des propri?t?s du background
- $background = array();
- if (isset($param['backimg']))
- {
- $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // nom de l'image
- $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // position horizontale de l'image
- $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // position verticale de l'image
- $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // taille de l'image (100% = largueur de la feuille)
-
- // conversion du nom de l'image, en cas de param?tres en _GET
- $background['img'] = str_replace('&', '&', $background['img']);
- // conversion des positions
- if ($background['posX']=='left') $background['posX'] = '0%';
- if ($background['posX']=='center') $background['posX'] = '50%';
- if ($background['posX']=='right') $background['posX'] = '100%';
- if ($background['posY']=='top') $background['posY'] = '0%';
- if ($background['posY']=='middle') $background['posY'] = '50%';
- if ($background['posY']=='bottom') $background['posY'] = '100%';
-
-
- // si il y a une image de pr?cis?
- if ($background['img'])
- {
- // est-ce que c'est une image ?
- $infos=@GetImageSize($background['img']);
- if (count($infos)>1)
- {
- // taille de l'image, en fonction de la taille sp?cifi?e.
- $Wi = $this->style->ConvertToMM($background['width'], $this->pdf->getW());
- $Hi = $Wi*$infos[1]/$infos[0];
-
- // r?cup?ration des dimensions et positions de l'image
- $background['width'] = $Wi;
- $background['posX'] = $this->style->ConvertToMM($background['posX'], $this->pdf->getW() - $Wi);
- $background['posY'] = $this->style->ConvertToMM($background['posY'], $this->pdf->getH() - $Hi);
- }
- else
- $background = array();
- }
- else
- $background = array();
- }
-
- // marges TOP et BOTTOM pour le texte.
- $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0';
- $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0';
- $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0';
- $background['right'] = isset($param['backright']) ? $param['backright'] : '0';
-
- if (preg_match('/^([0-9]*)$/isU', $background['top'])) $background['top'] .= 'mm';
- if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) $background['bottom'] .= 'mm';
- if (preg_match('/^([0-9]*)$/isU', $background['left'])) $background['left'] .= 'mm';
- if (preg_match('/^([0-9]*)$/isU', $background['right'])) $background['right'] .= 'mm';
-
- $background['top'] = $this->style->ConvertToMM($background['top'], $this->pdf->getH());
- $background['bottom'] = $this->style->ConvertToMM($background['bottom'], $this->pdf->getH());
- $background['left'] = $this->style->ConvertToMM($background['left'], $this->pdf->getW());
- $background['right'] = $this->style->ConvertToMM($background['right'], $this->pdf->getW());
-
- $res = false;
- $background['color'] = isset($param['backcolor']) ? $this->style->ConvertToColor($param['backcolor'], $res) : null;
- if (!$res) $background['color'] = null;
-
- $this->style->save();
- $this->style->analyse('PAGE', $param);
- $this->style->setPosition();
- $this->style->FontSet();
-
- // nouvelle page
- $this->setNewPage($format, $orientation, $background);
-
- // footer automatique
- if (isset($param['footer']))
- {
- $lst = explode(';', $param['footer']);
- foreach($lst as $key => $val) $lst[$key] = trim(strtolower($val));
- $page = in_array('page', $lst);
- $date = in_array('date', $lst);
- $heure = in_array('heure', $lst);
- $form = in_array('form', $lst);
- }
- else
- {
- $page = null;
- $date = null;
- $heure = null;
- $form = null;
- }
- $this->pdf->SetMyFooter($page, $date, $heure, $form);
- }
- else
- {
- $this->style->save();
- $this->style->analyse('PAGE', $param);
- $this->style->setPosition();
- $this->style->FontSet();
-
- $this->setNewPage();
- }
-
- return true;
- }
-
- /**
- * balise : PAGE
- * mode : FERMETURE
- *
- * @param array param?tres de l'?l?ment de parsing
- * @return null
- */
- protected function c_PAGE($param)
- {
- if ($this->forOneLine) return false;
-
- $this->maxH = 0;
-
- $this->style->load();
- $this->style->FontSet();
-
- if ($this->DEBUG_actif) $this->DEBUG_add('PAGE n?'.$this->page, false);
-
- return true;
- }
-
-
- protected function o_PAGE_HEADER($param)
- {
- if ($this->forOneLine) return false;
-
- $this->subHEADER = array();
- for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
- {
- $todo = $this->parsing->code[$this->parse_pos];
- if ($todo['name']=='page_header') $todo['name']='page_header_sub';
- $this->subHEADER[] = $todo;
- if (strtolower($todo['name'])=='page_header_sub' && $todo['close']) break;
- }
-
- $this->setPageHeader();
-
- return true;
- }
-
- protected function o_PAGE_FOOTER($param)
- {
- if ($this->forOneLine) return false;
-
- $this->subFOOTER = array();
- for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
- {
- $todo = $this->parsing->code[$this->parse_pos];
- if ($todo['name']=='page_footer') $todo['name']='page_footer_sub';
- $this->subFOOTER[] = $todo;
- if (strtolower($todo['name'])=='page_footer_sub' && $todo['close']) break;
- }
-
- $this->setPageFooter();
-
- return true;
- }
-
- protected function o_PAGE_HEADER_SUB($param)
- {
- if ($this->forOneLine) return false;
-
- // sauvegarde de l'?tat
- $this->subSTATES = array();
- $this->subSTATES['x'] = $this->pdf->getX();
- $this->subSTATES['y'] = $this->pdf->getY();
- $this->subSTATES['s'] = $this->style->value;
- $this->subSTATES['t'] = $this->style->table;
- $this->subSTATES['ml'] = $this->margeLeft;
- $this->subSTATES['mr'] = $this->margeRight;
- $this->subSTATES['mt'] = $this->margeTop;
- $this->subSTATES['mb'] = $this->margeBottom;
- $this->subSTATES['mp'] = $this->pageMarges;
-
- // nouvel etat pour le footer
- $this->pageMarges = array();
- $this->margeLeft = $this->defaultLeft;
- $this->margeRight = $this->defaultRight;
- $this->margeTop = $this->defaultTop;
- $this->margeBottom = $this->defaultBottom;
- $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
- $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
- $this->pdf->setXY($this->defaultLeft, $this->defaultTop);
-
- $this->style->initStyle();
- $this->style->resetStyle();
- $this->style->value['width'] = $this->pdf->getW() - $this->defaultLeft - $this->defaultRight;
- $this->style->table = array();
-
- $this->style->save();
- $this->style->analyse('page_header_sub', $param);
- $this->style->setPosition();
- $this->style->FontSet();
- $this->setNewPositionForNewLine();
- return true;
- }
-
- protected function c_PAGE_HEADER_SUB($param)
- {
- if ($this->forOneLine) return false;
-
- $this->style->load();
-
- // retablissement de l'etat
- $this->style->value = $this->subSTATES['s'];
- $this->style->table = $this->subSTATES['t'];
- $this->pageMarges = $this->subSTATES['mp'];
- $this->margeLeft = $this->subSTATES['ml'];
- $this->margeRight = $this->subSTATES['mr'];
- $this->margeTop = $this->subSTATES['mt'];
- $this->margeBottom = $this->subSTATES['mb'];
- $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
- $this->pdf->setbMargin($this->margeBottom);
- $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
- $this->pdf->setXY($this->subSTATES['x'], $this->subSTATES['y']);
-
- $this->style->FontSet();
- $this->maxH = 0;
-
- return true;
- }
-
- protected function o_PAGE_FOOTER_SUB($param)
- {
- if ($this->forOneLine) return false;
-
- $this->subSTATES = array();
- $this->subSTATES['x'] = $this->pdf->getX();
- $this->subSTATES['y'] = $this->pdf->getY();
- $this->subSTATES['s'] = $this->style->value;
- $this->subSTATES['t'] = $this->style->table;
- $this->subSTATES['ml'] = $this->margeLeft;
- $this->subSTATES['mr'] = $this->margeRight;
- $this->subSTATES['mt'] = $this->margeTop;
- $this->subSTATES['mb'] = $this->margeBottom;
- $this->subSTATES['mp'] = $this->pageMarges;
-
- // nouvel etat pour le footer
- $this->pageMarges = array();
- $this->margeLeft = $this->defaultLeft;
- $this->margeRight = $this->defaultRight;
- $this->margeTop = $this->defaultTop;
- $this->margeBottom = $this->defaultBottom;
- $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
- $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
- $this->pdf->setXY($this->defaultLeft, $this->defaultTop);
-
-
- $this->style->initStyle();
- $this->style->resetStyle();
- $this->style->value['width'] = $this->pdf->getW() - $this->defaultLeft - $this->defaultRight;
- $this->style->table = array();
-
- // on en cr?? un sous HTML que l'on transforme en PDF
- // pour r?cup?rer la hauteur
- // on extrait tout ce qui est contenu dans le FOOTER
- $sub = null;
- $this->CreateSubHTML($sub);
- $sub->parsing->code = $this->parsing->getLevel($this->parse_pos);
- $sub->MakeHTMLcode();
- $this->pdf->setY($this->pdf->getH() - $sub->maxY - $this->defaultBottom - 0.01);
- $this->destroySubHTML($sub);
-
- $this->style->save();
- $this->style->analyse('page_footer_sub', $param);
- $this->style->setPosition();
- $this->style->FontSet();
- $this->setNewPositionForNewLine();
-
- return true;
- }
-
- protected function c_PAGE_FOOTER_SUB($param)
- {
- if ($this->forOneLine) return false;
-
- $this->style->load();
-
- $this->style->value = $this->subSTATES['s'];
- $this->style->table = $this->subSTATES['t'];
- $this->pageMarges = $this->subSTATES['mp'];
- $this->margeLeft = $this->subSTATES['ml'];
- $this->margeRight = $this->subSTATES['mr'];
- $this->margeTop = $this->subSTATES['mt'];
- $this->margeBottom = $this->subSTATES['mb'];
- $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
- $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
- $this->pdf->setXY($this->subSTATES['x'], $this->subSTATES['y']);
-
- $this->style->FontSet();
- $this->maxH = 0;
-
- return true;
- }
-
- /**
- * balise : NOBREAK
- * mode : OUVERTURE
- *
- * @param array param?tres de l'?l?ment de parsing
- * @return null
- */
- protected function o_NOBREAK($param)
- {
- if ($this->forOneLine) return false;
-
- $this->maxH = 0;
-
- // on en cr?? un sous HTML que l'on transforme en PDF
- // pour analyse les dimensions
- // et voir si ca rentre
- $sub = null;
- $this->CreateSubHTML($sub);
- $sub->parsing->code = $this->parsing->getLevel($this->parse_pos);
- $sub->MakeHTMLcode();
-
- $y = $this->pdf->getY();
- if (
- $sub->maxY < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin()) &&
- $y + $sub->maxY>=($this->pdf->getH() - $this->pdf->getbMargin())
- )
- $this->setNewPage();
- $this->destroySubHTML($sub);
-
- return true;
- }
-
-
- /**
- * balise : NOBREAK
- * mode : FERMETURE
- *
- * @param array param?tres de l'?l?ment de parsing
- * @return null
- */
- protected function c_NOBREAK($param)
- {
- if ($this->forOneLine) return false;
-
- $this->maxH = 0;
-
- return true;
- }
-
- /**
- * balise : DIV
- * mode : OUVERTURE
- *
- * @param array param?tres de l'?l?ment de parsing
- * @return null
- */
- protected function o_DIV($param, $other = 'div')
- {
- if ($this->forOneLine) return false;
- if ($this->DEBUG_actif) $this->DEBUG_add('DIV', true);
-
- $this->style->save();
- $this->style->analyse($other, $param);
- $this->style->FontSet();
-
- $align_object = null;
- if ($this->style->value['margin-auto']) $align_object = 'center';
-
- $marge = array();
- $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
- $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
- $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
- $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
-
- // on extrait tout ce qui est contenu dans la DIV
- $level = $this->parsing->getLevel($this->parse_pos);
-
- // on en cr?? un sous HTML que l'on transforme en PDF
- // pour analyse les dimensions
- $w = 0; $h = 0;
- if (count($level))
- {
- $sub = null;
- $this->CreateSubHTML($sub);
- $sub->parsing->code = $level;
- $sub->MakeHTMLcode();
- $w = $sub->maxX;
- $h = $sub->maxY;
- $this->destroySubHTML($sub);
- }
- $w_reel = $w;
- $h_reel = $h;
-
- // if (($w==0 && $this->style->value['width']==0) || ($w>$this->style->value['width']) || $this->style->value['position']=='absolute')
- $w+= $marge['l']+$marge['r']+0.001;
-
- $h+= $marge['t']+$marge['b']+0.001;
-
- if ($this->style->value['overflow']=='hidden')
- {
- $over_w = max($w, $this->style->value['width']);
- $over_h = max($h, $this->style->value['height']);
- $overflow = true;
- $this->style->value['old_maxX'] = $this->maxX;
- $this->style->value['old_maxY'] = $this->maxY;
- $this->style->value['old_maxH'] = $this->maxH;
- $this->style->value['old_overflow'] = $this->isInOverflow;
- $this->isInOverflow = true;
- }
- else
- {
- $over_w = null;
- $over_h = null;
- $overflow = false;
- $this->style->value['width'] = max($w, $this->style->value['width']);
- $this->style->value['height'] = max($h, $this->style->value['height']);
- }
-
- switch($this->style->value['rotate'])
- {
- case 90:
- $tmp = $over_h; $over_h = $over_w; $over_w = $tmp;
- $tmp = $h_reel; $h_reel = $w_reel; $w_reel = $tmp;
- unset($tmp);
- $w = $this->style->value['height'];
- $h = $this->style->value['width'];
- $t_x =-$h;
- $t_y = 0;
- break;
-
- case 180:
- $w = $this->style->value['width'];
- $h = $this->style->value['height'];
- $t_x = -$w;
- $t_y = -$h;
- break;
-
- case 270:
- $tmp = $over_h; $over_h = $over_w; $over_w = $tmp;
- $tmp = $h_reel; $h_reel = $w_reel; $w_reel = $tmp;
- unset($t…
Large files files are truncated, but you can click here to view the full file