PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/common/libraries/plugin/html2pdf/html2pdf.class.php

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