PageRenderTime 108ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/include/html2pdf/html2pdf.class.php

https://bitbucket.org/sleininger/stock_online
PHP | 6125 lines | 4031 code | 857 blank | 1237 comment | 664 complexity | 2c96e3ec10ad42db995aacb6c834a163 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * Logiciel : HTML2PDF
  4. *
  5. * Convertisseur HTML => PDF, utilise TCPDF
  6. * Distribuי sous la licence LGPL.
  7. *
  8. * @author Laurent MINGUET <webmaster@html2pdf.fr>
  9. * @version 4.01
  10. */
  11. if (!defined('__CLASS_HTML2PDF__'))
  12. {
  13. define('__CLASS_HTML2PDF__', '4.01');
  14. require_once(dirname(__FILE__).'/_mypdf/mypdf.class.php'); // classe mypdf
  15. require_once(dirname(__FILE__).'/parsingHTML.class.php'); // classe de parsing HTML
  16. require_once(dirname(__FILE__).'/styleHTML.class.php'); // classe de gestion des styles
  17. class HTML2PDF
  18. {
  19. public $pdf = null; // objet PDF
  20. public $style = null; // objet de style
  21. public $parsing = null; // objet de parsing
  22. protected $langue = 'fr'; // langue des messages
  23. protected $sens = 'P'; // sens d'affichage Portrait ou Landscape
  24. protected $format = 'A4'; // format de la page : A4, A3, ...
  25. protected $encoding = ''; // charset encoding
  26. protected $unicode = true; // means that the input text is unicode (default = true)
  27. protected $background = array(); // informations sur le background
  28. protected $testTDin1page = true; // activer le test de TD ne devant pas depasser une page
  29. protected $testIsImage = true; // test si les images existes ou non
  30. protected $testIsDeprecated = false; // test si certaines fonctions sont deprecated
  31. protected $isSubPart = false; // indique que le convertisseur courant est un sous html
  32. protected $parse_pos = 0; // position du parsing
  33. protected $temp_pos = 0; // position temporaire pour multi tableau
  34. protected $page = 0; // numero de la page courante
  35. protected $sub_html = null; // sous html
  36. protected $sub_part = false; // indicateur de sous html
  37. protected $maxX = 0; // zone maxi X
  38. protected $maxY = 0; // zone maxi Y
  39. protected $maxE = 0; // nomre d'elements dans la zone
  40. protected $maxH = 0; // plus grande hauteur dans la ligne, pour saut de ligne א corriger
  41. protected $maxSave = array(); // tableau de sauvegarde des maximaux
  42. protected $currentH = 0; // hauteur de la ligne courante
  43. protected $firstPage = true; // premier page
  44. protected $defaultLeft = 0; // marges par default de la page
  45. protected $defaultTop = 0;
  46. protected $defaultRight = 0;
  47. protected $defaultBottom = 0;
  48. protected $margeLeft = 0; //marges rיelles de la page
  49. protected $margeTop = 0;
  50. protected $margeRight = 0;
  51. protected $margeBottom = 0;
  52. protected $marges = array(); // tableau de sauvegarde des differents etats des marges de la page courante
  53. protected $inLink = ''; // indique si on est א l'interieur d'un lien
  54. protected $lstAncre = array(); // liste des ancres dיtectיes ou crייes
  55. protected $subHEADER = array(); // tableau des sous commandes pour faire l'HEADER
  56. protected $subFOOTER = array(); // tableau des sous commandes pour faire le FOOTER
  57. protected $subSTATES = array(); // tableau de sauvegarde de certains paramטtres
  58. protected $defLIST = array(); // tableau de sauvegarde de l'etat des UL et OL
  59. protected $lstChamps = array(); // liste des champs
  60. protected $lstSelect = array(); // options du select en cours
  61. protected $previousCall = null; // dernier appel
  62. protected $pageMarges = array(); // marges spיcifiques dues aux floats
  63. protected $isInThead = false; // indique si on est dans un thead
  64. protected $isInTfoot = false; // indique si on est dans un tfoot
  65. protected $isInOverflow = false; // indique si on est dans une div overflow
  66. protected $isInFooter = false; // indique si on est dans un footer ou non
  67. protected $isInDraw = null; // indique si on est en mode dessin
  68. protected $isAfterFloat = false; // indique si on est apres un float
  69. protected $forOneLine = false; // indique si on est dans un sous HTML ne servant qu'a calculer la taille de la prochaine ligne
  70. protected $isInForm = false; // indique si on est dans un formulaire. Contient dans ce cas lא l'action de celui-ci
  71. protected $DEBUG_actif = false; // indique si on est en mode debug
  72. protected $DEBUG_ok_usage = false; // indique l'existance de la fonction memory_get_usage
  73. protected $DEBUG_ok_peak = false; // indique l'existance de la fonction memory_get_peak_usage
  74. protected $DEBUG_level = 0; // niveau du debug
  75. protected $DEBUG_start_time = 0; //
  76. protected $DEBUG_last_time = 0; //
  77. protected $defaultFont = null; // fonte par dיfaut si la fonte demandיe n'existe pas
  78. static protected $SUBOBJ = null; // sous objet HTML2PDF prיparי en cas de besoin
  79. static protected $TABLES = array(); // tableau global necessaire א la gestion des tables imbriquיes
  80. static protected $TEXTES = array(); // tableau comprennant le fichier de langue
  81. /**
  82. * Constructeur
  83. *
  84. * @param string sens portrait ou landscape
  85. * @param string format A4, A5, ...
  86. * @param string langue : fr, en, it...
  87. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  88. * @param String $encoding charset encoding; default is UTF-8
  89. * @param array marges par defaut, dans l'ordre (left, top, right, bottom)
  90. * @return null
  91. */
  92. public function __construct($sens = 'P', $format = 'A4', $langue='fr', $unicode=true, $encoding='UTF-8', $marges = array(5, 5, 5, 8))
  93. {
  94. // sauvegarde des paramטtres
  95. $this->page = 0;
  96. $this->sens = $sens;
  97. $this->format = $format;
  98. $this->unicode = $unicode;
  99. $this->encoding = $encoding;
  100. $this->firstPage = true;
  101. $this->langue = strtolower($langue);
  102. // chargement du fichier de langue
  103. HTML2PDF::textLOAD($this->langue);
  104. // crיation de l' objet PDF
  105. $this->pdf = new MyPDF($sens, 'mm', $format, $unicode, $encoding);
  106. // initialisation des styles
  107. $this->style = new styleHTML($this->pdf);
  108. $this->style->FontSet();
  109. $this->defLIST = array();
  110. // initialisations diverses
  111. $this->setTestTdInOnePage(true);
  112. $this->setTestIsImage(true);
  113. $this->setTestIsDeprecated(true);
  114. $this->setDefaultFont(null);
  115. // initialisation du parsing
  116. $this->parsing = new parsingHTML($this->encoding);
  117. $this->sub_html = null;
  118. $this->sub_part = false;
  119. // initialisation des marges
  120. if (!is_array($marges)) $marges = array($marges, $marges, $marges, $marges);
  121. $this->setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]);
  122. $this->setMargins();
  123. $this->marges = array();
  124. // initialisation des champs de formulaire
  125. $this->lstChamps = array();
  126. }
  127. /**
  128. * Destructeur
  129. *
  130. * @return null
  131. */
  132. public function __destruct()
  133. {
  134. }
  135. /**
  136. * activer le debug mode
  137. *
  138. * @return null
  139. */
  140. public function setModeDebug()
  141. {
  142. list($usec, $sec) = explode(' ', microtime());
  143. $this->DEBUG_actif = true;
  144. $this->DEBUG_ok_usage = function_exists('memory_get_usage');
  145. $this->DEBUG_ok_peak = function_exists('memory_get_peak_usage');
  146. $this->DEBUG_start_time = (float)$sec + (float)$usec;
  147. $this->DEBUG_last_time = (float)$sec + (float)$usec;
  148. $this->DEBUG_stepline('step', 'time', 'delta', 'memory', 'peak');
  149. $this->DEBUG_add('Init debug');
  150. }
  151. /**
  152. * rajouter une ligne de debug
  153. *
  154. * @param string nom de l'etape
  155. * @param boolean true=monter d'un niveau, false=descendre d'un niveau, null : ne rien faire
  156. * @return null
  157. */
  158. protected function DEBUG_add($nom, $level=null)
  159. {
  160. list($usec, $sec) = explode(' ', microtime());
  161. if ($level===true) $this->DEBUG_level++;
  162. $nom = str_repeat(' ',$this->DEBUG_level). $nom.($level===true ? ' Begin' : ($level===false ? ' End' : ''));
  163. $time = (float)$sec + (float)$usec;
  164. $usage = ($this->DEBUG_ok_usage ? memory_get_usage() : 0);
  165. $peak = ($this->DEBUG_ok_peak ? memory_get_peak_usage() : 0);
  166. $this->DEBUG_stepline(
  167. $nom,
  168. number_format(($time - $this->DEBUG_start_time)*1000, 1, '.', ' ').' ms',
  169. number_format(($time - $this->DEBUG_last_time)*1000, 1, '.', ' ').' ms',
  170. number_format($usage/1024, 1, '.', ' ').' Ko',
  171. number_format($peak/1024, 1, '.', ' ').' Ko');
  172. $this->DEBUG_last_time = $time;
  173. if ($level===false) $this->DEBUG_level--;
  174. return true;
  175. }
  176. /**
  177. * affiche une ligne de debug
  178. *
  179. * @param string nom de l'etape
  180. * @param string valeur 1
  181. * @param string valeur 2
  182. * @param string valeur 3
  183. * @param string valeur 4
  184. * @return null
  185. */
  186. protected function DEBUG_stepline($nom, $val1, $val2, $val3, $val4)
  187. {
  188. $txt = str_pad($nom, 30, ' ', STR_PAD_RIGHT).
  189. str_pad($val1, 12, ' ', STR_PAD_LEFT).
  190. str_pad($val2, 12, ' ', STR_PAD_LEFT).
  191. str_pad($val3, 15, ' ', STR_PAD_LEFT).
  192. str_pad($val4, 15, ' ', STR_PAD_LEFT);
  193. echo '<pre style="padding:0; margin:0">'.$txt.'</pre>';
  194. }
  195. /**
  196. * activer ou desactiver le test de TD ne devant pas depasser une page
  197. *
  198. * @param boolean nouvel etat
  199. * @return boolean ancien etat
  200. */
  201. public function setTestTdInOnePage($mode = true)
  202. {
  203. $old = $this->testTDin1page;
  204. $this->testTDin1page = $mode ? true : false;
  205. return $old;
  206. }
  207. /**
  208. * activer ou desactiver le test sur la prיsence des images
  209. *
  210. * @param boolean nouvel etat
  211. * @return boolean ancien etat
  212. */
  213. public function setTestIsImage($mode = true)
  214. {
  215. $old = $this->testIsImage;
  216. $this->testIsImage = $mode ? true : false;
  217. return $old;
  218. }
  219. /**
  220. * activer ou desactiver le test sur les fonctions deprecated
  221. *
  222. * @param boolean nouvel etat
  223. * @return boolean ancien etat
  224. */
  225. public function setTestIsDeprecated($mode = true)
  226. {
  227. $old = $this->testIsDeprecated;
  228. $this->testIsDeprecated = $mode ? true : false;
  229. return $old;
  230. }
  231. /**
  232. * dיfinit la fonte par dיfaut si aucun fonte n'est spיcifiיe, ou si la fonte demandיe n'existe pas
  233. *
  234. * @param string nom de la fonte par defaut. si null : Arial pour fonte non spיcifiיe, et erreur pour fonte non existante
  235. * @return string nom de l'ancienne fonte par defaut
  236. */
  237. public function setDefaultFont($default = null)
  238. {
  239. $old = $this->defaultFont;
  240. $this->defaultFont = $default;
  241. $this->style->setDefaultFont($default);
  242. return $old;
  243. }
  244. /**
  245. * dיfinir les marges par dיfault
  246. *
  247. * @param int en mm, marge left
  248. * @param int en mm, marge top
  249. * @param int en mm, marge right. si null, left=right
  250. * @param int en mm, marge bottom. si null, bottom=8
  251. * @return null
  252. */
  253. protected function setDefaultMargins($left, $top, $right = null, $bottom = null)
  254. {
  255. if ($right===null) $right = $left;
  256. if ($bottom===null) $bottom = 8;
  257. $this->defaultLeft = $this->style->ConvertToMM($left.'mm');
  258. $this->defaultTop = $this->style->ConvertToMM($top.'mm');
  259. $this->defaultRight = $this->style->ConvertToMM($right.'mm');
  260. $this->defaultBottom = $this->style->ConvertToMM($bottom.'mm');
  261. }
  262. /**
  263. * dיfinir les marges rיelles, fonctions de la balise page
  264. *
  265. * @return null
  266. */
  267. protected function setMargins()
  268. {
  269. $this->margeLeft = $this->defaultLeft + (isset($this->background['left']) ? $this->background['left'] : 0);
  270. $this->margeRight = $this->defaultRight + (isset($this->background['right']) ? $this->background['right'] : 0);
  271. $this->margeTop = $this->defaultTop + (isset($this->background['top']) ? $this->background['top'] : 0);
  272. $this->margeBottom = $this->defaultBottom + (isset($this->background['bottom']) ? $this->background['bottom'] : 0);
  273. $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
  274. $this->pdf->setcMargin(0);
  275. $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
  276. $this->pageMarges = array();
  277. $this->pageMarges[floor($this->margeTop*100)] = array($this->margeLeft, $this->pdf->getW()-$this->margeRight);
  278. }
  279. /**
  280. * recuperer les positions x minimales et maximales en fonction d'une hauteur
  281. *
  282. * @param float y
  283. * @return array(float, float)
  284. */
  285. protected function getMargins($y)
  286. {
  287. $y = floor($y*100);
  288. $x = array($this->pdf->getlMargin(), $this->pdf->getW()-$this->pdf->getrMargin());
  289. foreach($this->pageMarges as $m_y => $m_x)
  290. if ($m_y<=$y) $x = $m_x;
  291. return $x;
  292. }
  293. /**
  294. * ajouter une marge suite a un float
  295. *
  296. * @param string left ou right
  297. * @param float x1
  298. * @param float y1
  299. * @param float x2
  300. * @param float y2
  301. * @return null
  302. */
  303. protected function addMargins($float, $x1, $y1, $x2, $y2)
  304. {
  305. $old1 = $this->getMargins($y1);
  306. $old2 = $this->getMargins($y2);
  307. if ($float=='left') $old1[0] = $x2;
  308. if ($float=='right') $old1[1] = $x1;
  309. $y1 = floor($y1*100);
  310. $y2 = floor($y2*100);
  311. foreach($this->pageMarges as $m_y => $m_x)
  312. {
  313. if ($m_y<$y1) continue;
  314. if ($m_y>$y2) break;
  315. if ($float=='left' && $this->pageMarges[$m_y][0]<$x2) unset($this->pageMarges[$m_y]);
  316. if ($float=='right' && $this->pageMarges[$m_y][1]>$x1) unset($this->pageMarges[$m_y]);
  317. }
  318. $this->pageMarges[$y1] = $old1;
  319. $this->pageMarges[$y2] = $old2;
  320. ksort($this->pageMarges);
  321. $this->isAfterFloat = true;
  322. }
  323. /**
  324. * dיfinir des nouvelles marges et sauvegarder les anciennes
  325. *
  326. * @param float marge left
  327. * @param float marge top
  328. * @param float marge right
  329. * @return null
  330. */
  331. protected function saveMargin($ml, $mt, $mr)
  332. {
  333. $this->marges[] = array('l' => $this->pdf->getlMargin(), 't' => $this->pdf->gettMargin(), 'r' => $this->pdf->getrMargin(), 'page' => $this->pageMarges);
  334. $this->pdf->SetMargins($ml, $mt, $mr);
  335. $this->pageMarges = array();
  336. $this->pageMarges[floor($mt*100)] = array($ml, $this->pdf->getW()-$mr);
  337. }
  338. /**
  339. * rיcuperer les derniטres marches sauvיes
  340. *
  341. * @return null
  342. */
  343. protected function loadMargin()
  344. {
  345. $old = array_pop($this->marges);
  346. if ($old)
  347. {
  348. $ml = $old['l'];
  349. $mt = $old['t'];
  350. $mr = $old['r'];
  351. $mP = $old['page'];
  352. }
  353. else
  354. {
  355. $ml = $this->margeLeft;
  356. $mt = 0;
  357. $mr = $this->margeRight;
  358. $mP = array($mt => array($ml, $this->pdf->getW()-$mr));
  359. }
  360. $this->pdf->SetMargins($ml, $mt, $mr);
  361. $this->pageMarges = $mP;
  362. }
  363. /**
  364. * permet d'ajouter une fonte.
  365. *
  366. * @param string nom de la fonte
  367. * @param string style de la fonte
  368. * @param string fichier de la fonte
  369. * @return null
  370. */
  371. public function addFont($family, $style='', $file='')
  372. {
  373. $this->pdf->AddFont($family, $style, $file);
  374. }
  375. /**
  376. * sauvegarder l'יtat actuelle des maximums
  377. *
  378. * @return null
  379. */
  380. protected function saveMax()
  381. {
  382. $this->maxSave[] = array($this->maxX, $this->maxY, $this->maxH, $this->maxE);
  383. }
  384. /**
  385. * charger le dernier יtat sauvי des maximums
  386. *
  387. * @return null
  388. */
  389. protected function loadMax()
  390. {
  391. $old = array_pop($this->maxSave);
  392. if ($old)
  393. {
  394. $this->maxX = $old[0];
  395. $this->maxY = $old[1];
  396. $this->maxH = $old[2];
  397. $this->maxE = $old[3];
  398. }
  399. else
  400. {
  401. $this->maxX = 0;
  402. $this->maxY = 0;
  403. $this->maxH = 0;
  404. $this->maxE = 0;
  405. }
  406. }
  407. /**
  408. * afficher l'header contenu dans page_header
  409. *
  410. * @return null
  411. */
  412. protected function setPageHeader()
  413. {
  414. if (!count($this->subHEADER)) return false;
  415. $OLD_parse_pos = $this->parse_pos;
  416. $OLD_parse_code = $this->parsing->code;
  417. $this->parse_pos = 0;
  418. $this->parsing->code = $this->subHEADER;
  419. $this->makeHTMLcode();
  420. $this->parse_pos = $OLD_parse_pos;
  421. $this->parsing->code = $OLD_parse_code;
  422. }
  423. /**
  424. * afficher le footer contenu dans page_footer
  425. *
  426. * @return null
  427. */
  428. protected function setPageFooter()
  429. {
  430. if (!count($this->subFOOTER)) return false;
  431. $OLD_parse_pos = $this->parse_pos;
  432. $OLD_parse_code = $this->parsing->code;
  433. $this->parse_pos = 0;
  434. $this->parsing->code = $this->subFOOTER;
  435. $this->isInFooter = true;
  436. $this->makeHTMLcode();
  437. $this->isInFooter = false;
  438. $this->parse_pos = $OLD_parse_pos;
  439. $this->parsing->code = $OLD_parse_code;
  440. }
  441. /**
  442. * saut de ligne avec une hauteur spיcifique
  443. *
  444. * @param float hauteur de la ligne
  445. * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
  446. * @return null
  447. */
  448. protected function setNewLine($h, $curr = null)
  449. {
  450. $this->pdf->Ln($h);
  451. $this->setNewPositionForNewLine($curr);
  452. }
  453. /**
  454. * crיation d'une nouvelle page avec le format et l'orientation spיcifies
  455. *
  456. * @param mixed format de la page : A5, A4, array(width, height)
  457. * @param string sens P=portrait ou L=landscape
  458. * @param array tableau des propriיtיs du fond de la page
  459. * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
  460. * @return null
  461. */
  462. public function setNewPage($format = null, $orientation = '', $background = null, $curr = null)
  463. {
  464. $this->firstPage = false;
  465. $this->format = $format ? $format : $this->format;
  466. $this->sens = $orientation ? $orientation : $this->sens;
  467. $this->background = $background!==null ? $background : $this->background;
  468. $this->maxY = 0;
  469. $this->maxX = 0;
  470. $this->maxH = 0;
  471. $this->pdf->SetMargins($this->defaultLeft, $this->defaultTop, $this->defaultRight);
  472. $this->pdf->AddPage($this->sens, $this->format);
  473. $this->page++;
  474. if (!$this->sub_part && !$this->isSubPart)
  475. {
  476. if (is_array($this->background))
  477. {
  478. if (isset($this->background['color']) && $this->background['color'])
  479. {
  480. $this->pdf->setFillColorArray($this->background['color']);
  481. $this->pdf->Rect(0, 0, $this->pdf->getW(), $this->pdf->getH(), 'F');
  482. }
  483. if (isset($this->background['img']) && $this->background['img'])
  484. $this->pdf->Image($this->background['img'], $this->background['posX'], $this->background['posY'], $this->background['width']);
  485. }
  486. $this->setPageHeader();
  487. $this->setPageFooter();
  488. }
  489. $this->setMargins();
  490. $this->pdf->setY($this->margeTop);
  491. $this->setNewPositionForNewLine($curr);
  492. $this->maxH = 0;
  493. }
  494. /**
  495. * calcul de la position de debut de la prochaine ligne en fonction de l'alignement voulu
  496. *
  497. * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
  498. * @return null
  499. */
  500. protected function setNewPositionForNewLine($curr = null)
  501. {
  502. list($lx, $rx) = $this->getMargins($this->pdf->getY());
  503. $this->pdf->setX($lx);
  504. $wMax = $rx-$lx;
  505. $this->currentH = 0;
  506. if ($this->sub_part || $this->isSubPart || $this->forOneLine)
  507. {
  508. // $this->pdf->setWordSpacing(0);
  509. return null;
  510. }
  511. /*
  512. if (
  513. $this->style->value['text-align']!='right' &&
  514. $this->style->value['text-align']!='center' &&
  515. $this->style->value['text-align']!='justify'
  516. )
  517. {
  518. // $this->pdf->setWordSpacing(0);
  519. return null;
  520. }
  521. */
  522. $sub = null;
  523. $this->createSubHTML($sub);
  524. $sub->saveMargin(0, 0, $sub->pdf->getW()-$wMax);
  525. $sub->forOneLine = true;
  526. $sub->parse_pos = $this->parse_pos;
  527. $sub->parsing->code = $this->parsing->code;
  528. if ($curr!==null && $sub->parsing->code[$this->parse_pos]['name']=='write')
  529. {
  530. $txt = $sub->parsing->code[$this->parse_pos]['param']['txt'];
  531. $txt = str_replace('[[page_cu]]', $sub->page, $txt);
  532. $sub->parsing->code[$this->parse_pos]['param']['txt'] = substr($txt, $curr);
  533. }
  534. else
  535. $sub->parse_pos++;
  536. // pour chaque element identifiי par le parsing
  537. $res = null;
  538. for($sub->parse_pos; $sub->parse_pos<count($sub->parsing->code); $sub->parse_pos++)
  539. {
  540. $todo = $sub->parsing->code[$sub->parse_pos];
  541. $res = $sub->loadAction($todo);
  542. if (!$res) break;
  543. }
  544. $w = $sub->maxX; // largeur maximale
  545. $h = $sub->maxH; // hauteur maximale
  546. $e = ($res===null ? $sub->maxE : 0); // nombre d'יlיments maximal
  547. $this->destroySubHTML($sub);
  548. if ($this->style->value['text-align']=='center')
  549. $this->pdf->setX(($rx+$this->pdf->getX()-$w)*0.5-0.01);
  550. elseif ($this->style->value['text-align']=='right')
  551. $this->pdf->setX($rx-$w-0.01);
  552. else
  553. $this->pdf->setX($lx);
  554. $this->currentH = $h;
  555. /*
  556. if ($this->style->value['text-align']=='justify' && $e>1)
  557. $this->pdf->setWordSpacing(($wMax-$w)/($e-1));
  558. else
  559. $this->pdf->setWordSpacing(0);
  560. */
  561. }
  562. /**
  563. * rיcupיration du PDF
  564. *
  565. * @param string nom du fichier PDF
  566. * @param boolean destination
  567. * @return string contenu יventuel du pdf
  568. *
  569. *
  570. * Destination oש envoyer le document. Le paramטtre peut prendre les valeurs suivantes :
  571. * true : equivalent א I
  572. * false : equivalent א S
  573. * 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.
  574. * D : envoyer au navigateur en forחant le tיlיchargement, avec le nom indiquי dans name.
  575. * F : sauver dans un fichier local, avec le nom indiquי dans name (peut inclure un rיpertoire).
  576. * S : renvoyer le document sous forme de chaמne. name est ignorי.
  577. */
  578. public function Output($name = '', $dest = false)
  579. {
  580. // nettoyage
  581. HTML2PDF::$TABLES = array();
  582. if ($this->DEBUG_actif)
  583. {
  584. $this->DEBUG_add('Before output');
  585. $this->pdf->Close();
  586. exit;
  587. }
  588. // interpretation des paramטtres
  589. if ($dest===false) $dest = 'I';
  590. if ($dest===true) $dest = 'S';
  591. if ($dest==='') $dest = 'I';
  592. if ($name=='') $name='document.pdf';
  593. // verification de la destination
  594. $dest = strtoupper($dest);
  595. if (!in_array($dest, array('I', 'D', 'F', 'S'))) $dest = 'I';
  596. // verification du nom
  597. if (strtolower(substr($name, -4))!='.pdf')
  598. {
  599. echo 'ERROR : The output document name "'.$name.'" is not a PDF name';
  600. exit;
  601. }
  602. return $this->pdf->Output($name, $dest);
  603. }
  604. /**
  605. * preparation de HTML2PDF::$SUBOBJ utilisי pour la crיation des sous HTML2PDF
  606. *
  607. * @return null
  608. */
  609. protected function prepareSubObj()
  610. {
  611. $pdf = null;
  612. HTML2PDF::$SUBOBJ = new HTML2PDF(
  613. $this->sens,
  614. $this->format,
  615. $this->langue,
  616. $this->unicode,
  617. $this->encoding,
  618. array($this->defaultLeft,$this->defaultTop,$this->defaultRight,$this->defaultBottom)
  619. );
  620. // initialisation
  621. HTML2PDF::$SUBOBJ->setIsSubPart();
  622. HTML2PDF::$SUBOBJ->setTestTdInOnePage($this->testTDin1page);
  623. HTML2PDF::$SUBOBJ->setTestIsImage($this->testIsImage);
  624. HTML2PDF::$SUBOBJ->setTestIsDeprecated($this->testIsDeprecated);
  625. HTML2PDF::$SUBOBJ->setDefaultFont($this->defaultFont);
  626. HTML2PDF::$SUBOBJ->style->css = &$this->style->css;
  627. HTML2PDF::$SUBOBJ->style->css_keys = &$this->style->css_keys;
  628. HTML2PDF::$SUBOBJ->pdf->cloneFontFrom($this->pdf);
  629. HTML2PDF::$SUBOBJ->style->setPdfParent($pdf);
  630. }
  631. /**
  632. * fonction de clonage pour la creation d'un sous HTML2PDF א partir de HTML2PDF::$SUBOBJ
  633. *
  634. * @return null
  635. */
  636. public function __clone()
  637. {
  638. $this->pdf = clone $this->pdf;
  639. $this->parsing = clone $this->parsing;
  640. $this->style = clone $this->style;
  641. $this->style->setPdfParent($this->pdf);
  642. }
  643. /**
  644. * crיation d'un sous HTML2PDF pour la gestion des tableaux imbriquיs
  645. *
  646. * @param HTML2PDF futur sous HTML2PDF passי en rיfיrence pour crיation
  647. * @param integer marge eventuelle de l'objet si simulation d'un TD
  648. * @return null
  649. */
  650. protected function createSubHTML(&$sub_html, $cellmargin=0)
  651. {
  652. if (!HTML2PDF::$SUBOBJ) $this->prepareSubObj();
  653. // calcul de la largueur
  654. if ($this->style->value['width'])
  655. {
  656. $marge = $cellmargin*2;
  657. $marge+= $this->style->value['padding']['l'] + $this->style->value['padding']['r'];
  658. $marge+= $this->style->value['border']['l']['width'] + $this->style->value['border']['r']['width'];
  659. $marge = $this->pdf->getW() - $this->style->value['width'] + $marge;
  660. }
  661. else
  662. $marge = $this->margeLeft+$this->margeRight;
  663. //clonage
  664. $sub_html = clone HTML2PDF::$SUBOBJ;
  665. $sub_html->style->table = $this->style->table;
  666. $sub_html->style->value = $this->style->value;
  667. $sub_html->style->setOnlyLeft();
  668. $sub_html->setNewPage($this->format, $this->sens);
  669. $sub_html->initSubHtml($marge, $this->page, $this->defLIST);
  670. }
  671. /**
  672. * initialise le sous HTML2PDF. Ne pas utiliser directement. seul la fonction createSubHTML doit l'utiliser
  673. *
  674. * @return null
  675. */
  676. public function initSubHtml($marge, $page, $defLIST)
  677. {
  678. $this->saveMargin(0, 0, $marge);
  679. $this->defLIST = $defLIST;
  680. $this->page = $page;
  681. $this->pdf->setXY(0, 0);
  682. $this->style->FontSet();
  683. }
  684. public function setIsSubPart()
  685. {
  686. $this->isSubPart = true;
  687. }
  688. /**
  689. * destruction d'un sous HTML2PDF pour la gestion des tableaux imbriquיs
  690. *
  691. * @return null
  692. */
  693. protected function destroySubHTML(&$sub_html)
  694. {
  695. unset($sub_html);
  696. $sub_html = null;
  697. }
  698. /**
  699. * Convertir un nombre arabe en nombre romain
  700. *
  701. * @param integer nombre א convertir
  702. * @return string nombre converti
  703. */
  704. protected function listeArab2Rom($nb_ar)
  705. {
  706. $nb_b10 = array('I','X','C','M');
  707. $nb_b5 = array('V','L','D');
  708. $nb_ro = '';
  709. if ($nb_ar<1) return $nb_ar;
  710. if ($nb_ar>3999) return $nb_ar;
  711. for($i=3; $i>=0 ; $i--)
  712. {
  713. $chiffre=floor($nb_ar/pow(10,$i));
  714. if($chiffre>=1)
  715. {
  716. $nb_ar=$nb_ar-$chiffre*pow(10,$i);
  717. if($chiffre<=3)
  718. {
  719. for($j=$chiffre; $j>=1; $j--)
  720. {
  721. $nb_ro=$nb_ro.$nb_b10[$i];
  722. }
  723. }
  724. else if($chiffre==9)
  725. {
  726. $nb_ro=$nb_ro.$nb_b10[$i].$nb_b10[$i+1];
  727. }
  728. elseif($chiffre==4)
  729. {
  730. $nb_ro=$nb_ro.$nb_b10[$i].$nb_b5[$i];
  731. }
  732. else
  733. {
  734. $nb_ro=$nb_ro.$nb_b5[$i];
  735. for($j=$chiffre-5; $j>=1; $j--)
  736. {
  737. $nb_ro=$nb_ro.$nb_b10[$i];
  738. }
  739. }
  740. }
  741. }
  742. return $nb_ro;
  743. }
  744. /**
  745. * Ajouter un LI au niveau actuel
  746. *
  747. * @return null
  748. */
  749. protected function listeAddLi()
  750. {
  751. $this->defLIST[count($this->defLIST)-1]['nb']++;
  752. }
  753. protected function listeGetWidth() { return '7mm'; }
  754. protected function listeGetPadding() { return '1mm'; }
  755. /**
  756. * Recuperer le LI du niveau actuel
  757. *
  758. * @return string chaine א afficher
  759. */
  760. protected function listeGetLi()
  761. {
  762. $im = $this->defLIST[count($this->defLIST)-1]['img'];
  763. $st = $this->defLIST[count($this->defLIST)-1]['style'];
  764. $nb = $this->defLIST[count($this->defLIST)-1]['nb'];
  765. $up = (substr($st, 0, 6)=='upper-');
  766. if ($im) return array(false, false, $im);
  767. switch($st)
  768. {
  769. case 'none':
  770. return array('helvetica', true, ' ');
  771. case 'upper-alpha':
  772. case 'lower-alpha':
  773. $str = '';
  774. while($nb>26)
  775. {
  776. $str = chr(96+$nb%26).$str;
  777. $nb = floor($nb/26);
  778. }
  779. $str = chr(96+$nb).$str;
  780. return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
  781. case 'upper-roman':
  782. case 'lower-roman':
  783. $str = $this->listeArab2Rom($nb);
  784. return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
  785. case 'decimal':
  786. return array('helvetica', false, $nb.'.');
  787. case 'square':
  788. return array('zapfdingbats', true, chr(110));
  789. case 'circle':
  790. return array('zapfdingbats', true, chr(109));
  791. case 'disc':
  792. default:
  793. return array('zapfdingbats', true, chr(108));
  794. }
  795. }
  796. /**
  797. * Ajouter un niveau de liste
  798. *
  799. * @param string type de liste : ul, ol
  800. * @param string style de la liste
  801. * @return null
  802. */
  803. protected function listeAddLevel($type = 'ul', $style = '', $img = null)
  804. {
  805. if ($img)
  806. {
  807. if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match))
  808. $img = $match[1];
  809. else
  810. $img = null;
  811. }
  812. else
  813. $img = null;
  814. if (!in_array($type, array('ul', 'ol'))) $type = 'ul';
  815. if (!in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = '';
  816. if (!$style)
  817. {
  818. if ($type=='ul') $style = 'disc';
  819. else $style = 'decimal';
  820. }
  821. $this->defLIST[count($this->defLIST)] = array('style' => $style, 'nb' => 0, 'img' => $img);
  822. }
  823. /**
  824. * Supprimer un niveau de liste
  825. *
  826. * @return null
  827. */
  828. protected function listeDelLevel()
  829. {
  830. if (count($this->defLIST))
  831. {
  832. unset($this->defLIST[count($this->defLIST)-1]);
  833. $this->defLIST = array_values($this->defLIST);
  834. }
  835. }
  836. /**
  837. * traitement d'un code HTML fait pour HTML2PDF
  838. *
  839. * @param string code HTML א convertir
  840. * @param boolean afficher en pdf (false) ou en html adaptי (true)
  841. * @return null
  842. */
  843. public function writeHTML($html, $vue = false)
  844. {
  845. // si c'est une vrai page HTML, une conversion s'impose
  846. if (preg_match('/<body/isU', $html))
  847. $html = $this->getHtmlFromPage($html);
  848. $html = str_replace('[[page_nb]]', '{nb}', $html);
  849. $html = str_replace('[[date_y]]', date('Y'), $html);
  850. $html = str_replace('[[date_m]]', date('m'), $html);
  851. $html = str_replace('[[date_d]]', date('d'), $html);
  852. $html = str_replace('[[date_h]]', date('H'), $html);
  853. $html = str_replace('[[date_i]]', date('i'), $html);
  854. $html = str_replace('[[date_s]]', date('s'), $html);
  855. // si on veut voir le rיsultat en HTML => on appelle la fonction
  856. if ($vue) $this->vueHTML($html);
  857. // sinon, traitement pour conversion en PDF :
  858. // parsing
  859. $this->sub_pdf = false;
  860. $this->style->readStyle($html);
  861. $this->parsing->setHTML($html);
  862. $this->parsing->parse();
  863. $this->makeHTMLcode();
  864. }
  865. /**
  866. * traitement du code d'une vrai page HTML pour l'adapter א HTML2PDF
  867. *
  868. * @param string code HTML א adapter
  869. * @return string code HTML adaptי
  870. */
  871. public function getHtmlFromPage($html)
  872. {
  873. $html = str_replace('<BODY', '<body', $html);
  874. $html = str_replace('</BODY', '</body', $html);
  875. // extraction du contenu
  876. $res = explode('<body', $html);
  877. if (count($res)<2) return $html;
  878. $content = '<page'.$res[1];
  879. $content = explode('</body', $content);
  880. $content = $content[0].'</page>';
  881. // extraction des balises link
  882. preg_match_all('/<link([^>]*)>/isU', $html, $match);
  883. foreach($match[0] as $src)
  884. $content = $src.'</link>'.$content;
  885. // extraction des balises style
  886. preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
  887. foreach($match[0] as $src)
  888. $content = $src.$content;
  889. return $content;
  890. }
  891. /**
  892. * execute les diffיrentes actions du code HTML
  893. *
  894. * @return null
  895. */
  896. protected function makeHTMLcode()
  897. {
  898. // pour chaque element identifiי par le parsing
  899. for($this->parse_pos=0; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
  900. {
  901. // rיcupיration de l'יlיment
  902. $todo = $this->parsing->code[$this->parse_pos];
  903. // si c'est une ouverture de tableau
  904. if (in_array($todo['name'], array('table', 'ul', 'ol')) && !$todo['close'])
  905. {
  906. // on va crיer un sous HTML, et on va travailler sur une position temporaire
  907. $tag_open = $todo['name'];
  908. $this->sub_part = true;
  909. $this->temp_pos = $this->parse_pos;
  910. // pour tous les יlיments jusqu'א la fermeture de la table afin de prיparer les dimensions
  911. while(isset($this->parsing->code[$this->temp_pos]) && !($this->parsing->code[$this->temp_pos]['name']==$tag_open && $this->parsing->code[$this->temp_pos]['close']))
  912. {
  913. $this->loadAction($this->parsing->code[$this->temp_pos]);
  914. $this->temp_pos++;
  915. }
  916. if (isset($this->parsing->code[$this->temp_pos])) $this->loadAction($this->parsing->code[$this->temp_pos]);
  917. $this->sub_part = false;
  918. }
  919. // chargement de l'action correspondant א l'יlיment
  920. $this->loadAction($todo);
  921. }
  922. }
  923. /**
  924. * affichage en mode HTML du contenu
  925. *
  926. * @param string contenu
  927. * @return null
  928. */
  929. protected function vueHTML($content)
  930. {
  931. $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue01').' : $1<hr><div$1>', $content);
  932. $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue02').' : $1<hr><div$1>', $content);
  933. $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue03').' : $1<hr><div$1>', $content);
  934. $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content);
  935. $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content);
  936. $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content);
  937. $content = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $content);
  938. $content = preg_replace('/<\/barcode([^>]*)>/isU', '', $content);
  939. $content = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $content);
  940. $content = preg_replace('/<\/qrcode([^>]*)>/isU', '', $content);
  941. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  942. <html>
  943. <head>
  944. <title>'.HTML2PDF::textGET('vue04').' HTML</title>
  945. <meta http-equiv="Content-Type" content="text/html; charset='.$this->encoding.'" >
  946. </head>
  947. <body style="padding: 10px; font-size: 10pt;font-family: Verdana;">
  948. '.$content.'
  949. </body>
  950. </html>';
  951. exit;
  952. }
  953. /**
  954. * chargement de l'action correspondante א un element de parsing
  955. *
  956. * @param array יlיment de parsing
  957. * @return null
  958. */
  959. protected function loadAction($row)
  960. {
  961. // nom de l'action
  962. $fnc = ($row['close'] ? 'c_' : 'o_').strtoupper($row['name']);
  963. // parametres de l'action
  964. $param = $row['param'];
  965. // si aucune page n'est crיי, on la crיי
  966. if ($fnc!='o_PAGE' && $this->firstPage)
  967. {
  968. $this->setNewPage();
  969. }
  970. // lancement de l'action
  971. if (is_callable(array(&$this, $fnc)))
  972. {
  973. $res = $this->{$fnc}($param);
  974. $this->previousCall = $fnc;
  975. return $res;
  976. }
  977. else
  978. throw new HTML2PDF_exception(1, strtoupper($row['name']), $this->parsing->getHtmlErrorCode($row['html_pos']));
  979. }
  980. /**
  981. * balise : PAGE
  982. * mode : OUVERTURE
  983. *
  984. * @param array paramטtres de l'יlיment de parsing
  985. * @return null
  986. */
  987. protected function o_PAGE($param)
  988. {
  989. if ($this->forOneLine) return false;
  990. if ($this->DEBUG_actif) $this->DEBUG_add('PAGE n°'.($this->page+1), true);
  991. $newPageSet= (!isset($param['pageset']) || $param['pageset']!='old');
  992. $this->maxH = 0;
  993. if ($newPageSet)
  994. {
  995. $this->subHEADER = array();
  996. $this->subFOOTER = array();
  997. // identification de l'orientation demandיe
  998. $orientation = '';
  999. if (isset($param['orientation']))
  1000. {
  1001. $param['orientation'] = strtolower($param['orientation']);
  1002. if ($param['orientation']=='p') $orientation = 'P';
  1003. if ($param['orientation']=='portrait') $orientation = 'P';
  1004. if ($param['orientation']=='l') $orientation = 'L';
  1005. if ($param['orientation']=='paysage') $orientation = 'L';
  1006. if ($param['orientation']=='landscape') $orientation = 'L';
  1007. }
  1008. // identification de l'orientation demandיe
  1009. $format = null;
  1010. if (isset($param['format']))
  1011. {
  1012. $format = strtolower($param['format']);
  1013. if (preg_match('/^([0-9]+)x([0-9]+)$/isU', $format, $match))
  1014. {
  1015. $format = array(intval($match[1]), intval($match[2]));
  1016. }
  1017. }
  1018. // identification des propriיtיs du background
  1019. $background = array();
  1020. if (isset($param['backimg']))
  1021. {
  1022. $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // nom de l'image
  1023. $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // position horizontale de l'image
  1024. $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // position verticale de l'image
  1025. $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // taille de l'image (100% = largueur de la feuille)
  1026. // conversion du nom de l'image, en cas de paramטtres en _GET
  1027. $background['img'] = str_replace('&amp;', '&', $background['img']);
  1028. // conversion des positions
  1029. if ($background['posX']=='left') $background['posX'] = '0%';
  1030. if ($background['posX']=='center') $background['posX'] = '50%';
  1031. if ($background['posX']=='right') $background['posX'] = '100%';
  1032. if ($background['posY']=='top') $background['posY'] = '0%';
  1033. if ($background['posY']=='middle') $background['posY'] = '50%';
  1034. if ($background['posY']=='bottom') $background['posY'] = '100%';
  1035. // si il y a une image de prיcisי
  1036. if ($background['img'])
  1037. {
  1038. // est-ce que c'est une image ?
  1039. $infos=@GetImageSize($background['img']);
  1040. if (count($infos)>1)
  1041. {
  1042. // taille de l'image, en fonction de la taille spיcifiיe.
  1043. $Wi = $this->style->ConvertToMM($background['width'], $this->pdf->getW());
  1044. $Hi = $Wi*$infos[1]/$infos[0];
  1045. // rיcupיration des dimensions et positions de l'image
  1046. $background['width'] = $Wi;
  1047. $background['posX'] = $this->style->ConvertToMM($background['posX'], $this->pdf->getW() - $Wi);
  1048. $background['posY'] = $this->style->ConvertToMM($background['posY'], $this->pdf->getH() - $Hi);
  1049. }
  1050. else
  1051. $background = array();
  1052. }
  1053. else
  1054. $background = array();
  1055. }
  1056. // marges TOP et BOTTOM pour le texte.
  1057. $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0';
  1058. $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0';
  1059. $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0';
  1060. $background['right'] = isset($param['backright']) ? $param['backright'] : '0';
  1061. if (preg_match('/^([0-9]*)$/isU', $background['top'])) $background['top'] .= 'mm';
  1062. if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) $background['bottom'] .= 'mm';
  1063. if (preg_match('/^([0-9]*)$/isU', $background['left'])) $background['left'] .= 'mm';
  1064. if (preg_match('/^([0-9]*)$/isU', $background['right'])) $background['right'] .= 'mm';
  1065. $background['top'] = $this->style->ConvertToMM($background['top'], $this->pdf->getH());
  1066. $background['bottom'] = $this->style->ConvertToMM($background['bottom'], $this->pdf->getH());
  1067. $background['left'] = $this->style->ConvertToMM($background['left'], $this->pdf->getW());
  1068. $background['right'] = $this->style->ConvertToMM($background['right'], $this->pdf->getW());
  1069. $res = false;
  1070. $background['color'] = isset($param['backcolor']) ? $this->style->ConvertToColor($param['backcolor'], $res) : null;
  1071. if (!$res) $background['color'] = null;
  1072. $this->style->save();
  1073. $this->style->analyse('PAGE', $param);
  1074. $this->style->setPosition();
  1075. $this->style->FontSet();
  1076. // nouvelle page
  1077. $this->setNewPage($format, $orientation, $background);
  1078. // footer automatique
  1079. if (isset($param['footer']))
  1080. {
  1081. $lst = explode(';', $param['footer']);
  1082. foreach($lst as $key => $val) $lst[$key] = trim(strtolower($val));
  1083. $page = in_array('page', $lst);
  1084. $date = in_array('date', $lst);
  1085. $heure = in_array('heure', $lst);
  1086. $form = in_array('form', $lst);
  1087. }
  1088. else
  1089. {
  1090. $page = null;
  1091. $date = null;
  1092. $heure = null;
  1093. $form = null;
  1094. }
  1095. $this->pdf->SetMyFooter($page, $date, $heure, $form);
  1096. }
  1097. else
  1098. {
  1099. $this->style->save();
  1100. $this->style->analyse('PAGE', $param);
  1101. $this->style->setPosition();
  1102. $this->style->FontSet();
  1103. $this->setNewPage();
  1104. }
  1105. return true;
  1106. }
  1107. /**
  1108. * balise : PAGE
  1109. * mode : FERMETURE
  1110. *
  1111. * @param array paramטtres de l'יlיment de parsing
  1112. * @return null
  1113. */
  1114. protected function c_PAGE($param)
  1115. {
  1116. if ($this->forOneLine) return false;
  1117. $this->maxH = 0;
  1118. $this->style->load();
  1119. $this->style->FontSet();
  1120. if ($this->DEBUG_actif) $this->DEBUG_add('PAGE n°'.$this->page, false);
  1121. return true;
  1122. }
  1123. protected function o_PAGE_HEADER($param)
  1124. {
  1125. if ($this->forOneLine) return false;
  1126. $this->subHEADER = array();
  1127. for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
  1128. {
  1129. $todo = $this->parsing->code[$this->parse_pos];
  1130. if ($todo['name']=='page_header') $todo['name']='page_header_sub';
  1131. $this->subHEADER[] = $todo;
  1132. if (strtolower($todo['name'])=='page_header_sub' && $todo['close']) break;
  1133. }
  1134. $this->setPageHeader();
  1135. return true;
  1136. }
  1137. protected function o_PAGE_FOOTER($param)
  1138. {
  1139. if ($this->forOneLine) return false;
  1140. $this->subFOOTER = array();
  1141. for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
  1142. {
  1143. $todo = $this->parsing->code[$this->parse_pos];
  1144. if ($todo['name']=='page_footer') $todo['name']='page_footer_sub';
  1145. $this->subFOOTER[] = $todo;
  1146. if (strtolower($todo['name'])=='page_footer_sub' && $todo['close']) break;
  1147. }
  1148. $this->setPageFooter();
  1149. return true;
  1150. }
  1151. protected function o_PAGE_HEADER_SUB($param)
  1152. {
  1153. if ($this->forOneLine) return false;
  1154. // sauvegarde de l'יtat
  1155. $this->subSTATES = array();
  1156. $this->subSTATES['x'] = $this->pdf->getX();
  1157. $this->subSTATES['y'] = $this->pdf->getY();
  1158. $this->subSTATES['s'] = $this->style->value;
  1159. $this->subSTATES['t'] = $this->style->table;
  1160. $this->subSTATES['ml'] = $this->margeLeft;
  1161. $this->subSTATES['mr'] = $this->margeRight;
  1162. $this->subSTATES['mt'] = $this->margeTop;
  1163. $this->subSTATES['mb'] = $this->margeBottom;
  1164. $this->subSTATES['mp'] = $this->pageMarges;
  1165. // nouvel etat pour le footer
  1166. $this->pageMarges = array();
  1167. $this->margeLeft = $this->defaultLeft;
  1168. $this->margeRight = $this->defaultRight;
  1169. $this->margeTop = $this->defaultTop;
  1170. $this->margeBottom = $this->defaultBottom;
  1171. $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
  1172. $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
  1173. $this->pdf->setXY($this->defaultLeft, $this->defaultTop);
  1174. $this->style->initStyle();
  1175. $this->style->resetStyle();
  1176. $this->style->value['width'] = $this->pdf->getW() - $this->defaultLeft - $this->defaultRight;
  1177. $this->style->table = array();
  1178. $this->style->save();
  1179. $this->style->analyse('page_header_sub', $param);
  1180. $this->style->setPosition();
  1181. $this->style->FontSet();
  1182. $this->setNewPositionForNewLine();
  1183. return true;
  1184. }
  1185. protected function c_PAGE_HEADER_SUB($param)
  1186. {
  1187. if ($this->forOneLine) return false;
  1188. $this->style->load();
  1189. // retablissement de l'etat
  1190. $this->style->value = $this->subSTATES['s'];
  1191. $this->style->table = $this->subSTATES['t'];
  1192. $this->pageMarges = $this->subSTATES['mp'];
  1193. $this->margeLeft = $this->subSTATES['ml'];
  1194. $this->margeRight = $this->subSTATES['mr'];
  1195. $this->margeTop = $this->subSTATES['mt'];
  1196. $this->margeBottom = $this->subSTATES['mb'];
  1197. $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
  1198. $this->pdf->setbMargin($this->margeBottom);
  1199. $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
  1200. $this->pdf->setXY($this->subSTATES['x'], $this->subSTATES['y']);
  1201. $this->style->FontSet();
  1202. $this->maxH = 0;
  1203. return true;
  1204. }
  1205. protected function o_PAGE_FOOTER_SUB($param)
  1206. {
  1207. if ($this->forOneLine) return false;
  1208. $this->subSTATES = array();
  1209. $this->subSTATES['x'] = $this->pdf->getX();
  1210. $this->subSTATES['y'] = $this->pdf->getY();
  1211. $this->subSTATES['s'] = $this->style->value;
  1212. $this->subSTATES['t'] = $this->style->table;
  1213. $this->subSTATES['ml'] = $this->margeLeft;
  1214. $this->subSTATES['mr'] = $this->margeRight;
  1215. $this->subSTATES['mt'] = $this->margeTop;
  1216. $this->subSTATES['mb'] = $this->margeBottom;
  1217. $this->subSTATES['mp'] = $this->pageMarges;
  1218. // nouvel etat pour le footer
  1219. $this->pageMarges = array();
  1220. $this->margeLeft = $this->defaultLeft;
  1221. $this->margeRight = $this->defaultRight;
  1222. $this->margeTop = $this->defaultTop;
  1223. $this->margeBottom = $this->defaultBottom;
  1224. $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
  1225. $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
  1226. $this->pdf->setXY($this->defaultLeft, $this->defaultTop);
  1227. $this->style->initStyle();
  1228. $this->style->resetStyle();
  1229. $this->style->value['width'] = $this->pdf->getW() - $this->defaultLeft - $this->defaultRight;
  1230. $this->style->table = array();
  1231. // on en crיי un sous HTML que l'on transforme en PDF
  1232. // pour rיcupיrer la hauteur
  1233. // on extrait tout ce qui est contenu dans le FOOTER
  1234. $sub = null;
  1235. $this->CreateSubHTML($sub);
  1236. $sub->parsing->code = $this->parsing->getLevel($this->parse_pos);
  1237. $sub->MakeHTMLcode();
  1238. $this->pdf->setY($this->pdf->getH() - $sub->maxY - $this->defaultBottom - 0.01);
  1239. $this->destroySubHTML($sub);
  1240. $this->style->save();
  1241. $this->style->analyse('page_footer_sub', $param);
  1242. $this->style->setPosition();
  1243. $this->style->FontSet();
  1244. $this->setNewPositionForNewLine();
  1245. return true;
  1246. }
  1247. protected function c_PAGE_FOOTER_SUB($param)
  1248. {
  1249. if ($this->forOneLine) return false;
  1250. $this->style->load();
  1251. $this->style->value = $this->subSTATES['s'];
  1252. $this->style->table = $this->subSTATES['t'];
  1253. $this->pageMarges = $this->subSTATES['mp'];
  1254. $this->margeLeft = $this->subSTATES['ml'];
  1255. $this->margeRight = $this->subSTATES['mr'];
  1256. $this->margeTop = $this->subSTATES['mt'];
  1257. $this->margeBottom = $this->subSTATES['mb'];
  1258. $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
  1259. $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
  1260. $this->pdf->setXY($this->subSTATES['x'], $this->subSTATES['y']);
  1261. $this->style->FontSet();
  1262. $this->maxH = 0;
  1263. return true;
  1264. }
  1265. /**
  1266. * balise : NOBREAK
  1267. * mode : OUVERTURE
  1268. *
  1269. * @param array paramטtres de l'יlיment de parsing
  1270. * @return null
  1271. */
  1272. protected function o_NOBREAK($param)
  1273. {
  1274. if ($this->forOneLine) return false;
  1275. $this->maxH = 0;
  1276. // on en crיי un sous HTML que l'on transforme en PDF
  1277. // pour analyse les dimensions
  1278. // et voir si ca rentre
  1279. $sub = null;
  1280. $this->CreateSubHTML($sub);
  1281. $sub->parsing->code = $this->parsing->getLevel($this->parse_pos);
  1282. $sub->MakeHTMLcode();
  1283. $y = $this->pdf->getY();
  1284. if (
  1285. $sub->maxY < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin()) &&
  1286. $y + $sub->maxY>=($this->pdf->getH() - $this->pdf->getbMargin())
  1287. )
  1288. $this->setNewPage();
  1289. $this->destroySubHTML($sub);
  1290. return true;
  1291. }
  1292. /**
  1293. * balise : NOBREAK
  1294. * mode : FERMETURE
  1295. *
  1296. * @param array paramטtres de l'יlיment de parsing
  1297. * @return null
  1298. */
  1299. protected function c_NOBREAK($param)
  1300. {
  1301. if ($this->forOneLine) return false;
  1302. $this->maxH = 0;
  1303. return true;
  1304. }
  1305. /**
  1306. * balise : DIV
  1307. * mode : OUVERTURE
  1308. *
  1309. * @param array paramטtres de l'יlיment de parsing
  1310. * @return null
  1311. */
  1312. protected function o_DIV($param, $other = 'div')
  1313. {
  1314. if ($this->forOneLine) return false;
  1315. if ($this->DEBUG_actif) $this->DEBUG_add(strtoupper($other), true);
  1316. $this->style->save();
  1317. $this->style->analyse($other, $param);
  1318. $this->style->FontSet();
  1319. // gestion specifique a la balise legend pour l'afficher au bon endroit
  1320. if (in_array($other, array('fieldset', 'legend')))
  1321. {
  1322. if (isset($param['moveTop'])) $this->style->value['margin']['t'] += $param['moveTop'];
  1323. if (isset($param['moveLeft'])) $this->style->value['margin']['l'] += $param['moveLeft'];
  1324. if (isset($param['moveDown'])) $this->style->value['margin']['b'] += $param['moveDown'];
  1325. }
  1326. $align_object = null;
  1327. if ($this->style->value['margin-auto']) $align_object = 'center';
  1328. $marge = array();
  1329. $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
  1330. $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
  1331. $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
  1332. $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
  1333. // on extrait tout ce qui est contenu dans la DIV
  1334. $level = $this->parsing->getLevel($this->parse_pos);
  1335. // on en crיי un sous HTML que l'on transforme en PDF
  1336. // pour analyse les dimensions
  1337. $w = 0; $h = 0;
  1338. if (count($level))
  1339. {
  1340. $sub = null;
  1341. $this->CreateSubHTML($sub);
  1342. $sub->parsing->code = $level;
  1343. $sub->MakeHTMLcode();
  1344. $w = $sub->maxX;
  1345. $h = $sub->maxY;
  1346. $this->destroySubHTML($sub);
  1347. }
  1348. $w_reel = $w;
  1349. $h_reel = $h;
  1350. // if (($w==0 && $this->style->value['width']==0) || ($w>$this->style->value['width']) || $this->style->value['position']=='absolute')
  1351. $w+= $marge['l']+$marge['r']+0.001;
  1352. $h+= $marge['t']+$marge['b']+0.001;
  1353. if ($this->style->value['overflow']=='hidden')
  1354. {
  1355. $over_w = max($w, $this->style->value['width']);
  1356. $over_h = max($h, $this->style->value['height']);
  1357. $overflow = true;
  1358. $this->style->value['old_maxX'] = $this->maxX;
  1359. $this->style->value['old_maxY'] = $this->maxY;
  1360. $this->style->value['old_maxH'] = $this->maxH;
  1361. $this->style->value['old_overflow'] = $this->isInOverflow;
  1362. $this->isInOverflow = true;
  1363. }
  1364. else
  1365. {
  1366. $over_w = null;
  1367. $over_h = null;
  1368. $overflow = false;
  1369. $this->style->value['width'] = max($w, $this->style->value['width']);
  1370. $this->style->value['height'] = max($h, $this->style->value['height']);
  1371. }
  1372. switch($this->style->value['rotate'])
  1373. {
  1374. case 90:
  1375. $tmp = $over_h; $over_h = $over_w; $over_w = $tmp;
  1376. $tmp = $h_reel; $h_reel = $w_reel; $w_reel = $tmp;
  1377. unset($tmp);
  1378. $w = $this->style->value['height'];
  1379. $h = $this->style->value['width'];
  1380. $t_x =-$h;
  1381. $t_y = 0;
  1382. break;
  1383. case 180:
  1384. $w = $this->style->value['width'];
  1385. $h = $this->style->value['height'];
  1386. $t_x = -$w;
  1387. $t_y = -$h;
  1388. break;
  1389. case 270:
  1390. $tmp = $over_h; $over_h = $over_w; $over_w = $tmp;
  1391. $tmp = $h_reel; $h_reel = $w_reel; $w_reel = $tmp;
  1392. unset($tmp);
  1393. $w = $this->style->value['height'];
  1394. $h = $this->style->value['width'];
  1395. $t_x = 0;
  1396. $t_y =-$w;
  1397. break;
  1398. default:
  1399. $w = $this->style->value['width'];
  1400. $h = $this->style->value['height'];
  1401. $t_x = 0;
  1402. $t_y = 0;
  1403. break;
  1404. }
  1405. if (!$this->style->value['position'])
  1406. {
  1407. if (
  1408. $w < ($this->pdf->getW() - $this->pdf->getlMargin()-$this->pdf->getrMargin()) &&
  1409. $this->pdf->getX() + $w>=($this->pdf->getW() - $this->pdf->getrMargin())
  1410. )
  1411. $this->o_BR(array());
  1412. if (
  1413. ($h < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin())) &&
  1414. ($this->pdf->getY() + $h>=($this->pdf->getH() - $this->pdf->getbMargin())) &&
  1415. !$this->isInOverflow
  1416. )
  1417. $this->setNewPage();
  1418. // en cas d'alignement => correction
  1419. $old = $this->style->getOldValues();
  1420. $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
  1421. if ($parent_w>$w)
  1422. {
  1423. if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
  1424. else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
  1425. }
  1426. $this->style->setPosition();
  1427. }
  1428. else
  1429. {
  1430. // en cas d'alignement => correction
  1431. $old = $this->style->getOldValues();
  1432. $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
  1433. if ($parent_w>$w)
  1434. {
  1435. if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
  1436. else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
  1437. }
  1438. $this->style->setPosition();
  1439. $this->saveMax();
  1440. $this->maxX = 0;
  1441. $this->maxY = 0;
  1442. $this->maxH = 0;
  1443. $this->maxE = 0;
  1444. }
  1445. if ($this->style->value['rotate'])
  1446. {
  1447. $this->pdf->startTransform();
  1448. $this->pdf->setRotation($this->style->value['rotate']);
  1449. $this->pdf->setTranslate($t_x, $t_y);
  1450. }
  1451. // initialisation du style des bordures de la div
  1452. $this->drawRectangle(
  1453. $this->style->value['x'],
  1454. $this->style->value['y'],
  1455. $this->style->value['width'],
  1456. $this->style->value['height'],
  1457. $this->style->value['border'],
  1458. $this->style->value['padding'],
  1459. 0,
  1460. $this->style->value['background']
  1461. );
  1462. $marge = array();
  1463. $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
  1464. $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
  1465. $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
  1466. $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
  1467. $this->style->value['width'] -= $marge['l']+$marge['r'];
  1468. $this->style->value['height']-= $marge['t']+$marge['b'];
  1469. // positionnement en fonction des alignements
  1470. $x_corr = 0;
  1471. $y_corr = 0;
  1472. if (!$this->sub_part && !$this->isSubPart)
  1473. {
  1474. switch($this->style->value['text-align'])
  1475. {
  1476. case 'right': $x_corr = ($this->style->value['width']-$w_reel); break;
  1477. case 'center': $x_corr = ($this->style->value['width']-$w_reel)*0.5; break;
  1478. }
  1479. if ($x_corr>0) $x_corr=0;
  1480. switch($this->style->value['vertical-align'])
  1481. {
  1482. case 'bottom': $y_corr = ($this->style->value['height']-$h_reel); break;
  1483. case 'middle': $y_corr = ($this->style->value['height']-$h_reel)*0.5; break;
  1484. }
  1485. }
  1486. if ($overflow)
  1487. {
  1488. $over_w-= $marge['l']+$marge['r'];
  1489. $over_h-= $marge['t']+$marge['b'];
  1490. $this->pdf->clippingPathOpen(
  1491. $this->style->value['x']+$marge['l'],
  1492. $this->style->value['y']+$marge['t'],
  1493. $this->style->value['width'],
  1494. $this->style->value['height']
  1495. );
  1496. $this->style->value['x']+= $x_corr;
  1497. // limitation des marges aux dimensions du contenu
  1498. $mL = $this->style->value['x']+$marge['l'];
  1499. $mR = $this->pdf->getW() - $mL - $over_w;
  1500. }
  1501. else
  1502. {
  1503. // limitation des marges aux dimensions de la div
  1504. $mL = $this->style->value['x']+$marge['l'];
  1505. $mR = $this->pdf->getW() - $mL - $this->style->value['width'];
  1506. }
  1507. $x = $this->style->value['x']+$marge['l'];
  1508. $y = $this->style->value['y']+$marge['t']+$y_corr;
  1509. $this->saveMargin($mL, 0, $mR);
  1510. $this->pdf->setXY($x, $y);
  1511. $this->setNewPositionForNewLine();
  1512. return true;
  1513. }
  1514. protected function o_BLOCKQUOTE($param) { return $this->o_DIV($param, 'blockquote'); }
  1515. protected function o_LEGEND($param) { return $this->o_DIV($param, 'legend'); }
  1516. /**
  1517. * balise : FIELDSET
  1518. * mode : OUVERTURE
  1519. * ecrite par Pavel Kochman
  1520. *
  1521. * @param array paramטtres de l'יlיment de parsing
  1522. * @return null
  1523. */
  1524. protected function o_FIELDSET($param)
  1525. {
  1526. $this->style->save();
  1527. $this->style->analyse('fieldset', $param);
  1528. // get height of LEGEND element and make fieldset corrections
  1529. for($temp_pos = $this->parse_pos + 1; $temp_pos<count($this->parsing->code); $temp_pos++)
  1530. {
  1531. $todo = $this->parsing->code[$temp_pos];
  1532. if($todo['name'] == 'fieldset') break;
  1533. if($todo['name'] == 'legend' && !$todo['close'])
  1534. {
  1535. $legend_open_pos = $temp_pos;
  1536. $sub = null;
  1537. $this->CreateSubHTML($sub);
  1538. $sub->parsing->code = $this->parsing->getLevel($temp_pos - 1);
  1539. // pour chaque element identifiי par le parsing
  1540. $res = null;
  1541. for($sub->parse_pos = 0; $sub->parse_pos<count($sub->parsing->code); $sub->parse_pos++)
  1542. {
  1543. $todo = $sub->parsing->code[$sub->parse_pos];
  1544. $sub->loadAction($todo);
  1545. if ($todo['name'] == 'legend' && $todo['close'])
  1546. break;
  1547. }
  1548. $legendH = $sub->maxY;
  1549. $this->destroySubHTML($sub);
  1550. $move = $this->style->value['padding']['t'] + $this->style->value['border']['t']['width'] + 0.03;
  1551. $param['moveTop'] = $legendH / 2;
  1552. $this->parsing->code[$legend_open_pos]['param']['moveTop'] = - ($legendH / 2 + $move);
  1553. $this->parsing->code[$legend_open_pos]['param']['moveLeft'] = 2 - $this->style->value['border']['l']['width'] - $this->style->value['padding']['l'];
  1554. $this->parsing->code[$legend_open_pos]['param']['moveDown'] = $move;
  1555. break;
  1556. }
  1557. }
  1558. $this->style->load();
  1559. return $this->o_DIV($param, 'fieldset');
  1560. }
  1561. /**
  1562. * balise : DIV
  1563. * mode : FERMETURE
  1564. *
  1565. * @param array paramטtres de l'יlיment de parsing
  1566. * @return null
  1567. */
  1568. protected function c_DIV($param, $other='div')
  1569. {
  1570. if ($this->forOneLine) return false;
  1571. if ($this->style->value['overflow']=='hidden')
  1572. {
  1573. $this->maxX = $this->style->value['old_maxX'];
  1574. $this->maxY = $this->style->value['old_maxY'];
  1575. $this->maxH = $this->style->value['old_maxH'];
  1576. $this->isInOverflow = $this->style->value['old_overflow'];
  1577. $this->pdf->clippingPathClose();
  1578. }
  1579. if ($this->style->value['rotate'])
  1580. $this->pdf->stopTransform();
  1581. $marge = array();
  1582. $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
  1583. $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
  1584. $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
  1585. $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
  1586. $x = $this->style->value['x'];
  1587. $y = $this->style->value['y'];
  1588. $w = $this->style->value['width']+$marge['l']+$marge['r']+$this->style->value['margin']['r'];
  1589. $h = $this->style->value['height']+$marge['t']+$marge['b']+$this->style->value['margin']['b'];
  1590. switch($this->style->value['rotate'])
  1591. {
  1592. case 90:
  1593. $t = $w; $w = $h; $h = $t;
  1594. break;
  1595. case 270:
  1596. $t = $w; $w = $h; $h = $t;
  1597. break;
  1598. default:
  1599. break;
  1600. }
  1601. if ($this->style->value['position']!='absolute')
  1602. {
  1603. // position
  1604. $this->pdf->setXY($x+$w, $y);
  1605. // position MAX
  1606. $this->maxX = max($this->maxX, $x+$w);
  1607. $this->maxY = max($this->maxY, $y+$h);
  1608. $this->maxH = max($this->maxH, $h);
  1609. }
  1610. else
  1611. {
  1612. // position
  1613. $this->pdf->setXY($this->style->value['xc'], $this->style->value['yc']);
  1614. $this->loadMax();
  1615. }
  1616. $block = ($this->style->value['display']!='inline' && $this->style->value['position']!='absolute');
  1617. $this->style->load();
  1618. $this->style->FontSet();
  1619. $this->loadMargin();
  1620. if ($block) $this->o_BR(array());
  1621. if ($this->DEBUG_actif) $this->DEBUG_add(strtoupper($other), false);
  1622. return true;
  1623. }
  1624. protected function c_BLOCKQUOTE($param) { return $this->c_DIV($param, 'blockquote'); }
  1625. protected function c_FIELDSET($param) { return $this->c_DIV($param, 'fieldset'); }
  1626. protected function c_LEGEND($param) { return $this->c_DIV($param, 'legend'); }
  1627. /**
  1628. * balise : BARCODE
  1629. * mode : OUVERTURE
  1630. *
  1631. * @param array paramטtres de l'יlיment de parsing
  1632. * @return null
  1633. */
  1634. protected function o_BARCODE($param)
  1635. {
  1636. // pour compatibilitי < 3.29
  1637. $lst_barcode = array();
  1638. $lst_barcode['UPC_A'] = 'UPCA';
  1639. $lst_barcode['CODE39'] = 'C39';
  1640. if (!isset($param['type'])) $param['type'] = 'C39';
  1641. if (!isset($param['value'])) $param['value'] = 0;
  1642. if (!isset($param['label'])) $param['label'] = 'label';
  1643. if (!isset($param['style']['color'])) $param['style']['color'] = '#000000';
  1644. if ($this->testIsDeprecated && (isset($param['bar_h']) || isset($param['bar_w'])))
  1645. throw new HTML2PDF_exception(9, array('BARCODE', 'bar_h, bar_w'));
  1646. $param['type'] = strtoupper($param['type']);
  1647. if (isset($lst_barcode[$param['type']])) $param['type'] = $lst_barcode[$param['type']];
  1648. $this->style->save();
  1649. $this->style->analyse('barcode', $param);
  1650. $this->style->setPosition();
  1651. $this->style->FontSet();
  1652. $x = $this->pdf->getX();
  1653. $y = $this->pdf->getY();
  1654. $w = $this->style->value['width']; if (!$w) $w = $this->style->ConvertToMM('50mm');
  1655. $h = $this->style->value['height']; if (!$h) $h = $this->style->ConvertToMM('10mm');
  1656. $txt = ($param['label']!=='none' ? $this->style->value['font-size'] : false);
  1657. $c = $this->style->value['color'];
  1658. $infos = $this->pdf->myBarcode($param['value'], $param['type'], $x, $y, $w, $h, $txt, $c);
  1659. // position maximale globale
  1660. $this->maxX = max($this->maxX, $x+$infos[0]);
  1661. $this->maxY = max($this->maxY, $y+$infos[1]);
  1662. $this->maxH = max($this->maxH, $infos[1]);
  1663. $this->maxE++;
  1664. $this->pdf->setXY($x+$infos[0], $y);
  1665. $this->style->load();
  1666. $this->style->FontSet();
  1667. return true;
  1668. }
  1669. /**
  1670. * balise : BARCODE
  1671. * mode : FERMETURE
  1672. *
  1673. * @param array paramטtres de l'יlיment de parsing
  1674. * @return null
  1675. */
  1676. protected function c_BARCODE($param)
  1677. {
  1678. // completement inutile
  1679. return true;
  1680. }
  1681. /**
  1682. * balise : QRCODE
  1683. * mode : OUVERTURE
  1684. *
  1685. * @param array paramטtres de l'יlיment de parsing
  1686. * @return null
  1687. */
  1688. protected function o_QRCODE($param)
  1689. {
  1690. if ($this->testIsDeprecated && (isset($param['size']) || isset($param['noborder'])))
  1691. throw new HTML2PDF_exception(9, array('QRCODE', 'size, noborder'));
  1692. if ($this->DEBUG_actif) $this->DEBUG_add('QRCODE', true);
  1693. if (!isset($param['value'])) $param['value'] = '';
  1694. if (!isset($param['ec'])) $param['ec'] = 'H';
  1695. if (!isset($param['style']['color'])) $param['style']['color'] = '#000000';
  1696. if (!isset($param['style']['background-color'])) $param['style']['background-color'] = '#FFFFFF';
  1697. if (isset($param['style']['border']))
  1698. {
  1699. $borders = $param['style']['border']!='none';
  1700. unset($param['style']['border']);
  1701. }
  1702. else
  1703. $borders = true;
  1704. if ($param['value']==='') return true;
  1705. if (!in_array($param['ec'], array('L', 'M', 'Q', 'H'))) $param['ec'] = 'H';
  1706. $this->style->save();
  1707. $this->style->analyse('qrcode', $param);
  1708. $this->style->setPosition();
  1709. $this->style->FontSet();
  1710. $x = $this->pdf->getX();
  1711. $y = $this->pdf->getY();
  1712. $w = $this->style->value['width'];
  1713. $h = $this->style->value['height'];
  1714. $size = max($w, $h); if (!$size) $size = $this->style->ConvertToMM('50mm');
  1715. $style = array(
  1716. 'fgcolor' => $this->style->value['color'],
  1717. 'bgcolor' => $this->style->value['background']['color'],
  1718. );
  1719. if ($borders)
  1720. {
  1721. $style['border'] = true;
  1722. $style['padding'] = 'auto';
  1723. }
  1724. else
  1725. {
  1726. $style['border'] = false;
  1727. $style['padding'] = 0;
  1728. }
  1729. if (!$this->sub_part && !$this->isSubPart)
  1730. {
  1731. $this->pdf->write2DBarcode($param['value'], 'QRCODE,'.$param['ec'], $x, $y, $size, $size, $style);
  1732. }
  1733. // position maximale globale
  1734. $this->maxX = max($this->maxX, $x+$size);
  1735. $this->maxY = max($this->maxY, $y+$size);
  1736. $this->maxH = max($this->maxH, $size);
  1737. $this->pdf->setX($x+$size);
  1738. $this->style->load();
  1739. $this->style->FontSet();
  1740. return true;
  1741. }
  1742. /**
  1743. * balise : QRCODE
  1744. * mode : FERMETURE
  1745. *
  1746. * @param array paramטtres de l'יlיment de parsing
  1747. * @return null
  1748. */
  1749. protected function c_QRCODE($param)
  1750. {
  1751. if ($this->DEBUG_actif) $this->DEBUG_add('QRCODE', false);
  1752. // completement inutile
  1753. return true;
  1754. }
  1755. /**
  1756. * balise : BOOKMARK
  1757. * mode : OUVERTURE
  1758. *
  1759. * @param array paramטtres de l'יlיment de parsing
  1760. * @return null
  1761. */
  1762. protected function o_BOOKMARK($param)
  1763. {
  1764. $titre = isset($param['title']) ? trim($param['title']) : '';
  1765. $level = isset($param['level']) ? floor($param['level']) : 0;
  1766. if ($level<0) $level = 0;
  1767. if ($titre) $this->pdf->Bookmark($titre, $level, -1);
  1768. return true;
  1769. }
  1770. /**
  1771. * balise : BOOKMARK
  1772. * mode : FERMETURE
  1773. *
  1774. * @param array paramטtres de l'יlיment de parsing
  1775. * @return null
  1776. */
  1777. protected function c_BOOKMARK($param)
  1778. {
  1779. // completement inutile
  1780. return true;
  1781. }
  1782. function getElementY($h)
  1783. {
  1784. if ($this->sub_part || $this->isSubPart || !$this->currentH || $this->currentH<$h)
  1785. return 0;
  1786. return ($this->currentH-$h)*0.8;
  1787. }
  1788. /**
  1789. * balise : WRITE
  1790. * mode : OUVERTURE
  1791. *
  1792. * @param array paramטtres de l'יlיment de parsing
  1793. * @return null
  1794. */
  1795. protected function o_WRITE($param)
  1796. {
  1797. $fill = ($this->style->value['background']['color']!==null && $this->style->value['background']['image']===null);
  1798. if (in_array($this->style->value['id_balise'], array('fieldset', 'legend', 'div', 'table', 'tr', 'td', 'th')))
  1799. $fill = false;
  1800. // rיcupיration du texte א יcrire, et conversion
  1801. $txt = $param['txt'];
  1802. if ($this->isAfterFloat)
  1803. {
  1804. $txt = ltrim($txt);
  1805. $this->isAfterFloat = false;
  1806. }
  1807. $txt = str_replace('[[page_cu]]', $this->page, $txt);
  1808. if ($this->style->value['text-transform']!='none')
  1809. {
  1810. if ($this->style->value['text-transform']=='capitalize')
  1811. $txt = ucwords($txt);
  1812. else if ($this->style->value['text-transform']=='uppercase')
  1813. $txt = strtoupper($txt);
  1814. else if ($this->style->value['text-transform']=='lowercase')
  1815. $txt = strtolower($txt);
  1816. }
  1817. // tailles du texte
  1818. $h = 1.08*$this->style->value['font-size'];
  1819. $dh = $h*$this->style->value['mini-decal'];
  1820. $lh = $this->style->getLineHeight();
  1821. // identification de l'alignement
  1822. $align = 'L';
  1823. if ($this->style->value['text-align']=='li_right')
  1824. {
  1825. $w = $this->style->value['width'];
  1826. $align = 'R';
  1827. }
  1828. // prי calcul de la taille de chaque mot et de la phrase complete
  1829. $w = 0;
  1830. $words = explode(' ', $txt);
  1831. foreach($words as $k => $word)
  1832. {
  1833. $words[$k] = array($word, $this->pdf->GetStringWidth($word));
  1834. $w+= $words[$k][1];
  1835. }
  1836. $space = $this->pdf->GetStringWidth(' ');
  1837. $w+= $space*(count($words)-1);
  1838. $curr_pos = 0; // position dans le texte
  1839. $curr_max = strlen($txt); // taille maxi du texte
  1840. $maxX = 0; // plus grande largeur du texte apres retour א la ligne
  1841. $x = $this->pdf->getX(); // position du texte
  1842. $y = $this->pdf->getY();
  1843. $dy = $this->getElementY($lh);
  1844. list($left, $right) = $this->getMargins($y); // marges autorisees
  1845. $nb = 0; // nbr de lignes dיcoupיes
  1846. // tant que ca ne rentre pas sur la ligne et qu'on a du texte => on dיcoupe
  1847. while($x+$w>$right && $x<$right && count($words))
  1848. {
  1849. // trouver une phrase qui rentre dans la largeur, en ajoutant les mots 1 א 1
  1850. $i=0;
  1851. $old = array('', 0);
  1852. $str = $words[0];
  1853. $add = false;
  1854. while(($x+$str[1])<$right)
  1855. {
  1856. $i++;
  1857. $add = true;
  1858. array_shift($words);
  1859. $old = $str;
  1860. if (!count($words)) break;
  1861. $str[0].= ' '.$words[0][0];
  1862. $str[1]+= $space+$words[0][1];
  1863. }
  1864. $str = $old;
  1865. // si rien de rentre, et que le premier mot ne rentre de toute facon pas dans une ligne, on le force...
  1866. if ($i==0 && (($left+$words[0][1])>=$right))
  1867. {
  1868. $str = $words[0];
  1869. array_shift($words);
  1870. $i++;
  1871. $add = true;
  1872. }
  1873. $curr_pos+= ($curr_pos ? 1 : 0)+strlen($str[0]);
  1874. // ecriture du bout de phrase extrait et qui rentre
  1875. $wc = ($align=='L' ? $str[1] : $this->style->value['width']);
  1876. if ($right - $left<$wc) $wc = $right - $left;
  1877. /*
  1878. if ($this->pdf->ws)
  1879. {
  1880. $oldSpace = $this->pdf->CurrentFont['cw'][' '];
  1881. $this->pdf->CurrentFont['cw'][' ']*=(1.+$this->pdf->ws);
  1882. $wc = $str[1];
  1883. $this->pdf->CurrentFont['cw'][' '] = $oldSpace;
  1884. }
  1885. */
  1886. if (strlen($str[0]))
  1887. {
  1888. $this->pdf->setXY($this->pdf->getX(), $y+$dh+$dy);
  1889. $this->pdf->Cell($wc, $h, $str[0], 0, 0, $align, $fill, $this->inLink);
  1890. $this->pdf->setXY($this->pdf->getX(), $y);
  1891. }
  1892. $this->maxH = max($this->maxH, $lh);
  1893. // dיtermination de la largeur max
  1894. $maxX = max($maxX, $this->pdf->getX());
  1895. // nouvelle position et nouvelle largeur pour la boucle
  1896. $w-= $str[1];
  1897. $y = $this->pdf->getY();
  1898. $x = $this->pdf->getX();
  1899. $dy = $this->getElementY($lh);
  1900. // si il reste du text א afficher
  1901. if (count($words))
  1902. {
  1903. if ($add) $w-= $space;
  1904. if ($this->forOneLine)
  1905. {
  1906. $this->maxE+= $i+1;
  1907. $this->maxX = max($this->maxX, $maxX);
  1908. return null;
  1909. }
  1910. // retour א la ligne
  1911. $this->o_BR(array('style' => ''), $curr_pos);
  1912. $y = $this->pdf->getY();
  1913. $x = $this->pdf->getX();
  1914. $dy = $this->getElementY($lh);
  1915. // si la prochaine ligne ne rentre pas dans la page => nouvelle page
  1916. if ($y + $h>=$this->pdf->getH() - $this->pdf->getbMargin())
  1917. {
  1918. if (!$this->isInOverflow && !$this->isInFooter)
  1919. {
  1920. $this->setNewPage(null, '', null, $curr_pos);
  1921. $y = $this->pdf->getY();
  1922. $x = $this->pdf->getX();
  1923. $dy = $this->getElementY($lh);
  1924. }
  1925. }
  1926. // ligne suplיmentaire. au bout de 1000 : trop long => erreur
  1927. $nb++;
  1928. if ($nb>1000)
  1929. {
  1930. $txt = ''; foreach($words as $k => $word) $txt.= ($k ? ' ' : '').$word[0];
  1931. throw new HTML2PDF_exception(2, array($txt, $right-$left, $w));
  1932. }
  1933. list($left, $right) = $this->getMargins($y); // marges autorisees
  1934. }
  1935. }
  1936. // si il reste du text apres dיcoupe, c'est qu'il rentre direct => on l'affiche
  1937. if (count($words))
  1938. {
  1939. $txt = ''; foreach($words as $k => $word) $txt.= ($k ? ' ' : '').$word[0];
  1940. /*
  1941. if ($this->pdf->ws)
  1942. {
  1943. $oldSpace = $this->pdf->CurrentFont['cw'][' '];
  1944. $this->pdf->CurrentFont['cw'][' ']*=(1.+$this->pdf->ws);
  1945. $w = $this->pdf->GetStringWidth($txt);
  1946. $this->pdf->CurrentFont['cw'][' '] = $oldSpace;
  1947. }
  1948. */
  1949. $this->pdf->setXY($this->pdf->getX(), $y+$dh+$dy);
  1950. $this->pdf->Cell(($align=='L' ? $w : $this->style->value['width']), $h, $txt, 0, 0, $align, $fill, $this->inLink);
  1951. $this->pdf->setXY($this->pdf->getX(), $y);
  1952. $this->maxH = max($this->maxH, $lh);
  1953. $this->maxE+= count($words);
  1954. }
  1955. // dיtermination des positions MAX
  1956. $maxX = max($maxX, $this->pdf->getX());
  1957. $maxY = $this->pdf->getY()+$h;
  1958. // position maximale globale
  1959. $this->maxX = max($this->maxX, $maxX);
  1960. $this->maxY = max($this->maxY, $maxY);
  1961. return true;
  1962. }
  1963. /**
  1964. * tracer une image
  1965. *
  1966. * @param string nom du fichier source
  1967. * @return null
  1968. */
  1969. protected function Image($src, $sub_li=false)
  1970. {
  1971. // est-ce que c'est une image ?
  1972. $infos=@GetImageSize($src);
  1973. if (count($infos)<2)
  1974. {
  1975. if ($this->testIsImage)
  1976. throw new HTML2PDF_exception(6, $src);
  1977. $src = null;
  1978. $infos = array(16, 16);
  1979. }
  1980. // rיcupיration des dimensions dans l'unitי du PDF
  1981. $wi = $infos[0]/$this->pdf->getK();
  1982. $hi = $infos[1]/$this->pdf->getK();
  1983. // dיtermination des dimensions d'affichage en fonction du style
  1984. if ($this->style->value['width'] && $this->style->value['height'])
  1985. {
  1986. $w = $this->style->value['width'];
  1987. $h = $this->style->value['height'];
  1988. }
  1989. else if ($this->style->value['width'])
  1990. {
  1991. $w = $this->style->value['width'];
  1992. $h = $hi*$w/$wi;
  1993. }
  1994. else if ($this->style->value['height'])
  1995. {
  1996. $h = $this->style->value['height'];
  1997. $w = $wi*$h/$hi;
  1998. }
  1999. else
  2000. {
  2001. $w = 72./96.*$wi;
  2002. $h = 72./96.*$hi;
  2003. }
  2004. // detection du float
  2005. $float = $this->style->getFloat();
  2006. if ($float && $this->maxH)
  2007. if (!$this->o_BR(array()))
  2008. return false;
  2009. // position d'affichage
  2010. $x = $this->pdf->getX();
  2011. $y = $this->pdf->getY();
  2012. // si l'image ne rentre pas dans la ligne => nouvelle ligne
  2013. if (!$float && ($x + $w>$this->pdf->getW() - $this->pdf->getrMargin()) && $this->maxH)
  2014. {
  2015. if ($this->forOneLine) return null;
  2016. $hnl = max($this->maxH, $this->style->getLineHeight());
  2017. $this->setNewLine($hnl);
  2018. $x = $this->pdf->getX();
  2019. $y = $this->pdf->getY();
  2020. }
  2021. // si l'image ne rentre pas dans la page => nouvelle page
  2022. if (
  2023. ($y + $h>$this->pdf->getH() - $this->pdf->getbMargin()) &&
  2024. !$this->isInOverflow
  2025. )
  2026. {
  2027. $this->setNewPage();
  2028. $x = $this->pdf->getX();
  2029. $y = $this->pdf->getY();
  2030. }
  2031. // correction pour l'affichage d'une puce image
  2032. $hT = 0.80*$this->style->value['font-size'];
  2033. if ($sub_li && $h<$hT)
  2034. {
  2035. $y+=($hT-$h);
  2036. }
  2037. $yc = $y-$this->style->value['margin']['t'];
  2038. // dיtermination de la position rיelle d'affichage en fonction du text-align du parent
  2039. $old = $this->style->getOldValues();
  2040. if ( $old['width'])
  2041. {
  2042. $parent_w = $old['width'];
  2043. $parent_x = $x;
  2044. }
  2045. else
  2046. {
  2047. $parent_w = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
  2048. $parent_x = $this->pdf->getlMargin();
  2049. }
  2050. if ($float)
  2051. {
  2052. list($lx, $rx) = $this->getMargins($yc);
  2053. $parent_x = $lx;
  2054. $parent_w = $rx-$lx;
  2055. }
  2056. if ($parent_w>$w && $float!='left')
  2057. {
  2058. 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'];
  2059. }
  2060. // affichage de l'image, et positionnement א la suite
  2061. if (!$this->sub_part && !$this->isSubPart)
  2062. {
  2063. if ($src) $this->pdf->Image($src, $x, $y, $w, $h, '', $this->inLink);
  2064. else
  2065. {
  2066. $this->pdf->setFillColorArray(array(240, 220, 220));
  2067. $this->pdf->Rect($x, $y, $w, $h, 'F');
  2068. }
  2069. }
  2070. $x-= $this->style->value['margin']['l'];
  2071. $y-= $this->style->value['margin']['t'];
  2072. $w+= $this->style->value['margin']['l'] + $this->style->value['margin']['r'];
  2073. $h+= $this->style->value['margin']['t'] + $this->style->value['margin']['b'];
  2074. if ($float=='left')
  2075. {
  2076. $this->maxX = max($this->maxX, $x+$w);
  2077. $this->maxY = max($this->maxY, $y+$h);
  2078. $this->addMargins($float, $x, $y, $x+$w, $y+$h);
  2079. list($lx, $rx) = $this->getMargins($yc);
  2080. $this->pdf->setXY($lx, $yc);
  2081. }
  2082. else if ($float=='right')
  2083. {
  2084. // $this->maxX = max($this->maxX, $x+$w);
  2085. $this->maxY = max($this->maxY, $y+$h);
  2086. $this->addMargins($float, $x, $y, $x+$w, $y+$h);
  2087. list($lx, $rx) = $this->getMargins($yc);
  2088. $this->pdf->setXY($lx, $yc);
  2089. }
  2090. else
  2091. {
  2092. $this->pdf->setX($x+$w);
  2093. $this->maxX = max($this->maxX, $x+$w);
  2094. $this->maxY = max($this->maxY, $y+$h);
  2095. $this->maxH = max($this->maxH, $h);
  2096. }
  2097. return true;
  2098. }
  2099. /**
  2100. * Tracer un rectanble
  2101. *
  2102. * @param float position X
  2103. * @param float position Y
  2104. * @param float Largeur
  2105. * @param float Hauteur
  2106. * @param array Tableau de style de dיfinition des borders
  2107. * @param float padding - marge intיrieur au rectangle => non utile mais on le passe en paramטtre
  2108. * @param float margin - marge exterieur au rectangle
  2109. * @param array Tableau de style de dיfinition du background
  2110. * @return null
  2111. */
  2112. protected function drawRectangle($x, $y, $w, $h, $border, $padding, $margin, $background)
  2113. {
  2114. if ($this->sub_part || $this->isSubPart) return false;
  2115. if ($h===null) return false;
  2116. $x+= $margin;
  2117. $y+= $margin;
  2118. $w-= $margin*2;
  2119. $h-= $margin*2;
  2120. // rיcupיration des radius
  2121. $out_TL = $border['radius']['tl'];
  2122. $out_TR = $border['radius']['tr'];
  2123. $out_BR = $border['radius']['br'];
  2124. $out_BL = $border['radius']['bl'];
  2125. // verification des coins en radius
  2126. $out_TL = ($out_TL[0] && $out_TL[1]) ? $out_TL : null;
  2127. $out_TR = ($out_TR[0] && $out_TR[1]) ? $out_TR : null;
  2128. $out_BR = ($out_BR[0] && $out_BR[1]) ? $out_BR : null;
  2129. $out_BL = ($out_BL[0] && $out_BL[1]) ? $out_BL : null;
  2130. $in_TL = $out_TL;
  2131. $in_TR = $out_TR;
  2132. $in_BR = $out_BR;
  2133. $in_BL = $out_BL;
  2134. if (is_array($in_TL)) { $in_TL[0]-= $border['l']['width']; $in_TL[1]-= $border['t']['width']; }
  2135. if (is_array($in_TR)) { $in_TR[0]-= $border['r']['width']; $in_TR[1]-= $border['t']['width']; }
  2136. if (is_array($in_BR)) { $in_BR[0]-= $border['r']['width']; $in_BR[1]-= $border['b']['width']; }
  2137. if (is_array($in_BL)) { $in_BL[0]-= $border['l']['width']; $in_BL[1]-= $border['b']['width']; }
  2138. if ($in_TL[0]<=0 || $in_TL[1]<=0) $in_TL = null;
  2139. if ($in_TR[0]<=0 || $in_TR[1]<=0) $in_TR = null;
  2140. if ($in_BR[0]<=0 || $in_BR[1]<=0) $in_BR = null;
  2141. if ($in_BL[0]<=0 || $in_BL[1]<=0) $in_BL = null;
  2142. // traitement de la couleur de fond
  2143. $STYLE = '';
  2144. if ($background['color'])
  2145. {
  2146. $this->pdf->setFillColorArray($background['color']);
  2147. $STYLE.= 'F';
  2148. }
  2149. if ($STYLE)
  2150. {
  2151. $this->pdf->clippingPathOpen($x, $y, $w, $h, $out_TL,$out_TR, $out_BL, $out_BR);
  2152. $this->pdf->Rect($x, $y, $w, $h, $STYLE);
  2153. $this->pdf->clippingPathClose();
  2154. }
  2155. // traitement de l'image de fond
  2156. if ($background['image'])
  2157. {
  2158. $i_name = $background['image'];
  2159. $i_position = $background['position']!==null ? $background['position'] : array(0, 0);
  2160. $i_repeat = $background['repeat']!==null ? $background['repeat'] : array(true, true);
  2161. // taile du fond (il faut retirer les borders
  2162. $b_x = $x;
  2163. $b_y = $y;
  2164. $b_w = $w;
  2165. $b_h = $h;
  2166. if ($border['b']['width']) { $b_h-= $border['b']['width']; }
  2167. if ($border['l']['width']) { $b_w-= $border['l']['width']; $b_x+= $border['l']['width']; }
  2168. if ($border['t']['width']) { $b_h-= $border['t']['width']; $b_y+= $border['t']['width']; }
  2169. if ($border['r']['width']) { $b_w-= $border['r']['width']; }
  2170. // est-ce que c'est une image ?
  2171. $i_infos=@GetImageSize($i_name);
  2172. if (count($i_infos)<2)
  2173. {
  2174. if ($this->testIsImage)
  2175. throw new HTML2PDF_exception(6, $i_name);
  2176. }
  2177. else
  2178. {
  2179. // rיcupיration des dimensions dans l'unitי du PDF
  2180. $i_width = 72./96.*$i_infos[0]/$this->pdf->getK();
  2181. $i_height = 72./96.*$i_infos[1]/$this->pdf->getK();
  2182. if ($i_repeat[0]) $i_position[0] = $b_x;
  2183. else if(preg_match('/^([-]?[0-9\.]+)%/isU', $i_position[0], $match)) $i_position[0] = $b_x + $match[1]*($b_w-$i_width)/100;
  2184. else $i_position[0] = $b_x+$i_position[0];
  2185. if ($i_repeat[1]) $i_position[1] = $b_y;
  2186. else if(preg_match('/^([-]?[0-9\.]+)%/isU', $i_position[1], $match)) $i_position[1] = $b_y + $match[1]*($b_h-$i_height)/100;
  2187. else $i_position[1] = $b_y+$i_position[1];
  2188. $i_x_min = $b_x;
  2189. $i_x_max = $b_x+$b_w;
  2190. $i_y_min = $b_y;
  2191. $i_y_max = $b_y+$b_h;
  2192. if (!$i_repeat[0] && !$i_repeat[1])
  2193. {
  2194. $i_x_min = $i_position[0]; $i_x_max = $i_position[0]+$i_width;
  2195. $i_y_min = $i_position[1]; $i_y_max = $i_position[1]+$i_height;
  2196. }
  2197. else if ($i_repeat[0] && !$i_repeat[1])
  2198. {
  2199. $i_y_min = $i_position[1]; $i_y_max = $i_position[1]+$i_height;
  2200. }
  2201. elseif (!$i_repeat[0] && $i_repeat[1])
  2202. {
  2203. $i_x_min = $i_position[0]; $i_x_max = $i_position[0]+$i_width;
  2204. }
  2205. $this->pdf->clippingPathOpen($b_x, $b_y, $b_w, $b_h, $in_TL, $in_TR, $in_BL, $in_BR);
  2206. for ($i_y=$i_y_min; $i_y<$i_y_max; $i_y+=$i_height)
  2207. {
  2208. for ($i_x=$i_x_min; $i_x<$i_x_max; $i_x+=$i_width)
  2209. {
  2210. $c_x = null;
  2211. $c_y = null;
  2212. $c_w = $i_width;
  2213. $c_h = $i_height;
  2214. if ($i_y_max-$i_y<$i_height)
  2215. {
  2216. $c_x = $i_x;
  2217. $c_y = $i_y;
  2218. $c_h = $i_y_max-$i_y;
  2219. }
  2220. if ($i_x_max-$i_x<$i_width)
  2221. {
  2222. $c_x = $i_x;
  2223. $c_y = $i_y;
  2224. $c_w = $i_x_max-$i_x;
  2225. }
  2226. $this->pdf->Image($i_name, $i_x, $i_y, $i_width, $i_height, '', '');
  2227. }
  2228. }
  2229. $this->pdf->clippingPathClose();
  2230. }
  2231. }
  2232. $x-= 0.01;
  2233. $y-= 0.01;
  2234. $w+= 0.02;
  2235. $h+= 0.02;
  2236. if ($border['l']['width']) $border['l']['width']+= 0.02;
  2237. if ($border['t']['width']) $border['t']['width']+= 0.02;
  2238. if ($border['r']['width']) $border['r']['width']+= 0.02;
  2239. if ($border['b']['width']) $border['b']['width']+= 0.02;
  2240. $Bl = ($border['l']['width'] && $border['l']['color'][0]!==null);
  2241. $Bt = ($border['t']['width'] && $border['t']['color'][0]!==null);
  2242. $Br = ($border['r']['width'] && $border['r']['color'][0]!==null);
  2243. $Bb = ($border['b']['width'] && $border['b']['color'][0]!==null);
  2244. if (is_array($out_BL) && ($Bb || $Bl))
  2245. {
  2246. if ($in_BL)
  2247. {
  2248. $courbe = array();
  2249. $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h;
  2250. $courbe[] = $x; $courbe[] = $y+$h-$out_BL[1];
  2251. $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h-$border['b']['width'];
  2252. $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$h-$out_BL[1];
  2253. $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h-$out_BL[1];
  2254. }
  2255. else
  2256. {
  2257. $courbe = array();
  2258. $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h;
  2259. $courbe[] = $x; $courbe[] = $y+$h-$out_BL[1];
  2260. $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$h-$border['b']['width'];
  2261. $courbe[] = $x+$out_BL[0]; $courbe[] = $y+$h-$out_BL[1];
  2262. }
  2263. $this->drawCourbe($courbe, $border['l']['color']);
  2264. }
  2265. if (is_array($out_TL) && ($Bt || $Bl))
  2266. {
  2267. if ($in_TL)
  2268. {
  2269. $courbe = array();
  2270. $courbe[] = $x; $courbe[] = $y+$out_TL[1];
  2271. $courbe[] = $x+$out_TL[0]; $courbe[] = $y;
  2272. $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$out_TL[1];
  2273. $courbe[] = $x+$out_TL[0]; $courbe[] = $y+$border['t']['width'];
  2274. $courbe[] = $x+$out_TL[0]; $courbe[] = $y+$out_TL[1];
  2275. }
  2276. else
  2277. {
  2278. $courbe = array();
  2279. $courbe[] = $x; $courbe[] = $y+$out_TL[1];
  2280. $courbe[] = $x+$out_TL[0]; $courbe[] = $y;
  2281. $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$border['t']['width'];
  2282. $courbe[] = $x+$out_TL[0]; $courbe[] = $y+$out_TL[1];
  2283. }
  2284. $this->drawCourbe($courbe, $border['t']['color']);
  2285. }
  2286. if (is_array($out_TR) && ($Bt || $Br))
  2287. {
  2288. if ($in_TR)
  2289. {
  2290. $courbe = array();
  2291. $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y;
  2292. $courbe[] = $x+$w; $courbe[] = $y+$out_TR[1];
  2293. $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y+$border['t']['width'];
  2294. $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$out_TR[1];
  2295. $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y+$out_TR[1];
  2296. }
  2297. else
  2298. {
  2299. $courbe = array();
  2300. $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y;
  2301. $courbe[] = $x+$w; $courbe[] = $y+$out_TR[1];
  2302. $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$border['t']['width'];
  2303. $courbe[] = $x+$w-$out_TR[0]; $courbe[] = $y+$out_TR[1];
  2304. }
  2305. $this->drawCourbe($courbe, $border['r']['color']);
  2306. }
  2307. if (is_array($out_BR) && ($Bb || $Br))
  2308. {
  2309. if ($in_BR)
  2310. {
  2311. $courbe = array();
  2312. $courbe[] = $x+$w; $courbe[] = $y+$h-$out_BR[1];
  2313. $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h;
  2314. $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$h-$out_BR[1];
  2315. $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h-$border['b']['width'];
  2316. $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h-$out_BR[1];
  2317. }
  2318. else
  2319. {
  2320. $courbe = array();
  2321. $courbe[] = $x+$w; $courbe[] = $y+$h-$out_BR[1];
  2322. $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h;
  2323. $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$h-$border['b']['width'];
  2324. $courbe[] = $x+$w-$out_BR[0]; $courbe[] = $y+$h-$out_BR[1];
  2325. }
  2326. $this->drawCourbe($courbe, $border['b']['color']);
  2327. }
  2328. if ($Bl)
  2329. {
  2330. $pt = array();
  2331. $pt[] = $x; $pt[] = $y+$h;
  2332. $pt[] = $x; $pt[] = $y+$h-$border['b']['width'];
  2333. $pt[] = $x; $pt[] = $y+$border['t']['width'];
  2334. $pt[] = $x; $pt[] = $y;
  2335. $pt[] = $x+$border['l']['width']; $pt[] = $y+$border['t']['width'];
  2336. $pt[] = $x+$border['l']['width']; $pt[] = $y+$h-$border['b']['width'];
  2337. $bord = 3;
  2338. if (is_array($out_BL))
  2339. {
  2340. $bord-=1;
  2341. $pt[3] -= $out_BL[1] - $border['b']['width'];
  2342. if ($in_BL) $pt[11]-= $in_BL[1];
  2343. unset($pt[0]);unset($pt[1]);
  2344. }
  2345. if (is_array($out_TL))
  2346. {
  2347. $bord-=2;
  2348. $pt[5] += $out_TL[1]-$border['t']['width'];
  2349. if ($in_TL) $pt[9] += $in_TL[1];
  2350. unset($pt[6]);unset($pt[7]);
  2351. }
  2352. $pt = array_values($pt);
  2353. $this->drawLine($pt, $border['l']['color'], $border['l']['type'], $border['l']['width'], $bord);
  2354. }
  2355. if ($Bt)
  2356. {
  2357. $pt = array();
  2358. $pt[] = $x; $pt[] = $y;
  2359. $pt[] = $x+$border['l']['width']; $pt[] = $y;
  2360. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y;
  2361. $pt[] = $x+$w; $pt[] = $y;
  2362. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$border['t']['width'];
  2363. $pt[] = $x+$border['l']['width']; $pt[] = $y+$border['t']['width'];
  2364. $bord = 3;
  2365. if (is_array($out_TL))
  2366. {
  2367. $bord-=1;
  2368. $pt[2] += $out_TL[0] - $border['l']['width'];
  2369. if ($in_TL) $pt[10]+= $in_TL[0];
  2370. unset($pt[0]);unset($pt[1]);
  2371. }
  2372. if (is_array($out_TR))
  2373. {
  2374. $bord-=2;
  2375. $pt[4] -= $out_TR[0] - $border['r']['width'];
  2376. if ($in_TR) $pt[8] -= $in_TR[0];
  2377. unset($pt[6]);unset($pt[7]);
  2378. }
  2379. $pt = array_values($pt);
  2380. $this->drawLine($pt, $border['t']['color'], $border['t']['type'], $border['t']['width'], $bord);
  2381. }
  2382. if ($Br)
  2383. {
  2384. $pt = array();
  2385. $pt[] = $x+$w; $pt[] = $y;
  2386. $pt[] = $x+$w; $pt[] = $y+$border['t']['width'];
  2387. $pt[] = $x+$w; $pt[] = $y+$h-$border['b']['width'];
  2388. $pt[] = $x+$w; $pt[] = $y+$h;
  2389. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h-$border['b']['width'];
  2390. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$border['t']['width'];
  2391. $bord = 3;
  2392. if (is_array($out_TR))
  2393. {
  2394. $bord-=1;
  2395. $pt[3] += $out_TR[1] - $border['t']['width'];
  2396. if ($in_TR) $pt[11]+= $in_TR[1];
  2397. unset($pt[0]);unset($pt[1]);
  2398. }
  2399. if (is_array($out_BR))
  2400. {
  2401. $bord-=2;
  2402. $pt[5] -= $out_BR[1] - $border['b']['width'];
  2403. if ($in_BR) $pt[9] -= $in_BR[1];
  2404. unset($pt[6]);unset($pt[7]);
  2405. }
  2406. $pt = array_values($pt);
  2407. $this->drawLine($pt, $border['r']['color'], $border['r']['type'], $border['r']['width'], $bord);
  2408. }
  2409. if ($Bb)
  2410. {
  2411. $pt = array();
  2412. $pt[] = $x+$w; $pt[] = $y+$h;
  2413. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h;
  2414. $pt[] = $x+$border['l']['width']; $pt[] = $y+$h;
  2415. $pt[] = $x; $pt[] = $y+$h;
  2416. $pt[] = $x+$border['l']['width']; $pt[] = $y+$h-$border['b']['width'];
  2417. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h-$border['b']['width'];
  2418. $bord = 3;
  2419. if (is_array($out_BL))
  2420. {
  2421. $bord-=2;
  2422. $pt[4] += $out_BL[0] - $border['l']['width'];
  2423. if ($in_BL) $pt[8] += $in_BL[0];
  2424. unset($pt[6]);unset($pt[7]);
  2425. }
  2426. if (is_array($out_BR))
  2427. {
  2428. $bord-=1;
  2429. $pt[2] -= $out_BR[0] - $border['r']['width'];
  2430. if ($in_BR) $pt[10]-= $in_BR[0];
  2431. unset($pt[0]);unset($pt[1]);
  2432. }
  2433. $pt = array_values($pt);
  2434. $this->drawLine($pt, $border['b']['color'], $border['b']['type'], $border['b']['width'], $bord);
  2435. }
  2436. if ($background['color'])
  2437. {
  2438. $this->pdf->setFillColorArray($background['color']);
  2439. }
  2440. }
  2441. protected function drawCourbe($pt, $color)
  2442. {
  2443. $this->pdf->setFillColorArray($color);
  2444. if (count($pt)==10)
  2445. $this->pdf->drawCourbe($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7], $pt[8], $pt[9]);
  2446. else
  2447. $this->pdf->drawCoin($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7]);
  2448. }
  2449. /**
  2450. * Tracer une ligne epaisse dיfini par ses points avec des extreminites en biseau
  2451. *
  2452. * @param array liste des points definissant le tour de la ligne
  2453. * @param float couleur RVB
  2454. * @param string type de ligne
  2455. * @param float largeur de la ligne
  2456. * @return null
  2457. */
  2458. protected function drawLine($pt, $color, $type, $width, $bord=3)
  2459. {
  2460. $this->pdf->setFillColorArray($color);
  2461. if ($type=='dashed' || $type=='dotted')
  2462. {
  2463. if ($bord==1)
  2464. {
  2465. $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
  2466. $this->pdf->Polygon($tmp, 'F');
  2467. $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];
  2468. $pt = $tmp;
  2469. }
  2470. else if ($bord==2)
  2471. {
  2472. $tmp = array(); $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7];
  2473. $this->pdf->Polygon($tmp, 'F');
  2474. $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];
  2475. $pt = $tmp;
  2476. }
  2477. else if ($bord==3)
  2478. {
  2479. $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[10]; $tmp[]=$pt[11];
  2480. $this->pdf->Polygon($tmp, 'F');
  2481. $tmp = array(); $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
  2482. $this->pdf->Polygon($tmp, 'F');
  2483. $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];
  2484. $pt = $tmp;
  2485. }
  2486. if ($pt[2]==$pt[0])
  2487. {
  2488. $l = abs(($pt[3]-$pt[1])*0.5);
  2489. $px = 0;
  2490. $py = $width;
  2491. $x1 = $pt[0]; $y1 = ($pt[3]+$pt[1])*0.5;
  2492. $x2 = $pt[6]; $y2 = ($pt[7]+$pt[5])*0.5;
  2493. }
  2494. else
  2495. {
  2496. $l = abs(($pt[2]-$pt[0])*0.5);
  2497. $px = $width;
  2498. $py = 0;
  2499. $x1 = ($pt[2]+$pt[0])*0.5; $y1 = $pt[1];
  2500. $x2 = ($pt[6]+$pt[4])*0.5; $y2 = $pt[7];
  2501. }
  2502. if ($type=='dashed')
  2503. {
  2504. $px = $px*3.;
  2505. $py = $py*3.;
  2506. }
  2507. $mode = ($l/($px+$py)<.5);
  2508. for($i=0; $l-($px+$py)*($i-0.5)>0; $i++)
  2509. {
  2510. if (($i%2)==$mode)
  2511. {
  2512. $j = $i-0.5;
  2513. $lx1 = $px*($j); if ($lx1<-$l) $lx1 =-$l;
  2514. $ly1 = $py*($j); if ($ly1<-$l) $ly1 =-$l;
  2515. $lx2 = $px*($j+1); if ($lx2>$l) $lx2 = $l;
  2516. $ly2 = $py*($j+1); if ($ly2>$l) $ly2 = $l;
  2517. $tmp = array();
  2518. $tmp[] = $x1+$lx1; $tmp[] = $y1+$ly1;
  2519. $tmp[] = $x1+$lx2; $tmp[] = $y1+$ly2;
  2520. $tmp[] = $x2+$lx2; $tmp[] = $y2+$ly2;
  2521. $tmp[] = $x2+$lx1; $tmp[] = $y2+$ly1;
  2522. $this->pdf->Polygon($tmp, 'F');
  2523. if ($j>0)
  2524. {
  2525. $tmp = array();
  2526. $tmp[] = $x1-$lx1; $tmp[] = $y1-$ly1;
  2527. $tmp[] = $x1-$lx2; $tmp[] = $y1-$ly2;
  2528. $tmp[] = $x2-$lx2; $tmp[] = $y2-$ly2;
  2529. $tmp[] = $x2-$lx1; $tmp[] = $y2-$ly1;
  2530. $this->pdf->Polygon($tmp, 'F');
  2531. }
  2532. }
  2533. }
  2534. }
  2535. else if ($type=='double')
  2536. {
  2537. $pt1 = $pt;
  2538. $pt2 = $pt;
  2539. if (count($pt)==12)
  2540. {
  2541. $pt1[0] = ($pt[0]-$pt[10])*0.33 + $pt[10];
  2542. $pt1[1] = ($pt[1]-$pt[11])*0.33 + $pt[11];
  2543. $pt1[2] = ($pt[2]-$pt[10])*0.33 + $pt[10];
  2544. $pt1[3] = ($pt[3]-$pt[11])*0.33 + $pt[11];
  2545. $pt1[4] = ($pt[4]-$pt[8])*0.33 + $pt[8];
  2546. $pt1[5] = ($pt[5]-$pt[9])*0.33 + $pt[9];
  2547. $pt1[6] = ($pt[6]-$pt[8])*0.33 + $pt[8];
  2548. $pt1[7] = ($pt[7]-$pt[9])*0.33 + $pt[9];
  2549. $pt2[10]= ($pt[10]-$pt[0])*0.33 + $pt[0];
  2550. $pt2[11]= ($pt[11]-$pt[1])*0.33 + $pt[1];
  2551. $pt2[2] = ($pt[2] -$pt[0])*0.33 + $pt[0];
  2552. $pt2[3] = ($pt[3] -$pt[1])*0.33 + $pt[1];
  2553. $pt2[4] = ($pt[4] -$pt[6])*0.33 + $pt[6];
  2554. $pt2[5] = ($pt[5] -$pt[7])*0.33 + $pt[7];
  2555. $pt2[8] = ($pt[8] -$pt[6])*0.33 + $pt[6];
  2556. $pt2[9] = ($pt[9] -$pt[7])*0.33 + $pt[7];
  2557. }
  2558. else
  2559. {
  2560. $pt1[0] = ($pt[0]-$pt[6])*0.33 + $pt[6];
  2561. $pt1[1] = ($pt[1]-$pt[7])*0.33 + $pt[7];
  2562. $pt1[2] = ($pt[2]-$pt[4])*0.33 + $pt[4];
  2563. $pt1[3] = ($pt[3]-$pt[5])*0.33 + $pt[5];
  2564. $pt2[6] = ($pt[6]-$pt[0])*0.33 + $pt[0];
  2565. $pt2[7] = ($pt[7]-$pt[1])*0.33 + $pt[1];
  2566. $pt2[4] = ($pt[4]-$pt[2])*0.33 + $pt[2];
  2567. $pt2[5] = ($pt[5]-$pt[3])*0.33 + $pt[3];
  2568. }
  2569. $this->pdf->Polygon($pt1, 'F');
  2570. $this->pdf->Polygon($pt2, 'F');
  2571. }
  2572. else if ($type=='solid')
  2573. {
  2574. $this->pdf->Polygon($pt, 'F');
  2575. }
  2576. }
  2577. /**
  2578. * balise : BR
  2579. * mode : OUVERTURE
  2580. *
  2581. * @param array paramטtres de l'יlיment de parsing
  2582. * @param integer position reelle courante si saut de ligne pendant l'ecriture d'un texte
  2583. * @return null
  2584. */
  2585. protected function o_BR($param, $curr = null)
  2586. {
  2587. if ($this->forOneLine) return false;
  2588. $h = max($this->maxH, $this->style->getLineHeight());
  2589. // si la ligne est vide, la position maximale n'a pas יtי mise א jour => on la met א jour
  2590. if ($this->maxH==0) $this->maxY = max($this->maxY, $this->pdf->getY()+$h);
  2591. $this->makeBR($h, $curr);
  2592. $this->maxH = 0;
  2593. return true;
  2594. }
  2595. protected function makeBR($h, $curr = null)
  2596. {
  2597. // si le saut de ligne rentre => on le prend en compte, sinon nouvelle page
  2598. if ($h)
  2599. {
  2600. if (($this->pdf->getY()+$h<$this->pdf->getH() - $this->pdf->getbMargin()) || $this->isInOverflow || $this->isInFooter)
  2601. $this->setNewLine($h, $curr);
  2602. else
  2603. $this->setNewPage(null, '', null, $curr);
  2604. }
  2605. else
  2606. {
  2607. $this->setNewPositionForNewLine($curr);
  2608. }
  2609. $this->maxH = 0;
  2610. }
  2611. /**
  2612. * balise : HR
  2613. * mode : OUVERTURE
  2614. *
  2615. * @param array paramטtres de l'יlיment de parsing
  2616. * @return null
  2617. */
  2618. protected function o_HR($param)
  2619. {
  2620. if ($this->forOneLine) return false;
  2621. $old_align = $this->style->value['text-align'];
  2622. $this->style->value['text-align'] = 'left';
  2623. if ($this->maxH) $this->o_BR($param);
  2624. $f_size = $this->style->value['font-size'];
  2625. $this->style->value['font-size']=$f_size*0.5; $this->o_BR($param);
  2626. $this->style->value['font-size']=0;
  2627. $param['style']['width'] = '100%';
  2628. $this->style->save();
  2629. $this->style->value['height']=$this->style->ConvertToMM('1mm');
  2630. $this->style->analyse('hr', $param);
  2631. $this->style->setPosition();
  2632. $this->style->FontSet();
  2633. $h = $this->style->value['height'];
  2634. if ($h) $h-= $this->style->value['border']['t']['width']+$this->style->value['border']['b']['width'];
  2635. if ($h<=0) $h = $this->style->value['border']['t']['width']+$this->style->value['border']['b']['width'];
  2636. $this->drawRectangle($this->pdf->getX(), $this->pdf->getY(), $this->style->value['width'], $h, $this->style->value['border'], 0, 0, $this->style->value['background']);
  2637. $this->maxH = $h;
  2638. $this->style->load();
  2639. $this->style->FontSet();
  2640. $this->o_BR($param);
  2641. $this->style->value['font-size']=$f_size*0.5; $this->o_BR($param);
  2642. $this->style->value['font-size']=$f_size;
  2643. $this->style->value['text-align'] = $old_align;
  2644. $this->setNewPositionForNewLine();
  2645. return true;
  2646. }
  2647. /**
  2648. * balise : B
  2649. * mode : OUVERTURE
  2650. *
  2651. * @param array paramטtres de l'יlיment de parsing
  2652. * @return null
  2653. */
  2654. protected function o_B($param, $other = 'b')
  2655. {
  2656. $this->style->save();
  2657. $this->style->value['font-bold'] = true;
  2658. $this->style->analyse($other, $param);
  2659. $this->style->setPosition();
  2660. $this->style->FontSet();
  2661. return true;
  2662. }
  2663. protected function o_STRONG($param) { return $this->o_B($param, 'strong'); }
  2664. /**
  2665. * balise : B
  2666. * mode : FERMETURE
  2667. *
  2668. * @param array paramטtres de l'יlיment de parsing
  2669. * @return null
  2670. */
  2671. protected function c_B($param)
  2672. {
  2673. $this->style->load();
  2674. $this->style->FontSet();
  2675. return true;
  2676. }
  2677. protected function c_STRONG($param) { return $this->c_B($param); }
  2678. /**
  2679. * balise : I
  2680. * mode : OUVERTURE
  2681. *
  2682. * @param array paramטtres de l'יlיment de parsing
  2683. * @return null
  2684. */
  2685. protected function o_I($param, $other = 'i')
  2686. {
  2687. $this->style->save();
  2688. $this->style->value['font-italic'] = true;
  2689. $this->style->analyse($other, $param);
  2690. $this->style->setPosition();
  2691. $this->style->FontSet();
  2692. return true;
  2693. }
  2694. protected function o_ADDRESS($param) { return $this->o_I($param, 'address'); }
  2695. protected function o_CITE($param) { return $this->o_I($param, 'cite'); }
  2696. protected function o_EM($param) { return $this->o_I($param, 'em'); }
  2697. protected function o_SAMP($param) { return $this->o_I($param, 'samp'); }
  2698. /**
  2699. * balise : I
  2700. * mode : FERMETURE
  2701. *
  2702. * @param array paramטtres de l'יlיment de parsing
  2703. * @return null
  2704. */
  2705. protected function c_I($param)
  2706. {
  2707. $this->style->load();
  2708. $this->style->FontSet();
  2709. return true;
  2710. }
  2711. protected function c_ADDRESS($param) { return $this->c_I($param); }
  2712. protected function c_CITE($param) { return $this->c_I($param); }
  2713. protected function c_EM($param) { return $this->c_I($param); }
  2714. protected function c_SAMP($param) { return $this->c_I($param); }
  2715. /**
  2716. * balise : S
  2717. * mode : OUVERTURE
  2718. *
  2719. * @param array paramטtres de l'יlיment de parsing
  2720. * @return null
  2721. */
  2722. protected function o_S($param, $other = 's')
  2723. {
  2724. $this->style->save();
  2725. $this->style->value['font-linethrough'] = true;
  2726. $this->style->analyse($other, $param);
  2727. $this->style->setPosition();
  2728. $this->style->FontSet();
  2729. return true;
  2730. }
  2731. protected function o_DEL($param) { return $this->o_S($param, 'del'); }
  2732. /**
  2733. * balise : S
  2734. * mode : FERMETURE
  2735. *
  2736. * @param array paramטtres de l'יlיment de parsing
  2737. * @return null
  2738. */
  2739. protected function c_S($param)
  2740. {
  2741. $this->style->load();
  2742. $this->style->FontSet();
  2743. return true;
  2744. }
  2745. protected function c_DEL($param) { return $this->c_S($param); }
  2746. /**
  2747. * balise : U
  2748. * mode : OUVERTURE
  2749. *
  2750. * @param array paramטtres de l'יlיment de parsing
  2751. * @return null
  2752. */
  2753. protected function o_U($param, $other='u')
  2754. {
  2755. $this->style->save();
  2756. $this->style->value['font-underline'] = true;
  2757. $this->style->analyse($other, $param);
  2758. $this->style->setPosition();
  2759. $this->style->FontSet();
  2760. return true;
  2761. }
  2762. protected function o_INS($param) { return $this->o_U($param, 'ins'); }
  2763. /**
  2764. * balise : U
  2765. * mode : FERMETURE
  2766. *
  2767. * @param array paramטtres de l'יlיment de parsing
  2768. * @return null
  2769. */
  2770. protected function c_U($param)
  2771. {
  2772. $this->style->load();
  2773. $this->style->FontSet();
  2774. return true;
  2775. }
  2776. protected function c_INS($param) { return $this->c_U($param); }
  2777. /**
  2778. * balise : A
  2779. * mode : OUVERTURE
  2780. *
  2781. * @param array paramטtres de l'יlיment de parsing
  2782. * @return null
  2783. */
  2784. protected function o_A($param)
  2785. {
  2786. $this->inLink = str_replace('&amp;', '&', isset($param['href']) ? $param['href'] : '');
  2787. if (isset($param['name']))
  2788. {
  2789. $nom = $param['name'];
  2790. if (!isset($this->lstAncre[$nom])) $this->lstAncre[$nom] = array($this->pdf->AddLink(), false);
  2791. if (!$this->lstAncre[$nom][1])
  2792. {
  2793. $this->lstAncre[$nom][1] = true;
  2794. $this->pdf->SetLink($this->lstAncre[$nom][0], -1, -1);
  2795. }
  2796. }
  2797. if (preg_match('/^#([^#]+)$/isU', $this->inLink, $match))
  2798. {
  2799. $nom = $match[1];
  2800. if (!isset($this->lstAncre[$nom])) $this->lstAncre[$nom] = array($this->pdf->AddLink(), false);
  2801. $this->inLink = $this->lstAncre[$nom][0];
  2802. }
  2803. $this->style->save();
  2804. $this->style->value['font-underline'] = true;
  2805. $this->style->value['color'] = array(20, 20, 250);
  2806. $this->style->analyse('a', $param);
  2807. $this->style->setPosition();
  2808. $this->style->FontSet();
  2809. return true;
  2810. }
  2811. /**
  2812. * balise : A
  2813. * mode : FERMETURE
  2814. *
  2815. * @param array paramטtres de l'יlיment de parsing
  2816. * @return null
  2817. */
  2818. protected function c_A($param)
  2819. {
  2820. $this->inLink = '';
  2821. $this->style->load();
  2822. $this->style->FontSet();
  2823. return true;
  2824. }
  2825. /**
  2826. * balise : H1
  2827. * mode : OUVERTURE
  2828. *
  2829. * @param array paramטtres de l'יlיment de parsing
  2830. * @return null
  2831. */
  2832. protected function o_H1($param, $other = 'h1')
  2833. {
  2834. if ($this->forOneLine) return false;
  2835. if ($this->maxH) $this->o_BR(array());
  2836. $this->style->save();
  2837. $this->style->value['font-bold'] = true;
  2838. $size = array('h1' => '28px', 'h2' => '24px', 'h3' => '20px', 'h4' => '16px', 'h5' => '12px', 'h6' => '9px');
  2839. $this->style->value['margin']['l'] = 0;
  2840. $this->style->value['margin']['r'] = 0;
  2841. $this->style->value['margin']['t'] = $this->style->ConvertToMM('16px');
  2842. $this->style->value['margin']['b'] = $this->style->ConvertToMM('16px');
  2843. $this->style->value['font-size'] = $this->style->ConvertToMM($size[$other]);
  2844. $this->style->analyse($other, $param);
  2845. $this->style->setPosition();
  2846. $this->style->FontSet();
  2847. $this->setNewPositionForNewLine();
  2848. return true;
  2849. }
  2850. protected function o_H2($param) { return $this->o_H1($param, 'h2'); }
  2851. protected function o_H3($param) { return $this->o_H1($param, 'h3'); }
  2852. protected function o_H4($param) { return $this->o_H1($param, 'h4'); }
  2853. protected function o_H5($param) { return $this->o_H1($param, 'h5'); }
  2854. protected function o_H6($param) { return $this->o_H1($param, 'h6'); }
  2855. /**
  2856. * balise : H1
  2857. * mode : FERMETURE
  2858. *
  2859. * @param array paramטtres de l'יlיment de parsing
  2860. * @return null
  2861. */
  2862. protected function c_H1($param)
  2863. {
  2864. if ($this->forOneLine) return false;
  2865. // hauteur du H1
  2866. $this->maxH+= $this->style->value['margin']['b'];
  2867. $h = max($this->maxH, $this->style->getLineHeight());
  2868. $this->style->load();
  2869. $this->style->FontSet();
  2870. // saut de ligne et initialisation de la hauteur
  2871. $this->makeBR($h);
  2872. $this->maxH = 0;
  2873. return true;
  2874. }
  2875. protected function c_H2($param) { return $this->c_H1($param); }
  2876. protected function c_H3($param) { return $this->c_H1($param); }
  2877. protected function c_H4($param) { return $this->c_H1($param); }
  2878. protected function c_H5($param) { return $this->c_H1($param); }
  2879. protected function c_H6($param) { return $this->c_H1($param); }
  2880. /**
  2881. * balise : SPAN
  2882. * mode : OUVERTURE
  2883. *
  2884. * @param array paramטtres de l'יlיment de parsing
  2885. * @return null
  2886. */
  2887. protected function o_SPAN($param, $other = 'span')
  2888. {
  2889. $this->style->save();
  2890. $this->style->analyse($other, $param);
  2891. $this->style->setPosition();
  2892. $this->style->FontSet();
  2893. return true;
  2894. }
  2895. protected function o_FONT($param) { return $this->o_SPAN($param, 'font'); }
  2896. protected function o_LABEL($param) { return $this->o_SPAN($param, 'label');}
  2897. /**
  2898. * balise : SPAN
  2899. * mode : FERMETURE
  2900. *
  2901. * @param array paramטtres de l'יlיment de parsing
  2902. * @return null
  2903. */
  2904. protected function c_SPAN($param)
  2905. {
  2906. $this->style->restorePosition();
  2907. $this->style->load();
  2908. $this->style->FontSet();
  2909. return true;
  2910. }
  2911. protected function c_FONT($param) { return $this->c_SPAN($param); }
  2912. protected function c_LABEL($param) { return $this->c_SPAN($param); }
  2913. /**
  2914. * balise : P
  2915. * mode : OUVERTURE
  2916. *
  2917. * @param array paramטtres de l'יlיment de parsing
  2918. * @return null
  2919. */
  2920. protected function o_P($param)
  2921. {
  2922. if ($this->forOneLine) return false;
  2923. if (!in_array($this->previousCall, array('c_P', 'c_UL')))
  2924. {
  2925. if ($this->maxH) $this->o_BR(array());
  2926. }
  2927. $this->style->save();
  2928. $this->style->analyse('p', $param);
  2929. $this->style->setPosition();
  2930. $this->style->FontSet();
  2931. // annule les effets du setposition
  2932. $this->pdf->setXY($this->pdf->getX()-$this->style->value['margin']['l'], $this->pdf->getY()-$this->style->value['margin']['t']);
  2933. list($mL, $mR) = $this->getMargins($this->pdf->getY());
  2934. $mR = $this->pdf->getW()-$mR;
  2935. $mL+= $this->style->value['margin']['l']+$this->style->value['padding']['l'];
  2936. $mR+= $this->style->value['margin']['r']+$this->style->value['padding']['r'];
  2937. $this->saveMargin($mL,0,$mR);
  2938. if ($this->style->value['text-indent']>0)
  2939. {
  2940. $y = $this->pdf->getY()+$this->style->value['margin']['t']+$this->style->value['padding']['t'];
  2941. $this->pageMarges[floor($y*100)] = array($mL+$this->style->value['text-indent'], $this->pdf->getW()-$mR);
  2942. $y+= $this->style->getLineHeight()*0.1;
  2943. $this->pageMarges[floor($y*100)] = array($mL, $this->pdf->getW()-$mR);
  2944. }
  2945. $this->makeBR($this->style->value['margin']['t']+$this->style->value['padding']['t']);
  2946. return true;
  2947. }
  2948. /**
  2949. * balise : P
  2950. * mode : FERMETURE
  2951. *
  2952. * @param array paramטtres de l'יlיment de parsing
  2953. * @return null
  2954. */
  2955. protected function c_P($param)
  2956. {
  2957. if ($this->forOneLine) return false;
  2958. if ($this->maxH) $this->o_BR(array());
  2959. $this->loadMargin();
  2960. $h = $this->style->value['margin']['b']+$this->style->value['padding']['b'];
  2961. $this->style->load();
  2962. $this->style->FontSet();
  2963. $this->makeBR($h);
  2964. return true;
  2965. }
  2966. /**
  2967. * balise : PRE
  2968. * mode : OUVERTURE
  2969. *
  2970. * @param array paramטtres de l'יlיment de parsing
  2971. * @return null
  2972. */
  2973. protected function o_PRE($param, $other = 'pre')
  2974. {
  2975. if ($other=='pre' && $this->maxH) $this->o_BR(array());
  2976. $this->style->save();
  2977. $this->style->value['font-family'] = 'courier';
  2978. $this->style->analyse($other, $param);
  2979. $this->style->setPosition();
  2980. $this->style->FontSet();
  2981. if ($other=='pre') return $this->o_DIV($param, $other);
  2982. return true;
  2983. }
  2984. protected function o_CODE($param) { return $this->o_PRE($param, 'code'); }
  2985. /**
  2986. * balise : PRE
  2987. * mode : FERMETURE
  2988. *
  2989. * @param array paramטtres de l'יlיment de parsing
  2990. * @return null
  2991. */
  2992. protected function c_PRE($param, $other = 'pre')
  2993. {
  2994. if ($other=='pre')
  2995. {
  2996. if ($this->forOneLine) return false;
  2997. $this->c_DIV($param);
  2998. $this->o_BR(array());
  2999. }
  3000. $this->style->load();
  3001. $this->style->FontSet();
  3002. return true;
  3003. }
  3004. protected function c_CODE($param) { return $this->c_PRE($param, 'code'); }
  3005. /**
  3006. * balise : BIG
  3007. * mode : OUVERTURE
  3008. *
  3009. * @param array paramטtres de l'יlיment de parsing
  3010. * @return null
  3011. */
  3012. protected function o_BIG($param)
  3013. {
  3014. $this->style->save();
  3015. $this->style->value['mini-decal']-= $this->style->value['mini-size']*0.12;
  3016. $this->style->value['mini-size'] *= 1.2;
  3017. $this->style->analyse('big', $param);
  3018. $this->style->setPosition();
  3019. $this->style->FontSet();
  3020. return true;
  3021. }
  3022. /**
  3023. * balise : BIG
  3024. * mode : FERMETURE
  3025. *
  3026. * @param array paramטtres de l'יlיment de parsing
  3027. * @return null
  3028. */
  3029. protected function c_BIG($param)
  3030. {
  3031. $this->style->load();
  3032. $this->style->FontSet();
  3033. return true;
  3034. }
  3035. /**
  3036. * balise : SMALL
  3037. * mode : OUVERTURE
  3038. *
  3039. * @param array paramטtres de l'יlיment de parsing
  3040. * @return null
  3041. */
  3042. protected function o_SMALL($param)
  3043. {
  3044. $this->style->save();
  3045. $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.05;
  3046. $this->style->value['mini-size'] *= 0.82;
  3047. $this->style->analyse('small', $param);
  3048. $this->style->setPosition();
  3049. $this->style->FontSet();
  3050. return true;
  3051. }
  3052. /**
  3053. * balise : SMALL
  3054. * mode : FERMETURE
  3055. *
  3056. * @param array paramטtres de l'יlיment de parsing
  3057. * @return null
  3058. */
  3059. protected function c_SMALL($param)
  3060. {
  3061. $this->style->load();
  3062. $this->style->FontSet();
  3063. return true;
  3064. }
  3065. /**
  3066. * balise : SUP
  3067. * mode : OUVERTURE
  3068. *
  3069. * @param array paramטtres de l'יlיment de parsing
  3070. * @return null
  3071. */
  3072. protected function o_SUP($param)
  3073. {
  3074. $this->style->save();
  3075. $this->style->value['mini-decal']-= $this->style->value['mini-size']*0.15;
  3076. $this->style->value['mini-size'] *= 0.75;
  3077. $this->style->analyse('sup', $param);
  3078. $this->style->setPosition();
  3079. $this->style->FontSet();
  3080. return true;
  3081. }
  3082. /**
  3083. * balise : SUP
  3084. * mode : FERMETURE
  3085. *
  3086. * @param array paramטtres de l'יlיment de parsing
  3087. * @return null
  3088. */
  3089. protected function c_SUP($param)
  3090. {
  3091. $this->style->load();
  3092. $this->style->FontSet();
  3093. return true;
  3094. }
  3095. /**
  3096. * balise : SUB
  3097. * mode : OUVERTURE
  3098. *
  3099. * @param array paramטtres de l'יlיment de parsing
  3100. * @return null
  3101. */
  3102. protected function o_SUB($param)
  3103. {
  3104. $this->style->save();
  3105. $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.15;
  3106. $this->style->value['mini-size'] *= 0.75;
  3107. $this->style->analyse('sub', $param);
  3108. $this->style->setPosition();
  3109. $this->style->FontSet();
  3110. return true;
  3111. }
  3112. /**
  3113. * balise : SUB
  3114. * mode : FERMETURE
  3115. *
  3116. * @param array paramטtres de l'יlיment de parsing
  3117. * @return null
  3118. */
  3119. protected function c_SUB($param)
  3120. {
  3121. $this->style->load();
  3122. $this->style->FontSet();
  3123. return true;
  3124. }
  3125. /**
  3126. * balise : UL
  3127. * mode : OUVERTURE
  3128. *
  3129. * @param array paramטtres de l'יlיment de parsing
  3130. * @return null
  3131. */
  3132. protected function o_UL($param, $other = 'ul')
  3133. {
  3134. if ($this->forOneLine) return false;
  3135. if (!in_array($this->previousCall, array('c_P', 'c_UL')))
  3136. {
  3137. if ($this->maxH) $this->o_BR(array());
  3138. if (!count($this->defLIST)) $this->o_BR(array());
  3139. }
  3140. if (!isset($param['style']['width'])) $param['allwidth'] = true;
  3141. $param['cellspacing'] = 0;
  3142. // une liste est traitיe comme un tableau
  3143. $this->o_TABLE($param, $other);
  3144. // ajouter un niveau de liste
  3145. $this->listeAddLevel($other, $this->style->value['list-style-type'], $this->style->value['list-style-image']);
  3146. return true;
  3147. }
  3148. protected function o_OL($param) { return $this->o_UL($param, 'ol'); }
  3149. /**
  3150. * balise : UL
  3151. * mode : FERMETURE
  3152. *
  3153. * @param array paramטtres de l'יlיment de parsing
  3154. * @return null
  3155. */
  3156. protected function c_UL($param)
  3157. {
  3158. if ($this->forOneLine) return false;
  3159. // fin du tableau
  3160. $this->c_TABLE($param);
  3161. // enlever un niveau de liste
  3162. $this->listeDelLevel();
  3163. if (!$this->sub_part)
  3164. {
  3165. if (!count($this->defLIST)) $this->o_BR(array());
  3166. }
  3167. return true;
  3168. }
  3169. protected function c_OL($param) { return $this->c_UL($param); }
  3170. /**
  3171. * balise : LI
  3172. * mode : OUVERTURE
  3173. *
  3174. * @param array paramטtres de l'יlיment de parsing
  3175. * @return null
  3176. */
  3177. protected function o_LI($param)
  3178. {
  3179. if ($this->forOneLine) return false;
  3180. // ajouter une puce au niveau actuel
  3181. $this->listeAddLi();
  3182. if (!isset($param['style']['width'])) $param['style']['width'] = '100%';
  3183. // preparation du style de la puce
  3184. $paramPUCE = $param;
  3185. $inf = $this->listeGetLi();
  3186. if ($inf[0])
  3187. {
  3188. $paramPUCE['style']['font-family'] = $inf[0];
  3189. $paramPUCE['style']['text-align'] = 'li_right';
  3190. $paramPUCE['style']['vertical-align'] = 'top';
  3191. $paramPUCE['style']['width'] = $this->listeGetWidth();
  3192. $paramPUCE['style']['padding-right'] = $this->listeGetPadding();
  3193. $paramPUCE['txt'] = $inf[2];
  3194. }
  3195. else
  3196. {
  3197. $paramPUCE['style']['text-align'] = 'li_right';
  3198. $paramPUCE['style']['vertical-align'] = 'top';
  3199. $paramPUCE['style']['width'] = $this->listeGetWidth();
  3200. $paramPUCE['style']['padding-right'] = $this->listeGetPadding();
  3201. $paramPUCE['src'] = $inf[2];
  3202. $paramPUCE['sub_li'] = true;
  3203. }
  3204. // nouvelle ligne
  3205. $this->o_TR($param, 'li');
  3206. $this->style->save();
  3207. if ($inf[1]) // small
  3208. {
  3209. $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.045;
  3210. $this->style->value['mini-size'] *= 0.75;
  3211. }
  3212. // si on est dans un sub_html => preparation, sinon affichage classique
  3213. if ($this->sub_part)
  3214. {
  3215. // TD pour la puce
  3216. $tmp_pos = $this->temp_pos;
  3217. $tmp_lst1 = $this->parsing->code[$tmp_pos+1];
  3218. $tmp_lst2 = $this->parsing->code[$tmp_pos+2];
  3219. $this->parsing->code[$tmp_pos+1] = array();
  3220. $this->parsing->code[$tmp_pos+1]['name'] = (isset($paramPUCE['src'])) ? 'img' : 'write';
  3221. $this->parsing->code[$tmp_pos+1]['param'] = $paramPUCE; unset($this->parsing->code[$tmp_pos+1]['param']['style']['width']);
  3222. $this->parsing->code[$tmp_pos+1]['close'] = 0;
  3223. $this->parsing->code[$tmp_pos+2] = array();
  3224. $this->parsing->code[$tmp_pos+2]['name'] = 'li';
  3225. $this->parsing->code[$tmp_pos+2]['param'] = $paramPUCE;
  3226. $this->parsing->code[$tmp_pos+2]['close'] = 1;
  3227. $this->o_TD($paramPUCE, 'li_sub');
  3228. $this->c_TD($param);
  3229. $this->temp_pos = $tmp_pos;
  3230. $this->parsing->code[$tmp_pos+1] = $tmp_lst1;
  3231. $this->parsing->code[$tmp_pos+2] = $tmp_lst2;
  3232. }
  3233. else
  3234. {
  3235. // TD pour la puce
  3236. $this->o_TD($paramPUCE, 'li_sub');
  3237. unset($paramPUCE['style']['width']);
  3238. if (isset($paramPUCE['src'])) $this->o_IMG($paramPUCE);
  3239. else $this->o_WRITE($paramPUCE);
  3240. $this->c_TD($paramPUCE);
  3241. }
  3242. $this->style->load();
  3243. // td pour le contenu
  3244. $this->o_TD($param, 'li');
  3245. return true;
  3246. }
  3247. /**
  3248. * balise : LI
  3249. * mode : FERMETURE
  3250. *
  3251. * @param array paramטtres de l'יlיment de parsing
  3252. * @return null
  3253. */
  3254. protected function c_LI($param)
  3255. {
  3256. if ($this->forOneLine) return false;
  3257. // fin du contenu
  3258. $this->c_TD($param);
  3259. // fin de la ligne
  3260. $this->c_TR($param);
  3261. return true;
  3262. }
  3263. /**
  3264. * balise : TBODY
  3265. * mode : OUVERTURE
  3266. *
  3267. * @param array paramטtres de l'יlיment de parsing
  3268. * @return null
  3269. */
  3270. protected function o_TBODY($param)
  3271. {
  3272. if ($this->forOneLine) return false;
  3273. $this->style->save();
  3274. $this->style->analyse('tbody', $param);
  3275. $this->style->setPosition();
  3276. $this->style->FontSet();
  3277. return true;
  3278. }
  3279. /**
  3280. * balise : TBODY
  3281. * mode : FERMETURE
  3282. *
  3283. * @param array paramטtres de l'יlיment de parsing
  3284. * @return null
  3285. */
  3286. protected function c_TBODY($param)
  3287. {
  3288. if ($this->forOneLine) return false;
  3289. $this->style->load();
  3290. $this->style->FontSet();
  3291. return true;
  3292. }
  3293. /**
  3294. * balise : THEAD
  3295. * mode : OUVERTURE
  3296. *
  3297. * @param array paramטtres de l'יlיment de parsing
  3298. * @return null
  3299. */
  3300. protected function o_THEAD($param)
  3301. {
  3302. if ($this->forOneLine) return false;
  3303. $this->style->save();
  3304. $this->style->analyse('thead', $param);
  3305. $this->style->setPosition();
  3306. $this->style->FontSet();
  3307. // si on est en mode sub_html : sauvegarde du numיro du TR
  3308. if ($this->sub_part)
  3309. {
  3310. HTML2PDF::$TABLES[$param['num']]['thead']['tr'][0] = HTML2PDF::$TABLES[$param['num']]['tr_curr'];
  3311. HTML2PDF::$TABLES[$param['num']]['thead']['code'] = array();
  3312. for($pos=$this->temp_pos; $pos<count($this->parsing->code); $pos++)
  3313. {
  3314. $todo = $this->parsing->code[$pos];
  3315. if (strtolower($todo['name'])=='thead') $todo['name'] = 'thead_sub';
  3316. HTML2PDF::$TABLES[$param['num']]['thead']['code'][] = $todo;
  3317. if (strtolower($todo['name'])=='thead_sub' && $todo['close']) break;
  3318. }
  3319. }
  3320. else
  3321. {
  3322. $level = $this->parsing->getLevel($this->parse_pos);
  3323. $this->parse_pos+= count($level);
  3324. HTML2PDF::$TABLES[$param['num']]['tr_curr']+= count(HTML2PDF::$TABLES[$param['num']]['thead']['tr']);
  3325. }
  3326. return true;
  3327. }
  3328. /**
  3329. * balise : THEAD
  3330. * mode : FERMETURE
  3331. *
  3332. * @param array paramטtres de l'יlיment de parsing
  3333. * @return null
  3334. */
  3335. protected function c_THEAD($param)
  3336. {
  3337. if ($this->forOneLine) return false;
  3338. $this->style->load();
  3339. $this->style->FontSet();
  3340. // si on est en mode sub_html : sauvegarde du numיro du TR
  3341. if ($this->sub_part)
  3342. {
  3343. $min = HTML2PDF::$TABLES[$param['num']]['thead']['tr'][0];
  3344. $max = HTML2PDF::$TABLES[$param['num']]['tr_curr']-1;
  3345. HTML2PDF::$TABLES[$param['num']]['thead']['tr'] = range($min, $max);
  3346. }
  3347. return true;
  3348. }
  3349. /**
  3350. * balise : TFOOT
  3351. * mode : OUVERTURE
  3352. *
  3353. * @param array paramטtres de l'יlיment de parsing
  3354. * @return null
  3355. */
  3356. protected function o_TFOOT($param)
  3357. {
  3358. if ($this->forOneLine) return false;
  3359. $this->style->save();
  3360. $this->style->analyse('tfoot', $param);
  3361. $this->style->setPosition();
  3362. $this->style->FontSet();
  3363. // si on est en mode sub_html : sauvegarde du numיro du TR
  3364. if ($this->sub_part)
  3365. {
  3366. HTML2PDF::$TABLES[$param['num']]['tfoot']['tr'][0] = HTML2PDF::$TABLES[$param['num']]['tr_curr'];
  3367. HTML2PDF::$TABLES[$param['num']]['tfoot']['code'] = array();
  3368. for($pos=$this->temp_pos; $pos<count($this->parsing->code); $pos++)
  3369. {
  3370. $todo = $this->parsing->code[$pos];
  3371. if (strtolower($todo['name'])=='tfoot') $todo['name'] = 'tfoot_sub';
  3372. HTML2PDF::$TABLES[$param['num']]['tfoot']['code'][] = $todo;
  3373. if (strtolower($todo['name'])=='tfoot_sub' && $todo['close']) break;
  3374. }
  3375. }
  3376. else
  3377. {
  3378. $level = $this->parsing->getLevel($this->parse_pos);
  3379. $this->parse_pos+= count($level);
  3380. HTML2PDF::$TABLES[$param['num']]['tr_curr']+= count(HTML2PDF::$TABLES[$param['num']]['tfoot']['tr']);
  3381. }
  3382. return true;
  3383. }
  3384. /**
  3385. * balise : TFOOT
  3386. * mode : FERMETURE
  3387. *
  3388. * @param array paramטtres de l'יlיment de parsing
  3389. * @return null
  3390. */
  3391. protected function c_TFOOT($param)
  3392. {
  3393. if ($this->forOneLine) return false;
  3394. $this->style->load();
  3395. $this->style->FontSet();
  3396. // si on est en mode sub_html : sauvegarde du numיro du TR
  3397. if ($this->sub_part)
  3398. {
  3399. $min = HTML2PDF::$TABLES[$param['num']]['tfoot']['tr'][0];
  3400. $max = HTML2PDF::$TABLES[$param['num']]['tr_curr']-1;
  3401. HTML2PDF::$TABLES[$param['num']]['tfoot']['tr'] = range($min, $max);
  3402. }
  3403. return true;
  3404. }
  3405. /**
  3406. * balise : THEAD_SUB
  3407. * mode : OUVERTURE
  3408. *
  3409. * @param array paramטtres de l'יlיment de parsing
  3410. * @return null
  3411. */
  3412. protected function o_THEAD_SUB($param)
  3413. {
  3414. if ($this->forOneLine) return false;
  3415. $this->style->save();
  3416. $this->style->analyse('thead', $param);
  3417. $this->style->setPosition();
  3418. $this->style->FontSet();
  3419. return true;
  3420. }
  3421. /**
  3422. * balise : THEAD_SUB
  3423. * mode : FERMETURE
  3424. *
  3425. * @param array paramטtres de l'יlיment de parsing
  3426. * @return null
  3427. */
  3428. protected function c_THEAD_SUB($param)
  3429. {
  3430. if ($this->forOneLine) return false;
  3431. $this->style->load();
  3432. $this->style->FontSet();
  3433. return true;
  3434. }
  3435. /**
  3436. * balise : TFOOT_SUB
  3437. * mode : OUVERTURE
  3438. *
  3439. * @param array paramטtres de l'יlיment de parsing
  3440. * @return null
  3441. */
  3442. protected function o_TFOOT_SUB($param)
  3443. {
  3444. if ($this->forOneLine) return false;
  3445. $this->style->save();
  3446. $this->style->analyse('tfoot', $param);
  3447. $this->style->setPosition();
  3448. $this->style->FontSet();
  3449. return true;
  3450. }
  3451. /**
  3452. * balise : TFOOT_SUB
  3453. * mode : FERMETURE
  3454. *
  3455. * @param array paramטtres de l'יlיment de parsing
  3456. * @return null
  3457. */
  3458. protected function c_TFOOT_SUB($param)
  3459. {
  3460. if ($this->forOneLine) return false;
  3461. $this->style->load();
  3462. $this->style->FontSet();
  3463. return true;
  3464. }
  3465. /**
  3466. * balise : FORM
  3467. * mode : OUVERTURE
  3468. *
  3469. * @param array paramטtres de l'יlיment de parsing
  3470. * @return null
  3471. */
  3472. protected function o_FORM($param)
  3473. {
  3474. $this->style->save();
  3475. $this->style->analyse('form', $param);
  3476. $this->style->setPosition();
  3477. $this->style->FontSet();
  3478. $this->pdf->setFormDefaultProp(array(
  3479. 'lineWidth'=>1,
  3480. 'borderStyle'=>'solid',
  3481. 'fillColor'=>array(220, 220, 255),
  3482. 'strokeColor'=>array(128, 128, 200)
  3483. ));
  3484. $this->isInForm = isset($param['action']) ? $param['action'] : '';
  3485. return true;
  3486. }
  3487. /**
  3488. * balise : FORM
  3489. * mode : FERMETURE
  3490. *
  3491. * @param array paramטtres de l'יlיment de parsing
  3492. * @return null
  3493. */
  3494. protected function c_FORM($param)
  3495. {
  3496. $this->isInForm = false;
  3497. $this->style->load();
  3498. $this->style->FontSet();
  3499. return true;
  3500. }
  3501. /**
  3502. * balise : TABLE
  3503. * mode : OUVERTURE
  3504. *
  3505. * @param array paramטtres de l'יlיment de parsing
  3506. * @return null
  3507. */
  3508. protected function o_TABLE($param, $other = 'table')
  3509. {
  3510. if ($this->maxH)
  3511. {
  3512. if ($this->forOneLine) return false;
  3513. $this->o_BR(array());
  3514. }
  3515. if ($this->forOneLine)
  3516. {
  3517. $this->maxE++;
  3518. $this->maxX = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
  3519. return false;
  3520. }
  3521. $this->maxH = 0;
  3522. $align_object = isset($param['align']) ? strtolower($param['align']) : 'left';
  3523. if (isset($param['align'])) unset($param['align']);
  3524. if (!in_array($align_object, array('left', 'center', 'right'))) $align_object = 'left';
  3525. // lecture et initialisation du style
  3526. $this->style->save();
  3527. $this->style->analyse($other, $param);
  3528. $this->style->setPosition();
  3529. $this->style->FontSet();
  3530. if ($this->style->value['margin-auto']) $align_object = 'center';
  3531. // est-on en collapse
  3532. $collapse = false;
  3533. if ($other=='table')
  3534. $collapse = isset($this->style->value['border']['collapse']) ? $this->style->value['border']['collapse'] : false;
  3535. // si oui il faut adaptי les borders
  3536. if ($collapse)
  3537. {
  3538. $param['style']['border'] = 'none';
  3539. $param['cellspacing'] = 0;
  3540. $none = $this->style->readBorder('none');
  3541. $this->style->value['border']['t'] = $none;
  3542. $this->style->value['border']['r'] = $none;
  3543. $this->style->value['border']['b'] = $none;
  3544. $this->style->value['border']['l'] = $none;
  3545. }
  3546. // si on est en mode sub_html : initialisation des dimensions et autres
  3547. if ($this->sub_part)
  3548. {
  3549. if ($this->DEBUG_actif) $this->DEBUG_add('Table n°'.$param['num'], true);
  3550. HTML2PDF::$TABLES[$param['num']] = array();
  3551. HTML2PDF::$TABLES[$param['num']]['border'] = isset($param['border']) ? $this->style->readBorder($param['border']) : null; // border spיcifique si border precisי en paramטtre
  3552. HTML2PDF::$TABLES[$param['num']]['cellpadding'] = $this->style->ConvertToMM(isset($param['cellpadding']) ? $param['cellpadding'] : '1px'); // cellpadding du tableau
  3553. HTML2PDF::$TABLES[$param['num']]['cellspacing'] = $this->style->ConvertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); // cellspacing du tableau
  3554. HTML2PDF::$TABLES[$param['num']]['cases'] = array(); // liste des propriיtיs des cases
  3555. HTML2PDF::$TABLES[$param['num']]['corr'] = array(); // tableau de correlation pour les colspan et rowspan
  3556. HTML2PDF::$TABLES[$param['num']]['corr_x'] = 0; // position dans le tableau de correlation
  3557. HTML2PDF::$TABLES[$param['num']]['corr_y'] = 0; // position dans le tableau de correlation
  3558. HTML2PDF::$TABLES[$param['num']]['td_curr'] = 0; // colonne courante
  3559. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = 0; // ligne courante
  3560. HTML2PDF::$TABLES[$param['num']]['curr_x'] = $this->pdf->getX(); // position courante X
  3561. HTML2PDF::$TABLES[$param['num']]['curr_y'] = $this->pdf->getY(); // position courante Y
  3562. HTML2PDF::$TABLES[$param['num']]['width'] = 0; // largeur globale
  3563. HTML2PDF::$TABLES[$param['num']]['height'] = 0; // hauteur globale
  3564. HTML2PDF::$TABLES[$param['num']]['align'] = $align_object;
  3565. HTML2PDF::$TABLES[$param['num']]['marge'] = array();
  3566. HTML2PDF::$TABLES[$param['num']]['marge']['t'] = $this->style->value['padding']['t']+$this->style->value['border']['t']['width']+HTML2PDF::$TABLES[$param['num']]['cellspacing']*0.5;
  3567. HTML2PDF::$TABLES[$param['num']]['marge']['r'] = $this->style->value['padding']['r']+$this->style->value['border']['r']['width']+HTML2PDF::$TABLES[$param['num']]['cellspacing']*0.5;
  3568. HTML2PDF::$TABLES[$param['num']]['marge']['b'] = $this->style->value['padding']['b']+$this->style->value['border']['b']['width']+HTML2PDF::$TABLES[$param['num']]['cellspacing']*0.5;
  3569. HTML2PDF::$TABLES[$param['num']]['marge']['l'] = $this->style->value['padding']['l']+$this->style->value['border']['l']['width']+HTML2PDF::$TABLES[$param['num']]['cellspacing']*0.5;
  3570. HTML2PDF::$TABLES[$param['num']]['page'] = 0; // nombre de pages
  3571. HTML2PDF::$TABLES[$param['num']]['new_page'] = true; // nouvelle page pour le TR courant
  3572. HTML2PDF::$TABLES[$param['num']]['style_value'] = null; // style du tableau
  3573. HTML2PDF::$TABLES[$param['num']]['thead'] = array(); // infos sur le thead
  3574. HTML2PDF::$TABLES[$param['num']]['tfoot'] = array(); // infos sur le tfoot
  3575. HTML2PDF::$TABLES[$param['num']]['thead']['tr'] = array(); // tr du thead
  3576. HTML2PDF::$TABLES[$param['num']]['tfoot']['tr'] = array(); // tr du tfoot
  3577. HTML2PDF::$TABLES[$param['num']]['thead']['height'] = 0; // hauteur du thead
  3578. HTML2PDF::$TABLES[$param['num']]['tfoot']['height'] = 0; // hauteur du tfoot
  3579. HTML2PDF::$TABLES[$param['num']]['thead']['code'] = array(); // contenu HTML du thead
  3580. HTML2PDF::$TABLES[$param['num']]['tfoot']['code'] = array(); // contenu HTML du tfoot
  3581. HTML2PDF::$TABLES[$param['num']]['cols'] = array(); // definition via les balises col
  3582. $this->saveMargin($this->pdf->getlMargin(), $this->pdf->gettMargin(), $this->pdf->getrMargin());
  3583. // adaptation de la largeur en fonction des marges du tableau
  3584. $this->style->value['width']-= HTML2PDF::$TABLES[$param['num']]['marge']['l'] + HTML2PDF::$TABLES[$param['num']]['marge']['r'];
  3585. }
  3586. else
  3587. {
  3588. // on repart א la premiere page du tableau et א la premiere case
  3589. HTML2PDF::$TABLES[$param['num']]['page'] = 0;
  3590. HTML2PDF::$TABLES[$param['num']]['td_curr'] = 0;
  3591. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = 0;
  3592. HTML2PDF::$TABLES[$param['num']]['td_x'] = HTML2PDF::$TABLES[$param['num']]['marge']['l']+HTML2PDF::$TABLES[$param['num']]['curr_x'];
  3593. HTML2PDF::$TABLES[$param['num']]['td_y'] = HTML2PDF::$TABLES[$param['num']]['marge']['t']+HTML2PDF::$TABLES[$param['num']]['curr_y'];
  3594. // initialisation du style des bordures de la premiere partie de tableau
  3595. $this->drawRectangle(
  3596. HTML2PDF::$TABLES[$param['num']]['curr_x'],
  3597. HTML2PDF::$TABLES[$param['num']]['curr_y'],
  3598. HTML2PDF::$TABLES[$param['num']]['width'],
  3599. isset(HTML2PDF::$TABLES[$param['num']]['height'][0]) ? HTML2PDF::$TABLES[$param['num']]['height'][0] : null,
  3600. $this->style->value['border'],
  3601. $this->style->value['padding'],
  3602. 0,
  3603. $this->style->value['background']
  3604. );
  3605. HTML2PDF::$TABLES[$param['num']]['style_value'] = $this->style->value;
  3606. }
  3607. return true;
  3608. }
  3609. /**
  3610. * balise : TABLE
  3611. * mode : FERMETURE
  3612. *
  3613. * @param array paramטtres de l'יlיment de parsing
  3614. * @return null
  3615. */
  3616. protected function c_TABLE($param)
  3617. {
  3618. if ($this->forOneLine) return false;
  3619. $this->maxH = 0;
  3620. // restauration du style
  3621. $this->style->load();
  3622. $this->style->FontSet();
  3623. // si on est en mode sub_html : initialisation des dimensions et autres
  3624. if ($this->sub_part)
  3625. {
  3626. // ajustement de la taille des cases
  3627. $this->calculTailleCases(HTML2PDF::$TABLES[$param['num']]['cases'], HTML2PDF::$TABLES[$param['num']]['corr']);
  3628. // calcul de la hauteur du THEAD et du TFOOT
  3629. $lst = array('thead', 'tfoot');
  3630. foreach($lst as $mode)
  3631. {
  3632. HTML2PDF::$TABLES[$param['num']][$mode]['height'] = 0;
  3633. foreach(HTML2PDF::$TABLES[$param['num']][$mode]['tr'] as $tr)
  3634. {
  3635. // hauteur de la ligne tr
  3636. $h = 0;
  3637. for($i=0; $i<count(HTML2PDF::$TABLES[$param['num']]['cases'][$tr]); $i++)
  3638. if (HTML2PDF::$TABLES[$param['num']]['cases'][$tr][$i]['rowspan']==1)
  3639. $h = max($h, HTML2PDF::$TABLES[$param['num']]['cases'][$tr][$i]['h']);
  3640. HTML2PDF::$TABLES[$param['num']][$mode]['height']+= $h;
  3641. }
  3642. }
  3643. // calcul des dimensions du tableau - Largeur
  3644. HTML2PDF::$TABLES[$param['num']]['width'] = HTML2PDF::$TABLES[$param['num']]['marge']['l'] + HTML2PDF::$TABLES[$param['num']]['marge']['r'];
  3645. if (isset(HTML2PDF::$TABLES[$param['num']]['cases'][0]))
  3646. foreach(HTML2PDF::$TABLES[$param['num']]['cases'][0] as $case)
  3647. HTML2PDF::$TABLES[$param['num']]['width']+= $case['w'];
  3648. // positionnement du tableau horizontalement;
  3649. $old = $this->style->getOldValues();
  3650. $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
  3651. $x = HTML2PDF::$TABLES[$param['num']]['curr_x'];
  3652. $w = HTML2PDF::$TABLES[$param['num']]['width'];
  3653. if ($parent_w>$w)
  3654. {
  3655. if (HTML2PDF::$TABLES[$param['num']]['align']=='center')
  3656. $x = $x + ($parent_w-$w)*0.5;
  3657. else if (HTML2PDF::$TABLES[$param['num']]['align']=='right')
  3658. $x = $x + $parent_w-$w;
  3659. HTML2PDF::$TABLES[$param['num']]['curr_x'] = $x;
  3660. }
  3661. // calcul des dimensions du tableau - hauteur du tableau sur chaque page
  3662. HTML2PDF::$TABLES[$param['num']]['height'] = array();
  3663. $h0 = HTML2PDF::$TABLES[$param['num']]['marge']['t'] + HTML2PDF::$TABLES[$param['num']]['marge']['b']; // minimum de hauteur א cause des marges
  3664. $h0+= HTML2PDF::$TABLES[$param['num']]['thead']['height'] + HTML2PDF::$TABLES[$param['num']]['tfoot']['height']; // et du tfoot et thead
  3665. $max = $this->pdf->getH() - $this->pdf->getbMargin(); // max de hauteur par page
  3666. $y = HTML2PDF::$TABLES[$param['num']]['curr_y']; // position Y actuelle
  3667. $height = $h0;
  3668. // on va lire les hauteurs de chaque ligne, une א une, et voir si ca rentre sur la page.
  3669. for($k=0; $k<count(HTML2PDF::$TABLES[$param['num']]['cases']); $k++)
  3670. {
  3671. // si c'est des lignes du thead ou du tfoot : on passe
  3672. if (in_array($k, HTML2PDF::$TABLES[$param['num']]['thead']['tr'])) continue;
  3673. if (in_array($k, HTML2PDF::$TABLES[$param['num']]['tfoot']['tr'])) continue;
  3674. // hauteur de la ligne $k
  3675. $th = 0;
  3676. $h = 0;
  3677. for($i=0; $i<count(HTML2PDF::$TABLES[$param['num']]['cases'][$k]); $i++)
  3678. {
  3679. $h = max($h, HTML2PDF::$TABLES[$param['num']]['cases'][$k][$i]['h']);
  3680. if (HTML2PDF::$TABLES[$param['num']]['cases'][$k][$i]['rowspan']==1)
  3681. $th = max($th, HTML2PDF::$TABLES[$param['num']]['cases'][$k][$i]['h']);
  3682. }
  3683. // si la ligne ne rentre pas dans la page
  3684. // => la hauteur sur cette page est trouvיe, et on passe א la page d'apres
  3685. if ($y+$h+$height>$max)
  3686. {
  3687. if ($height==$h0) $height = null;
  3688. HTML2PDF::$TABLES[$param['num']]['height'][] = $height;
  3689. $height = $h0;
  3690. $y = $this->margeTop;
  3691. }
  3692. $height+= $th;
  3693. }
  3694. // rajout du reste de tableau (si il existe) א la derniere page
  3695. if ($height!=$h0 || $k==0) HTML2PDF::$TABLES[$param['num']]['height'][] = $height;
  3696. }
  3697. else
  3698. {
  3699. if (count(HTML2PDF::$TABLES[$param['num']]['tfoot']['code']))
  3700. {
  3701. $tmp_tr = HTML2PDF::$TABLES[$param['num']]['tr_curr'];
  3702. $tmp_td = HTML2PDF::$TABLES[$param['num']]['td_curr'];
  3703. $OLD_parse_pos = $this->parse_pos;
  3704. $OLD_parse_code = $this->parsing->code;
  3705. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = HTML2PDF::$TABLES[$param['num']]['tfoot']['tr'][0];
  3706. HTML2PDF::$TABLES[$param['num']]['td_curr'] = 0;
  3707. $this->parse_pos = 0;
  3708. $this->parsing->code = HTML2PDF::$TABLES[$param['num']]['tfoot']['code'];
  3709. $this->makeHTMLcode();
  3710. $this->parse_pos = $OLD_parse_pos;
  3711. $this->parsing->code = $OLD_parse_code;
  3712. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = $tmp_tr;
  3713. HTML2PDF::$TABLES[$param['num']]['td_curr'] = $tmp_td;
  3714. }
  3715. // determination des coordonnיes de sortie du tableau
  3716. $x = HTML2PDF::$TABLES[$param['num']]['curr_x'] + HTML2PDF::$TABLES[$param['num']]['width'];
  3717. if (count(HTML2PDF::$TABLES[$param['num']]['height'])>1)
  3718. $y = $this->margeTop+HTML2PDF::$TABLES[$param['num']]['height'][count(HTML2PDF::$TABLES[$param['num']]['height'])-1];
  3719. else if (count(HTML2PDF::$TABLES[$param['num']]['height'])==1)
  3720. $y = HTML2PDF::$TABLES[$param['num']]['curr_y']+HTML2PDF::$TABLES[$param['num']]['height'][count(HTML2PDF::$TABLES[$param['num']]['height'])-1];
  3721. else
  3722. $y = HTML2PDF::$TABLES[$param['num']]['curr_y'];
  3723. // taille du tableau
  3724. $this->maxX = max($this->maxX, $x);
  3725. $this->maxY = max($this->maxY, $y);
  3726. // nouvelle position apres le tableau
  3727. $this->pdf->setXY($this->pdf->getlMargin(), $y);
  3728. // restauration des marges
  3729. $this->loadMargin();
  3730. if ($this->DEBUG_actif) $this->DEBUG_add('Table n°'.$param['num'], false);
  3731. }
  3732. return true;
  3733. }
  3734. /**
  3735. * balise : COL
  3736. * mode : OUVERTURE (pas de fermeture)
  3737. *
  3738. * @param array paramטtres de l'יlיment de parsing
  3739. * @return null
  3740. */
  3741. protected function o_COL($param)
  3742. {
  3743. $span = isset($param['span']) ? $param['span'] : 1;
  3744. for($k=0; $k<$span; $k++)
  3745. HTML2PDF::$TABLES[$param['num']]['cols'][] = $param;
  3746. }
  3747. /**
  3748. * balise : TR
  3749. * mode : OUVERTURE
  3750. *
  3751. * @param array paramטtres de l'יlיment de parsing
  3752. * @return null
  3753. */
  3754. protected function o_TR($param, $other = 'tr')
  3755. {
  3756. if ($this->forOneLine) return false;
  3757. $this->maxH = 0;
  3758. // analyse du style
  3759. $this->style->save();
  3760. $this->style->analyse($other, $param);
  3761. $this->style->setPosition();
  3762. $this->style->FontSet();
  3763. // positionnement dans le tableau
  3764. HTML2PDF::$TABLES[$param['num']]['tr_curr']++;
  3765. HTML2PDF::$TABLES[$param['num']]['td_curr']= 0;
  3766. // si on est pas dans un sub_html
  3767. if (!$this->sub_part)
  3768. {
  3769. // Y courant apres la ligne
  3770. $ty=null;
  3771. for($ii=0; $ii<count(HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1]); $ii++)
  3772. $ty = max($ty, HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][$ii]['h']);
  3773. $hfoot = HTML2PDF::$TABLES[$param['num']]['tfoot']['height'];
  3774. // si la ligne ne rentre pas dans la page => nouvelle page
  3775. if (!$this->isInTfoot && HTML2PDF::$TABLES[$param['num']]['td_y'] + HTML2PDF::$TABLES[$param['num']]['marge']['b'] + $ty +$hfoot> $this->pdf->getH() - $this->pdf->getbMargin())
  3776. {
  3777. if (count(HTML2PDF::$TABLES[$param['num']]['tfoot']['code']))
  3778. {
  3779. $tmp_tr = HTML2PDF::$TABLES[$param['num']]['tr_curr'];
  3780. $tmp_td = HTML2PDF::$TABLES[$param['num']]['td_curr'];
  3781. $OLD_parse_pos = $this->parse_pos;
  3782. $OLD_parse_code = $this->parsing->code;
  3783. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = HTML2PDF::$TABLES[$param['num']]['tfoot']['tr'][0];
  3784. HTML2PDF::$TABLES[$param['num']]['td_curr'] = 0;
  3785. $this->parse_pos = 0;
  3786. $this->parsing->code = HTML2PDF::$TABLES[$param['num']]['tfoot']['code'];
  3787. $this->isInTfoot = true;
  3788. $this->makeHTMLcode();
  3789. $this->isInTfoot = false;
  3790. $this->parse_pos = $OLD_parse_pos;
  3791. $this->parsing->code = $OLD_parse_code;
  3792. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = $tmp_tr;
  3793. HTML2PDF::$TABLES[$param['num']]['td_curr'] = $tmp_td;
  3794. }
  3795. HTML2PDF::$TABLES[$param['num']]['new_page'] = true;
  3796. $this->setNewPage();
  3797. HTML2PDF::$TABLES[$param['num']]['page']++;
  3798. HTML2PDF::$TABLES[$param['num']]['curr_y'] = $this->pdf->getY();
  3799. HTML2PDF::$TABLES[$param['num']]['td_y'] = HTML2PDF::$TABLES[$param['num']]['curr_y']+HTML2PDF::$TABLES[$param['num']]['marge']['t'];
  3800. // si la hauteur de cette partie a bien יtי calculיe, on trace le cadre
  3801. if (isset(HTML2PDF::$TABLES[$param['num']]['height'][HTML2PDF::$TABLES[$param['num']]['page']]))
  3802. {
  3803. $old = $this->style->value;
  3804. $this->style->value = HTML2PDF::$TABLES[$param['num']]['style_value'];
  3805. // initialisation du style des bordures de la premiere partie de tableau
  3806. $this->drawRectangle(
  3807. HTML2PDF::$TABLES[$param['num']]['curr_x'],
  3808. HTML2PDF::$TABLES[$param['num']]['curr_y'],
  3809. HTML2PDF::$TABLES[$param['num']]['width'],
  3810. HTML2PDF::$TABLES[$param['num']]['height'][HTML2PDF::$TABLES[$param['num']]['page']],
  3811. $this->style->value['border'],
  3812. $this->style->value['padding'],
  3813. HTML2PDF::$TABLES[$param['num']]['cellspacing']*0.5,
  3814. $this->style->value['background']
  3815. );
  3816. $this->style->value = $old;
  3817. }
  3818. }
  3819. if (HTML2PDF::$TABLES[$param['num']]['new_page'] && count(HTML2PDF::$TABLES[$param['num']]['thead']['code']))
  3820. {
  3821. HTML2PDF::$TABLES[$param['num']]['new_page'] = false;
  3822. $tmp_tr = HTML2PDF::$TABLES[$param['num']]['tr_curr'];
  3823. $tmp_td = HTML2PDF::$TABLES[$param['num']]['td_curr'];
  3824. $OLD_parse_pos = $this->parse_pos;
  3825. $OLD_parse_code = $this->parsing->code;
  3826. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = HTML2PDF::$TABLES[$param['num']]['thead']['tr'][0];
  3827. HTML2PDF::$TABLES[$param['num']]['td_curr'] = 0;
  3828. $this->parse_pos = 0;
  3829. $this->parsing->code = HTML2PDF::$TABLES[$param['num']]['thead']['code'];
  3830. $this->isInThead = true;
  3831. $this->makeHTMLcode();
  3832. $this->isInThead = false;
  3833. $this->parse_pos = $OLD_parse_pos;
  3834. $this->parsing->code = $OLD_parse_code;
  3835. HTML2PDF::$TABLES[$param['num']]['tr_curr'] = $tmp_tr;
  3836. HTML2PDF::$TABLES[$param['num']]['td_curr'] = $tmp_td;
  3837. HTML2PDF::$TABLES[$param['num']]['new_page'] = true;
  3838. }
  3839. }
  3840. else
  3841. {
  3842. HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1] = array();
  3843. if (!isset(HTML2PDF::$TABLES[$param['num']]['corr'][HTML2PDF::$TABLES[$param['num']]['corr_y']]))
  3844. HTML2PDF::$TABLES[$param['num']]['corr'][HTML2PDF::$TABLES[$param['num']]['corr_y']] = array();
  3845. HTML2PDF::$TABLES[$param['num']]['corr_x']=0;
  3846. while(isset(HTML2PDF::$TABLES[$param['num']]['corr'][HTML2PDF::$TABLES[$param['num']]['corr_y']][HTML2PDF::$TABLES[$param['num']]['corr_x']]))
  3847. HTML2PDF::$TABLES[$param['num']]['corr_x']++;
  3848. }
  3849. return true;
  3850. }
  3851. /**
  3852. * balise : TR
  3853. * mode : FERMETURE
  3854. *
  3855. * @param array paramטtres de l'יlיment de parsing
  3856. * @return null
  3857. */
  3858. protected function c_TR($param)
  3859. {
  3860. if ($this->forOneLine) return false;
  3861. $this->maxH = 0;
  3862. // restauration du style
  3863. $this->style->load();
  3864. $this->style->FontSet();
  3865. // si on est pas dans un sub_html
  3866. if (!$this->sub_part)
  3867. {
  3868. // Y courant apres la ligne
  3869. $ty=null;
  3870. for($ii=0; $ii<count(HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1]); $ii++)
  3871. if (HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][$ii]['rowspan']==1)
  3872. $ty = HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][$ii]['h'];
  3873. // mise א jour des coordonnיes courantes
  3874. HTML2PDF::$TABLES[$param['num']]['td_x'] = HTML2PDF::$TABLES[$param['num']]['curr_x']+HTML2PDF::$TABLES[$param['num']]['marge']['l'];
  3875. HTML2PDF::$TABLES[$param['num']]['td_y']+= $ty;
  3876. HTML2PDF::$TABLES[$param['num']]['new_page'] = false;
  3877. }
  3878. else
  3879. {
  3880. HTML2PDF::$TABLES[$param['num']]['corr_y']++;
  3881. }
  3882. return true;
  3883. }
  3884. /**
  3885. * balise : TD
  3886. * mode : OUVERTURE
  3887. *
  3888. * @param array paramטtres de l'יlיment de parsing
  3889. * @return null
  3890. */
  3891. protected function o_TD($param, $other = 'td')
  3892. {
  3893. if ($this->forOneLine) return false;
  3894. $this->maxH = 0;
  3895. $param['cellpadding'] = HTML2PDF::$TABLES[$param['num']]['cellpadding'].'mm';
  3896. $param['cellspacing'] = HTML2PDF::$TABLES[$param['num']]['cellspacing'].'mm';
  3897. if ($other=='li')
  3898. {
  3899. $special_li = true;
  3900. }
  3901. else
  3902. {
  3903. $special_li = false;
  3904. if ($other=='li_sub')
  3905. {
  3906. $param['style']['border'] = 'none';
  3907. $param['style']['background-color'] = 'transparent';
  3908. $param['style']['background-image'] = 'none';
  3909. $param['style']['background-position'] = '';
  3910. $param['style']['background-repeat'] = '';
  3911. $other = 'li';
  3912. }
  3913. }
  3914. // est-on en collapse, et egalement y-a-t'il des definitions de colonne
  3915. $x = HTML2PDF::$TABLES[$param['num']]['td_curr'];
  3916. $y = HTML2PDF::$TABLES[$param['num']]['tr_curr']-1;
  3917. $colspan = isset($param['colspan']) ? $param['colspan'] : 1;
  3918. $rowspan = isset($param['rowspan']) ? $param['rowspan'] : 1;
  3919. $collapse = false;
  3920. if (in_array($other, array('td', 'th')))
  3921. {
  3922. $num_col = isset(HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['Xr']) ? HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['Xr'] : HTML2PDF::$TABLES[$param['num']]['corr_x'];
  3923. // si une definition de colonne est presente
  3924. if (isset(HTML2PDF::$TABLES[$param['num']]['cols'][$num_col]))
  3925. {
  3926. // on la recupere
  3927. $col_param = HTML2PDF::$TABLES[$param['num']]['cols'][$num_col];
  3928. // pour les colspan, on recupere toutes les largeurs
  3929. $col_param['style']['width'] = array();
  3930. for($k=0; $k<$colspan; $k++)
  3931. {
  3932. if (isset(HTML2PDF::$TABLES[$param['num']]['cols'][$num_col+$k]['style']['width']))
  3933. $col_param['style']['width'][] = HTML2PDF::$TABLES[$param['num']]['cols'][$num_col+$k]['style']['width'];
  3934. }
  3935. // on les somme
  3936. $total = '';
  3937. $last = $this->style->getLastWidth();
  3938. if (count($col_param['style']['width']))
  3939. {
  3940. $total = $col_param['style']['width'][0]; unset($col_param['style']['width'][0]);
  3941. foreach($col_param['style']['width'] as $width)
  3942. {
  3943. if (substr($total, -1)=='%' && substr($width, -1)=='%')
  3944. $total = (str_replace('%', '', $total)+str_replace('%', '', $width)).'%';
  3945. else
  3946. $total = ($this->style->ConvertToMM($total, $last) + $this->style->ConvertToMM($width, $last)).'mm';
  3947. }
  3948. }
  3949. // et on recupere la largeur finale
  3950. if ($total)
  3951. $col_param['style']['width'] = $total;
  3952. else
  3953. unset($col_param['style']['width']);
  3954. // on merge les 2 styles (col + td)
  3955. $param['style'] = array_merge($col_param['style'], $param['style']);
  3956. // si une classe est dיfinie, on la merge egalement
  3957. if (isset($col_param['class']))
  3958. $param['class'] = $col_param['class'].(isset($param['class']) ? ' '.$param['class'] : '');
  3959. }
  3960. $collapse = isset($this->style->value['border']['collapse']) ? $this->style->value['border']['collapse'] : false;
  3961. }
  3962. // analyse du style
  3963. $this->style->save();
  3964. $heritage = null;
  3965. if (in_array($other, array('td', 'th')))
  3966. {
  3967. $heritage = array();
  3968. $old = $this->style->getLastValue('background');
  3969. if ($old && ($old['color'] || $old['image']))
  3970. $heritage['background'] = $old;
  3971. if (HTML2PDF::$TABLES[$param['num']]['border'])
  3972. {
  3973. $heritage['border'] = array();
  3974. $heritage['border']['l'] = HTML2PDF::$TABLES[$param['num']]['border'];
  3975. $heritage['border']['t'] = HTML2PDF::$TABLES[$param['num']]['border'];
  3976. $heritage['border']['r'] = HTML2PDF::$TABLES[$param['num']]['border'];
  3977. $heritage['border']['b'] = HTML2PDF::$TABLES[$param['num']]['border'];
  3978. }
  3979. }
  3980. $return = $this->style->analyse($other, $param, $heritage);
  3981. if ($special_li)
  3982. {
  3983. $this->style->value['width']-= $this->style->ConvertToMM($this->listeGetWidth());
  3984. $this->style->value['width']-= $this->style->ConvertToMM($this->listeGetPadding());
  3985. }
  3986. $this->style->setPosition();
  3987. $this->style->FontSet();
  3988. // si on est en collapse : modification du style
  3989. if ($collapse)
  3990. {
  3991. if (!$this->sub_part)
  3992. {
  3993. if (
  3994. (HTML2PDF::$TABLES[$param['num']]['tr_curr']>1 && !HTML2PDF::$TABLES[$param['num']]['new_page']) ||
  3995. (!$this->isInThead && count(HTML2PDF::$TABLES[$param['num']]['thead']['code']))
  3996. )
  3997. {
  3998. $this->style->value['border']['t'] = $this->style->readBorder('none');
  3999. }
  4000. }
  4001. if (HTML2PDF::$TABLES[$param['num']]['td_curr']>0)
  4002. {
  4003. if (!$return) $this->style->value['width']+= $this->style->value['border']['l']['width'];
  4004. $this->style->value['border']['l'] = $this->style->readBorder('none');
  4005. }
  4006. }
  4007. $marge = array();
  4008. $marge['t'] = $this->style->value['padding']['t']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['t']['width'];
  4009. $marge['r'] = $this->style->value['padding']['r']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['r']['width'];
  4010. $marge['b'] = $this->style->value['padding']['b']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['b']['width'];
  4011. $marge['l'] = $this->style->value['padding']['l']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['l']['width'];
  4012. // si on est dans un sub_html
  4013. if ($this->sub_part)
  4014. {
  4015. // on se positionne dans le tableau
  4016. HTML2PDF::$TABLES[$param['num']]['td_curr']++;
  4017. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x] = array();
  4018. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['w'] = 0;
  4019. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['h'] = 0;
  4020. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['dw'] = 0;
  4021. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['colspan'] = $colspan;
  4022. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['rowspan'] = $rowspan;
  4023. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['Xr'] = HTML2PDF::$TABLES[$param['num']]['corr_x'];
  4024. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['Yr'] = HTML2PDF::$TABLES[$param['num']]['corr_y'];
  4025. for($j=0; $j<$rowspan; $j++)
  4026. {
  4027. for($i=0; $i<$colspan; $i++)
  4028. {
  4029. HTML2PDF::$TABLES[$param['num']]['corr']
  4030. [HTML2PDF::$TABLES[$param['num']]['corr_y']+$j]
  4031. [HTML2PDF::$TABLES[$param['num']]['corr_x']+$i] = ($i+$j>0) ? '' : array($x,$y,$colspan,$rowspan);
  4032. }
  4033. }
  4034. HTML2PDF::$TABLES[$param['num']]['corr_x']+= $colspan;
  4035. while(isset(HTML2PDF::$TABLES[$param['num']]['corr'][HTML2PDF::$TABLES[$param['num']]['corr_y']][HTML2PDF::$TABLES[$param['num']]['corr_x']]))
  4036. HTML2PDF::$TABLES[$param['num']]['corr_x']++;
  4037. // on extrait tout ce qui est contenu dans le TD
  4038. // on en crיי un sous HTML que l'on transforme en PDF
  4039. // pour analyse les dimensions
  4040. // et les rיcupיrer dans le tableau global.
  4041. $level = $this->parsing->getLevel($this->temp_pos);
  4042. $this->CreateSubHTML($this->sub_html);
  4043. $this->sub_html->parsing->code = $level;
  4044. $this->sub_html->MakeHTMLcode();
  4045. $this->temp_pos+= count($level);
  4046. }
  4047. else
  4048. {
  4049. // on se positionne dans le tableau
  4050. HTML2PDF::$TABLES[$param['num']]['td_curr']++;
  4051. HTML2PDF::$TABLES[$param['num']]['td_x']+= HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['dw'];
  4052. // initialisation du style des bordures de la premiere partie de tableau
  4053. $this->drawRectangle(
  4054. HTML2PDF::$TABLES[$param['num']]['td_x'],
  4055. HTML2PDF::$TABLES[$param['num']]['td_y'],
  4056. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['w'],
  4057. HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['h'],
  4058. $this->style->value['border'],
  4059. $this->style->value['padding'],
  4060. HTML2PDF::$TABLES[$param['num']]['cellspacing']*0.5,
  4061. $this->style->value['background']
  4062. );
  4063. $this->style->value['width'] = HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['w'] - $marge['l'] - $marge['r'];
  4064. // limitation des marges aux dimensions de la case
  4065. $mL = HTML2PDF::$TABLES[$param['num']]['td_x']+$marge['l'];
  4066. $mR = $this->pdf->getW() - $mL - $this->style->value['width'];
  4067. $this->saveMargin($mL, 0, $mR);
  4068. // positionnement en fonction
  4069. $h_corr = HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['h'];
  4070. $h_reel = HTML2PDF::$TABLES[$param['num']]['cases'][$y][$x]['real_h'];
  4071. switch($this->style->value['vertical-align'])
  4072. {
  4073. case 'bottom':
  4074. $y_corr = $h_corr-$h_reel;
  4075. break;
  4076. case 'middle':
  4077. $y_corr = ($h_corr-$h_reel)*0.5;
  4078. break;
  4079. case 'top':
  4080. default:
  4081. $y_corr = 0;
  4082. break;
  4083. }
  4084. $x = HTML2PDF::$TABLES[$param['num']]['td_x']+$marge['l'];
  4085. $y = HTML2PDF::$TABLES[$param['num']]['td_y']+$marge['t']+$y_corr;
  4086. $this->pdf->setXY($x, $y);
  4087. $this->setNewPositionForNewLine();
  4088. }
  4089. return true;
  4090. }
  4091. /**
  4092. * balise : TD
  4093. * mode : FERMETURE
  4094. *
  4095. * @param array paramטtres de l'יlיment de parsing
  4096. * @return null
  4097. */
  4098. protected function c_TD($param)
  4099. {
  4100. if ($this->forOneLine) return false;
  4101. $this->maxH = 0;
  4102. // rיcupיration de la marge
  4103. $marge = array();
  4104. $marge['t'] = $this->style->value['padding']['t']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['t']['width'];
  4105. $marge['r'] = $this->style->value['padding']['r']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['r']['width'];
  4106. $marge['b'] = $this->style->value['padding']['b']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['b']['width'];
  4107. $marge['l'] = $this->style->value['padding']['l']+0.5*HTML2PDF::$TABLES[$param['num']]['cellspacing']+$this->style->value['border']['l']['width'];
  4108. $marge['t']+= 0.001;
  4109. $marge['r']+= 0.001;
  4110. $marge['b']+= 0.001;
  4111. $marge['l']+= 0.001;
  4112. // si on est dans un sub_html
  4113. if ($this->sub_part)
  4114. {
  4115. if ($this->testTDin1page && $this->sub_html->pdf->getPage()>1)
  4116. throw new HTML2PDF_exception(7);
  4117. // dimentions de cette case
  4118. $w0 = $this->sub_html->maxX + $marge['l'] + $marge['r'];
  4119. $h0 = $this->sub_html->maxY + $marge['t'] + $marge['b'];
  4120. // dimensions imposיes par le style
  4121. $w2 = $this->style->value['width'] + $marge['l'] + $marge['r'];
  4122. $h2 = $this->style->value['height'] + $marge['t'] + $marge['b'];
  4123. // dimension finale de la case = max des 2 ci-dessus
  4124. HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][HTML2PDF::$TABLES[$param['num']]['td_curr']-1]['w'] = max(array($w0, $w2));
  4125. HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][HTML2PDF::$TABLES[$param['num']]['td_curr']-1]['h'] = max(array($h0, $h2));
  4126. HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][HTML2PDF::$TABLES[$param['num']]['td_curr']-1]['real_w'] = $w0;
  4127. HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][HTML2PDF::$TABLES[$param['num']]['td_curr']-1]['real_h'] = $h0;
  4128. // suppresion du sous_html
  4129. $this->destroySubHTML($this->sub_html);
  4130. }
  4131. else
  4132. {
  4133. $this->loadMargin();
  4134. //positionnement
  4135. HTML2PDF::$TABLES[$param['num']]['td_x']+= HTML2PDF::$TABLES[$param['num']]['cases'][HTML2PDF::$TABLES[$param['num']]['tr_curr']-1][HTML2PDF::$TABLES[$param['num']]['td_curr']-1]['w'];
  4136. }
  4137. // restauration du style
  4138. $this->style->load();
  4139. $this->style->FontSet();
  4140. return true;
  4141. }
  4142. protected function calculTailleCases(&$cases, &$corr)
  4143. {
  4144. /* // construction d'un tableau de correlation
  4145. $corr = array();
  4146. // on fait correspondre chaque case d'un tableau normי aux cases rיelles, en prennant en compte les colspan et rowspan
  4147. $Yr=0;
  4148. for($y=0; $y<count($cases); $y++)
  4149. {
  4150. $Xr=0; while(isset($corr[$Yr][$Xr])) $Xr++;
  4151. for($x=0; $x<count($cases[$y]); $x++)
  4152. {
  4153. for($j=0; $j<$cases[$y][$x]['rowspan']; $j++)
  4154. {
  4155. for($i=0; $i<$cases[$y][$x]['colspan']; $i++)
  4156. {
  4157. $corr[$Yr+$j][$Xr+$i] = ($i+$j>0) ? '' : array($x, $y, $cases[$y][$x]['colspan'], $cases[$y][$x]['rowspan']);
  4158. }
  4159. }
  4160. $Xr+= $cases[$y][$x]['colspan'];
  4161. while(isset($corr[$Yr][$Xr])) $Xr++;
  4162. }
  4163. $Yr++;
  4164. }
  4165. */
  4166. if (!isset($corr[0])) return true;
  4167. // on dיtermine, pour les cases sans colspan, la largeur maximale de chaque colone
  4168. $sw = array();
  4169. for($x=0; $x<count($corr[0]); $x++)
  4170. {
  4171. $m=0;
  4172. for($y=0; $y<count($corr); $y++)
  4173. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2]==1)
  4174. $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']);
  4175. $sw[$x] = $m;
  4176. }
  4177. // on vיrifie que cette taille est valide avec les colones en colspan
  4178. for($x=0; $x<count($corr[0]); $x++)
  4179. {
  4180. for($y=0; $y<count($corr); $y++)
  4181. {
  4182. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2]>1)
  4183. {
  4184. // somme des colonnes correspondant au colspan
  4185. $s = 0; for($i=0; $i<$corr[$y][$x][2]; $i++) $s+= $sw[$x+$i];
  4186. // si la somme est infיrieure א la taille necessaire => rטgle de 3 pour adapter
  4187. if ($s>0 && $s<$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'])
  4188. for($i=0; $i<$corr[$y][$x][2]; $i++)
  4189. $sw[$x+$i] = $sw[$x+$i]/$s*$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'];
  4190. }
  4191. }
  4192. }
  4193. // on applique les nouvelles largeurs
  4194. for($x=0; $x<count($corr[0]); $x++)
  4195. {
  4196. for($y=0; $y<count($corr); $y++)
  4197. {
  4198. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]))
  4199. {
  4200. if ($corr[$y][$x][2]==1)
  4201. {
  4202. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $sw[$x];
  4203. }
  4204. else
  4205. {
  4206. // somme des colonnes correspondant au colspan
  4207. $s = 0; for($i=0; $i<$corr[$y][$x][2]; $i++) $s+= $sw[$x+$i];
  4208. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $s;
  4209. }
  4210. }
  4211. }
  4212. }
  4213. // on dיtermine, pour les cases sans rowspan, la hauteur maximale de chaque colone
  4214. $sh = array();
  4215. for($y=0; $y<count($corr); $y++)
  4216. {
  4217. $m=0;
  4218. for($x=0; $x<count($corr[0]); $x++)
  4219. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3]==1)
  4220. $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']);
  4221. $sh[$y] = $m;
  4222. }
  4223. // on vיrifie que cette taille est valide avec les lignes en rowspan
  4224. for($y=0; $y<count($corr); $y++)
  4225. {
  4226. for($x=0; $x<count($corr[0]); $x++)
  4227. {
  4228. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3]>1)
  4229. {
  4230. // somme des colonnes correspondant au colspan
  4231. $s = 0; for($i=0; $i<$corr[$y][$x][3]; $i++) $s+= $sh[$y+$i];
  4232. // si la somme est infיrieure א la taille necessaire => rטgle de 3 pour adapter
  4233. if ($s>0 && $s<$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'])
  4234. for($i=0; $i<$corr[$y][$x][3]; $i++)
  4235. $sh[$y+$i] = $sh[$y+$i]/$s*$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'];
  4236. }
  4237. }
  4238. }
  4239. // on applique les nouvelles hauteurs
  4240. for($y=0; $y<count($corr); $y++)
  4241. {
  4242. for($x=0; $x<count($corr[0]); $x++)
  4243. {
  4244. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]))
  4245. {
  4246. if ($corr[$y][$x][3]==1)
  4247. {
  4248. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $sh[$y];
  4249. }
  4250. else
  4251. {
  4252. // somme des lignes correspondant au rowspan
  4253. $s = 0; for($i=0; $i<$corr[$y][$x][3]; $i++) $s+= $sh[$y+$i];
  4254. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $s;
  4255. for($j=1; $j<$corr[$y][$x][3]; $j++)
  4256. {
  4257. $tx = $x+1;
  4258. $ty = $y+$j;
  4259. for(true; isset($corr[$ty][$tx]) && !is_array($corr[$ty][$tx]); $tx++);
  4260. 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'];
  4261. }
  4262. }
  4263. }
  4264. }
  4265. }
  4266. }
  4267. /**
  4268. * balise : TH
  4269. * mode : OUVERTURE
  4270. *
  4271. * @param array paramטtres de l'יlיment de parsing
  4272. * @return null
  4273. */
  4274. protected function o_TH($param)
  4275. {
  4276. if ($this->forOneLine) return false;
  4277. $this->maxH = 0;
  4278. // identique א TD mais en gras
  4279. if (!isset($param['style']['font-weight'])) $param['style']['font-weight'] = 'bold';
  4280. $this->o_TD($param, 'th');
  4281. return true;
  4282. }
  4283. /**
  4284. * balise : TH
  4285. * mode : FERMETURE
  4286. *
  4287. * @param array paramטtres de l'יlיment de parsing
  4288. * @return null
  4289. */
  4290. protected function c_TH($param)
  4291. {
  4292. if ($this->forOneLine) return false;
  4293. $this->maxH = 0;
  4294. // identique א TD
  4295. $this->c_TD($param);
  4296. return true;
  4297. }
  4298. /**
  4299. * balise : IMG
  4300. * mode : OUVERTURE
  4301. *
  4302. * @param array paramטtres de l'יlיment de parsing
  4303. * @return null
  4304. */
  4305. protected function o_IMG($param)
  4306. {
  4307. // analyse du style
  4308. $src = str_replace('&amp;', '&', $param['src']);
  4309. $this->style->save();
  4310. $this->style->value['width'] = 0;
  4311. $this->style->value['height'] = 0;
  4312. $this->style->value['border'] = array(
  4313. 'type' => 'none',
  4314. 'width' => 0,
  4315. 'color' => array(0, 0, 0),
  4316. );
  4317. $this->style->value['background'] = array(
  4318. 'color' => null,
  4319. 'image' => null,
  4320. 'position' => null,
  4321. 'repeat' => null
  4322. );
  4323. $this->style->analyse('img', $param);
  4324. $this->style->setPosition();
  4325. $this->style->FontSet();
  4326. // affichage de l'image
  4327. $res = $this->Image($src, isset($param['sub_li']));
  4328. if (!$res) return $res;
  4329. // restauration du style
  4330. $this->style->load();
  4331. $this->style->FontSet();
  4332. $this->maxE++;
  4333. return true;
  4334. }
  4335. /**
  4336. * balise : SELECT
  4337. * mode : OUVERTURE
  4338. *
  4339. * @param array paramטtres de l'יlיment de parsing
  4340. * @return null
  4341. */
  4342. protected function o_SELECT($param)
  4343. {
  4344. // preparation du champs
  4345. if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
  4346. $param['name'] = strtolower($param['name']);
  4347. if (isset($this->lstChamps[$param['name']]))
  4348. $this->lstChamps[$param['name']]++;
  4349. else
  4350. $this->lstChamps[$param['name']] = 1;
  4351. $this->style->save();
  4352. $this->style->analyse('select', $param);
  4353. $this->style->setPosition();
  4354. $this->style->FontSet();
  4355. $this->lstSelect = array();
  4356. $this->lstSelect['name'] = $param['name'];
  4357. $this->lstSelect['multi'] = isset($param['multiple']) ? true : false;
  4358. $this->lstSelect['size'] = isset($param['size']) ? $param['size'] : 1;
  4359. $this->lstSelect['options'] = array();
  4360. if ($this->lstSelect['multi'] && $this->lstSelect['size']<3) $this->lstSelect['size'] = 3;
  4361. return true;
  4362. }
  4363. /**
  4364. * balise : OPTION
  4365. * mode : OUVERTURE
  4366. *
  4367. * @param array paramטtres de l'יlיment de parsing
  4368. * @return null
  4369. */
  4370. protected function o_OPTION($param)
  4371. {
  4372. // on extrait tout ce qui est contenu dans l'option
  4373. $level = $this->parsing->getLevel($this->parse_pos);
  4374. $this->parse_pos+= count($level);
  4375. $value = isset($param['value']) ? $param['value'] : 'auto_opt_'.(count($this->lstSelect)+1);
  4376. $this->lstSelect['options'][$value] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : '';
  4377. return true;
  4378. }
  4379. /**
  4380. * balise : OPTION
  4381. * mode : FERMETURE
  4382. *
  4383. * @param array paramטtres de l'יlיment de parsing
  4384. * @return null
  4385. */
  4386. protected function c_OPTION($param) { return true; }
  4387. /**
  4388. * balise : SELECT
  4389. * mode : FERMETURE
  4390. *
  4391. * @param array paramטtres de l'יlיment de parsing
  4392. * @return null
  4393. */
  4394. protected function c_SELECT()
  4395. {
  4396. // position d'affichage
  4397. $x = $this->pdf->getX();
  4398. $y = $this->pdf->getY();
  4399. $f = 1.08*$this->style->value['font-size'];
  4400. $w = $this->style->value['width']; if (!$w) $w = 50;
  4401. $h = ($f*1.07*$this->lstSelect['size'] + 1);
  4402. $opts = array();
  4403. if ($this->lstSelect['multi']) $opts['multipleSelection'] = 'true';
  4404. if ($this->lstSelect['size']>1)
  4405. $this->pdf->ListBox ($this->lstSelect['name'], $w, $h, $this->lstSelect['options'], $opts);
  4406. else
  4407. $this->pdf->ComboBox($this->lstSelect['name'], $w, $h, $this->lstSelect['options']);
  4408. $this->maxX = max($this->maxX, $x+$w);
  4409. $this->maxY = max($this->maxY, $y+$h);
  4410. $this->maxH = max($this->maxH, $h);
  4411. $this->pdf->setX($x+$w);
  4412. $this->style->load();
  4413. $this->style->FontSet();
  4414. $this->lstSelect = array();
  4415. return true;
  4416. }
  4417. /**
  4418. * balise : TEXTAREA
  4419. * mode : OUVERTURE
  4420. *
  4421. * @param array paramטtres de l'יlיment de parsing
  4422. * @return null
  4423. */
  4424. protected function o_TEXTAREA($param)
  4425. {
  4426. // preparation du champs
  4427. if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
  4428. $param['name'] = strtolower($param['name']);
  4429. if (isset($this->lstChamps[$param['name']]))
  4430. $this->lstChamps[$param['name']]++;
  4431. else
  4432. $this->lstChamps[$param['name']] = 1;
  4433. $this->style->save();
  4434. $this->style->analyse('textarea', $param);
  4435. $this->style->setPosition();
  4436. $this->style->FontSet();
  4437. // position d'affichage
  4438. $x = $this->pdf->getX();
  4439. $y = $this->pdf->getY();
  4440. $fx = 0.65*$this->style->value['font-size'];
  4441. $fy = 1.08*$this->style->value['font-size'];
  4442. // on extrait tout ce qui est contenu dans le textarea
  4443. $level = $this->parsing->getLevel($this->parse_pos);
  4444. $this->parse_pos+= count($level);
  4445. $w = $fx*(isset($param['cols']) ? $param['cols'] : 22)+1;
  4446. $h = $fy*1.07*(isset($param['rows']) ? $param['rows'] : 3)+3;
  4447. // if ($this->style->value['width']) $w = $this->style->value['width'];
  4448. // if ($this->style->value['height']) $h = $this->style->value['height'];
  4449. $prop = array();
  4450. $prop['multiline'] = true;
  4451. $prop['value'] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : '';
  4452. $this->pdf->TextField($param['name'], $w, $h, $prop, array(), $x, $y);
  4453. $this->maxX = max($this->maxX, $x+$w);
  4454. $this->maxY = max($this->maxY, $y+$h);
  4455. $this->maxH = max($this->maxH, $h);
  4456. $this->pdf->setX($x+$w);
  4457. return true;
  4458. }
  4459. /**
  4460. * balise : TEXTAREA
  4461. * mode : FERMETURE
  4462. *
  4463. * @param array paramטtres de l'יlיment de parsing
  4464. * @return null
  4465. */
  4466. protected function c_TEXTAREA()
  4467. {
  4468. $this->style->load();
  4469. $this->style->FontSet();
  4470. return true;
  4471. }
  4472. /**
  4473. * balise : INPUT
  4474. * mode : OUVERTURE
  4475. *
  4476. * @param array paramטtres de l'יlיment de parsing
  4477. * @return null
  4478. */
  4479. protected function o_INPUT($param)
  4480. {
  4481. // preparation du champs
  4482. if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
  4483. if (!isset($param['value'])) $param['value'] = '';
  4484. if (!isset($param['type'])) $param['type'] = 'text';
  4485. $param['name'] = strtolower($param['name']);
  4486. $param['type'] = strtolower($param['type']);
  4487. if (!in_array($param['type'], array('text', 'checkbox', 'radio', 'hidden', 'submit', 'reset', 'button'))) $param['type'] = 'text';
  4488. if (isset($this->lstChamps[$param['name']]))
  4489. $this->lstChamps[$param['name']]++;
  4490. else
  4491. $this->lstChamps[$param['name']] = 1;
  4492. $this->style->save();
  4493. $this->style->analyse('input', $param);
  4494. $this->style->setPosition();
  4495. $this->style->FontSet();
  4496. $name = $param['name'];
  4497. // position d'affichage
  4498. $x = $this->pdf->getX();
  4499. $y = $this->pdf->getY();
  4500. $f = 1.08*$this->style->value['font-size'];
  4501. switch($param['type'])
  4502. {
  4503. case 'checkbox':
  4504. $w = 3;
  4505. $h = $w;
  4506. if ($h<$f) $y+= ($f-$h)*0.5;
  4507. $this->pdf->CheckBox($name, $w, isset($param['checked']), array(), array(), ($param['value'] ? $param['value'] : 'Yes'), $x, $y);
  4508. break;
  4509. case 'radio':
  4510. $w = 3;
  4511. $h = $w;
  4512. if ($h<$f) $y+= ($f-$h)*0.5;
  4513. $this->pdf->RadioButton($name, $w, array(), array(), ($param['value'] ? $param['value'] : 'On'), isset($param['selected']), $x, $y);
  4514. break;
  4515. case 'hidden':
  4516. $w = 0;
  4517. $h = 0;
  4518. $prop = array();
  4519. $prop['value'] = $param['value'];
  4520. $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y);
  4521. break;
  4522. case 'text':
  4523. $w = $this->style->value['width']; if (!$w) $w = 40;
  4524. $h = $f*1.3;
  4525. $prop = array();
  4526. $prop['value'] = $param['value'];
  4527. $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y);
  4528. break;
  4529. case 'submit':
  4530. $w = $this->style->value['width']; if (!$w) $w = 40;
  4531. $h = $this->style->value['height']; if (!$h) $h = $f*1.3;
  4532. $action = array('S'=>'SubmitForm', 'F'=>$this->isInForm, 'Flags'=>array('ExportFormat'));
  4533. $this->pdf->Button($name, $w, $h, $param['value'], $action, array(), array(), $x, $y);
  4534. break;
  4535. case 'reset':
  4536. $w = $this->style->value['width']; if (!$w) $w = 40;
  4537. $h = $this->style->value['height']; if (!$h) $h = $f*1.3;
  4538. $action = array('S'=>'ResetForm');
  4539. $this->pdf->Button($name, $w, $h, $param['value'], $action, array(), array(), $x, $y);
  4540. break;
  4541. case 'button':
  4542. $w = $this->style->value['width']; if (!$w) $w = 40;
  4543. $h = $this->style->value['height']; if (!$h) $h = $f*1.3;
  4544. $action = isset($param['onclick']) ? $param['onclick'] : '';
  4545. $this->pdf->Button($name, $w, $h, $param['value'], $action, array(), array(), $x, $y);
  4546. break;
  4547. default:
  4548. $w = 0;
  4549. $h = 0;
  4550. break;
  4551. }
  4552. $this->maxX = max($this->maxX, $x+$w);
  4553. $this->maxY = max($this->maxY, $y+$h);
  4554. $this->maxH = max($this->maxH, $h);
  4555. $this->pdf->setX($x+$w);
  4556. $this->style->load();
  4557. $this->style->FontSet();
  4558. return true;
  4559. }
  4560. /**
  4561. * balise : DRAW
  4562. * mode : OUVERTURE
  4563. *
  4564. * @param array paramטtres de l'יlיment de parsing
  4565. * @return null
  4566. */
  4567. protected function o_DRAW($param)
  4568. {
  4569. if ($this->forOneLine) return false;
  4570. if ($this->DEBUG_actif) $this->DEBUG_add('DRAW', true);
  4571. $this->style->save();
  4572. $this->style->analyse('draw', $param);
  4573. $this->style->FontSet();
  4574. $align_object = null;
  4575. if ($this->style->value['margin-auto']) $align_object = 'center';
  4576. $over_w = $this->style->value['width'];
  4577. $over_h = $this->style->value['height'];
  4578. $this->style->value['old_maxX'] = $this->maxX;
  4579. $this->style->value['old_maxY'] = $this->maxY;
  4580. $this->style->value['old_maxH'] = $this->maxH;
  4581. $w = $this->style->value['width'];
  4582. $h = $this->style->value['height'];
  4583. if (!$this->style->value['position'])
  4584. {
  4585. if (
  4586. $w < ($this->pdf->getW() - $this->pdf->getlMargin()-$this->pdf->getrMargin()) &&
  4587. $this->pdf->getX() + $w>=($this->pdf->getW() - $this->pdf->getrMargin())
  4588. )
  4589. $this->o_BR(array());
  4590. if (
  4591. ($h < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin())) &&
  4592. ($this->pdf->getY() + $h>=($this->pdf->getH() - $this->pdf->getbMargin())) &&
  4593. !$this->isInOverflow
  4594. )
  4595. $this->setNewPage();
  4596. // en cas d'alignement => correction
  4597. $old = $this->style->getOldValues();
  4598. $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
  4599. if ($parent_w>$w)
  4600. {
  4601. if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
  4602. else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
  4603. }
  4604. $this->style->setPosition();
  4605. }
  4606. else
  4607. {
  4608. // en cas d'alignement => correction
  4609. $old = $this->style->getOldValues();
  4610. $parent_w = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
  4611. if ($parent_w>$w)
  4612. {
  4613. if ($align_object=='center') $this->pdf->setX($this->pdf->getX() + ($parent_w-$w)*0.5);
  4614. else if ($align_object=='right') $this->pdf->setX($this->pdf->getX() + $parent_w-$w);
  4615. }
  4616. $this->style->setPosition();
  4617. $this->saveMax();
  4618. $this->maxX = 0;
  4619. $this->maxY = 0;
  4620. $this->maxH = 0;
  4621. $this->maxE = 0;
  4622. }
  4623. // initialisation du style des bordures de la div
  4624. $this->drawRectangle(
  4625. $this->style->value['x'],
  4626. $this->style->value['y'],
  4627. $this->style->value['width'],
  4628. $this->style->value['height'],
  4629. $this->style->value['border'],
  4630. $this->style->value['padding'],
  4631. 0,
  4632. $this->style->value['background']
  4633. );
  4634. $marge = array();
  4635. $marge['l'] = $this->style->value['border']['l']['width'];
  4636. $marge['r'] = $this->style->value['border']['r']['width'];
  4637. $marge['t'] = $this->style->value['border']['t']['width'];
  4638. $marge['b'] = $this->style->value['border']['b']['width'];
  4639. $this->style->value['width'] -= $marge['l']+$marge['r'];
  4640. $this->style->value['height']-= $marge['t']+$marge['b'];
  4641. $over_w-= $marge['l']+$marge['r'];
  4642. $over_h-= $marge['t']+$marge['b'];
  4643. $this->pdf->clippingPathOpen(
  4644. $this->style->value['x']+$marge['l'],
  4645. $this->style->value['y']+$marge['t'],
  4646. $this->style->value['width'],
  4647. $this->style->value['height']
  4648. );
  4649. // limitation des marges aux dimensions du contenu
  4650. $mL = $this->style->value['x']+$marge['l'];
  4651. $mR = $this->pdf->getW() - $mL - $over_w;
  4652. $x = $this->style->value['x']+$marge['l'];
  4653. $y = $this->style->value['y']+$marge['t'];
  4654. $this->saveMargin($mL, 0, $mR);
  4655. $this->pdf->setXY($x, $y);
  4656. $this->isInDraw = array(
  4657. 'x' => $x,
  4658. 'y' => $y,
  4659. 'w' => $over_w,
  4660. 'h' => $over_h,
  4661. );
  4662. $this->pdf->doTransform(array(1,0,0,1,$x,$y));
  4663. $this->pdf->SetAlpha(1.);
  4664. return true;
  4665. }
  4666. /**
  4667. * balise : DRAW
  4668. * mode : FERMETURE
  4669. *
  4670. * @param array paramטtres de l'יlיment de parsing
  4671. * @return null
  4672. */
  4673. protected function c_DRAW($param)
  4674. {
  4675. if ($this->forOneLine) return false;
  4676. $this->pdf->SetAlpha(1.);
  4677. $this->pdf->undoTransform();
  4678. $this->pdf->clippingPathClose();
  4679. $this->maxX = $this->style->value['old_maxX'];
  4680. $this->maxY = $this->style->value['old_maxY'];
  4681. $this->maxH = $this->style->value['old_maxH'];
  4682. $marge = array();
  4683. $marge['l'] = $this->style->value['border']['l']['width'];
  4684. $marge['r'] = $this->style->value['border']['r']['width'];
  4685. $marge['t'] = $this->style->value['border']['t']['width'];
  4686. $marge['b'] = $this->style->value['border']['b']['width'];
  4687. $x = $this->style->value['x'];
  4688. $y = $this->style->value['y'];
  4689. $w = $this->style->value['width']+$marge['l']+$marge['r'];
  4690. $h = $this->style->value['height']+$marge['t']+$marge['b'];
  4691. if ($this->style->value['position']!='absolute')
  4692. {
  4693. // position
  4694. $this->pdf->setXY($x+$w, $y);
  4695. // position MAX
  4696. $this->maxX = max($this->maxX, $x+$w);
  4697. $this->maxY = max($this->maxY, $y+$h);
  4698. $this->maxH = max($this->maxH, $h);
  4699. }
  4700. else
  4701. {
  4702. // position
  4703. $this->pdf->setXY($this->style->value['xc'], $this->style->value['yc']);
  4704. $this->loadMax();
  4705. }
  4706. $block = ($this->style->value['display']!='inline' && $this->style->value['position']!='absolute');
  4707. $this->style->load();
  4708. $this->style->FontSet();
  4709. $this->loadMargin();
  4710. if ($block) $this->o_BR(array());
  4711. if ($this->DEBUG_actif) $this->DEBUG_add('DRAW', false);
  4712. $this->isInDraw = null;
  4713. return true;
  4714. }
  4715. /**
  4716. * balise : LINE
  4717. * mode : OUVERTURE
  4718. *
  4719. * @param array paramטtres de l'יlיment de parsing
  4720. * @return null
  4721. */
  4722. protected function o_LINE($param)
  4723. {
  4724. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'LINE');
  4725. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4726. $this->style->save();
  4727. $styles = $this->style->getSvgStyle('path', $param);
  4728. $styles['fill'] = null;
  4729. $style = $this->pdf->svgSetStyle($styles);
  4730. $x1 = isset($param['x1']) ? $this->style->ConvertToMM($param['x1'], $this->isInDraw['w']) : 0.;
  4731. $y1 = isset($param['y1']) ? $this->style->ConvertToMM($param['y1'], $this->isInDraw['h']) : 0.;
  4732. $x2 = isset($param['x2']) ? $this->style->ConvertToMM($param['x2'], $this->isInDraw['w']) : 0.;
  4733. $y2 = isset($param['y2']) ? $this->style->ConvertToMM($param['y2'], $this->isInDraw['h']) : 0.;
  4734. $this->pdf->svgLine($x1, $y1, $x2, $y2);
  4735. $this->pdf->undoTransform();
  4736. $this->style->load();
  4737. }
  4738. /**
  4739. * balise : RECT
  4740. * mode : OUVERTURE
  4741. *
  4742. * @param array paramטtres de l'יlיment de parsing
  4743. * @return null
  4744. */
  4745. protected function o_RECT($param)
  4746. {
  4747. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'RECT');
  4748. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4749. $this->style->save();
  4750. $styles = $this->style->getSvgStyle('path', $param);
  4751. $style = $this->pdf->svgSetStyle($styles);
  4752. $x = isset($param['x']) ? $this->style->ConvertToMM($param['x'], $this->isInDraw['w']) : 0.;
  4753. $y = isset($param['y']) ? $this->style->ConvertToMM($param['y'], $this->isInDraw['h']) : 0.;
  4754. $w = isset($param['w']) ? $this->style->ConvertToMM($param['w'], $this->isInDraw['w']) : 0.;
  4755. $h = isset($param['h']) ? $this->style->ConvertToMM($param['h'], $this->isInDraw['h']) : 0.;
  4756. $this->pdf->svgRect($x, $y, $w, $h, $style);
  4757. $this->pdf->undoTransform();
  4758. $this->style->load();
  4759. }
  4760. /**
  4761. * balise : CIRCLE
  4762. * mode : OUVERTURE
  4763. *
  4764. * @param array paramטtres de l'יlיment de parsing
  4765. * @return null
  4766. */
  4767. protected function o_CIRCLE($param)
  4768. {
  4769. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'CIRCLE');
  4770. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4771. $this->style->save();
  4772. $styles = $this->style->getSvgStyle('path', $param);
  4773. $style = $this->pdf->svgSetStyle($styles);
  4774. $cx = isset($param['cx']) ? $this->style->ConvertToMM($param['cx'], $this->isInDraw['w']) : 0.;
  4775. $cy = isset($param['cy']) ? $this->style->ConvertToMM($param['cy'], $this->isInDraw['h']) : 0.;
  4776. $r = isset($param['r']) ? $this->style->ConvertToMM($param['r'], $this->isInDraw['w']) : 0.;
  4777. $this->pdf->svgEllipse($cx, $cy, $r, $r, $style);
  4778. $this->pdf->undoTransform();
  4779. $this->style->load();
  4780. }
  4781. /**
  4782. * balise : ELLIPSE
  4783. * mode : OUVERTURE
  4784. *
  4785. * @param array paramטtres de l'יlיment de parsing
  4786. * @return null
  4787. */
  4788. protected function o_ELLIPSE($param)
  4789. {
  4790. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'ELLIPSE');
  4791. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4792. $this->style->save();
  4793. $styles = $this->style->getSvgStyle('path', $param);
  4794. $style = $this->pdf->svgSetStyle($styles);
  4795. $cx = isset($param['cx']) ? $this->style->ConvertToMM($param['cx'], $this->isInDraw['w']) : 0.;
  4796. $cy = isset($param['cy']) ? $this->style->ConvertToMM($param['cy'], $this->isInDraw['h']) : 0.;
  4797. $rx = isset($param['ry']) ? $this->style->ConvertToMM($param['rx'], $this->isInDraw['w']) : 0.;
  4798. $ry = isset($param['rx']) ? $this->style->ConvertToMM($param['ry'], $this->isInDraw['h']) : 0.;
  4799. $this->pdf->svgEllipse($cx, $cy, $rx, $ry, $style);
  4800. $this->pdf->undoTransform();
  4801. $this->style->load();
  4802. }
  4803. /**
  4804. * balise : POLYLINE
  4805. * mode : OUVERTURE
  4806. *
  4807. * @param array paramטtres de l'יlיment de parsing
  4808. * @return null
  4809. */
  4810. protected function o_POLYLINE($param)
  4811. {
  4812. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'POLYGON');
  4813. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4814. $this->style->save();
  4815. $styles = $this->style->getSvgStyle('path', $param);
  4816. $style = $this->pdf->svgSetStyle($styles);
  4817. $path = isset($param['points']) ? $param['points'] : null;
  4818. if ($path)
  4819. {
  4820. $path = str_replace(',', ' ', $path);
  4821. $path = preg_replace('/[\s]+/', ' ', trim($path));
  4822. // decoupage et nettoyage
  4823. $path = explode(' ', $path);
  4824. foreach($path as $k => $v)
  4825. {
  4826. $path[$k] = trim($v);
  4827. if ($path[$k]==='') unset($path[$k]);
  4828. }
  4829. $path = array_values($path);
  4830. $actions = array();
  4831. for($k=0; $k<count($path); $k+=2)
  4832. {
  4833. $actions[] = array(($k ? 'L' : 'M') ,
  4834. $this->style->ConvertToMM($path[$k+0], $this->isInDraw['w']),
  4835. $this->style->ConvertToMM($path[$k+1], $this->isInDraw['h']));
  4836. }
  4837. // on trace
  4838. $this->pdf->svgPolygone($actions, $style);
  4839. }
  4840. $this->pdf->undoTransform();
  4841. $this->style->load();
  4842. }
  4843. /**
  4844. * balise : POLYGON
  4845. * mode : OUVERTURE
  4846. *
  4847. * @param array paramטtres de l'יlיment de parsing
  4848. * @return null
  4849. */
  4850. protected function o_POLYGON($param)
  4851. {
  4852. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'POLYGON');
  4853. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4854. $this->style->save();
  4855. $styles = $this->style->getSvgStyle('path', $param);
  4856. $style = $this->pdf->svgSetStyle($styles);
  4857. $path = isset($param['points']) ? $param['points'] : null;
  4858. if ($path)
  4859. {
  4860. $path = str_replace(',', ' ', $path);
  4861. $path = preg_replace('/[\s]+/', ' ', trim($path));
  4862. // decoupage et nettoyage
  4863. $path = explode(' ', $path);
  4864. foreach($path as $k => $v)
  4865. {
  4866. $path[$k] = trim($v);
  4867. if ($path[$k]==='') unset($path[$k]);
  4868. }
  4869. $path = array_values($path);
  4870. $actions = array();
  4871. for($k=0; $k<count($path); $k+=2)
  4872. {
  4873. $actions[] = array(($k ? 'L' : 'M') ,
  4874. $this->style->ConvertToMM($path[$k+0], $this->isInDraw['w']),
  4875. $this->style->ConvertToMM($path[$k+1], $this->isInDraw['h']));
  4876. }
  4877. $actions[] = array('z');
  4878. // on trace
  4879. $this->pdf->svgPolygone($actions, $style);
  4880. }
  4881. $this->pdf->undoTransform();
  4882. $this->style->load();
  4883. }
  4884. /**
  4885. * balise : PATH
  4886. * mode : OUVERTURE
  4887. *
  4888. * @param array paramטtres de l'יlיment de parsing
  4889. * @return null
  4890. */
  4891. protected function o_PATH($param)
  4892. {
  4893. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'PATH');
  4894. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4895. $this->style->save();
  4896. $styles = $this->style->getSvgStyle('path', $param);
  4897. $style = $this->pdf->svgSetStyle($styles);
  4898. $path = isset($param['d']) ? $param['d'] : null;
  4899. if ($path)
  4900. {
  4901. // preparation
  4902. $path = str_replace(',', ' ', $path);
  4903. $path = preg_replace('/([a-zA-Z])([0-9\.\-])/', '$1 $2', $path);
  4904. $path = preg_replace('/([0-9\.])([a-zA-Z])/', '$1 $2', $path);
  4905. $path = preg_replace('/[\s]+/', ' ', trim($path));
  4906. $path = preg_replace('/ ([a-z]{2})/', '$1', $path);
  4907. // decoupage et nettoyage
  4908. $path = explode(' ', $path);
  4909. foreach($path as $k => $v)
  4910. {
  4911. $path[$k] = trim($v);
  4912. if ($path[$k]==='') unset($path[$k]);
  4913. }
  4914. $path = array_values($path);
  4915. // conversion des unites
  4916. $actions = array();
  4917. $action = array();
  4918. for($k=0; $k<count($path); $k+=count($action))
  4919. {
  4920. $action = array();
  4921. $action[] = $path[$k];
  4922. switch($path[$k])
  4923. {
  4924. case 'C':
  4925. case 'c':
  4926. $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x1
  4927. $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // y1
  4928. $action[] = $this->style->ConvertToMM($path[$k+3], $this->isInDraw['w']); // x2
  4929. $action[] = $this->style->ConvertToMM($path[$k+4], $this->isInDraw['h']); // y2
  4930. $action[] = $this->style->ConvertToMM($path[$k+5], $this->isInDraw['w']); // x
  4931. $action[] = $this->style->ConvertToMM($path[$k+6], $this->isInDraw['h']); // y
  4932. break;
  4933. case 'Q':
  4934. case 'S':
  4935. case 'q':
  4936. case 's':
  4937. $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x2
  4938. $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // y2
  4939. $action[] = $this->style->ConvertToMM($path[$k+3], $this->isInDraw['w']); // x
  4940. $action[] = $this->style->ConvertToMM($path[$k+4], $this->isInDraw['h']); // y
  4941. break;
  4942. case 'A':
  4943. case 'a':
  4944. $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // rx
  4945. $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // ry
  4946. $action[] = 1.*$path[$k+3]; // angle de deviation de l'axe X
  4947. $action[] = ($path[$k+4]=='1') ? 1 : 0; // large-arc-flag
  4948. $action[] = ($path[$k+5]=='1') ? 1 : 0; // sweep-flag
  4949. $action[] = $this->style->ConvertToMM($path[$k+6], $this->isInDraw['w']); // x
  4950. $action[] = $this->style->ConvertToMM($path[$k+7], $this->isInDraw['h']); // y
  4951. break;
  4952. case 'M':
  4953. case 'L':
  4954. case 'T':
  4955. case 'm':
  4956. case 'l':
  4957. case 't':
  4958. $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x
  4959. $action[] = $this->style->ConvertToMM($path[$k+2], $this->isInDraw['h']); // y
  4960. break;
  4961. case 'H':
  4962. case 'h':
  4963. $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['w']); // x
  4964. break;
  4965. case 'V':
  4966. case 'v':
  4967. $action[] = $this->style->ConvertToMM($path[$k+1], $this->isInDraw['h']); // y
  4968. break;
  4969. case 'z':
  4970. case 'Z':
  4971. default:
  4972. break;
  4973. }
  4974. $actions[] = $action;
  4975. }
  4976. // on trace
  4977. $this->pdf->svgPolygone($actions, $style);
  4978. }
  4979. $this->pdf->undoTransform();
  4980. $this->style->load();
  4981. }
  4982. /**
  4983. * balise : G
  4984. * mode : OUVERTURE
  4985. *
  4986. * @param array paramטtres de l'יlיment de parsing
  4987. * @return null
  4988. */
  4989. protected function o_G($param)
  4990. {
  4991. if (!$this->isInDraw) throw new HTML2PDF_exception(8, 'LINE');
  4992. $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
  4993. $this->style->save();
  4994. $styles = $this->style->getSvgStyle('path', $param);
  4995. $style = $this->pdf->svgSetStyle($styles);
  4996. }
  4997. /**
  4998. * balise : G
  4999. * mode : FERMETURE
  5000. *
  5001. * @param array paramטtres de l'יlיment de parsing
  5002. * @return null
  5003. */
  5004. protected function c_G($param)
  5005. {
  5006. $this->pdf->undoTransform();
  5007. $this->style->load();
  5008. }
  5009. protected function _prepareTransform($transform)
  5010. {
  5011. if (!$transform) return null;
  5012. $actions = array();
  5013. if (!preg_match_all('/([a-z]+)\(([^\)]*)\)/isU', $transform, $match)) return null;
  5014. for($k=0; $k<count($match[0]); $k++)
  5015. {
  5016. $nom = strtolower($match[1][$k]);
  5017. $val = explode(',', trim($match[2][$k]));
  5018. foreach($val as $i => $j)
  5019. $val[$i] = trim($j);
  5020. switch($nom)
  5021. {
  5022. case 'scale':
  5023. if (!isset($val[0])) $val[0] = 1.; else $val[0] = 1.*$val[0];
  5024. if (!isset($val[1])) $val[1] = $val[0]; else $val[1] = 1.*$val[1];
  5025. $actions[] = array($val[0],0,0,$val[1],0,0);
  5026. break;
  5027. case 'translate':
  5028. if (!isset($val[0])) $val[0] = 0.; else $val[0] = $this->style->ConvertToMM($val[0], $this->isInDraw['w']);
  5029. if (!isset($val[1])) $val[1] = 0.; else $val[1] = $this->style->ConvertToMM($val[1], $this->isInDraw['h']);
  5030. $actions[] = array(1,0,0,1,$val[0],$val[1]);
  5031. break;
  5032. case 'rotate':
  5033. if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*M_PI/180.;
  5034. if (!isset($val[1])) $val[1] = 0.; else $val[1] = $this->style->ConvertToMM($val[1], $this->isInDraw['w']);
  5035. if (!isset($val[2])) $val[2] = 0.; else $val[2] = $this->style->ConvertToMM($val[2], $this->isInDraw['h']);
  5036. if ($val[1] || $val[2]) $actions[] = array(1,0,0,1,-$val[1],-$val[2]);
  5037. $actions[] = array(cos($val[0]),sin($val[0]),-sin($val[0]),cos($val[0]),0,0);
  5038. if ($val[1] || $val[2]) $actions[] = array(1,0,0,1,$val[1],$val[2]);
  5039. break;
  5040. case 'skewx':
  5041. if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*M_PI/180.;
  5042. $actions[] = array(1,0,tan($val[0]),1,0,0);
  5043. break;
  5044. case 'skewy':
  5045. if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*M_PI/180.;
  5046. $actions[] = array(1,tan($val[0]),0,1,0,0);
  5047. break;
  5048. case 'matrix':
  5049. if (!isset($val[0])) $val[0] = 0.; else $val[0] = $val[0]*1.;
  5050. if (!isset($val[1])) $val[1] = 0.; else $val[1] = $val[1]*1.;
  5051. if (!isset($val[2])) $val[2] = 0.; else $val[2] = $val[2]*1.;
  5052. if (!isset($val[3])) $val[3] = 0.; else $val[3] = $val[3]*1.;
  5053. if (!isset($val[4])) $val[4] = 0.; else $val[4] = $this->style->ConvertToMM($val[4], $this->isInDraw['w']);
  5054. if (!isset($val[5])) $val[5] = 0.; else $val[5] = $this->style->ConvertToMM($val[5], $this->isInDraw['h']);
  5055. $actions[] =$val;
  5056. break;
  5057. }
  5058. }
  5059. if (!$actions) return null;
  5060. $m = $actions[0]; unset($actions[0]);
  5061. foreach($actions as $n)
  5062. {
  5063. $m = array(
  5064. $m[0]*$n[0]+$m[2]*$n[1],
  5065. $m[1]*$n[0]+$m[3]*$n[1],
  5066. $m[0]*$n[2]+$m[2]*$n[3],
  5067. $m[1]*$n[2]+$m[3]*$n[3],
  5068. $m[0]*$n[4]+$m[2]*$n[5]+$m[4],
  5069. $m[1]*$n[4]+$m[3]*$n[5]+$m[5]
  5070. );
  5071. }
  5072. return $m;
  5073. }
  5074. protected function _getDrawNumber(&$lst, $key, $n=1, $correct=false)
  5075. {
  5076. $res = array_fill(0, $n, 0);
  5077. $tmp = isset($lst[$key]) ? $lst[$key] : null;
  5078. if (!$tmp) return $res;
  5079. $tmp = explode(' ', trim(preg_replace('/[\s]+/', ' ', $tmp)));
  5080. foreach($tmp as $k => $v)
  5081. {
  5082. $v = trim($v);
  5083. if (!$correct)
  5084. {
  5085. $res[$k] = $this->style->ConvertToMM($v);
  5086. }
  5087. else
  5088. {
  5089. $res[$k] = $this->style->ConvertToMM($v, ($k%2) ? $this->isInDraw['h'] : $this->isInDraw['w']);
  5090. }
  5091. }
  5092. return $res;
  5093. }
  5094. /**
  5095. * permet d'afficher un index automatique utilisant les bookmark
  5096. *
  5097. * @param string titre du sommaire
  5098. * @param int taille en mm de la fonte du titre du sommaire
  5099. * @param int taille en mm de la fonte du texte du sommaire
  5100. * @param boolean ajouter un bookmark spיcifique pour l'index, juste avant le dיbut de celui-ci
  5101. * @param boolean afficher les numיros de page associיs א chaque bookmark
  5102. * @param int si prיsent : page oש afficher le sommaire. sinon : nouvelle page
  5103. * @param string nom de la fonte א utiliser
  5104. * @return null
  5105. */
  5106. public function createIndex($titre = 'Index', $size_title = 20, $size_bookmark = 15, $bookmark_title = true, $display_page = true, $on_page = null, $font_name = 'helvetica')
  5107. {
  5108. $old_page = $this->INDEX_NewPage($on_page);
  5109. $this->pdf->createIndex($this, $titre, $size_title, $size_bookmark, $bookmark_title, $display_page, $on_page, $font_name);
  5110. if ($old_page) $this->pdf->setPage($old_page);
  5111. }
  5112. /**
  5113. * nouvelle page pour l'index. ne pas utiliser directement. seul MyPDF doit l'utiliser !!!!
  5114. *
  5115. * @param int page courante
  5116. * @return null
  5117. */
  5118. public function INDEX_NewPage(&$page)
  5119. {
  5120. if ($page)
  5121. {
  5122. $old_page = $this->pdf->getPage();
  5123. $this->pdf->setPage($page);
  5124. $this->pdf->setXY($this->margeLeft, $this->margeTop);
  5125. $this->maxH = 0;
  5126. $page++;
  5127. return $old_page;
  5128. }
  5129. else
  5130. {
  5131. $this->setNewPage();
  5132. return null;
  5133. }
  5134. }
  5135. /**
  5136. * chargement du fichier de langue
  5137. *
  5138. * @param string langue
  5139. * @return null
  5140. */
  5141. static protected function textLOAD($langue)
  5142. {
  5143. if (count(HTML2PDF::$TEXTES)) return true;
  5144. if (!preg_match('/^([a-z0-9]+)$/isU', $langue))
  5145. {
  5146. echo 'ERROR : language code <b>'.$langue.'</b> incorrect.';
  5147. exit;
  5148. }
  5149. $file = dirname(__FILE__).'/langues/'.strtolower($langue).'.txt';
  5150. if (!is_file($file))
  5151. {
  5152. echo 'ERROR : language code <b>'.$langue.'</b> unknown.<br>';
  5153. echo 'You can create the translation file <b>'.$file.'</b> and send it to me in order to integrate it into a future version.';
  5154. exit;
  5155. }
  5156. $texte = array();
  5157. $infos = file($file);
  5158. foreach($infos as $val)
  5159. {
  5160. $val = trim($val);
  5161. $val = explode("\t", $val);
  5162. if (count($val)<2) continue;
  5163. $t_k = trim($val[0]); unset($val[0]);
  5164. $t_v = trim(implode(' ', $val));
  5165. if ($t_k && $t_v) $texte[$t_k] = $t_v;
  5166. }
  5167. HTML2PDF::$TEXTES = $texte;
  5168. return true;
  5169. }
  5170. /**
  5171. * recuperer un texte precis
  5172. *
  5173. * @param string code du texte
  5174. * @return null
  5175. */
  5176. static public function textGET($key)
  5177. {
  5178. if (!isset(HTML2PDF::$TEXTES[$key])) return '######';
  5179. return HTML2PDF::$TEXTES[$key];
  5180. }
  5181. }
  5182. class HTML2PDF_exception extends exception
  5183. {
  5184. protected $tag = null;
  5185. protected $html = null;
  5186. protected $image = null;
  5187. protected $message_html = '';
  5188. /**
  5189. * generer une erreur HTML2PDF
  5190. *
  5191. * @param int numero de l'erreur
  5192. * @param mixed indications suplementaires sur l'erreur
  5193. * @return string code HTML eventuel associי א l'erreur
  5194. */
  5195. final public function __construct($err = 0, $other = null, $html = '')
  5196. {
  5197. // creation du message d'erreur
  5198. $msg = '';
  5199. switch($err)
  5200. {
  5201. case 1:
  5202. $msg = (HTML2PDF::textGET('err01'));
  5203. $msg = str_replace('[[OTHER]]', $other, $msg);
  5204. $this->tag = $other;
  5205. break;
  5206. case 2:
  5207. $msg = (HTML2PDF::textGET('err02'));
  5208. $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
  5209. $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
  5210. $msg = str_replace('[[OTHER_2]]', $other[2], $msg);
  5211. break;
  5212. case 3:
  5213. $msg = (HTML2PDF::textGET('err03'));
  5214. $msg = str_replace('[[OTHER]]', $other, $msg);
  5215. $this->tag = $other;
  5216. break;
  5217. case 4:
  5218. $msg = (HTML2PDF::textGET('err04'));
  5219. $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
  5220. break;
  5221. case 5:
  5222. $msg = (HTML2PDF::textGET('err05'));
  5223. $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
  5224. break;
  5225. case 6:
  5226. $msg = (HTML2PDF::textGET('err06'));
  5227. $msg = str_replace('[[OTHER]]', $other, $msg);
  5228. $this->image = $other;
  5229. break;
  5230. case 7:
  5231. $msg = (HTML2PDF::textGET('err07'));
  5232. break;
  5233. case 8:
  5234. $msg = (HTML2PDF::textGET('err08'));
  5235. $msg = str_replace('[[OTHER]]', $other, $msg);
  5236. $this->tag = $other;
  5237. break;
  5238. case 9:
  5239. $msg = (HTML2PDF::textGET('err09'));
  5240. $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
  5241. $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
  5242. $this->tag = $other[0];
  5243. break;
  5244. }
  5245. // creation du message HTML
  5246. $this->message_html = '<span style="color: #AA0000; font-weight: bold;">'.(HTML2PDF::textGET('txt01')).$err.'</span><br>';
  5247. $this->message_html.= (HTML2PDF::textGET('txt02')).' '.$this->file.'<br>';
  5248. $this->message_html.= (HTML2PDF::textGET('txt03')).' '.$this->line.'<br>';
  5249. $this->message_html.= '<br>';
  5250. $this->message_html.= $msg;
  5251. // creation du message classique
  5252. $msg = HTML2PDF::textGET('txt01').$err.' : '.strip_tags($msg);
  5253. if ($html)
  5254. {
  5255. $this->message_html.= "<br><br>HTML : ...".trim(htmlentities($html)).'...';
  5256. $this->html = $html;
  5257. $msg.= ' HTML : ...'.trim($html).'...';
  5258. }
  5259. parent::__construct($msg, $err);
  5260. }
  5261. public function __toString() { return $this->message_html; }
  5262. public function getTAG() { return $this->tag; }
  5263. public function getHTML() { return $this->html; }
  5264. public function getIMAGE() { return $this->image; }
  5265. }
  5266. }