PageRenderTime 82ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/app/vendors/html2pdf/html2pdf.class.php

https://github.com/ata/steak
PHP | 4302 lines | 2750 code | 560 blank | 992 comment | 403 complexity | af7fa387a21226aff0240c7c665bd32d MD5 | raw file
  1. <?php
  2. /**
  3. * Logiciel : HTML2PDF
  4. *
  5. * Convertisseur HTML => PDF, utilise fpdf de Olivier PLATHEY
  6. * Distribué sous la licence GPL.
  7. *
  8. * @author Laurent MINGUET <webmaster@spipu.net>
  9. * @version 3.21 - 05/05/2009
  10. */
  11. if (!defined('__CLASS_HTML2PDF__'))
  12. {
  13. define('__CLASS_HTML2PDF__', '3.21');
  14. // vous pouvez utiliser cette fonction de debug comme suit
  15. // pour voir le temps et la mémoire utilisés (sous linux) pour la conversion :
  16. // echo HTML2PDFgetTimerDebug();
  17. // $html2pdf->WriteHTML($content);
  18. // echo HTML2PDFgetTimerDebug();
  19. function HTML2PDFgetTimerDebug($debug=false)
  20. {
  21. global $TIMER_ACTION_LAST;
  22. list($usec, $sec) = explode(" ", microtime());
  23. $time = (float)$sec + (float)$usec;
  24. $mem = HTML2PDFgetMem();
  25. if (!$TIMER_ACTION_LAST)
  26. {
  27. if ($debug) $ret = null;
  28. else $ret = 'Debug : init'."<br />\n";
  29. }
  30. else
  31. {
  32. $aff_time = $time-$TIMER_ACTION_LAST[0];
  33. $aff_mem = $mem;
  34. if ($debug) $ret = array($aff_time, $aff_mem);
  35. else $ret = 'Timer : '.number_format($aff_time, 3, '.', '').'s - Memory used '.$aff_mem.' Ko'."<br />\n";
  36. }
  37. $TIMER_ACTION_LAST = array($time, $mem);
  38. return $ret;
  39. }
  40. function HTML2PDFgetMem() { return function_exists('memory_get_usage') ? floor(memory_get_usage()/1024) : 0; }
  41. require_once(dirname(__FILE__).'/_mypdf/mypdf.class.php'); // classe mypdf dérivé de fpdf de Olivier PLATHEY
  42. require_once(dirname(__FILE__).'/parsingHTML.class.php'); // classe de parsing HTML
  43. require_once(dirname(__FILE__).'/styleHTML.class.php'); // classe de gestion des styles
  44. global $HTML2PDF_TABLEAU; $HTML2PDF_TABLEAU = array(); // tableau global necessaire à la gestion des tables imbriquées
  45. class HTML2PDF
  46. {
  47. var $langue = 'fr'; // langue des messages
  48. var $sens = 'P'; // sens d'affichage Portrait ou Landscape
  49. var $format = 'A4'; // format de la page : A4, A3, ...
  50. var $background = array(); // informations sur le background
  51. var $testTDin1page = true; // activer le test de TD ne devant pas depasser une page
  52. var $style = null; // objet de style
  53. var $parsing = null; // objet de parsing
  54. var $parse_pos = 0; // position du parsing
  55. var $temp_pos = 0; // position temporaire pour multi tableau
  56. var $sub_html = null; // sous html
  57. var $sub_part = false; // indicateur de sous html
  58. var $isSubPart = false; // indique que le convertisseur courant est un sous html
  59. var $pdf = null; // objet PDF
  60. var $maxX = 0; // zone maxi X
  61. var $maxY = 0; // zone maxi Y
  62. var $FirstPage = true; // premier page
  63. var $defaultLeft = 0; // marges par default de la page
  64. var $defaultTop = 0;
  65. var $defaultRight = 0;
  66. var $defaultBottom = 0;
  67. var $margeLeft = 0; //marges réelles de la page
  68. var $margeTop = 0;
  69. var $margeRight = 0;
  70. var $margeBottom = 0;
  71. var $marges = array();
  72. var $Maxs = array();
  73. var $maxH = 0; // plus grande hauteur dans la ligne, pour saut de ligne à corriger
  74. var $inLink = ''; // indique si on est à l'interieur d'un lien
  75. var $lstAncre = array(); // liste des ancres détectées ou créées
  76. var $subHEADER = array(); // tableau des sous commandes pour faire l'HEADER
  77. var $subFOOTER = array(); // tableau des sous commandes pour faire le FOOTER
  78. var $subSTATES = array(); // tableau de sauvegarde de certains paramètres
  79. var $defLIST = array(); // tableau de sauvegarde de l'etat des UL et OL
  80. var $lstChamps = array(); // liste des champs
  81. var $lstSelect = array(); // options du select en cours
  82. var $previousCall = null; // dernier appel
  83. var $isInTfoot = false; // indique si on est dans un tfoot
  84. var $pageMarges = array(); // marges spécifiques dues aux floats
  85. var $isAfterFloat = false; // indique si on est apres un float
  86. /**
  87. * Constructeur
  88. *
  89. * @param string sens portrait ou landscape
  90. * @param string format A4, A5, ...
  91. * @param string langue : fr, en, it...
  92. * @param array marges par defaut, dans l'ordre (left, top, right, bottom)
  93. * @param boolean forcer la création de la premiere page, ne pas utiliser, c'est utilisé en interne pour la gestion des tableaux
  94. * @return null
  95. */
  96. function HTML2PDF($sens = 'P', $format = 'A4', $langue='fr', $marges = array(5, 5, 5, 8), $force_page = false)
  97. {
  98. // sauvegarde des paramètres
  99. $this->sens = $sens;
  100. $this->format = $format;
  101. $this->FirstPage = true;
  102. $this->langue = strtolower($langue);
  103. $this->setTestTdInOnePage(true);
  104. // chargement du fichier de langue
  105. $this->textLOAD($this->langue);
  106. // création de l' objet PDF
  107. $this->pdf = new MyPDF($sens, 'mm', $format);
  108. // initialisation des styles
  109. $this->style = new styleHTML($this->pdf);
  110. $this->style->FontSet();
  111. $this->defLIST = array();
  112. // initialisation du parsing
  113. $this->parsing = new parsingHTML();
  114. $this->sub_html = null;
  115. $this->sub_part = false;
  116. // initialisation des marges
  117. $this->setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]);
  118. $this->setMargins();
  119. $this->marges = array();
  120. // initialisation des champs de formulaire
  121. $this->lstChamps = array();
  122. // premier page forcée
  123. if ($force_page) $this->setNewPage($this->sens);
  124. }
  125. /**
  126. * activer ou desactiver le test de TD ne devant pas depasser une page
  127. *
  128. * @param boolean nouvel etat
  129. * @return boolean ancien etat
  130. */
  131. function setTestTdInOnePage($mode = true)
  132. {
  133. $old = $this->testTDin1page;
  134. $this->testTDin1page = $mode ? true : false;
  135. return $old;
  136. }
  137. /**
  138. * définir les marges par défault
  139. *
  140. * @param int en mm, marge left
  141. * @param int en mm, marge top
  142. * @param int en mm, marge right. si null, left=right
  143. * @param int en mm, marge bottom. si null, bottom=8
  144. * @return null
  145. */
  146. function setDefaultMargins($left, $top, $right = null, $bottom = null)
  147. {
  148. if ($right===null) $right = $left;
  149. if ($bottom===null) $bottom = 8;
  150. $this->defaultLeft = $this->style->ConvertToMM($left.'mm');
  151. $this->defaultTop = $this->style->ConvertToMM($top.'mm');
  152. $this->defaultRight = $this->style->ConvertToMM($right.'mm');
  153. $this->defaultBottom = $this->style->ConvertToMM($bottom.'mm');
  154. }
  155. /**
  156. * définir les marges réelles, fonctions de la balise page
  157. *
  158. * @return null
  159. */
  160. function setMargins()
  161. {
  162. $this->margeLeft = $this->defaultLeft + (isset($this->background['left']) ? $this->background['left'] : 0);
  163. $this->margeRight = $this->defaultRight + (isset($this->background['right']) ? $this->background['right'] : 0);
  164. $this->margeTop = $this->defaultTop + (isset($this->background['top']) ? $this->background['top'] : 0);
  165. $this->margeBottom = $this->defaultBottom + (isset($this->background['bottom']) ? $this->background['bottom'] : 0);
  166. $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
  167. $this->pdf->cMargin = 0;
  168. $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
  169. }
  170. /**
  171. * recuperer les positions x minimales et maximales en fonction d'une hauteur
  172. *
  173. * @param float y
  174. * @return array(float, float)
  175. */
  176. function getMargins($y)
  177. {
  178. $y = floor($y*100);
  179. $x = array($this->pdf->lMargin, $this->pdf->w-$this->pdf->rMargin);
  180. foreach($this->pageMarges as $m_y => $m_x)
  181. if ($m_y<=$y) $x = $m_x;
  182. return $x;
  183. }
  184. /**
  185. * ajouter une marge suite a un float
  186. *
  187. * @param string left ou right
  188. * @param float x1
  189. * @param float y1
  190. * @param float x2
  191. * @param float y2
  192. * @return null
  193. */
  194. function addMargins($float, $x1, $y1, $x2, $y2)
  195. {
  196. $old1 = $this->getMargins($y1);
  197. $old2 = $this->getMargins($y2);
  198. if ($float=='left') $old1[0] = $x2;
  199. if ($float=='right') $old1[1] = $x1;
  200. $y1 = floor($y1*100);
  201. $y2 = floor($y2*100);
  202. foreach($this->pageMarges as $m_y => $m_x)
  203. {
  204. if ($m_y<$y1) continue;
  205. if ($m_y>$y2) break;
  206. if ($float=='left' && $this->pageMarges[$m_y][0]<$x2) unset($this->pageMarges[$m_y]);
  207. if ($float=='right' && $this->pageMarges[$m_y][1]>$x1) unset($this->pageMarges[$m_y]);
  208. }
  209. $this->pageMarges[$y1] = $old1;
  210. $this->pageMarges[$y2] = $old2;
  211. ksort($this->pageMarges);
  212. $this->isAfterFloat = true;
  213. }
  214. /**
  215. * définir des nouvelles marges et sauvegarder les anciennes
  216. *
  217. * @param float marge left
  218. * @param float marge top
  219. * @param float marge right
  220. * @return null
  221. */
  222. function saveMargin($ml, $mt, $mr)
  223. {
  224. $this->marges[] = array('l' => $this->pdf->lMargin, 't' => $this->pdf->tMargin, 'r' => $this->pdf->rMargin, 'page' => $this->pageMarges);
  225. $this->pdf->SetMargins($ml, $mt, $mr);
  226. $this->pageMarges = array();
  227. $this->pageMarges[floor($mt*100)] = array($ml, $this->pdf->w-$mr);
  228. }
  229. /**
  230. * récuperer les dernières marches sauvées
  231. *
  232. * @return null
  233. */
  234. function loadMargin()
  235. {
  236. $old = array_pop($this->marges);
  237. if ($old)
  238. {
  239. $ml = $old['l'];
  240. $mt = $old['t'];
  241. $mr = $old['r'];
  242. $mP = $old['page'];
  243. }
  244. else
  245. {
  246. $ml = $this->margeLeft;
  247. $mt = 0;
  248. $mr = $this->margeRight;
  249. $mP = array($mt => array($ml, $this->pdf->w-$mr));
  250. }
  251. $this->pdf->SetMargins($ml, $mt, $mr);
  252. $this->pageMarges = $mP;
  253. }
  254. /**
  255. * permet d'ajouter une fonte.
  256. *
  257. * @param string nom de la fonte
  258. * @param string style de la fonte
  259. * @param string fichier de la fonte
  260. * @return null
  261. */
  262. function AddFont($family, $style='', $file='')
  263. {
  264. $this->pdf->AddFont($family, $style, $file);
  265. }
  266. /**
  267. * sauvegarder l'état actuelle des maximums
  268. *
  269. * @return null
  270. */
  271. function saveMax()
  272. {
  273. $this->Maxs[] = array($this->maxX, $this->maxY, $this->maxH);
  274. }
  275. /**
  276. * charger le dernier état sauvé des maximums
  277. *
  278. * @return null
  279. */
  280. function loadMax()
  281. {
  282. $old = array_pop($this->Maxs);
  283. if ($old)
  284. {
  285. $this->maxX = $old[0];
  286. $this->maxY = $old[1];
  287. $this->maxH = $old[2];
  288. }
  289. else
  290. {
  291. $this->maxX = 0;
  292. $this->maxY = 0;
  293. $this->maxH = 0;
  294. }
  295. }
  296. /**
  297. * afficher l'header contenu dans page_header
  298. *
  299. * @return null
  300. */
  301. function SetPageHeader()
  302. {
  303. if (!count($this->subHEADER)) return false;
  304. $OLD_parse_pos = $this->parse_pos;
  305. $OLD_parse_code = $this->parsing->code;
  306. $this->parse_pos = 0;
  307. $this->parsing->code = $this->subHEADER;
  308. $this->MakeHTMLcode();
  309. $this->parse_pos = $OLD_parse_pos;
  310. $this->parsing->code = $OLD_parse_code;
  311. }
  312. /**
  313. * afficher le footer contenu dans page_footer
  314. *
  315. * @return null
  316. */
  317. function SetPageFooter()
  318. {
  319. if (!count($this->subFOOTER)) return false;
  320. $OLD_parse_pos = $this->parse_pos;
  321. $OLD_parse_code = $this->parsing->code;
  322. $this->parse_pos = 0;
  323. $this->parsing->code = $this->subFOOTER;
  324. $this->MakeHTMLcode();
  325. $this->parse_pos = $OLD_parse_pos;
  326. $this->parsing->code = $OLD_parse_code;
  327. }
  328. /**
  329. * saut de ligne avec une hauteur spécifique
  330. *
  331. * @param float hauteur de la ligne
  332. * @return null
  333. */
  334. function setNewLine($h)
  335. {
  336. $this->pdf->Ln($h);
  337. list($lx, $rx) = $this->getMargins($this->pdf->y);
  338. $this->pdf->x=$lx;
  339. }
  340. /**
  341. * création d'une nouvelle page avec une orientation particuliere
  342. *
  343. * @param string sens P=portrait ou L=landscape
  344. * @param array tableau des propriétés du fond de la page
  345. * @return null
  346. */
  347. function setNewPage($orientation = '', $background = null)
  348. {
  349. /*
  350. if (!$this->FirstPage)
  351. {
  352. $info = debug_backtrace(); foreach($info as $k => $v) { unset($info[$k]['object']); unset($info[$k]['type']); unset($info[$k]['args']);}
  353. echo '<pre>'.print_r($info, true).'</pre><hr>';
  354. }
  355. */
  356. $this->FirstPage = false;
  357. $this->sens = $orientation ? $orientation : $this->sens;
  358. $this->background = $background!==null ? $background : $this->background;
  359. $this->maxY = 0;
  360. $this->maxX = 0;
  361. $this->pdf->lMargin = $this->defaultLeft;
  362. $this->pdf->rMargin = $this->defaultRight;
  363. $this->pdf->tMargin = $this->defaultTop;
  364. $this->pdf->AddPage($this->sens);
  365. if (!$this->sub_part && !$this->isSubPart)
  366. {
  367. if (is_array($this->background))
  368. {
  369. if (isset($this->background['color']) && $this->background['color'])
  370. {
  371. $this->pdf->SetFillColor($this->background['color'][0], $this->background['color'][1], $this->background['color'][2]);
  372. $this->pdf->Rect(0, 0, $this->pdf->w, $this->pdf->h, 'F');
  373. }
  374. if (isset($this->background['img']) && $this->background['img'])
  375. $this->pdf->Image($this->background['img'], $this->background['posX'], $this->background['posY'], $this->background['width']);
  376. }
  377. $this->SetPageHeader();
  378. $this->SetPageFooter();
  379. }
  380. $this->SetMargins();
  381. $this->pdf->y = $this->margeTop;
  382. list($lx, $rx) = $this->getMargins($this->pdf->y);
  383. $this->pdf->x=$lx;
  384. }
  385. /**
  386. * récupération du PDF
  387. *
  388. * @param string nom du fichier PDF
  389. * @param boolean destination
  390. * @return string contenu éventuel du pdf
  391. *
  392. *
  393. * Destination où envoyer le document. Le paramètre peut prendre les valeurs suivantes :
  394. * true : equivalent à I
  395. * false : equivalent à S
  396. * 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.
  397. * D : envoyer au navigateur en forçant le téléchargement, avec le nom indiqué dans name.
  398. * F : sauver dans un fichier local, avec le nom indiqué dans name (peut inclure un répertoire).
  399. * S : renvoyer le document sous forme de chaîne. name est ignoré.
  400. */
  401. function Output($name = '', $dest = false)
  402. {
  403. // nettoyage
  404. global $HTML2PDF_TABLEAU; $HTML2PDF_TABLEAU = array();
  405. // interpretation des paramètres
  406. if ($dest===false) $dest = 'I';
  407. if ($dest===true) $dest = 'S';
  408. if ($dest==='') $dest = 'I';
  409. if ($name=='') $name='document.pdf';
  410. // verification de la destination
  411. $dest = strtoupper($dest);
  412. if (!in_array($dest, array('I', 'D', 'F', 'S'))) $dest = 'I';
  413. // verification du nom
  414. if (strtolower(substr($name, -4))!='.pdf')
  415. {
  416. echo 'ERROR : The output document name "'.$name.'" is not a PDF name';
  417. exit;
  418. }
  419. return $this->pdf->Output($name, $dest);
  420. }
  421. /**
  422. * création d'un sous HTML2PDF pour la gestion des tableaux imbriqués
  423. *
  424. * @param HTML2PDF futur sous HTML2PDF passé en référence pour créatio
  425. * @return null
  426. */
  427. function CreateSubHTML(&$sub_html, $cellmargin=0)
  428. {
  429. // initialisation du sous objet
  430. $sub_html = new HTML2PDF(
  431. $this->sens,
  432. $this->format,
  433. $this->langue,
  434. array($this->defaultLeft,$this->defaultTop,$this->defaultRight,$this->defaultBottom),
  435. true
  436. );
  437. $sub_html->isSubPart = true;
  438. $sub_html->setTestTdInOnePage($this->testTDin1page);
  439. $sub_html->style->css = $this->style->css;
  440. $sub_html->style->css_keys = $this->style->css_keys;
  441. $sub_html->style->table = $this->style->table;
  442. $sub_html->style->value = $this->style->value;
  443. $sub_html->style->value['text-align'] = 'left';
  444. $sub_html->defLIST = $this->defLIST;
  445. // initialisation de la largeur
  446. if ($this->style->value['width'])
  447. {
  448. $marge = $cellmargin*2;
  449. $marge+= $this->style->value['padding']['l'] + $this->style->value['padding']['r'];
  450. $marge+= $this->style->value['border']['l']['width'] + $this->style->value['border']['r']['width'];
  451. $marge = $sub_html->pdf->w - $this->style->value['width'] + $marge;
  452. }
  453. else
  454. $marge = $this->margeLeft+$this->margeRight;
  455. $sub_html->saveMargin(0, 0, $marge);
  456. // initialisation des fontes
  457. $sub_html->pdf->fonts = &$this->pdf->fonts;
  458. $sub_html->pdf->FontFiles = &$this->pdf->FontFiles;
  459. $sub_html->pdf->diffs = &$this->pdf->diffs;
  460. // initialisation des positions et autre
  461. $sub_html->maxX = 0;
  462. $sub_html->maxY = 0;
  463. $sub_html->maxH = 0;
  464. $sub_html->pdf->setX(0);
  465. $sub_html->pdf->setY(0);
  466. $sub_html->style->FontSet();
  467. }
  468. /**
  469. * destruction d'un sous HTML2PDF pour la gestion des tableaux imbriqués
  470. *
  471. * @return null
  472. */
  473. function DestroySubHTML()
  474. {
  475. unset($this->sub_html);
  476. $this->sub_html = null;
  477. }
  478. /**
  479. * Convertir un nombre arabe en nombre romain
  480. *
  481. * @param integer nombre à convertir
  482. * @return string nombre converti
  483. */
  484. function listeArab2Rom($nb_ar)
  485. {
  486. $nb_b10 = array('I','X','C','M');
  487. $nb_b5 = array('V','L','D');
  488. $nb_ro = '';
  489. if ($nb_ar<1) return $nb_ar;
  490. if ($nb_ar>3999) return $nb_ar;
  491. for($i=3; $i>=0 ; $i--)
  492. {
  493. $chiffre=floor($nb_ar/pow(10,$i));
  494. if($chiffre>=1)
  495. {
  496. $nb_ar=$nb_ar-$chiffre*pow(10,$i);
  497. if($chiffre<=3)
  498. {
  499. for($j=$chiffre; $j>=1; $j--)
  500. {
  501. $nb_ro=$nb_ro.$nb_b10[$i];
  502. }
  503. }
  504. else if($chiffre==9)
  505. {
  506. $nb_ro=$nb_ro.$nb_b10[$i].$nb_b10[$i+1];
  507. }
  508. elseif($chiffre==4)
  509. {
  510. $nb_ro=$nb_ro.$nb_b10[$i].$nb_b5[$i];
  511. }
  512. else
  513. {
  514. $nb_ro=$nb_ro.$nb_b5[$i];
  515. for($j=$chiffre-5; $j>=1; $j--)
  516. {
  517. $nb_ro=$nb_ro.$nb_b10[$i];
  518. }
  519. }
  520. }
  521. }
  522. return $nb_ro;
  523. }
  524. /**
  525. * Ajouter un LI au niveau actuel
  526. *
  527. * @return null
  528. */
  529. function listeAddLi()
  530. {
  531. $this->defLIST[count($this->defLIST)-1]['nb']++;
  532. }
  533. function listeGetWidth() { return '7mm'; }
  534. function listeGetPadding() { return '1mm'; }
  535. /**
  536. * Recuperer le LI du niveau actuel
  537. *
  538. * @return string chaine à afficher
  539. */
  540. function listeGetLi()
  541. {
  542. $im = $this->defLIST[count($this->defLIST)-1]['img'];
  543. $st = $this->defLIST[count($this->defLIST)-1]['style'];
  544. $nb = $this->defLIST[count($this->defLIST)-1]['nb'];
  545. $up = (substr($st, 0, 6)=='upper-');
  546. if ($im) return array(false, false, $im);
  547. switch($st)
  548. {
  549. case 'none':
  550. return array('arial', true, ' ');
  551. case 'upper-alpha':
  552. case 'lower-alpha':
  553. $str = '';
  554. while($nb>26)
  555. {
  556. $str = chr(96+$nb%26).$str;
  557. $nb = floor($nb/26);
  558. }
  559. $str = chr(96+$nb).$str;
  560. return array('arial', false, ($up ? strtoupper($str) : $str).'.');
  561. case 'upper-roman':
  562. case 'lower-roman':
  563. $str = $this->listeArab2Rom($nb);
  564. return array('arial', false, ($up ? strtoupper($str) : $str).'.');
  565. case 'decimal':
  566. return array('arial', false, $nb.'.');
  567. case 'square':
  568. return array('zapfdingbats', true, chr(110));
  569. case 'circle':
  570. return array('zapfdingbats', true, chr(109));
  571. case 'disc':
  572. default:
  573. return array('zapfdingbats', true, chr(108));
  574. }
  575. }
  576. /**
  577. * Ajouter un niveau de liste
  578. *
  579. * @param string type de liste : ul, ol
  580. * @param string style de la liste
  581. * @return null
  582. */
  583. function listeAddLevel($type = 'ul', $style = '', $img = null)
  584. {
  585. if ($img)
  586. {
  587. if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match))
  588. $img = $match[1];
  589. else
  590. $img = null;
  591. }
  592. else
  593. $img = null;
  594. if (!in_array($type, array('ul', 'ol'))) $type = 'ul';
  595. if (!in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = '';
  596. if (!$style)
  597. {
  598. if ($type=='ul') $style = 'disc';
  599. else $style = 'decimal';
  600. }
  601. $this->defLIST[count($this->defLIST)] = array('style' => $style, 'nb' => 0, 'img' => $img);
  602. }
  603. /**
  604. * Supprimer un niveau de liste
  605. *
  606. * @return null
  607. */
  608. function listeDelLevel()
  609. {
  610. if (count($this->defLIST))
  611. {
  612. unset($this->defLIST[count($this->defLIST)-1]);
  613. $this->defLIST = array_values($this->defLIST);
  614. }
  615. }
  616. /**
  617. * traitement d'un code HTML
  618. *
  619. * @param string code HTML à convertir
  620. * @param boolean afficher en pdf (false) ou en html (true)
  621. * @return null
  622. */
  623. function WriteHTML($html, $vue = false)
  624. {
  625. $html = str_replace('[[page_nb]]', '{nb}', $html);
  626. $html = str_replace('[[date_y]]', date('Y'), $html);
  627. $html = str_replace('[[date_m]]', date('m'), $html);
  628. $html = str_replace('[[date_d]]', date('d'), $html);
  629. $html = str_replace('[[date_h]]', date('H'), $html);
  630. $html = str_replace('[[date_i]]', date('i'), $html);
  631. $html = str_replace('[[date_s]]', date('s'), $html);
  632. // si on veut voir le résultat en HTML => on appelle la fonction
  633. if ($vue) $this->vueHTML($html);
  634. // sinon, traitement pour conversion en PDF :
  635. // parsing
  636. $this->sub_pdf = false;
  637. $this->style->readStyle($html);
  638. $this->parsing->setHTML($html);
  639. $this->parsing->parse();
  640. $this->MakeHTMLcode();
  641. }
  642. function MakeHTMLcode()
  643. {
  644. // pour chaque element identifié par le parsing
  645. for($this->parse_pos=0; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
  646. {
  647. // récupération de l'élément
  648. $todo = $this->parsing->code[$this->parse_pos];
  649. // si c'est une ouverture de tableau
  650. if (in_array($todo['name'], array('table', 'ul', 'ol')) && !$todo['close'])
  651. {
  652. // on va créer un sous HTML, et on va travailler sur une position temporaire
  653. $tag_open = $todo['name'];
  654. $this->sub_part = true;
  655. $this->temp_pos = $this->parse_pos;
  656. // pour tous les éléments jusqu'à la fermeture de la table afin de préparer les dimensions
  657. while(isset($this->parsing->code[$this->temp_pos]) && !($this->parsing->code[$this->temp_pos]['name']==$tag_open && $this->parsing->code[$this->temp_pos]['close']))
  658. {
  659. $this->loadAction($this->parsing->code[$this->temp_pos]);
  660. $this->temp_pos++;
  661. }
  662. if (isset($this->parsing->code[$this->temp_pos])) $this->loadAction($this->parsing->code[$this->temp_pos]);
  663. $this->sub_part = false;
  664. }
  665. // chargement de l'action correspondant à l'élément
  666. $this->loadAction($todo);
  667. }
  668. }
  669. /**
  670. * affichage en mode HTML du contenu
  671. *
  672. * @param string contenu
  673. * @return null
  674. */
  675. function vueHTML($content)
  676. {
  677. $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue01').' : $1<hr><div$1>', $content);
  678. $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue02').' : $1<hr><div$1>', $content);
  679. $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue03').' : $1<hr><div$1>', $content);
  680. $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content);
  681. $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content);
  682. $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content);
  683. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  684. <html>
  685. <head>
  686. <title>'.HTML2PDF::textGET('vue04').' HTML</title>
  687. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
  688. </head>
  689. <body style="padding: 10px; font-size: 10pt;font-family: Arial;">
  690. '.$content.'
  691. </body>
  692. </html>';
  693. exit;
  694. }
  695. /**
  696. * chargement de l'action correspondante à un element de parsing
  697. *
  698. * @param array élément de parsing
  699. * @return null
  700. */
  701. function loadAction($row)
  702. {
  703. // nom de l'action
  704. $fnc = ($row['close'] ? 'c_' : 'o_').strtoupper($row['name']);
  705. // parametres de l'action
  706. $param = $row['param'];
  707. // si aucune page n'est créé, on la créé
  708. if ($fnc!='o_PAGE' && $this->FirstPage)
  709. {
  710. $this->setNewPage();
  711. }
  712. // lancement de l'action
  713. if (is_callable(array(&$this, $fnc)))
  714. {
  715. $this->{$fnc}($param);
  716. $this->previousCall = $fnc;
  717. }
  718. else
  719. {
  720. HTML2PDF::makeError(1, __FILE__, __LINE__, strtoupper($row['name']));
  721. }
  722. }
  723. /**
  724. * balise : PAGE
  725. * mode : OUVERTURE
  726. *
  727. * @param array paramètres de l'élément de parsing
  728. * @return null
  729. */
  730. function o_PAGE($param)
  731. {
  732. $newPageSet= (!isset($param['pageset']) || $param['pageset']!='old');
  733. $this->maxH = 0;
  734. if ($newPageSet)
  735. {
  736. $this->subHEADER = array();
  737. $this->subFOOTER = array();
  738. // identification de l'orientation demandée
  739. $orientation = '';
  740. if (isset($param['orientation']))
  741. {
  742. $param['orientation'] = strtolower($param['orientation']);
  743. if ($param['orientation']=='p') $orientation = 'P';
  744. if ($param['orientation']=='portrait') $orientation = 'P';
  745. if ($param['orientation']=='l') $orientation = 'L';
  746. if ($param['orientation']=='paysage') $orientation = 'L';
  747. if ($param['orientation']=='landscape') $orientation = 'L';
  748. }
  749. // identification des propriétés du background
  750. $background = array();
  751. if (isset($param['backimg']))
  752. {
  753. $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // nom de l'image
  754. $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // position horizontale de l'image
  755. $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // position verticale de l'image
  756. $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // taille de l'image (100% = largueur de la feuille)
  757. // conversion du nom de l'image, en cas de paramètres en _GET
  758. $background['img'] = str_replace('&amp;', '&', $background['img']);
  759. // conversion des positions
  760. if ($background['posX']=='left') $background['posX'] = '0%';
  761. if ($background['posX']=='center') $background['posX'] = '50%';
  762. if ($background['posX']=='right') $background['posX'] = '100%';
  763. if ($background['posY']=='top') $background['posY'] = '0%';
  764. if ($background['posY']=='middle') $background['posY'] = '50%';
  765. if ($background['posY']=='bottom') $background['posY'] = '100%';
  766. // si il y a une image de précisé
  767. if ($background['img'])
  768. {
  769. // est-ce que c'est une image ?
  770. $infos=@GetImageSize($background['img']);
  771. if (count($infos)>1)
  772. {
  773. // taille de l'image, en fonction de la taille spécifiée.
  774. $Wi = $this->style->ConvertToMM($background['width'], $this->pdf->w);
  775. $Hi = $Wi*$infos[1]/$infos[0];
  776. // récupération des dimensions et positions de l'image
  777. $background['width'] = $Wi;
  778. $background['posX'] = $this->style->ConvertToMM($background['posX'], $this->pdf->w - $Wi);
  779. $background['posY'] = $this->style->ConvertToMM($background['posY'], $this->pdf->h - $Hi);
  780. }
  781. else
  782. $background = array();
  783. }
  784. else
  785. $background = array();
  786. }
  787. // marges TOP et BOTTOM pour le texte.
  788. $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0';
  789. $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0';
  790. $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0';
  791. $background['right'] = isset($param['backright']) ? $param['backright'] : '0';
  792. if (preg_match('/^([0-9]*)$/isU', $background['top'])) $background['top'] .= 'mm';
  793. if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) $background['bottom'] .= 'mm';
  794. if (preg_match('/^([0-9]*)$/isU', $background['left'])) $background['left'] .= 'mm';
  795. if (preg_match('/^([0-9]*)$/isU', $background['right'])) $background['right'] .= 'mm';
  796. $background['top'] = $this->style->ConvertToMM($background['top'], $this->pdf->h);
  797. $background['bottom'] = $this->style->ConvertToMM($background['bottom'], $this->pdf->h);
  798. $background['left'] = $this->style->ConvertToMM($background['left'], $this->pdf->w);
  799. $background['right'] = $this->style->ConvertToMM($background['right'], $this->pdf->w);
  800. $res = false;
  801. $background['color'] = isset($param['backcolor']) ? $this->style->ConvertToRVB($param['backcolor'], $res) : null;
  802. if (!$res) $background['color'] = null;
  803. $this->style->save();
  804. $this->style->analyse('PAGE', $param);
  805. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  806. $this->style->FontSet();
  807. // nouvelle page
  808. $this->setNewPage($orientation, $background);
  809. // footer automatique
  810. if (isset($param['footer']))
  811. {
  812. $lst = explode(';', $param['footer']);
  813. foreach($lst as $key => $val) $lst[$key] = trim(strtolower($val));
  814. $page = in_array('page', $lst);
  815. $date = in_array('date', $lst);
  816. $heure = in_array('heure', $lst);
  817. $form = in_array('form', $lst);
  818. }
  819. else
  820. {
  821. $page = null;
  822. $date = null;
  823. $heure = null;
  824. $form = null;
  825. }
  826. $this->pdf->SetMyFooter($page, $date, $heure, $form);
  827. }
  828. else
  829. {
  830. $this->style->save();
  831. $this->style->analyse('PAGE', $param);
  832. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  833. $this->style->FontSet();
  834. $this->setNewPage();
  835. }
  836. }
  837. /**
  838. * balise : PAGE
  839. * mode : FERMETURE
  840. *
  841. * @param array paramètres de l'élément de parsing
  842. * @return null
  843. */
  844. function c_PAGE($param)
  845. {
  846. $this->maxH = 0;
  847. $this->style->load();
  848. $this->style->FontSet();
  849. }
  850. function o_PAGE_HEADER($param)
  851. {
  852. $this->subHEADER = array();
  853. for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
  854. {
  855. $todo = $this->parsing->code[$this->parse_pos];
  856. if ($todo['name']=='page_header') $todo['name']='page_header_sub';
  857. $this->subHEADER[] = $todo;
  858. if (strtolower($todo['name'])=='page_header_sub' && $todo['close']) break;
  859. }
  860. $this->SetPageHeader();
  861. }
  862. function o_PAGE_FOOTER($param)
  863. {
  864. $this->subFOOTER = array();
  865. for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
  866. {
  867. $todo = $this->parsing->code[$this->parse_pos];
  868. if ($todo['name']=='page_footer') $todo['name']='page_footer_sub';
  869. $this->subFOOTER[] = $todo;
  870. if (strtolower($todo['name'])=='page_footer_sub' && $todo['close']) break;
  871. }
  872. $this->SetPageFooter();
  873. }
  874. function o_PAGE_HEADER_SUB($param)
  875. {
  876. $this->subSTATES = array();
  877. $this->subSTATES['x'] = $this->pdf->x;
  878. $this->subSTATES['y'] = $this->pdf->y;
  879. $this->subSTATES['s'] = $this->style->value;
  880. $this->subSTATES['t'] = $this->style->table;
  881. $this->subSTATES['ml'] = $this->pdf->lMargin;
  882. $this->subSTATES['mr'] = $this->pdf->rMargin;
  883. $this->subSTATES['mt'] = $this->pdf->tMargin;
  884. $this->subSTATES['mb'] = $this->pdf->bMargin;
  885. $this->pdf->x = $this->defaultLeft;
  886. $this->pdf->y = $this->defaultTop;
  887. $this->style->initStyle();
  888. $this->style->resetStyle();
  889. $this->style->value['width'] = $this->pdf->w - $this->defaultLeft - $this->defaultRight;
  890. $this->style->table = array();
  891. $this->pdf->lMargin = $this->defaultLeft;
  892. $this->pdf->rMargin = $this->defaultRight;
  893. $this->pdf->tMargin = $this->defaultTop;
  894. $this->pdf->bMargin = $this->defaultBottom;
  895. $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
  896. $this->style->save();
  897. $this->style->analyse('page_header_sub', $param);
  898. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  899. $this->style->FontSet();
  900. }
  901. function c_PAGE_HEADER_SUB($param)
  902. {
  903. $this->style->load();
  904. $this->pdf->x = $this->subSTATES['x'];
  905. $this->pdf->y = $this->subSTATES['y'];
  906. $this->style->value = $this->subSTATES['s'];
  907. $this->style->table = $this->subSTATES['t'];
  908. $this->pdf->lMargin = $this->subSTATES['ml'];
  909. $this->pdf->rMargin = $this->subSTATES['mr'];
  910. $this->pdf->tMargin = $this->subSTATES['mt'];
  911. $this->pdf->bMargin = $this->subSTATES['mb'];
  912. $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
  913. $this->style->FontSet();
  914. }
  915. function o_PAGE_FOOTER_SUB($param)
  916. {
  917. $this->subSTATES = array();
  918. $this->subSTATES['x'] = $this->pdf->x;
  919. $this->subSTATES['y'] = $this->pdf->y;
  920. $this->subSTATES['s'] = $this->style->value;
  921. $this->subSTATES['t'] = $this->style->table;
  922. $this->subSTATES['ml'] = $this->pdf->lMargin;
  923. $this->subSTATES['mr'] = $this->pdf->rMargin;
  924. $this->subSTATES['mt'] = $this->pdf->tMargin;
  925. $this->subSTATES['mb'] = $this->pdf->bMargin;
  926. $this->pdf->x = $this->defaultLeft;
  927. $this->pdf->y = $this->defaultTop;
  928. $this->style->initStyle();
  929. $this->style->resetStyle();
  930. $this->style->value['width'] = $this->pdf->w - $this->defaultLeft - $this->defaultRight;
  931. $this->style->table = array();
  932. $this->pdf->lMargin = $this->defaultLeft;
  933. $this->pdf->rMargin = $this->defaultRight;
  934. $this->pdf->tMargin = $this->defaultTop;
  935. $this->pdf->bMargin = $this->defaultBottom;
  936. $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
  937. // on en créé un sous HTML que l'on transforme en PDF
  938. // pour récupérer la hauteur
  939. // on extrait tout ce qui est contenu dans le FOOTER
  940. $sub = null;
  941. $res = $this->parsing->getLevel($this->parse_pos);
  942. $this->CreateSubHTML($sub);
  943. $sub->writeHTML($res[1]);
  944. $this->pdf->y = $this->pdf->h - $sub->maxY - $this->defaultBottom - 0.01;
  945. unset($sub);
  946. $this->style->save();
  947. $this->style->analyse('page_footer_sub', $param);
  948. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  949. $this->style->FontSet();
  950. }
  951. function c_PAGE_FOOTER_SUB($param)
  952. {
  953. $this->style->load();
  954. $this->pdf->x = $this->subSTATES['x'];
  955. $this->pdf->y = $this->subSTATES['y'];
  956. $this->style->value = $this->subSTATES['s'];
  957. $this->style->table = $this->subSTATES['t'];
  958. $this->pdf->lMargin = $this->subSTATES['ml'];
  959. $this->pdf->rMargin = $this->subSTATES['mr'];
  960. $this->pdf->tMargin = $this->subSTATES['mt'];
  961. $this->pdf->bMargin = $this->subSTATES['mb'];
  962. $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
  963. $this->style->FontSet();
  964. }
  965. /**
  966. * balise : NOBREAK
  967. * mode : OUVERTURE
  968. *
  969. * @param array paramètres de l'élément de parsing
  970. * @return null
  971. */
  972. function o_NOBREAK($param)
  973. {
  974. $this->maxH = 0;
  975. // on extrait tout ce qui est contenu dans le NOBREAK
  976. $res = $this->parsing->getLevel($this->parse_pos);
  977. // on en créé un sous HTML que l'on transforme en PDF
  978. // pour analyse les dimensions
  979. // et voir si ca rentre
  980. $sub = null;
  981. $this->CreateSubHTML($sub);
  982. $sub->writeHTML($res[1]);
  983. $y = $this->pdf->getY();
  984. if (
  985. $sub->maxY < ($this->pdf->h - $this->pdf->tMargin-$this->pdf->bMargin) &&
  986. $y + $sub->maxY>=($this->pdf->h - $this->pdf->bMargin)
  987. )
  988. $this->setNewPage();
  989. unset($sub);
  990. }
  991. /**
  992. * balise : NOBREAK
  993. * mode : FERMETURE
  994. *
  995. * @param array paramètres de l'élément de parsing
  996. * @return null
  997. */
  998. function c_NOBREAK($param)
  999. {
  1000. $this->maxH = 0;
  1001. }
  1002. /**
  1003. * balise : DIV
  1004. * mode : OUVERTURE
  1005. *
  1006. * @param array paramètres de l'élément de parsing
  1007. * @return null
  1008. */
  1009. function o_DIV($param, $other = 'div')
  1010. {
  1011. $this->style->save();
  1012. $this->style->analyse($other, $param);
  1013. $this->style->FontSet();
  1014. $align_object = null;
  1015. if ($this->style->value['margin-auto']) $align_object = 'center';
  1016. $marge = array();
  1017. $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
  1018. $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
  1019. $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
  1020. $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
  1021. // on extrait tout ce qui est contenu dans la DIV
  1022. $res = $this->parsing->getLevel($this->parse_pos);
  1023. // on en créé un sous HTML que l'on transforme en PDF
  1024. // pour analyse les dimensions
  1025. $w = 0; $h = 0;
  1026. if (trim($res[1]))
  1027. {
  1028. $sub = null;
  1029. $this->CreateSubHTML($sub);
  1030. $sub->writeHTML($res[1]);
  1031. $w = $sub->maxX;
  1032. $h = $sub->maxY;
  1033. unset($sub);
  1034. }
  1035. $w+= $marge['l']+$marge['r'];
  1036. $h+= $marge['t']+$marge['b'];
  1037. $this->style->value['width'] = max($w, $this->style->value['width']);
  1038. $this->style->value['height'] = max($h, $this->style->value['height']);
  1039. if (!$this->style->value['position'])
  1040. {
  1041. if (
  1042. $this->style->value['width'] < ($this->pdf->w - $this->pdf->lMargin-$this->pdf->rMargin) &&
  1043. $this->pdf->x + $this->style->value['width']>=($this->pdf->w - $this->pdf->rMargin)
  1044. )
  1045. $this->o_BR(array());
  1046. if (
  1047. $this->style->value['height'] < ($this->pdf->h - $this->pdf->tMargin-$this->pdf->bMargin) &&
  1048. $this->pdf->y + $this->style->value['height']>=($this->pdf->h - $this->pdf->bMargin)
  1049. )
  1050. $this->setNewPage();
  1051. // en cas d'alignement => correction
  1052. $w = $this->style->value['width'];
  1053. $old = isset($this->style->table[count($this->style->table)-1]) ? $this->style->table[count($this->style->table)-1] : $this->style->value;
  1054. $parent_w = $old['width'] ? $old['width'] : $this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin;
  1055. if ($parent_w>$w)
  1056. {
  1057. if ($align_object=='center') $this->pdf->x = $this->pdf->x + ($parent_w-$w)*0.5;
  1058. else if ($align_object=='right') $this->pdf->x = $this->pdf->x + $parent_w-$w;
  1059. }
  1060. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1061. }
  1062. else
  1063. {
  1064. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1065. $this->saveMax();
  1066. $this->saveX = 0;
  1067. $this->saveY = 0;
  1068. $this->saveH = 0;
  1069. }
  1070. // initialisation du style des bordures de la premiere partie de tableau
  1071. $this->Rectangle(
  1072. $this->style->value['x'],
  1073. $this->style->value['y'],
  1074. $this->style->value['width'],
  1075. $this->style->value['height'],
  1076. $this->style->value['border'],
  1077. $this->style->value['padding'],
  1078. 0,
  1079. $this->style->value['background']
  1080. );
  1081. $marge = array();
  1082. $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
  1083. $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
  1084. $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
  1085. $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
  1086. $this->style->value['width'] = $this->style->value['width']-$marge['l']-$marge['r'];
  1087. $this->style->value['height'] = $this->style->value['height']-$marge['r']-$marge['b'];
  1088. // limitation des marges aux dimensions de la div
  1089. $mL = $this->style->value['x']+$marge['l'];
  1090. $mR = $this->pdf->w - $mL - $this->style->value['width'];
  1091. $this->saveMargin($mL, 0, $mR);
  1092. // positionnement en fonction
  1093. $h_corr = $this->style->value['height'];
  1094. $h_reel = $h-$marge['b']-$marge['t'];
  1095. switch($this->style->value['vertical-align'])
  1096. {
  1097. case 'bottom':
  1098. $y_corr = $h_corr-$h_reel;
  1099. break;
  1100. case 'middle':
  1101. $y_corr = ($h_corr-$h_reel)*0.5;
  1102. break;
  1103. case 'top':
  1104. default:
  1105. $y_corr = 0;
  1106. break;
  1107. }
  1108. $this->pdf->setX($this->style->value['x']+$marge['l']);
  1109. $this->pdf->setY($this->style->value['y']+$marge['t']+$y_corr);
  1110. }
  1111. function o_BLOCKQUOTE($param) { $this->o_DIV($param, 'blockquote'); }
  1112. /**
  1113. * balise : DIV
  1114. * mode : FERMETURE
  1115. *
  1116. * @param array paramètres de l'élément de parsing
  1117. * @return null
  1118. */
  1119. function c_DIV($param)
  1120. {
  1121. $marge = array();
  1122. $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
  1123. $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
  1124. $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
  1125. $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
  1126. $x = $this->style->value['x'];
  1127. $y = $this->style->value['y'];
  1128. $w = $this->style->value['width']+$marge['l']+$marge['r'];
  1129. $h = $this->style->value['height']+$marge['t']+$marge['b'];
  1130. // correction pour les margins
  1131. $w+= $this->style->value['margin']['r'];
  1132. $h+= $this->style->value['margin']['b'];
  1133. if ($this->style->value['position']!='absolute')
  1134. {
  1135. // position
  1136. $this->pdf->x = $x+$w;
  1137. $this->pdf->y = $y;
  1138. // position MAX
  1139. $this->maxX = max($this->maxX, $x+$w);
  1140. $this->maxY = max($this->maxY, $y+$h);
  1141. $this->maxH = max($this->maxH, $h);
  1142. }
  1143. else
  1144. {
  1145. // position
  1146. $this->pdf->x = $this->style->value['xc'];
  1147. $this->pdf->y = $this->style->value['yc'];
  1148. $this->loadMax();
  1149. }
  1150. $block = ($this->style->value['display']!='inline' && $this->style->value['position']!='absolute');
  1151. $this->style->load();
  1152. $this->style->FontSet();
  1153. $this->loadMargin();
  1154. if ($block) $this->o_BR(array());
  1155. }
  1156. function c_BLOCKQUOTE($param) { $this->c_DIV($param); }
  1157. /**
  1158. * balise : BARCODE
  1159. * mode : OUVERTURE
  1160. *
  1161. * @param array paramètres de l'élément de parsing
  1162. * @return null
  1163. */
  1164. function o_BARCODE($param)
  1165. {
  1166. $lst_barcode = array(
  1167. 'EAN13' => '0.35mm',
  1168. 'UPC_A' => '0.35mm',
  1169. 'CODE39' => '1.00mm',
  1170. );
  1171. if (isset($param['type'])) $param['type'] = strtoupper($param['type']);
  1172. if (!isset($param['type']) || !isset($lst_barcode[$param['type']])) $param['type']=='CODE39';
  1173. if (!isset($param['value'])) $param['value'] = 0;
  1174. if (!isset($param['bar_w'])) $param['bar_w'] = $lst_barcode[$param['type']];
  1175. if (!isset($param['bar_h'])) $param['bar_h'] = '10mm';
  1176. if (!isset($param['style']['color'])) $param['style']['color'] = '#000000';
  1177. $param['style']['background-color'] = $param['style']['color'];
  1178. $this->style->save();
  1179. $this->style->analyse('barcode', $param);
  1180. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1181. $this->style->FontSet();
  1182. $x = $this->pdf->getX();
  1183. $y = $this->pdf->getY();
  1184. $w = $this->style->ConvertToMM($param['bar_w']);
  1185. $h = $this->style->ConvertToMM($param['bar_h']);
  1186. $infos = $this->pdf->{'BARCODE_'.$param['type']}($x, $y, $param['value'], $h, $w);
  1187. // position maximale globale
  1188. $this->maxX = max($this->maxX, $x+$infos[0]);
  1189. $this->maxY = max($this->maxY, $y+$infos[1]);
  1190. $this->maxH = max($this->maxH, $infos[1]);
  1191. $this->pdf->setX($x+$infos[0]);
  1192. $this->style->load();
  1193. $this->style->FontSet();
  1194. }
  1195. /**
  1196. * balise : BARCODE
  1197. * mode : FERMETURE
  1198. *
  1199. * @param array paramètres de l'élément de parsing
  1200. * @return null
  1201. */
  1202. function c_BARCODE($param)
  1203. {
  1204. // completement inutile
  1205. }
  1206. /**
  1207. * balise : BOOKMARK
  1208. * mode : OUVERTURE
  1209. *
  1210. * @param array paramètres de l'élément de parsing
  1211. * @return null
  1212. */
  1213. function o_BOOKMARK($param)
  1214. {
  1215. $titre = isset($param['title']) ? trim($param['title']) : '';
  1216. $level = isset($param['level']) ? floor($param['level']) : 0;
  1217. if ($level<0) $level = 0;
  1218. if ($titre) $this->pdf->Bookmark($titre, $level, -1);
  1219. }
  1220. /**
  1221. * balise : BOOKMARK
  1222. * mode : FERMETURE
  1223. *
  1224. * @param array paramètres de l'élément de parsing
  1225. * @return null
  1226. */
  1227. function c_BOOKMARK($param)
  1228. {
  1229. // completement inutile
  1230. }
  1231. /**
  1232. * balise : WRITE
  1233. * mode : OUVERTURE
  1234. *
  1235. * @param array paramètres de l'élément de parsing
  1236. * @return null
  1237. */
  1238. function o_WRITE($param)
  1239. {
  1240. $fill = false; //($this->style->value['background']['color']!=null);
  1241. // récupération du texte à écrire, et conversion
  1242. $txt = $param['txt'];
  1243. $txt = str_replace('&euro;', '€', $txt);
  1244. if ($this->isAfterFloat)
  1245. {
  1246. $txt = preg_replace('/^([\s]*)([^\s])/isU', '$2', $txt);
  1247. $this->isAfterFloat = false;
  1248. }
  1249. $txt = html_entity_decode($txt, ENT_QUOTES, 'ISO-8859-15');
  1250. // $txt = utf8_decode(html_entity_decode($txt, ENT_QUOTES, 'UTF-8'));
  1251. $txt = str_replace('[[page_cu]]', $this->pdf->PageNo(), $txt);
  1252. // tailles du texte
  1253. $h = 1.08*$this->style->value['font-size'];
  1254. $dh = $h*$this->style->value['mini-decal'];
  1255. $w = $this->pdf->GetStringWidth($txt);
  1256. // identification de l'alignement
  1257. $align = 'L';
  1258. if ($this->style->value['text-align']!='left')
  1259. {
  1260. $w = $this->style->value['width'];
  1261. if ($this->style->value['text-align']=='center') $align = 'C';
  1262. if ($this->style->value['text-align']=='right') $align = 'R';
  1263. }
  1264. $maxX = 0; // plus grande largeur du texte apres retour à la ligne
  1265. $x = $this->pdf->getX(); // position du texte
  1266. $y = $this->pdf->getY();
  1267. $w = $this->pdf->GetStringWidth($txt); // largeur du texte
  1268. list($left, $right) = $this->getMargins($y); // marges autorisees
  1269. $nb = 0; // nbr de lignes découpées
  1270. // tant que ca ne rentre pas sur la ligne et qu'on a du texte => on découpe
  1271. while($x+$w>$right && $x<$right && strlen($txt))
  1272. {
  1273. // liste des mots
  1274. $lst = explode(' ', $txt);
  1275. // trouver une phrase qui rentre dans la largeur, en ajoutant les mots 1 à 1
  1276. $i=0;
  1277. $old = '';
  1278. $str = $lst[0];
  1279. while(($x+$this->pdf->GetStringWidth($str))<=$right)
  1280. {
  1281. unset($lst[$i]);
  1282. $old = $str;
  1283. $i++;
  1284. $str.= ' '.$lst[$i];
  1285. }
  1286. $str = $old;
  1287. // si rien de rentre, et que le premier mot ne rentre de toute facon pas dans une ligne, on le force...
  1288. if ($i==0 && (($left+$this->pdf->GetStringWidth($lst[0]))>=$right))
  1289. {
  1290. $str = $lst[0];
  1291. unset($lst[0]);
  1292. }
  1293. // récupération des mots restant, et calcul de la largeur
  1294. $txt = implode(' ', $lst);
  1295. $w = $this->pdf->GetStringWidth($str);
  1296. // ecriture du bout de phrase extrait et qui rentre
  1297. $wc = ($align=='L' ? $w : $this->style->value['width']);
  1298. if ($right - $left<$wc) $wc = $right - $left;
  1299. $this->pdf->Cell($wc, $h+$dh, $str, 0, 0, $align, $fill, $this->inLink);
  1300. $this->maxH = max($this->maxH, $this->style->getLineHeight());
  1301. // détermination de la largeur max
  1302. $maxX = max($maxX, $this->pdf->getX());
  1303. // nouvelle position et nouvelle largeur pour la boucle
  1304. $w = $this->pdf->GetStringWidth($txt);
  1305. $y = $this->pdf->getY();
  1306. $x = $this->pdf->getX();
  1307. // si il reste du text à afficher
  1308. if (strlen($txt))
  1309. {
  1310. // retour à la ligne
  1311. $this->o_BR(array('style' => ''));
  1312. $y = $this->pdf->getY();
  1313. $x = $this->pdf->getX();
  1314. // si la prochaine ligne ne rentre pas dans la page => nouvelle page
  1315. if ($y + $h>$this->pdf->h - $this->pdf->bMargin) $this->setNewPage();
  1316. // ligne suplémentaire. au bout de 1000 : trop long => erreur
  1317. $nb++;
  1318. if ($nb>1000) HTML2PDF::makeError(2, __FILE__, __LINE__, array($txt, $right-$left, $this->pdf->GetStringWidth($txt)));
  1319. list($left, $right) = $this->getMargins($y); // marges autorisees
  1320. }
  1321. }
  1322. // si il reste du text apres découpe, c'est qu'il rentre direct => on l'affiche
  1323. if (strlen($txt))
  1324. {
  1325. $this->pdf->Cell(($align=='L' ? $w : $this->style->value['width']), $h+$dh, $txt, 0, 0, $align, $fill, $this->inLink);
  1326. $this->maxH = max($this->maxH, $this->style->getLineHeight());
  1327. }
  1328. // détermination des positions MAX
  1329. $maxX = max($maxX, $this->pdf->getX());
  1330. $maxY = $this->pdf->getY()+$h;
  1331. // position maximale globale
  1332. $this->maxX = max($this->maxX, $maxX);
  1333. $this->maxY = max($this->maxY, $maxY);
  1334. }
  1335. /**
  1336. * tracer une image
  1337. *
  1338. * @param string nom du fichier source
  1339. * @return null
  1340. */
  1341. function Image($src, $sub_li=false)
  1342. {
  1343. // est-ce que c'est une image ?
  1344. $infos=@GetImageSize($src);
  1345. if (count($infos)<2)
  1346. {
  1347. HTML2PDF::makeError(6, __FILE__, __LINE__, $src);
  1348. return false;
  1349. }
  1350. // récupération des dimensions dans l'unité du PDF
  1351. $wi = $infos[0]/$this->pdf->k;
  1352. $hi = $infos[1]/$this->pdf->k;
  1353. // détermination des dimensions d'affichage en fonction du style
  1354. if ($this->style->value['width'] && $this->style->value['height'])
  1355. {
  1356. $w = $this->style->value['width'];
  1357. $h = $this->style->value['height'];
  1358. }
  1359. else if ($this->style->value['width'])
  1360. {
  1361. $w = $this->style->value['width'];
  1362. $h = $hi*$w/$wi;
  1363. }
  1364. else if ($this->style->value['height'])
  1365. {
  1366. $h = $this->style->value['height'];
  1367. $w = $wi*$h/$hi;
  1368. }
  1369. else
  1370. {
  1371. $w = 72./96.*$wi;
  1372. $h = 72./96.*$hi;
  1373. }
  1374. // detection du float
  1375. $float = $this->style->getFloat();
  1376. if ($float && $this->maxH) $this->o_BR(array());
  1377. // position d'affichage
  1378. $x = $this->pdf->getX();
  1379. $y = $this->pdf->getY();
  1380. // si l'image ne rentre pas dans la page => nouvelle page
  1381. if ($y + $h>$this->pdf->h - $this->pdf->bMargin)
  1382. {
  1383. $this->setNewPage();
  1384. $x = $this->pdf->getX();
  1385. $y = $this->pdf->getY();
  1386. }
  1387. // correction pour l'affichage d'une puce image
  1388. $hT = 0.80*$this->style->value['font-size'];
  1389. if ($sub_li && $h<$hT)
  1390. {
  1391. $y+=($hT-$h);
  1392. }
  1393. $yc = $y-$this->style->value['margin']['t'];
  1394. // détermination de la position réelle d'affichage en fonction du text-align du parent
  1395. $old = isset($this->style->table[count($this->style->table)-1]) ? $this->style->table[count($this->style->table)-1] : $this->style->value;
  1396. if ( $old['width'])
  1397. {
  1398. $parent_w = $old['width'];
  1399. $parent_x = $x;
  1400. }
  1401. else
  1402. {
  1403. $parent_w = $this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin;
  1404. $parent_x = $this->pdf->lMargin;
  1405. }
  1406. if ($float)
  1407. {
  1408. list($lx, $rx) = $this->getMargins($yc);
  1409. $parent_x = $lx;
  1410. $parent_w = $rx-$lx;
  1411. }
  1412. if ($parent_w>$w && $float!='left')
  1413. {
  1414. if ($float=='right' || $this->style->value['text-align']=='right') $x = $parent_x + $parent_w - $w-$this->style->value['margin']['r']-$this->style->value['margin']['l'];
  1415. else if ($this->style->value['text-align']=='center') $x = $parent_x + 0.5*($parent_w - $w);
  1416. }
  1417. // affichage de l'image, et positionnement à la suite
  1418. if (!$this->sub_part && !$this->isSubPart) $this->pdf->Image($src, $x, $y, $w, $h, '', $this->inLink);
  1419. $x-= $this->style->value['margin']['l'];
  1420. $y-= $this->style->value['margin']['t'];
  1421. $w+= $this->style->value['margin']['l'] + $this->style->value['margin']['r'];
  1422. $h+= $this->style->value['margin']['t'] + $this->style->value['margin']['b'];
  1423. if ($float=='left')
  1424. {
  1425. $this->maxX = max($this->maxX, $x+$w);
  1426. $this->maxY = max($this->maxY, $y+$h);
  1427. $this->addMargins($float, $x, $y, $x+$w, $y+$h);
  1428. list($lx, $rx) = $this->getMargins($yc);
  1429. $this->pdf->x = $lx;
  1430. $this->pdf->y = $yc;
  1431. }
  1432. else if ($float=='right')
  1433. {
  1434. // $this->maxX = max($this->maxX, $x+$w);
  1435. $this->maxY = max($this->maxY, $y+$h);
  1436. $this->addMargins($float, $x, $y, $x+$w, $y+$h);
  1437. list($lx, $rx) = $this->getMargins($yc);
  1438. $this->pdf->x = $lx;
  1439. $this->pdf->y = $yc;
  1440. }
  1441. else
  1442. {
  1443. $this->pdf->SetX($x+$w);
  1444. $this->maxX = max($this->maxX, $x+$w);
  1445. $this->maxY = max($this->maxY, $y+$h);
  1446. $this->maxH = max($this->maxH, $h);
  1447. }
  1448. }
  1449. /**
  1450. * Tracer un rectanble
  1451. *
  1452. * @param float position X
  1453. * @param float position Y
  1454. * @param float Largeur
  1455. * @param float Hauteur
  1456. * @param array Tableau de style de définition des borders
  1457. * @param float padding - marge intérieur au rectangle => non utile mais on le passe en paramètre
  1458. * @param float margin - marge exterieur au rectangle
  1459. * @param array Tableau de style de définition du background
  1460. * @return null
  1461. */
  1462. function Rectangle($x, $y, $w, $h, $border, $padding, $margin, $background)
  1463. {
  1464. if ($this->sub_part || $this->isSubPart) return false;
  1465. if ($h===null) return false;
  1466. $x+= $margin;
  1467. $y+= $margin;
  1468. $w-= $margin*2;
  1469. $h-= $margin*2;
  1470. // récupération des radius
  1471. $radius_h = $border['radius'][0];
  1472. $radius_v = $border['radius'][1];
  1473. // verification des coins en radius
  1474. $coin_TL = ($radius_h && $radius_v && $radius_v>$border['t']['width'] && $radius_h>$border['l']['width']) ? array($radius_h, $radius_v) : null;
  1475. $coin_TR = ($radius_h && $radius_v && $radius_v>$border['t']['width'] && $radius_h>$border['r']['width']) ? array($radius_h, $radius_v) : null;
  1476. $coin_BL = ($radius_h && $radius_v && $radius_v>$border['b']['width'] && $radius_h>$border['l']['width']) ? array($radius_h, $radius_v) : null;
  1477. $coin_BR = ($radius_h && $radius_v && $radius_v>$border['b']['width'] && $radius_h>$border['r']['width']) ? array($radius_h, $radius_v) : null;
  1478. // traitement de la couleur de fond
  1479. $STYLE = '';
  1480. if ($background['color'])
  1481. {
  1482. $this->pdf->SetFillColor($background['color'][0], $background['color'][1], $background['color'][2]);
  1483. $STYLE.= 'F';
  1484. }
  1485. if ($STYLE)
  1486. {
  1487. $this->pdf->clippingPathOpen($x, $y, $w, $h, $coin_TL,$coin_TR, $coin_BL, $coin_BR);
  1488. $this->pdf->Rect($x, $y, $w, $h, $STYLE);
  1489. $this->pdf->clippingPathClose();
  1490. }
  1491. // traitement de l'image de fond
  1492. if ($background['image'])
  1493. {
  1494. $i_name = $background['image'];
  1495. $i_position = $background['position']!==null ? $background['position'] : array(0, 0);
  1496. $i_repeat = $background['repeat']!==null ? $background['repeat'] : array(true, true);
  1497. // taile du fond (il faut retirer les borders
  1498. $b_x = $x;
  1499. $b_y = $y;
  1500. $b_w = $w;
  1501. $b_h = $h;
  1502. if ($border['b']['width']) { $b_h-= $border['b']['width']; }
  1503. if ($border['l']['width']) { $b_w-= $border['l']['width']; $b_x+= $border['l']['width']; }
  1504. if ($border['t']['width']) { $b_h-= $border['t']['width']; $b_y+= $border['t']['width']; }
  1505. if ($border['r']['width']) { $b_w-= $border['r']['width']; }
  1506. // est-ce que c'est une image ?
  1507. $i_infos=@GetImageSize($i_name);
  1508. if (count($i_infos)<2)
  1509. {
  1510. HTML2PDF::makeError(6, __FILE__, __LINE__, $i_name);
  1511. return false;
  1512. }
  1513. // récupération des dimensions dans l'unité du PDF
  1514. $i_width = 72./96.*$i_infos[0]/$this->pdf->k;
  1515. $i_height = 72./96.*$i_infos[1]/$this->pdf->k;
  1516. if ($i_repeat[0]) $i_position[0] = $b_x;
  1517. else if(preg_match('/^([-]?[0-9\.]+)%/isU', $i_position[0], $match)) $i_position[0] = $b_x + $match[1]*($b_w-$i_width)/100;
  1518. else $i_position[0] = $b_x+$i_position[0];
  1519. if ($i_repeat[1]) $i_position[1] = $b_y;
  1520. else if(preg_match('/^([-]?[0-9\.]+)%/isU', $i_position[1], $match)) $i_position[1] = $b_y + $match[1]*($b_h-$i_height)/100;
  1521. else $i_position[1] = $b_y+$i_position[1];
  1522. $i_x_min = $b_x;
  1523. $i_x_max = $b_x+$b_w;
  1524. $i_y_min = $b_y;
  1525. $i_y_max = $b_y+$b_h;
  1526. if (!$i_repeat[0] && !$i_repeat[1])
  1527. {
  1528. $i_x_min = $i_position[0]; $i_x_max = $i_position[0]+$i_width;
  1529. $i_y_min = $i_position[1]; $i_y_max = $i_position[1]+$i_height;
  1530. }
  1531. else if ($i_repeat[0] && !$i_repeat[1])
  1532. {
  1533. $i_y_min = $i_position[1]; $i_y_max = $i_position[1]+$i_height;
  1534. }
  1535. elseif (!$i_repeat[0] && $i_repeat[1])
  1536. {
  1537. $i_x_min = $i_position[0]; $i_x_max = $i_position[0]+$i_width;
  1538. }
  1539. if (is_array($coin_TL)) { $coin_TL[0]-= $border['l']['width']; $coin_TL[1]-= $border['t']['width']; }
  1540. if (is_array($coin_TR)) { $coin_TR[0]-= $border['r']['width']; $coin_TR[1]-= $border['t']['width']; }
  1541. if (is_array($coin_BL)) { $coin_BL[0]-= $border['l']['width']; $coin_BL[1]-= $border['b']['width']; }
  1542. if (is_array($coin_BR)) { $coin_BR[0]-= $border['r']['width']; $coin_BR[1]-= $border['b']['width']; }
  1543. $this->pdf->clippingPathOpen($b_x, $b_y, $b_w, $b_h, $coin_TL, $coin_TR, $coin_BL, $coin_BR);
  1544. for ($i_y=$i_y_min; $i_y<$i_y_max; $i_y+=$i_height)
  1545. {
  1546. for ($i_x=$i_x_min; $i_x<$i_x_max; $i_x+=$i_width)
  1547. {
  1548. $c_x = null;
  1549. $c_y = null;
  1550. $c_w = $i_width;
  1551. $c_h = $i_height;
  1552. if ($i_y_max-$i_y<$i_height)
  1553. {
  1554. $c_x = $i_x;
  1555. $c_y = $i_y;
  1556. $c_h = $i_y_max-$i_y;
  1557. }
  1558. if ($i_x_max-$i_x<$i_width)
  1559. {
  1560. $c_x = $i_x;
  1561. $c_y = $i_y;
  1562. $c_w = $i_x_max-$i_x;
  1563. }
  1564. $this->pdf->Image($i_name, $i_x, $i_y, $i_width, $i_height, '', '');
  1565. }
  1566. }
  1567. $this->pdf->clippingPathClose();
  1568. }
  1569. $x-= 0.01;
  1570. $y-= 0.01;
  1571. $w+= 0.02;
  1572. $h+= 0.02;
  1573. if ($border['b']['width']) $border['b']['width']+= 0.02;
  1574. if ($border['l']['width']) $border['l']['width']+= 0.02;
  1575. if ($border['t']['width']) $border['t']['width']+= 0.02;
  1576. if ($border['r']['width']) $border['r']['width']+= 0.02;
  1577. if ($border['b']['width'] && $border['b']['color'][0]!==null)
  1578. {
  1579. $pt = array();
  1580. $pt[] = $x+$w; $pt[] = $y+$h;
  1581. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h;
  1582. $pt[] = $x+$border['l']['width']; $pt[] = $y+$h;
  1583. $pt[] = $x; $pt[] = $y+$h;
  1584. $pt[] = $x+$border['l']['width']; $pt[] = $y+$h-$border['b']['width'];
  1585. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h-$border['b']['width'];
  1586. $bord = 3;
  1587. if (is_array($coin_BL))
  1588. {
  1589. $bord-=2;
  1590. $pt[4] += $radius_h-$border['l']['width'];
  1591. $pt[8] += $radius_h-$border['l']['width'];
  1592. unset($pt[6]);unset($pt[7]);
  1593. }
  1594. if (is_array($coin_BR))
  1595. {
  1596. $courbe = array();
  1597. $courbe[] = $x+$w; $courbe[] = $y+$h-$radius_v;
  1598. $courbe[] = $x+$w-$radius_h; $courbe[] = $y+$h;
  1599. $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$h-$radius_v;
  1600. $courbe[] = $x+$w-$radius_h; $courbe[] = $y+$h-$border['b']['width'];
  1601. $courbe[] = $x+$w-$radius_h; $courbe[] = $y+$h-$radius_v;
  1602. $this->Courbe($courbe, $border['b']['color']);
  1603. $bord-=1;
  1604. $pt[2] -= $radius_h-$border['r']['width'];
  1605. $pt[10]-= $radius_h-$border['r']['width'];
  1606. unset($pt[0]);unset($pt[1]);
  1607. }
  1608. $pt = array_values($pt);
  1609. $this->Line($pt, $border['b']['color'], $border['b']['type'], $border['b']['width'], $bord);
  1610. }
  1611. if ($border['l']['width'] && $border['l']['color'][0]!==null)
  1612. {
  1613. $pt = array();
  1614. $pt[] = $x; $pt[] = $y+$h;
  1615. $pt[] = $x; $pt[] = $y+$h-$border['b']['width'];
  1616. $pt[] = $x; $pt[] = $y+$border['t']['width'];
  1617. $pt[] = $x; $pt[] = $y;
  1618. $pt[] = $x+$border['l']['width']; $pt[] = $y+$border['t']['width'];
  1619. $pt[] = $x+$border['l']['width']; $pt[] = $y+$h-$border['b']['width'];
  1620. $bord = 3;
  1621. if (is_array($coin_BL))
  1622. {
  1623. $courbe = array();
  1624. $courbe[] = $x+$radius_h; $courbe[] = $y+$h;
  1625. $courbe[] = $x; $courbe[] = $y+$h-$radius_v;
  1626. $courbe[] = $x+$radius_h; $courbe[] = $y+$h-$border['b']['width'];
  1627. $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$h-$radius_v;
  1628. $courbe[] = $x+$radius_h; $courbe[] = $y+$h-$radius_v;
  1629. $this->Courbe($courbe, $border['l']['color']);
  1630. $bord-=1;
  1631. $pt[3] -= $radius_v-$border['b']['width'];
  1632. $pt[11]-= $radius_v-$border['b']['width'];
  1633. unset($pt[0]);unset($pt[1]);
  1634. }
  1635. if (is_array($coin_TL))
  1636. {
  1637. $bord-=2;
  1638. $pt[5] += $radius_v-$border['t']['width'];
  1639. $pt[9] += $radius_v-$border['t']['width'];
  1640. unset($pt[6]);unset($pt[7]);
  1641. }
  1642. $pt = array_values($pt);
  1643. $this->Line($pt, $border['l']['color'], $border['l']['type'], $border['l']['width'], $bord);
  1644. }
  1645. if ($border['t']['width'] && $border['t']['color'][0]!==null)
  1646. {
  1647. $pt = array();
  1648. $pt[] = $x; $pt[] = $y;
  1649. $pt[] = $x+$border['l']['width']; $pt[] = $y;
  1650. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y;
  1651. $pt[] = $x+$w; $pt[] = $y;
  1652. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$border['t']['width'];
  1653. $pt[] = $x+$border['l']['width']; $pt[] = $y+$border['t']['width'];
  1654. $bord = 3;
  1655. if (is_array($coin_TL))
  1656. {
  1657. $courbe = array();
  1658. $courbe[] = $x; $courbe[] = $y+$radius_v;
  1659. $courbe[] = $x+$radius_h; $courbe[] = $y;
  1660. $courbe[] = $x+$border['l']['width']; $courbe[] = $y+$radius_v;
  1661. $courbe[] = $x+$radius_h; $courbe[] = $y+$border['t']['width'];
  1662. $courbe[] = $x+$radius_h; $courbe[] = $y+$radius_v;
  1663. $this->Courbe($courbe, $border['t']['color']);
  1664. $bord-=1;
  1665. $pt[2] += $radius_h-$border['l']['width'];
  1666. $pt[10]+= $radius_h-$border['l']['width'];
  1667. unset($pt[0]);unset($pt[1]);
  1668. }
  1669. if (is_array($coin_TR))
  1670. {
  1671. $bord-=2;
  1672. $pt[4] -= $radius_h-$border['r']['width'];
  1673. $pt[8] -= $radius_h-$border['r']['width'];
  1674. unset($pt[6]);unset($pt[7]);
  1675. }
  1676. $pt = array_values($pt);
  1677. $this->Line($pt, $border['t']['color'], $border['t']['type'], $border['t']['width'], $bord);
  1678. }
  1679. if ($border['r']['width'] && $border['r']['color'][0]!==null)
  1680. {
  1681. $pt = array();
  1682. $pt[] = $x+$w; $pt[] = $y;
  1683. $pt[] = $x+$w; $pt[] = $y+$border['t']['width'];
  1684. $pt[] = $x+$w; $pt[] = $y+$h-$border['b']['width'];
  1685. $pt[] = $x+$w; $pt[] = $y+$h;
  1686. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$h-$border['b']['width'];
  1687. $pt[] = $x+$w-$border['r']['width']; $pt[] = $y+$border['t']['width'];
  1688. $bord = 3;
  1689. if (is_array($coin_TR))
  1690. {
  1691. $courbe = array();
  1692. $courbe[] = $x+$w-$radius_h; $courbe[] = $y;
  1693. $courbe[] = $x+$w; $courbe[] = $y+$radius_v;
  1694. $courbe[] = $x+$w-$radius_h; $courbe[] = $y+$border['t']['width'];
  1695. $courbe[] = $x+$w-$border['r']['width']; $courbe[] = $y+$radius_v;
  1696. $courbe[] = $x+$w-$radius_h; $courbe[] = $y+$radius_v;
  1697. $this->Courbe($courbe, $border['r']['color']);
  1698. $bord-=1;
  1699. $pt[3] += $radius_v-$border['t']['width'];
  1700. $pt[11]+= $radius_v-$border['t']['width'];
  1701. unset($pt[0]);unset($pt[1]);
  1702. }
  1703. if (is_array($coin_BR))
  1704. {
  1705. $bord-=2;
  1706. $pt[5] -= $radius_v-$border['b']['width'];
  1707. $pt[9] -= $radius_v-$border['b']['width'];
  1708. unset($pt[6]);unset($pt[7]);
  1709. }
  1710. $pt = array_values($pt);
  1711. $this->Line($pt, $border['r']['color'], $border['r']['type'], $border['r']['width'], $bord);
  1712. }
  1713. if ($background) $this->pdf->SetFillColor($background['color'][0], $background['color'][1], $background['color'][2]);
  1714. }
  1715. function Courbe($pt, $color)
  1716. {
  1717. $this->pdf->SetFillColor($color[0], $color[1], $color[2]);
  1718. $this->pdf->drawCourbe($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7], $pt[8], $pt[9]);
  1719. }
  1720. /**
  1721. * Tracer une ligne epaisse défini par ses points avec des extreminites en biseau
  1722. *
  1723. * @param array liste des points definissant le tour de la ligne
  1724. * @param float couleur RVB
  1725. * @param string type de ligne
  1726. * @param float largeur de la ligne
  1727. * @return null
  1728. */
  1729. function Line($pt, $color, $type, $width, $bord=3)
  1730. {
  1731. $this->pdf->SetFillColor($color[0], $color[1], $color[2]);
  1732. if ($type=='dashed' || $type=='dotted')
  1733. {
  1734. if ($bord==1)
  1735. {
  1736. $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
  1737. $this->pdf->Polygon($tmp, 'F');
  1738. $tmp = array(); $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
  1739. $pt = $tmp;
  1740. }
  1741. else if ($bord==2)
  1742. {
  1743. $tmp = array(); $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7];
  1744. $this->pdf->Polygon($tmp, 'F');
  1745. $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[6]; $tmp[]=$pt[7]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
  1746. $pt = $tmp;
  1747. }
  1748. else if ($bord==3)
  1749. {
  1750. $tmp = array(); $tmp[]=$pt[0]; $tmp[]=$pt[1]; $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[10]; $tmp[]=$pt[11];
  1751. $this->pdf->Polygon($tmp, 'F');
  1752. $tmp = array(); $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[6]; $tmp[]=$pt[7]; $tmp[]=$pt[8]; $tmp[]=$pt[9];
  1753. $this->pdf->Polygon($tmp, 'F');
  1754. $tmp = array(); $tmp[]=$pt[2]; $tmp[]=$pt[3]; $tmp[]=$pt[4]; $tmp[]=$pt[5]; $tmp[]=$pt[8]; $tmp[]=$pt[9]; $tmp[]=$pt[10]; $tmp[]=$pt[11];
  1755. $pt = $tmp;
  1756. }
  1757. if ($pt[2]==$pt[0])
  1758. {
  1759. $l = abs(($pt[3]-$pt[1])*0.5);
  1760. $px = 0;
  1761. $py = $width;
  1762. $x1 = $pt[0]; $y1 = ($pt[3]+$pt[1])*0.5;
  1763. $x2 = $pt[6]; $y2 = ($pt[7]+$pt[5])*0.5;
  1764. }
  1765. else
  1766. {
  1767. $l = abs(($pt[2]-$pt[0])*0.5);
  1768. $px = $width;
  1769. $py = 0;
  1770. $x1 = ($pt[2]+$pt[0])*0.5; $y1 = $pt[1];
  1771. $x2 = ($pt[6]+$pt[4])*0.5; $y2 = $pt[7];
  1772. }
  1773. if ($type=='dashed')
  1774. {
  1775. $px = $px*3.;
  1776. $py = $py*3.;
  1777. }
  1778. $mode = ($l/($px+$py)<.5);
  1779. for($i=0; $l-($px+$py)*($i-0.5)>0; $i++)
  1780. {
  1781. if (($i%2)==$mode)
  1782. {
  1783. $j = $i-0.5;
  1784. $lx1 = $px*($j); if ($lx1<-$l) $lx1 =-$l;
  1785. $ly1 = $py*($j); if ($ly1<-$l) $ly1 =-$l;
  1786. $lx2 = $px*($j+1); if ($lx2>$l) $lx2 = $l;
  1787. $ly2 = $py*($j+1); if ($ly2>$l) $ly2 = $l;
  1788. $tmp = array();
  1789. $tmp[] = $x1+$lx1; $tmp[] = $y1+$ly1;
  1790. $tmp[] = $x1+$lx2; $tmp[] = $y1+$ly2;
  1791. $tmp[] = $x2+$lx2; $tmp[] = $y2+$ly2;
  1792. $tmp[] = $x2+$lx1; $tmp[] = $y2+$ly1;
  1793. $this->pdf->Polygon($tmp, 'F');
  1794. if ($j>0)
  1795. {
  1796. $tmp = array();
  1797. $tmp[] = $x1-$lx1; $tmp[] = $y1-$ly1;
  1798. $tmp[] = $x1-$lx2; $tmp[] = $y1-$ly2;
  1799. $tmp[] = $x2-$lx2; $tmp[] = $y2-$ly2;
  1800. $tmp[] = $x2-$lx1; $tmp[] = $y2-$ly1;
  1801. $this->pdf->Polygon($tmp, 'F');
  1802. }
  1803. }
  1804. }
  1805. }
  1806. else if ($type=='solid')
  1807. {
  1808. $this->pdf->Polygon($pt, 'F');
  1809. }
  1810. }
  1811. /**
  1812. * balise : BR
  1813. * mode : OUVERTURE
  1814. *
  1815. * @param array paramètres de l'élément de parsing
  1816. * @return null
  1817. */
  1818. function o_BR($param)
  1819. {
  1820. $h = $this->style->getLineHeight();
  1821. $h = max($this->maxH, $h);
  1822. $y = $this->pdf->getY();
  1823. // si la ligne est vide, la position maximale n'a pas été mise à jour => on la met à jour
  1824. if ($this->maxH==0) $this->maxY = max($this->maxY, $y+$h);
  1825. // si le saut de ligne rentre => on le prend en compte, sinon nouvelle page
  1826. if ($y+$h<$this->pdf->h - $this->pdf->bMargin) $this->setNewLine($h);
  1827. else $this->setNewPage();
  1828. $this->maxH = 0;
  1829. }
  1830. /**
  1831. * balise : HR
  1832. * mode : OUVERTURE
  1833. *
  1834. * @param array paramètres de l'élément de parsing
  1835. * @return null
  1836. */
  1837. function o_HR($param)
  1838. {
  1839. if ($this->maxH) $this->o_BR($param);
  1840. $f_size = $this->style->value['font-size'];
  1841. $this->style->value['font-size']=$f_size*0.5; $this->o_BR($param);
  1842. $this->style->value['font-size']=0;
  1843. $param['style']['width'] = '100%';
  1844. $this->style->save();
  1845. $this->style->value['height']=$this->style->ConvertToMM('1mm');
  1846. $this->style->analyse('hr', $param);
  1847. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1848. $this->style->FontSet();
  1849. $h = $this->style->value['height'];
  1850. if ($h) $h-= $this->style->value['border']['t']['width']+$this->style->value['border']['b']['width'];
  1851. if ($h<=0) $h = $this->style->value['border']['t']['width']+$this->style->value['border']['b']['width'];
  1852. $this->Rectangle($this->pdf->x, $this->pdf->y, $this->style->value['width'], $h, $this->style->value['border'], 0, 0, $this->style->value['background']);
  1853. $this->maxH = $h;
  1854. $this->style->load();
  1855. $this->style->FontSet();
  1856. $this->o_BR($param);
  1857. $this->style->value['font-size']=$f_size*0.5; $this->o_BR($param);
  1858. $this->style->value['font-size']=$f_size;
  1859. }
  1860. /**
  1861. * balise : B
  1862. * mode : OUVERTURE
  1863. *
  1864. * @param array paramètres de l'élément de parsing
  1865. * @return null
  1866. */
  1867. function o_B($param, $other = 'b')
  1868. {
  1869. $this->style->save();
  1870. $this->style->value['font-bold'] = true;
  1871. $this->style->analyse($other, $param);
  1872. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1873. $this->style->FontSet();
  1874. }
  1875. function o_STRONG($param) { $this->o_B($param, 'strong'); }
  1876. /**
  1877. * balise : B
  1878. * mode : FERMETURE
  1879. *
  1880. * @param array paramètres de l'élément de parsing
  1881. * @return null
  1882. */
  1883. function c_B($param)
  1884. {
  1885. $this->style->load();
  1886. $this->style->FontSet();
  1887. }
  1888. function c_STRONG($param) { $this->c_B($param); }
  1889. /**
  1890. * balise : I
  1891. * mode : OUVERTURE
  1892. *
  1893. * @param array paramètres de l'élément de parsing
  1894. * @return null
  1895. */
  1896. function o_I($param, $other = 'i')
  1897. {
  1898. $this->style->save();
  1899. $this->style->value['font-italic'] = true;
  1900. $this->style->analyse($other, $param);
  1901. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1902. $this->style->FontSet();
  1903. }
  1904. function o_ADDRESS($param) { $this->o_I($param, 'address'); }
  1905. function o_CITE($param) { $this->o_I($param, 'cite'); }
  1906. function o_EM($param) { $this->o_I($param, 'em'); }
  1907. function o_SAMP($param) { $this->o_I($param, 'samp'); }
  1908. /**
  1909. * balise : I
  1910. * mode : FERMETURE
  1911. *
  1912. * @param array paramètres de l'élément de parsing
  1913. * @return null
  1914. */
  1915. function c_I($param)
  1916. {
  1917. $this->style->load();
  1918. $this->style->FontSet();
  1919. }
  1920. function c_ADDRESS($param) { $this->c_I($param); }
  1921. function c_CITE($param) { $this->c_I($param); }
  1922. function c_EM($param) { $this->c_I($param); }
  1923. function c_SAMP($param) { $this->c_I($param); }
  1924. /**
  1925. * balise : S
  1926. * mode : OUVERTURE
  1927. *
  1928. * @param array paramètres de l'élément de parsing
  1929. * @return null
  1930. */
  1931. function o_S($param)
  1932. {
  1933. $this->style->save();
  1934. $this->style->value['font-linethrough'] = true;
  1935. $this->style->analyse('s', $param);
  1936. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1937. $this->style->FontSet();
  1938. }
  1939. /**
  1940. * balise : S
  1941. * mode : FERMETURE
  1942. *
  1943. * @param array paramètres de l'élément de parsing
  1944. * @return null
  1945. */
  1946. function c_S($param)
  1947. {
  1948. $this->style->load();
  1949. $this->style->FontSet();
  1950. }
  1951. /**
  1952. * balise : U
  1953. * mode : OUVERTURE
  1954. *
  1955. * @param array paramètres de l'élément de parsing
  1956. * @return null
  1957. */
  1958. function o_U($param)
  1959. {
  1960. $this->style->save();
  1961. $this->style->value['font-underline'] = true;
  1962. $this->style->analyse('u', $param);
  1963. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  1964. $this->style->FontSet();
  1965. }
  1966. /**
  1967. * balise : U
  1968. * mode : FERMETURE
  1969. *
  1970. * @param array paramètres de l'élément de parsing
  1971. * @return null
  1972. */
  1973. function c_U($param)
  1974. {
  1975. $this->style->load();
  1976. $this->style->FontSet();
  1977. }
  1978. /**
  1979. * balise : A
  1980. * mode : OUVERTURE
  1981. *
  1982. * @param array paramètres de l'élément de parsing
  1983. * @return null
  1984. */
  1985. function o_A($param)
  1986. {
  1987. $this->inLink = str_replace('&amp;', '&', isset($param['href']) ? $param['href'] : '');
  1988. if (isset($param['name']))
  1989. {
  1990. $nom = $param['name'];
  1991. if (!isset($this->lstAncre[$nom])) $this->lstAncre[$nom] = array($this->pdf->AddLink(), false);
  1992. if (!$this->lstAncre[$nom][1])
  1993. {
  1994. $this->lstAncre[$nom][1] = true;
  1995. $this->pdf->SetLink($this->lstAncre[$nom][0], -1, -1);
  1996. }
  1997. }
  1998. if (preg_match('/^#([^#]+)$/isU', $this->inLink, $match))
  1999. {
  2000. $nom = $match[1];
  2001. if (!isset($this->lstAncre[$nom])) $this->lstAncre[$nom] = array($this->pdf->AddLink(), false);
  2002. $this->inLink = $this->lstAncre[$nom][0];
  2003. }
  2004. $this->style->save();
  2005. $this->style->value['font-underline'] = true;
  2006. $this->style->value['color'] = array(20, 20, 250);
  2007. $this->style->analyse('a', $param);
  2008. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2009. $this->style->FontSet();
  2010. }
  2011. /**
  2012. * balise : A
  2013. * mode : FERMETURE
  2014. *
  2015. * @param array paramètres de l'élément de parsing
  2016. * @return null
  2017. */
  2018. function c_A($param)
  2019. {
  2020. $this->inLink = '';
  2021. $this->style->load();
  2022. $this->style->FontSet();
  2023. }
  2024. /**
  2025. * balise : H1
  2026. * mode : OUVERTURE
  2027. *
  2028. * @param array paramètres de l'élément de parsing
  2029. * @return null
  2030. */
  2031. function o_H1($param)
  2032. {
  2033. $this->o_BR(array());
  2034. $this->style->save();
  2035. $this->style->value['font-bold'] = true;
  2036. $this->style->value['font-size'] = $this->style->ConvertToMM('28px');
  2037. $this->style->analyse('h1', $param);
  2038. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2039. $this->style->FontSet();
  2040. }
  2041. /**
  2042. * balise : H1
  2043. * mode : FERMETURE
  2044. *
  2045. * @param array paramètres de l'élément de parsing
  2046. * @return null
  2047. */
  2048. function c_H1($param)
  2049. {
  2050. $this->o_BR(array());
  2051. $this->style->load();
  2052. $this->style->FontSet();
  2053. $this->o_BR(array());
  2054. }
  2055. /**
  2056. * balise : H2
  2057. * mode : OUVERTURE
  2058. *
  2059. * @param array paramètres de l'élément de parsing
  2060. * @return null
  2061. */
  2062. function o_H2($param)
  2063. {
  2064. $this->o_BR(array());
  2065. $this->style->save();
  2066. $this->style->value['font-bold'] = true;
  2067. $this->style->value['font-size'] = $this->style->ConvertToMM('24px');
  2068. $this->style->analyse('h2', $param);
  2069. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2070. $this->style->FontSet();
  2071. }
  2072. /**
  2073. * balise : H2
  2074. * mode : FERMETURE
  2075. *
  2076. * @param array paramètres de l'élément de parsing
  2077. * @return null
  2078. */
  2079. function c_H2($param)
  2080. {
  2081. $this->o_BR(array());
  2082. $this->style->load();
  2083. $this->style->FontSet();
  2084. $this->o_BR(array());
  2085. }
  2086. /**
  2087. * balise : H3
  2088. * mode : OUVERTURE
  2089. *
  2090. * @param array paramètres de l'élément de parsing
  2091. * @return null
  2092. */
  2093. function o_H3($param)
  2094. {
  2095. $this->o_BR(array());
  2096. $this->style->save();
  2097. $this->style->value['font-bold'] = true;
  2098. $this->style->value['font-size'] = $this->style->ConvertToMM('20px');
  2099. $this->style->analyse('h3', $param);
  2100. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2101. $this->style->FontSet();
  2102. }
  2103. /**
  2104. * balise : H3
  2105. * mode : FERMETURE
  2106. *
  2107. * @param array paramètres de l'élément de parsing
  2108. * @return null
  2109. */
  2110. function c_H3($param)
  2111. {
  2112. $this->o_BR(array());
  2113. $this->style->load();
  2114. $this->style->FontSet();
  2115. $this->o_BR(array());
  2116. }
  2117. /**
  2118. * balise : H4
  2119. * mode : OUVERTURE
  2120. *
  2121. * @param array paramètres de l'élément de parsing
  2122. * @return null
  2123. */
  2124. function o_H4($param)
  2125. {
  2126. $this->o_BR(array());
  2127. $this->style->save();
  2128. $this->style->value['font-bold'] = true;
  2129. $this->style->value['font-size'] = $this->style->ConvertToMM('16px');
  2130. $this->style->analyse('h4', $param);
  2131. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2132. $this->style->FontSet();
  2133. }
  2134. /**
  2135. * balise : H4
  2136. * mode : FERMETURE
  2137. *
  2138. * @param array paramètres de l'élément de parsing
  2139. * @return null
  2140. */
  2141. function c_H4($param)
  2142. {
  2143. $this->o_BR(array());
  2144. $this->style->load();
  2145. $this->style->FontSet();
  2146. $this->o_BR(array());
  2147. }
  2148. /**
  2149. * balise : H5
  2150. * mode : OUVERTURE
  2151. *
  2152. * @param array paramètres de l'élément de parsing
  2153. * @return null
  2154. */
  2155. function o_H5($param)
  2156. {
  2157. $this->o_BR(array());
  2158. $this->style->save();
  2159. $this->style->value['font-bold'] = true;
  2160. $this->style->value['font-size'] = $this->style->ConvertToMM('12px');
  2161. $this->style->analyse('h5', $param);
  2162. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2163. $this->style->FontSet();
  2164. }
  2165. /**
  2166. * balise : H5
  2167. * mode : FERMETURE
  2168. *
  2169. * @param array paramètres de l'élément de parsing
  2170. * @return null
  2171. */
  2172. function c_H5($param)
  2173. {
  2174. $this->o_BR(array());
  2175. $this->style->load();
  2176. $this->style->FontSet();
  2177. $this->o_BR(array());
  2178. }
  2179. /**
  2180. * balise : H6
  2181. * mode : OUVERTURE
  2182. *
  2183. * @param array paramètres de l'élément de parsing
  2184. * @return null
  2185. */
  2186. function o_H6($param)
  2187. {
  2188. $this->o_BR(array());
  2189. $this->style->save();
  2190. $this->style->value['font-bold'] = true;
  2191. $this->style->value['font-size'] = $this->style->ConvertToMM('9px');
  2192. $this->style->analyse('h6', $param);
  2193. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2194. $this->style->FontSet();
  2195. }
  2196. /**
  2197. * balise : H6
  2198. * mode : FERMETURE
  2199. *
  2200. * @param array paramètres de l'élément de parsing
  2201. * @return null
  2202. */
  2203. function c_H6($param)
  2204. {
  2205. $this->o_BR(array());
  2206. $this->style->load();
  2207. $this->style->FontSet();
  2208. $this->o_BR(array());
  2209. }
  2210. /**
  2211. * balise : SPAN
  2212. * mode : OUVERTURE
  2213. *
  2214. * @param array paramètres de l'élément de parsing
  2215. * @return null
  2216. */
  2217. function o_SPAN($param, $other = 'span')
  2218. {
  2219. $this->style->save();
  2220. $this->style->analyse($other, $param);
  2221. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2222. $this->style->FontSet();
  2223. }
  2224. function o_FONT($param) { $this->o_SPAN($param, 'font'); }
  2225. /**
  2226. * balise : SPAN
  2227. * mode : FERMETURE
  2228. *
  2229. * @param array paramètres de l'élément de parsing
  2230. * @return null
  2231. */
  2232. function c_SPAN($param)
  2233. {
  2234. $this->style->load();
  2235. $this->style->FontSet();
  2236. }
  2237. function c_FONT($param) { $this->c_SPAN($param); }
  2238. /**
  2239. * balise : P
  2240. * mode : OUVERTURE
  2241. *
  2242. * @param array paramètres de l'élément de parsing
  2243. * @return null
  2244. */
  2245. function o_P($param)
  2246. {
  2247. if (!in_array($this->previousCall, array('c_P', 'c_UL')))
  2248. {
  2249. if ($this->maxH) $this->o_BR(array());
  2250. $this->o_BR(array());
  2251. }
  2252. $this->style->save();
  2253. $this->style->analyse('p', $param);
  2254. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2255. $this->style->FontSet();
  2256. if ($this->style->value['text-indent']>0) $this->pdf->x+= $this->style->value['text-indent'];
  2257. }
  2258. /**
  2259. * balise : P
  2260. * mode : FERMETURE
  2261. *
  2262. * @param array paramètres de l'élément de parsing
  2263. * @return null
  2264. */
  2265. function c_P($param)
  2266. {
  2267. if ($this->maxH) $this->o_BR(array());
  2268. $this->o_BR(array());
  2269. $this->style->load();
  2270. $this->style->FontSet();
  2271. }
  2272. /**
  2273. * balise : PRE
  2274. * mode : OUVERTURE
  2275. *
  2276. * @param array paramètres de l'élément de parsing
  2277. * @return null
  2278. */
  2279. function o_PRE($param, $other = 'pre')
  2280. {
  2281. if ($other=='pre' && $this->maxH) $this->o_BR(array());
  2282. $this->style->save();
  2283. $this->style->value['font-family'] = 'courier';
  2284. $this->style->analyse($other, $param);
  2285. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2286. $this->style->FontSet();
  2287. if ($other=='pre') $this->o_DIV($param, $other);
  2288. }
  2289. function o_CODE($param) { $this->o_PRE($param, 'code'); }
  2290. /**
  2291. * balise : PRE
  2292. * mode : FERMETURE
  2293. *
  2294. * @param array paramètres de l'élément de parsing
  2295. * @return null
  2296. */
  2297. function c_PRE($param, $other = 'pre')
  2298. {
  2299. if ($other=='pre')
  2300. {
  2301. $this->c_DIV($param);
  2302. $this->o_BR(array());
  2303. }
  2304. $this->style->load();
  2305. $this->style->FontSet();
  2306. }
  2307. function c_CODE($param) { $this->c_PRE($param, 'code'); }
  2308. /**
  2309. * balise : BIG
  2310. * mode : OUVERTURE
  2311. *
  2312. * @param array paramètres de l'élément de parsing
  2313. * @return null
  2314. */
  2315. function o_BIG($param)
  2316. {
  2317. $this->style->save();
  2318. $this->style->value['mini-decal']-= $this->style->value['mini-size']*0.2;
  2319. $this->style->value['mini-size'] *= 1.2;
  2320. $this->style->analyse('big', $param);
  2321. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2322. $this->style->FontSet();
  2323. }
  2324. /**
  2325. * balise : BIG
  2326. * mode : FERMETURE
  2327. *
  2328. * @param array paramètres de l'élément de parsing
  2329. * @return null
  2330. */
  2331. function c_BIG($param)
  2332. {
  2333. $this->style->load();
  2334. $this->style->FontSet();
  2335. }
  2336. /**
  2337. * balise : SMALL
  2338. * mode : OUVERTURE
  2339. *
  2340. * @param array paramètres de l'élément de parsing
  2341. * @return null
  2342. */
  2343. function o_SMALL($param)
  2344. {
  2345. $this->style->save();
  2346. $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.18;
  2347. $this->style->value['mini-size'] *= 0.82;
  2348. $this->style->analyse('small', $param);
  2349. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2350. $this->style->FontSet();
  2351. }
  2352. /**
  2353. * balise : SMALL
  2354. * mode : FERMETURE
  2355. *
  2356. * @param array paramètres de l'élément de parsing
  2357. * @return null
  2358. */
  2359. function c_SMALL($param)
  2360. {
  2361. $this->style->load();
  2362. $this->style->FontSet();
  2363. }
  2364. /**
  2365. * balise : SUP
  2366. * mode : OUVERTURE
  2367. *
  2368. * @param array paramètres de l'élément de parsing
  2369. * @return null
  2370. */
  2371. function o_SUP($param)
  2372. {
  2373. $this->style->save();
  2374. $this->style->value['mini-decal']-= $this->style->value['mini-size']*0.25;
  2375. $this->style->value['mini-size'] *= 0.75;
  2376. $this->style->analyse('sup', $param);
  2377. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2378. $this->style->FontSet();
  2379. }
  2380. /**
  2381. * balise : SUP
  2382. * mode : FERMETURE
  2383. *
  2384. * @param array paramètres de l'élément de parsing
  2385. * @return null
  2386. */
  2387. function c_SUP($param)
  2388. {
  2389. $this->style->load();
  2390. $this->style->FontSet();
  2391. }
  2392. /**
  2393. * balise : SUB
  2394. * mode : OUVERTURE
  2395. *
  2396. * @param array paramètres de l'élément de parsing
  2397. * @return null
  2398. */
  2399. function o_SUB($param)
  2400. {
  2401. $this->style->save();
  2402. $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.25;
  2403. $this->style->value['mini-size'] *= 0.75;
  2404. $this->style->analyse('sub', $param);
  2405. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2406. $this->style->FontSet();
  2407. $this->inSub = 1;
  2408. }
  2409. /**
  2410. * balise : SUB
  2411. * mode : FERMETURE
  2412. *
  2413. * @param array paramètres de l'élément de parsing
  2414. * @return null
  2415. */
  2416. function c_SUB($param)
  2417. {
  2418. $this->style->load();
  2419. $this->style->FontSet();
  2420. }
  2421. /**
  2422. * balise : UL
  2423. * mode : OUVERTURE
  2424. *
  2425. * @param array paramètres de l'élément de parsing
  2426. * @return null
  2427. */
  2428. function o_UL($param, $other = 'ul')
  2429. {
  2430. if (!in_array($this->previousCall, array('c_P', 'c_UL')))
  2431. {
  2432. if ($this->maxH) $this->o_BR(array());
  2433. if (!count($this->defLIST)) $this->o_BR(array());
  2434. }
  2435. if (!isset($param['style']['width'])) $param['allwidth'] = true;
  2436. $param['cellspacing'] = 0;
  2437. // une liste est traitée comme un tableau
  2438. $this->o_TABLE($param, $other);
  2439. // ajouter un niveau de liste
  2440. $this->listeAddLevel($other, $this->style->value['list-style-type'], $this->style->value['list-style-image']);
  2441. }
  2442. function o_OL($param) { $this->o_UL($param, 'ol'); }
  2443. /**
  2444. * balise : UL
  2445. * mode : FERMETURE
  2446. *
  2447. * @param array paramètres de l'élément de parsing
  2448. * @return null
  2449. */
  2450. function c_UL($param)
  2451. {
  2452. // fin du tableau
  2453. $this->c_TABLE($param);
  2454. // enlever un niveau de liste
  2455. $this->listeDelLevel();
  2456. if (!$this->sub_part)
  2457. {
  2458. if (!count($this->defLIST)) $this->o_BR(array());
  2459. }
  2460. }
  2461. function c_OL($param) { $this->c_UL($param); }
  2462. /**
  2463. * balise : LI
  2464. * mode : OUVERTURE
  2465. *
  2466. * @param array paramètres de l'élément de parsing
  2467. * @return null
  2468. */
  2469. function o_LI($param)
  2470. {
  2471. // ajouter une puce au niveau actuel
  2472. $this->listeAddLi();
  2473. if (!isset($param['style']['width'])) $param['style']['width'] = '100%';
  2474. // preparation du style de la puce
  2475. $paramPUCE = $param;
  2476. $inf = $this->listeGetLi();
  2477. if ($inf[0])
  2478. {
  2479. $paramPUCE['style']['font-family'] = $inf[0];
  2480. $paramPUCE['style']['text-align'] = 'right';
  2481. $paramPUCE['style']['vertical-align'] = 'top';
  2482. $paramPUCE['style']['width'] = $this->listeGetWidth();
  2483. $paramPUCE['style']['padding-right'] = $this->listeGetPadding();
  2484. $paramPUCE['txt'] = $inf[2];
  2485. }
  2486. else
  2487. {
  2488. $paramPUCE['style']['text-align'] = 'right';
  2489. $paramPUCE['style']['vertical-align'] = 'top';
  2490. $paramPUCE['style']['width'] = $this->listeGetWidth();
  2491. $paramPUCE['style']['padding-right'] = $this->listeGetPadding();
  2492. $paramPUCE['src'] = $inf[2];
  2493. $paramPUCE['sub_li'] = true;
  2494. }
  2495. // nouvelle ligne
  2496. $this->o_TR($param, 'li');
  2497. $this->style->save();
  2498. if ($inf[1])
  2499. {
  2500. $this->style->value['mini-decal']+= $this->style->value['mini-size']*0.25;
  2501. $this->style->value['mini-size'] *= 0.75;
  2502. }
  2503. // si on est dans un sub_html => preparation, sinon affichage classique
  2504. if ($this->sub_part)
  2505. {
  2506. // TD pour la puce
  2507. $tmp_pos = $this->temp_pos;
  2508. $tmp_lst1 = $this->parsing->code[$tmp_pos+1];
  2509. $tmp_lst2 = $this->parsing->code[$tmp_pos+2];
  2510. $this->parsing->code[$tmp_pos+1] = array();
  2511. $this->parsing->code[$tmp_pos+1]['name'] = (isset($paramPUCE['src'])) ? 'img' : 'write';
  2512. $this->parsing->code[$tmp_pos+1]['param'] = $paramPUCE; unset($this->parsing->code[$tmp_pos+1]['param']['style']['width']);
  2513. $this->parsing->code[$tmp_pos+1]['close'] = 0;
  2514. $this->parsing->code[$tmp_pos+2] = array();
  2515. $this->parsing->code[$tmp_pos+2]['name'] = 'li';
  2516. $this->parsing->code[$tmp_pos+2]['param'] = $paramPUCE;
  2517. $this->parsing->code[$tmp_pos+2]['close'] = 1;
  2518. $this->o_TD($paramPUCE, 'li_sub');
  2519. $this->c_TD($param);
  2520. $this->temp_pos = $tmp_pos;
  2521. $this->parsing->code[$tmp_pos+1] = $tmp_lst1;
  2522. $this->parsing->code[$tmp_pos+2] = $tmp_lst2;
  2523. }
  2524. else
  2525. {
  2526. // TD pour la puce
  2527. $this->o_TD($paramPUCE, 'li_sub');
  2528. unset($paramPUCE['style']['width']);
  2529. if (isset($paramPUCE['src'])) $this->o_IMG($paramPUCE);
  2530. else $this->o_WRITE($paramPUCE);
  2531. $this->c_TD($paramPUCE);
  2532. }
  2533. $this->style->load();
  2534. // td pour le contenu
  2535. $this->o_TD($param, 'li');
  2536. }
  2537. /**
  2538. * balise : LI
  2539. * mode : FERMETURE
  2540. *
  2541. * @param array paramètres de l'élément de parsing
  2542. * @return null
  2543. */
  2544. function c_LI($param)
  2545. {
  2546. // fin du contenu
  2547. $this->c_TD($param, 'li');
  2548. // fin de la ligne
  2549. $this->c_TR($param, 'li');
  2550. }
  2551. /**
  2552. * balise : TBODY
  2553. * mode : OUVERTURE
  2554. *
  2555. * @param array paramètres de l'élément de parsing
  2556. * @return null
  2557. */
  2558. function o_TBODY($param)
  2559. {
  2560. $this->style->save();
  2561. $this->style->analyse('tbody', $param);
  2562. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2563. $this->style->FontSet();
  2564. }
  2565. /**
  2566. * balise : TBODY
  2567. * mode : FERMETURE
  2568. *
  2569. * @param array paramètres de l'élément de parsing
  2570. * @return null
  2571. */
  2572. function c_TBODY($param)
  2573. {
  2574. $this->style->load();
  2575. $this->style->FontSet();
  2576. }
  2577. /**
  2578. * balise : THEAD
  2579. * mode : OUVERTURE
  2580. *
  2581. * @param array paramètres de l'élément de parsing
  2582. * @return null
  2583. */
  2584. function o_THEAD($param)
  2585. {
  2586. global $HTML2PDF_TABLEAU;
  2587. $this->style->save();
  2588. $this->style->analyse('thead', $param);
  2589. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2590. $this->style->FontSet();
  2591. // si on est en mode sub_html : sauvegarde du numéro du TR
  2592. if ($this->sub_part)
  2593. {
  2594. $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'][0] = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
  2595. $HTML2PDF_TABLEAU[$param['num']]['thead']['code'] = array();
  2596. for($pos=$this->temp_pos; $pos<count($this->parsing->code); $pos++)
  2597. {
  2598. $todo = $this->parsing->code[$pos];
  2599. if (strtolower($todo['name'])=='thead') $todo['name'] = 'thead_sub';
  2600. $HTML2PDF_TABLEAU[$param['num']]['thead']['code'][] = $todo;
  2601. if (strtolower($todo['name'])=='thead_sub' && $todo['close']) break;
  2602. }
  2603. }
  2604. else
  2605. {
  2606. $res = $this->parsing->getLevel($this->parse_pos);
  2607. $this->parse_pos = $res[0]-1;
  2608. $HTML2PDF_TABLEAU[$param['num']]['tr_curr']+= count($HTML2PDF_TABLEAU[$param['num']]['thead']['tr']);
  2609. }
  2610. }
  2611. /**
  2612. * balise : THEAD
  2613. * mode : FERMETURE
  2614. *
  2615. * @param array paramètres de l'élément de parsing
  2616. * @return null
  2617. */
  2618. function c_THEAD($param)
  2619. {
  2620. $this->style->load();
  2621. $this->style->FontSet();
  2622. // si on est en mode sub_html : sauvegarde du numéro du TR
  2623. if ($this->sub_part)
  2624. {
  2625. global $HTML2PDF_TABLEAU;
  2626. $min = $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'][0];
  2627. $max = $HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1;
  2628. $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'] = range($min, $max);
  2629. }
  2630. }
  2631. /**
  2632. * balise : TFOOT
  2633. * mode : OUVERTURE
  2634. *
  2635. * @param array paramètres de l'élément de parsing
  2636. * @return null
  2637. */
  2638. function o_TFOOT($param)
  2639. {
  2640. global $HTML2PDF_TABLEAU;
  2641. $this->style->save();
  2642. $this->style->analyse('tfoot', $param);
  2643. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2644. $this->style->FontSet();
  2645. // si on est en mode sub_html : sauvegarde du numéro du TR
  2646. if ($this->sub_part)
  2647. {
  2648. $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0] = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
  2649. $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'] = array();
  2650. for($pos=$this->temp_pos; $pos<count($this->parsing->code); $pos++)
  2651. {
  2652. $todo = $this->parsing->code[$pos];
  2653. if (strtolower($todo['name'])=='tfoot') $todo['name'] = 'tfoot_sub';
  2654. $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'][] = $todo;
  2655. if (strtolower($todo['name'])=='tfoot_sub' && $todo['close']) break;
  2656. }
  2657. }
  2658. else
  2659. {
  2660. $res = $this->parsing->getLevel($this->parse_pos+1);
  2661. $this->parse_pos = $res[0];
  2662. $HTML2PDF_TABLEAU[$param['num']]['tr_curr']+= count($HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr']);
  2663. }
  2664. }
  2665. /**
  2666. * balise : TFOOT
  2667. * mode : FERMETURE
  2668. *
  2669. * @param array paramètres de l'élément de parsing
  2670. * @return null
  2671. */
  2672. function c_TFOOT($param)
  2673. {
  2674. $this->style->load();
  2675. $this->style->FontSet();
  2676. // si on est en mode sub_html : sauvegarde du numéro du TR
  2677. if ($this->sub_part)
  2678. {
  2679. global $HTML2PDF_TABLEAU;
  2680. $min = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0];
  2681. $max = $HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1;
  2682. $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'] = range($min, $max);
  2683. }
  2684. }
  2685. /**
  2686. * balise : THEAD_SUB
  2687. * mode : OUVERTURE
  2688. *
  2689. * @param array paramètres de l'élément de parsing
  2690. * @return null
  2691. */
  2692. function o_THEAD_SUB($param)
  2693. {
  2694. $this->style->save();
  2695. $this->style->analyse('thead', $param);
  2696. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2697. $this->style->FontSet();
  2698. }
  2699. /**
  2700. * balise : THEAD_SUB
  2701. * mode : FERMETURE
  2702. *
  2703. * @param array paramètres de l'élément de parsing
  2704. * @return null
  2705. */
  2706. function c_THEAD_SUB($param)
  2707. {
  2708. $this->style->load();
  2709. $this->style->FontSet();
  2710. }
  2711. /**
  2712. * balise : TFOOT_SUB
  2713. * mode : OUVERTURE
  2714. *
  2715. * @param array paramètres de l'élément de parsing
  2716. * @return null
  2717. */
  2718. function o_TFOOT_SUB($param)
  2719. {
  2720. $this->style->save();
  2721. $this->style->analyse('tfoot', $param);
  2722. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2723. $this->style->FontSet();
  2724. }
  2725. /**
  2726. * balise : TFOOT_SUB
  2727. * mode : FERMETURE
  2728. *
  2729. * @param array paramètres de l'élément de parsing
  2730. * @return null
  2731. */
  2732. function c_TFOOT_SUB($param)
  2733. {
  2734. $this->style->load();
  2735. $this->style->FontSet();
  2736. }
  2737. /**
  2738. * balise : FORM
  2739. * mode : OUVERTURE
  2740. *
  2741. * @param array paramètres de l'élément de parsing
  2742. * @return null
  2743. */
  2744. function o_FORM($param)
  2745. {
  2746. $this->style->save();
  2747. $this->style->analyse('form', $param);
  2748. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2749. $this->style->FontSet();
  2750. }
  2751. /**
  2752. * balise : FORM
  2753. * mode : FERMETURE
  2754. *
  2755. * @param array paramètres de l'élément de parsing
  2756. * @return null
  2757. */
  2758. function c_FORM($param)
  2759. {
  2760. $this->style->load();
  2761. $this->style->FontSet();
  2762. }
  2763. /**
  2764. * balise : TABLE
  2765. * mode : OUVERTURE
  2766. *
  2767. * @param array paramètres de l'élément de parsing
  2768. * @return null
  2769. */
  2770. function o_TABLE($param, $other = 'table')
  2771. {
  2772. $this->maxH = 0;
  2773. // utilisation du tableau des paramétres des tables
  2774. global $HTML2PDF_TABLEAU;
  2775. $align_object = isset($param['align']) ? strtolower($param['align']) : 'left';
  2776. if (isset($param['align'])) unset($param['align']);
  2777. if (!in_array($align_object, array('left', 'center', 'right'))) $align_object = 'left';
  2778. // lecture et initialisation du style
  2779. $this->style->save();
  2780. $this->style->analyse($other, $param);
  2781. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2782. $this->style->FontSet();
  2783. if ($this->style->value['margin-auto']) $align_object = 'center';
  2784. // est-on en collapse
  2785. $collapse = false;
  2786. if ($other=='table')
  2787. $collapse = isset($this->style->value['border']['collapse']) ? $this->style->value['border']['collapse'] : false;
  2788. // si oui il faut adapté les borders
  2789. if ($collapse)
  2790. {
  2791. $param['style']['border'] = 'none';
  2792. $param['cellspacing'] = 0;
  2793. $none = $this->style->readBorder('none');
  2794. $this->style->value['border']['t'] = $none;
  2795. $this->style->value['border']['r'] = $none;
  2796. $this->style->value['border']['b'] = $none;
  2797. $this->style->value['border']['l'] = $none;
  2798. }
  2799. // si on est en mode sub_html : initialisation des dimensions et autres
  2800. if ($this->sub_part)
  2801. {
  2802. $HTML2PDF_TABLEAU[$param['num']] = array();
  2803. $HTML2PDF_TABLEAU[$param['num']]['cellpadding'] = $this->style->ConvertToMM(isset($param['cellpadding']) ? $param['cellpadding'] : '1px'); // cellpadding du tableau
  2804. $HTML2PDF_TABLEAU[$param['num']]['cellspacing'] = $this->style->ConvertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); // cellspacing du tableau
  2805. $HTML2PDF_TABLEAU[$param['num']]['cases'] = array(); // liste des propriétés des cases
  2806. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0; // colonne courante
  2807. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = 0; // ligne courante
  2808. $HTML2PDF_TABLEAU[$param['num']]['curr_x'] = $this->pdf->getX(); // position courante X
  2809. $HTML2PDF_TABLEAU[$param['num']]['curr_y'] = $this->pdf->getY(); // position courante Y
  2810. $HTML2PDF_TABLEAU[$param['num']]['width'] = 0; // largeur globale
  2811. $HTML2PDF_TABLEAU[$param['num']]['height'] = 0; // hauteur globale
  2812. $HTML2PDF_TABLEAU[$param['num']]['align'] = $align_object;
  2813. $HTML2PDF_TABLEAU[$param['num']]['marge'] = array();
  2814. $HTML2PDF_TABLEAU[$param['num']]['marge']['t'] = $this->style->value['padding']['t']+$this->style->value['border']['t']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
  2815. $HTML2PDF_TABLEAU[$param['num']]['marge']['r'] = $this->style->value['padding']['r']+$this->style->value['border']['r']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
  2816. $HTML2PDF_TABLEAU[$param['num']]['marge']['b'] = $this->style->value['padding']['b']+$this->style->value['border']['b']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
  2817. $HTML2PDF_TABLEAU[$param['num']]['marge']['l'] = $this->style->value['padding']['l']+$this->style->value['border']['l']['width']+$HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5;
  2818. $HTML2PDF_TABLEAU[$param['num']]['page'] = 0; // nombre de pages
  2819. $HTML2PDF_TABLEAU[$param['num']]['new_page'] = true; // nouvelle page pour le TR courant
  2820. $HTML2PDF_TABLEAU[$param['num']]['style_value'] = null; // style du tableau
  2821. $HTML2PDF_TABLEAU[$param['num']]['thead'] = array(); // infos sur le thead
  2822. $HTML2PDF_TABLEAU[$param['num']]['tfoot'] = array(); // infos sur le tfoot
  2823. $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'] = array(); // tr du thead
  2824. $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'] = array(); // tr du tfoot
  2825. $HTML2PDF_TABLEAU[$param['num']]['thead']['height'] = 0; // hauteur du thead
  2826. $HTML2PDF_TABLEAU[$param['num']]['tfoot']['height'] = 0; // hauteur du tfoot
  2827. $HTML2PDF_TABLEAU[$param['num']]['thead']['code'] = array(); // contenu HTML du thead
  2828. $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'] = array(); // contenu HTML du tfoot
  2829. $this->saveMargin($this->pdf->lMargin, $this->pdf->tMargin, $this->pdf->rMargin);
  2830. // adaptation de la largeur en fonction des marges du tableau
  2831. $this->style->value['width']-= $HTML2PDF_TABLEAU[$param['num']]['marge']['l'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['r'];
  2832. }
  2833. else
  2834. {
  2835. // on repart à la premiere page du tableau et à la premiere case
  2836. $HTML2PDF_TABLEAU[$param['num']]['page'] = 0;
  2837. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
  2838. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = 0;
  2839. $HTML2PDF_TABLEAU[$param['num']]['td_x'] = $HTML2PDF_TABLEAU[$param['num']]['marge']['l']+$HTML2PDF_TABLEAU[$param['num']]['curr_x'];
  2840. $HTML2PDF_TABLEAU[$param['num']]['td_y'] = $HTML2PDF_TABLEAU[$param['num']]['marge']['t']+$HTML2PDF_TABLEAU[$param['num']]['curr_y'];
  2841. // initialisation du style des bordures de la premiere partie de tableau
  2842. $this->Rectangle(
  2843. $HTML2PDF_TABLEAU[$param['num']]['curr_x'],
  2844. $HTML2PDF_TABLEAU[$param['num']]['curr_y'],
  2845. $HTML2PDF_TABLEAU[$param['num']]['width'],
  2846. isset($HTML2PDF_TABLEAU[$param['num']]['height'][0]) ? $HTML2PDF_TABLEAU[$param['num']]['height'][0] : null,
  2847. $this->style->value['border'],
  2848. $this->style->value['padding'],
  2849. 0,
  2850. $this->style->value['background']
  2851. );
  2852. $HTML2PDF_TABLEAU[$param['num']]['style_value'] = $this->style->value;
  2853. }
  2854. }
  2855. /**
  2856. * balise : TABLE
  2857. * mode : FERMETURE
  2858. *
  2859. * @param array paramètres de l'élément de parsing
  2860. * @return null
  2861. */
  2862. function c_TABLE($param)
  2863. {
  2864. $this->maxH = 0;
  2865. global $HTML2PDF_TABLEAU;
  2866. // restauration du style
  2867. $this->style->load();
  2868. $this->style->FontSet();
  2869. // si on est en mode sub_html : initialisation des dimensions et autres
  2870. if ($this->sub_part)
  2871. {
  2872. // ajustement de la taille des cases
  2873. $this->calculTailleCases($HTML2PDF_TABLEAU[$param['num']]['cases']);
  2874. // calcul de la hauteur du THEAD et du TFOOT
  2875. $lst = array('thead', 'tfoot');
  2876. foreach($lst as $mode)
  2877. {
  2878. $HTML2PDF_TABLEAU[$param['num']][$mode]['height'] = 0;
  2879. foreach($HTML2PDF_TABLEAU[$param['num']][$mode]['tr'] as $tr)
  2880. {
  2881. // hauteur de la ligne tr
  2882. $h = 0;
  2883. for($i=0; $i<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$tr]); $i++)
  2884. if ($HTML2PDF_TABLEAU[$param['num']]['cases'][$tr][$i]['rowspan']==1)
  2885. $h = max($h, $HTML2PDF_TABLEAU[$param['num']]['cases'][$tr][$i]['h']);
  2886. $HTML2PDF_TABLEAU[$param['num']][$mode]['height']+= $h;
  2887. }
  2888. }
  2889. // calcul des dimensions du tableau - Largeur
  2890. $HTML2PDF_TABLEAU[$param['num']]['width'] = $HTML2PDF_TABLEAU[$param['num']]['marge']['l'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['r'];
  2891. if (isset($HTML2PDF_TABLEAU[$param['num']]['cases'][0]))
  2892. foreach($HTML2PDF_TABLEAU[$param['num']]['cases'][0] as $case)
  2893. $HTML2PDF_TABLEAU[$param['num']]['width']+= $case['w'];
  2894. // positionnement du tableau horizontalement;
  2895. $old = isset($this->style->table[count($this->style->table)-1]) ? $this->style->table[count($this->style->table)-1] : $this->style->value;
  2896. $parent_w = $old['width'] ? $old['width'] : $this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin;
  2897. $x = $HTML2PDF_TABLEAU[$param['num']]['curr_x'];
  2898. $w = $HTML2PDF_TABLEAU[$param['num']]['width'];
  2899. if ($parent_w>$w)
  2900. {
  2901. if ($HTML2PDF_TABLEAU[$param['num']]['align']=='center')
  2902. $x = $x + ($parent_w-$w)*0.5;
  2903. else if ($HTML2PDF_TABLEAU[$param['num']]['align']=='right')
  2904. $x = $x + $parent_w-$w;
  2905. $HTML2PDF_TABLEAU[$param['num']]['curr_x'] = $x;
  2906. }
  2907. // calcul des dimensions du tableau - hauteur du tableau sur chaque page
  2908. $HTML2PDF_TABLEAU[$param['num']]['height'] = array();
  2909. $h0 = $HTML2PDF_TABLEAU[$param['num']]['marge']['t'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['b']; // minimum de hauteur à cause des marges
  2910. $h0+= $HTML2PDF_TABLEAU[$param['num']]['thead']['height'] + $HTML2PDF_TABLEAU[$param['num']]['tfoot']['height']; // et du tfoot et thead
  2911. $max = $this->pdf->h - $this->pdf->bMargin; // max de hauteur par page
  2912. $y = $HTML2PDF_TABLEAU[$param['num']]['curr_y']; // position Y actuelle
  2913. $height = $h0;
  2914. // on va lire les hauteurs de chaque ligne, une à une, et voir si ca rentre sur la page.
  2915. for($k=0; $k<count($HTML2PDF_TABLEAU[$param['num']]['cases']); $k++)
  2916. {
  2917. // si c'est des lignes du thead ou du tfoot : on passe
  2918. if (in_array($k, $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'])) continue;
  2919. if (in_array($k, $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'])) continue;
  2920. // hauteur de la ligne $k
  2921. $th = 0;
  2922. $h = 0;
  2923. for($i=0; $i<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$k]); $i++)
  2924. {
  2925. $h = max($h, $HTML2PDF_TABLEAU[$param['num']]['cases'][$k][$i]['h']);
  2926. if ($HTML2PDF_TABLEAU[$param['num']]['cases'][$k][$i]['rowspan']==1)
  2927. $th = max($th, $HTML2PDF_TABLEAU[$param['num']]['cases'][$k][$i]['h']);
  2928. }
  2929. // si la ligne ne rentre pas dans la page
  2930. // => la hauteur sur cette page est trouvée, et on passe à la page d'apres
  2931. if ($y+$h+$height>$max)
  2932. {
  2933. if ($height==$h0) $height = null;
  2934. $HTML2PDF_TABLEAU[$param['num']]['height'][] = $height;
  2935. $height = $h0;
  2936. $y = $this->margeTop;
  2937. }
  2938. $height+= $th;
  2939. }
  2940. // rajout du reste de tableau (si il existe) à la derniere page
  2941. if ($height!=$h0 || $k==0) $HTML2PDF_TABLEAU[$param['num']]['height'][] = $height;
  2942. }
  2943. else
  2944. {
  2945. if (count($HTML2PDF_TABLEAU[$param['num']]['tfoot']['code']))
  2946. {
  2947. $tmp_tr = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
  2948. $tmp_td = $HTML2PDF_TABLEAU[$param['num']]['td_curr'];
  2949. $OLD_parse_pos = $this->parse_pos;
  2950. $OLD_parse_code = $this->parsing->code;
  2951. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0];
  2952. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
  2953. $this->parse_pos = 0;
  2954. $this->parsing->code = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'];
  2955. $this->MakeHTMLcode();
  2956. $this->parse_pos = $OLD_parse_pos;
  2957. $this->parsing->code = $OLD_parse_code;
  2958. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $tmp_tr;
  2959. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = $tmp_td;
  2960. }
  2961. // determination des coordonnées de sortie du tableau
  2962. $x = $HTML2PDF_TABLEAU[$param['num']]['curr_x'] + $HTML2PDF_TABLEAU[$param['num']]['width'];
  2963. if (count($HTML2PDF_TABLEAU[$param['num']]['height'])>1)
  2964. $y = $this->margeTop+$HTML2PDF_TABLEAU[$param['num']]['height'][count($HTML2PDF_TABLEAU[$param['num']]['height'])-1];
  2965. else if (count($HTML2PDF_TABLEAU[$param['num']]['height'])==1)
  2966. $y = $HTML2PDF_TABLEAU[$param['num']]['curr_y']+$HTML2PDF_TABLEAU[$param['num']]['height'][count($HTML2PDF_TABLEAU[$param['num']]['height'])-1];
  2967. else
  2968. $y = $HTML2PDF_TABLEAU[$param['num']]['curr_y'];
  2969. // restauration des marges
  2970. $this->loadMargin();
  2971. // position de sortie du tableau
  2972. $this->pdf->setX($x);
  2973. $this->pdf->setY($y);
  2974. $this->maxX = max($this->maxX, $x);
  2975. $this->maxY = max($this->maxY, $y);
  2976. }
  2977. }
  2978. /**
  2979. * balise : TR
  2980. * mode : OUVERTURE
  2981. *
  2982. * @param array paramètres de l'élément de parsing
  2983. * @return null
  2984. */
  2985. function o_TR($param, $other = 'tr')
  2986. {
  2987. $this->maxH = 0;
  2988. global $HTML2PDF_TABLEAU;
  2989. // analyse du style
  2990. $this->style->save();
  2991. $this->style->analyse($other, $param);
  2992. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  2993. $this->style->FontSet();
  2994. // positionnement dans le tableau
  2995. $HTML2PDF_TABLEAU[$param['num']]['tr_curr']++;
  2996. $HTML2PDF_TABLEAU[$param['num']]['td_curr']= 0;
  2997. // si on est pas dans un sub_html
  2998. if (!$this->sub_part)
  2999. {
  3000. // Y courant apres la ligne
  3001. $ty=null;
  3002. for($ii=0; $ii<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1]); $ii++)
  3003. $ty = max($ty, $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$ii]['h']);
  3004. $hfoot = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['height'];
  3005. // si la ligne ne rentre pas dans la page => nouvelle page
  3006. if (!$this->isInTfoot && $HTML2PDF_TABLEAU[$param['num']]['td_y'] + $HTML2PDF_TABLEAU[$param['num']]['marge']['b'] + $ty +$hfoot> $this->pdf->h - $this->pdf->bMargin)
  3007. {
  3008. if (count($HTML2PDF_TABLEAU[$param['num']]['tfoot']['code']))
  3009. {
  3010. $tmp_tr = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
  3011. $tmp_td = $HTML2PDF_TABLEAU[$param['num']]['td_curr'];
  3012. $OLD_parse_pos = $this->parse_pos;
  3013. $OLD_parse_code = $this->parsing->code;
  3014. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['tr'][0];
  3015. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
  3016. $this->parse_pos = 0;
  3017. $this->parsing->code = $HTML2PDF_TABLEAU[$param['num']]['tfoot']['code'];
  3018. $this->isInTfoot = true;
  3019. $this->MakeHTMLcode();
  3020. $this->isInTfoot = false;
  3021. $this->parse_pos = $OLD_parse_pos;
  3022. $this->parsing->code = $OLD_parse_code;
  3023. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $tmp_tr;
  3024. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = $tmp_td;
  3025. }
  3026. $HTML2PDF_TABLEAU[$param['num']]['new_page'] = true;
  3027. $this->setNewPage();
  3028. $HTML2PDF_TABLEAU[$param['num']]['page']++;
  3029. $HTML2PDF_TABLEAU[$param['num']]['curr_y'] = $this->pdf->getY();
  3030. $HTML2PDF_TABLEAU[$param['num']]['td_y'] = $HTML2PDF_TABLEAU[$param['num']]['curr_y']+$HTML2PDF_TABLEAU[$param['num']]['marge']['t'];
  3031. // si la hauteur de cette partie a bien été calculée, on trace le cadre
  3032. if (isset($HTML2PDF_TABLEAU[$param['num']]['height'][$HTML2PDF_TABLEAU[$param['num']]['page']]))
  3033. {
  3034. $old = $this->style->value;
  3035. $this->style->value = $HTML2PDF_TABLEAU[$param['num']]['style_value'];
  3036. // initialisation du style des bordures de la premiere partie de tableau
  3037. $this->Rectangle(
  3038. $HTML2PDF_TABLEAU[$param['num']]['curr_x'],
  3039. $HTML2PDF_TABLEAU[$param['num']]['curr_y'],
  3040. $HTML2PDF_TABLEAU[$param['num']]['width'],
  3041. $HTML2PDF_TABLEAU[$param['num']]['height'][$HTML2PDF_TABLEAU[$param['num']]['page']],
  3042. $this->style->value['border'],
  3043. $this->style->value['padding'],
  3044. $HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5,
  3045. $this->style->value['background']
  3046. );
  3047. $this->style->value = $old;
  3048. }
  3049. }
  3050. if ($HTML2PDF_TABLEAU[$param['num']]['new_page'] && count($HTML2PDF_TABLEAU[$param['num']]['thead']['code']))
  3051. {
  3052. $HTML2PDF_TABLEAU[$param['num']]['new_page'] = false;
  3053. $tmp_tr = $HTML2PDF_TABLEAU[$param['num']]['tr_curr'];
  3054. $tmp_td = $HTML2PDF_TABLEAU[$param['num']]['td_curr'];
  3055. $OLD_parse_pos = $this->parse_pos;
  3056. $OLD_parse_code = $this->parsing->code;
  3057. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $HTML2PDF_TABLEAU[$param['num']]['thead']['tr'][0];
  3058. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = 0;
  3059. $this->parse_pos = 0;
  3060. $this->parsing->code = $HTML2PDF_TABLEAU[$param['num']]['thead']['code'];
  3061. $this->MakeHTMLcode();
  3062. $this->parse_pos = $OLD_parse_pos;
  3063. $this->parsing->code = $OLD_parse_code;
  3064. $HTML2PDF_TABLEAU[$param['num']]['tr_curr'] = $tmp_tr;
  3065. $HTML2PDF_TABLEAU[$param['num']]['td_curr'] = $tmp_td;
  3066. $HTML2PDF_TABLEAU[$param['num']]['new_page'] = true;
  3067. }
  3068. }
  3069. else
  3070. {
  3071. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1] = array();
  3072. }
  3073. }
  3074. /**
  3075. * balise : TR
  3076. * mode : FERMETURE
  3077. *
  3078. * @param array paramètres de l'élément de parsing
  3079. * @return null
  3080. */
  3081. function c_TR($param)
  3082. {
  3083. $this->maxH = 0;
  3084. global $HTML2PDF_TABLEAU;
  3085. // restauration du style
  3086. $this->style->load();
  3087. $this->style->FontSet();
  3088. // si on est pas dans un sub_html
  3089. if (!$this->sub_part)
  3090. {
  3091. // Y courant apres la ligne
  3092. $ty=null;
  3093. for($ii=0; $ii<count($HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1]); $ii++)
  3094. if ($HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$ii]['rowspan']==1)
  3095. $ty = $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$ii]['h'];
  3096. // mise à jour des coordonnées courantes
  3097. $HTML2PDF_TABLEAU[$param['num']]['td_x'] = $HTML2PDF_TABLEAU[$param['num']]['curr_x']+$HTML2PDF_TABLEAU[$param['num']]['marge']['l'];
  3098. $HTML2PDF_TABLEAU[$param['num']]['td_y']+= $ty;
  3099. $HTML2PDF_TABLEAU[$param['num']]['new_page'] = false;
  3100. }
  3101. }
  3102. /**
  3103. * balise : TD
  3104. * mode : OUVERTURE
  3105. *
  3106. * @param array paramètres de l'élément de parsing
  3107. * @return null
  3108. */
  3109. function o_TD($param, $other = 'td')
  3110. {
  3111. $this->maxH = 0;
  3112. global $HTML2PDF_TABLEAU;
  3113. $param['cellpadding'] = $HTML2PDF_TABLEAU[$param['num']]['cellpadding'].'mm';
  3114. $param['cellspacing'] = $HTML2PDF_TABLEAU[$param['num']]['cellspacing'].'mm';
  3115. if ($other=='li')
  3116. {
  3117. $special_li = true;
  3118. }
  3119. else
  3120. {
  3121. $special_li = false;
  3122. if ($other=='li_sub')
  3123. {
  3124. $param['style']['border'] = 'none';
  3125. $param['style']['background-color'] = 'transparent';
  3126. $param['style']['background-image'] = 'none';
  3127. $param['style']['background-position'] = '';
  3128. $param['style']['background-repeat'] = '';
  3129. $other = 'li';
  3130. }
  3131. }
  3132. // est-on en collapse
  3133. $collapse = false;
  3134. if (in_array($other, array('td', 'th')))
  3135. $collapse = isset($this->style->value['border']['collapse']) ? $this->style->value['border']['collapse'] : false;
  3136. // analyse du style
  3137. $this->style->save();
  3138. $this->style->analyse($other, $param);
  3139. if ($special_li)
  3140. {
  3141. $this->style->value['width']-= $this->style->ConvertToMM($this->listeGetWidth());
  3142. $this->style->value['width']-= $this->style->ConvertToMM($this->listeGetPadding());
  3143. }
  3144. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  3145. $this->style->FontSet();
  3146. // si on est en collapse : modification du style
  3147. if ($collapse)
  3148. {
  3149. if (!$this->sub_part)
  3150. {
  3151. if ($HTML2PDF_TABLEAU[$param['num']]['tr_curr']>1 && !$HTML2PDF_TABLEAU[$param['num']]['new_page'])
  3152. $this->style->value['border']['t'] = $this->style->readBorder('none');
  3153. }
  3154. if ($HTML2PDF_TABLEAU[$param['num']]['td_curr']>0)
  3155. $this->style->value['border']['l'] = $this->style->readBorder('none');
  3156. }
  3157. $marge = array();
  3158. $marge['t'] = $this->style->value['padding']['t']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['t']['width'];
  3159. $marge['r'] = $this->style->value['padding']['r']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['r']['width'];
  3160. $marge['b'] = $this->style->value['padding']['b']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['b']['width'];
  3161. $marge['l'] = $this->style->value['padding']['l']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['l']['width'];
  3162. // si on est dans un sub_html
  3163. if ($this->sub_part)
  3164. {
  3165. // on se positionne dans le tableau
  3166. $HTML2PDF_TABLEAU[$param['num']]['td_curr']++;
  3167. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1] = array();
  3168. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['w'] = 0;
  3169. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['h'] = 0;
  3170. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['dw'] = 0;
  3171. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['colspan'] = isset($param['colspan']) ? $param['colspan'] : 1;
  3172. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['rowspan'] = isset($param['rowspan']) ? $param['rowspan'] : 1;
  3173. // on extrait tout ce qui est contenu dans le TD
  3174. $res = $this->parsing->getLevel($this->temp_pos);
  3175. // on en créé un sous HTML que l'on transforme en PDF
  3176. // pour analyse les dimensions
  3177. // et les récupérer dans le tableau global.
  3178. $this->CreateSubHTML($this->sub_html);
  3179. $this->sub_html->writeHTML($res[1]);
  3180. $this->temp_pos = $res[0]-2;
  3181. }
  3182. else
  3183. {
  3184. // on se positionne dans le tableau
  3185. $HTML2PDF_TABLEAU[$param['num']]['td_curr']++;
  3186. $HTML2PDF_TABLEAU[$param['num']]['td_x']+= $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['dw'];
  3187. // initialisation du style des bordures de la premiere partie de tableau
  3188. $this->Rectangle(
  3189. $HTML2PDF_TABLEAU[$param['num']]['td_x'],
  3190. $HTML2PDF_TABLEAU[$param['num']]['td_y'],
  3191. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['w'],
  3192. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['h'],
  3193. $this->style->value['border'],
  3194. $this->style->value['padding'],
  3195. $HTML2PDF_TABLEAU[$param['num']]['cellspacing']*0.5,
  3196. $this->style->value['background']
  3197. );
  3198. $this->style->value['width'] = $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['w'] - $marge['l'] - $marge['r'];
  3199. // limitation des marges aux dimensions de la case
  3200. $mL = $HTML2PDF_TABLEAU[$param['num']]['td_x']+$marge['l'];
  3201. $mR = $this->pdf->w - $mL - $this->style->value['width'];
  3202. $this->saveMargin($mL, 0, $mR);
  3203. // positionnement en fonction
  3204. $h_corr = $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['h'];
  3205. $h_reel = $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['real_h'];
  3206. switch($this->style->value['vertical-align'])
  3207. {
  3208. case 'bottom':
  3209. $y_corr = $h_corr-$h_reel;
  3210. break;
  3211. case 'middle':
  3212. $y_corr = ($h_corr-$h_reel)*0.5;
  3213. break;
  3214. case 'top':
  3215. default:
  3216. $y_corr = 0;
  3217. break;
  3218. }
  3219. $this->pdf->setX($HTML2PDF_TABLEAU[$param['num']]['td_x']+$marge['l']);
  3220. $this->pdf->setY($HTML2PDF_TABLEAU[$param['num']]['td_y']+$marge['t']+$y_corr);
  3221. }
  3222. }
  3223. /**
  3224. * balise : TD
  3225. * mode : FERMETURE
  3226. *
  3227. * @param array paramètres de l'élément de parsing
  3228. * @return null
  3229. */
  3230. function c_TD($param)
  3231. {
  3232. $this->maxH = 0;
  3233. global $HTML2PDF_TABLEAU;
  3234. // récupération de la marge
  3235. $marge = array();
  3236. $marge['t'] = $this->style->value['padding']['t']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['t']['width'];
  3237. $marge['r'] = $this->style->value['padding']['r']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['r']['width'];
  3238. $marge['b'] = $this->style->value['padding']['b']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['b']['width'];
  3239. $marge['l'] = $this->style->value['padding']['l']+0.5*$HTML2PDF_TABLEAU[$param['num']]['cellspacing']+$this->style->value['border']['l']['width'];
  3240. $marge['t']+= 0.01;
  3241. $marge['r']+= 0.01;
  3242. $marge['b']+= 0.01;
  3243. $marge['l']+= 0.01;
  3244. // si on est dans un sub_html
  3245. if ($this->sub_part)
  3246. {
  3247. if ($this->testTDin1page && $this->sub_html->pdf->page>1) HTML2PDF::makeError(7, __FILE__, __LINE__);
  3248. // dimentions de cette case
  3249. $w0 = $this->sub_html->maxX + $marge['l'] + $marge['r'];
  3250. $h0 = $this->sub_html->maxY + $marge['t'] + $marge['b'];
  3251. // dimensions imposées par le style
  3252. $w2 = $this->style->value['width'] + $marge['l'] + $marge['r'];
  3253. $h2 = $this->style->value['height'] + $marge['t'] + $marge['b'];
  3254. // dimension finale de la case = max des 2 ci-dessus
  3255. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['w'] = max(array($w0, $w2));
  3256. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['h'] = max(array($h0, $h2));
  3257. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['real_w'] = $w0;
  3258. $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['real_h'] = $h0;
  3259. // suppresion du sous_html
  3260. $this->DestroySubHTML();
  3261. }
  3262. else
  3263. {
  3264. $this->loadMargin();
  3265. //positionnement
  3266. $HTML2PDF_TABLEAU[$param['num']]['td_x']+= $HTML2PDF_TABLEAU[$param['num']]['cases'][$HTML2PDF_TABLEAU[$param['num']]['tr_curr']-1][$HTML2PDF_TABLEAU[$param['num']]['td_curr']-1]['w'];
  3267. }
  3268. // restauration du style
  3269. $this->style->load();
  3270. $this->style->FontSet();
  3271. }
  3272. function calculTailleCases(&$cases)
  3273. {
  3274. // construction d'un tableau de correlation
  3275. $corr = array();
  3276. // on fait correspondre chaque case d'un tableau normé aux cases réelles, en prennant en compte les colspan et rowspan
  3277. $Yr=0;
  3278. for($y=0; $y<count($cases); $y++)
  3279. {
  3280. $Xr=0; while(isset($corr[$Yr][$Xr])) $Xr++;
  3281. for($x=0; $x<count($cases[$y]); $x++)
  3282. {
  3283. for($j=0; $j<$cases[$y][$x]['rowspan']; $j++)
  3284. {
  3285. for($i=0; $i<$cases[$y][$x]['colspan']; $i++)
  3286. {
  3287. $corr[$Yr+$j][$Xr+$i] = ($i+$j>0) ? '' : array($x, $y, $cases[$y][$x]['colspan'], $cases[$y][$x]['rowspan']);
  3288. }
  3289. }
  3290. $Xr+= $cases[$y][$x]['colspan'];
  3291. while(isset($corr[$Yr][$Xr])) $Xr++;
  3292. }
  3293. $Yr++;
  3294. }
  3295. if (!isset($corr[0])) return true;
  3296. // on détermine, pour les cases sans colspan, la largeur maximale de chaque colone
  3297. $sw = array();
  3298. for($x=0; $x<count($corr[0]); $x++)
  3299. {
  3300. $m=0;
  3301. for($y=0; $y<count($corr); $y++)
  3302. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2]==1)
  3303. $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']);
  3304. $sw[$x] = $m;
  3305. }
  3306. // on vérifie que cette taille est valide avec les colones en colspan
  3307. for($x=0; $x<count($corr[0]); $x++)
  3308. {
  3309. for($y=0; $y<count($corr); $y++)
  3310. {
  3311. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2]>1)
  3312. {
  3313. // somme des colonnes correspondant au colspan
  3314. $s = 0; for($i=0; $i<$corr[$y][$x][2]; $i++) $s+= $sw[$x+$i];
  3315. // si la somme est inférieure à la taille necessaire => règle de 3 pour adapter
  3316. if ($s>0 && $s<$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'])
  3317. for($i=0; $i<$corr[$y][$x][2]; $i++)
  3318. $sw[$x+$i] = $sw[$x+$i]/$s*$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'];
  3319. }
  3320. }
  3321. }
  3322. // on applique les nouvelles largeurs
  3323. for($x=0; $x<count($corr[0]); $x++)
  3324. {
  3325. for($y=0; $y<count($corr); $y++)
  3326. {
  3327. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]))
  3328. {
  3329. if ($corr[$y][$x][2]==1)
  3330. {
  3331. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $sw[$x];
  3332. }
  3333. else
  3334. {
  3335. // somme des colonnes correspondant au colspan
  3336. $s = 0; for($i=0; $i<$corr[$y][$x][2]; $i++) $s+= $sw[$x+$i];
  3337. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $s;
  3338. }
  3339. }
  3340. }
  3341. }
  3342. // on détermine, pour les cases sans rowspan, la hauteur maximale de chaque colone
  3343. $sh = array();
  3344. for($y=0; $y<count($corr); $y++)
  3345. {
  3346. $m=0;
  3347. for($x=0; $x<count($corr[0]); $x++)
  3348. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3]==1)
  3349. $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']);
  3350. $sh[$y] = $m;
  3351. }
  3352. // on vérifie que cette taille est valide avec les lignes en rowspan
  3353. for($y=0; $y<count($corr); $y++)
  3354. {
  3355. for($x=0; $x<count($corr[0]); $x++)
  3356. {
  3357. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3]>1)
  3358. {
  3359. // somme des colonnes correspondant au colspan
  3360. $s = 0; for($i=0; $i<$corr[$y][$x][3]; $i++) $s+= $sh[$y+$i];
  3361. // si la somme est inférieure à la taille necessaire => règle de 3 pour adapter
  3362. if ($s>0 && $s<$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'])
  3363. for($i=0; $i<$corr[$y][$x][3]; $i++)
  3364. $sh[$y+$i] = $sh[$y+$i]/$s*$cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'];
  3365. }
  3366. }
  3367. }
  3368. // on applique les nouvelles hauteurs
  3369. for($y=0; $y<count($corr); $y++)
  3370. {
  3371. for($x=0; $x<count($corr[0]); $x++)
  3372. {
  3373. if (isset($corr[$y][$x]) && is_array($corr[$y][$x]))
  3374. {
  3375. if ($corr[$y][$x][3]==1)
  3376. {
  3377. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $sh[$y];
  3378. }
  3379. else
  3380. {
  3381. // somme des lignes correspondant au rowspan
  3382. $s = 0; for($i=0; $i<$corr[$y][$x][3]; $i++) $s+= $sh[$y+$i];
  3383. $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $s;
  3384. for($j=1; $j<$corr[$y][$x][3]; $j++)
  3385. {
  3386. $tx = $x+1;
  3387. $ty = $y+$j;
  3388. for(true; isset($corr[$ty][$tx]) && !is_array($corr[$ty][$tx]); $tx++);
  3389. if (isset($corr[$ty][$tx])) $cases[$corr[$ty][$tx][1]][$corr[$ty][$tx][0]]['dw']+= $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'];
  3390. }
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. /**
  3397. * balise : TH
  3398. * mode : OUVERTURE
  3399. *
  3400. * @param array paramètres de l'élément de parsing
  3401. * @return null
  3402. */
  3403. function o_TH($param)
  3404. {
  3405. $this->maxH = 0;
  3406. // identique à TD mais en gras
  3407. if (!isset($param['style']['font-weight'])) $param['style']['font-weight'] = 'bold';
  3408. $this->o_TD($param, 'th');
  3409. }
  3410. /**
  3411. * balise : TH
  3412. * mode : FERMETURE
  3413. *
  3414. * @param array paramètres de l'élément de parsing
  3415. * @return null
  3416. */
  3417. function c_TH($param)
  3418. {
  3419. $this->maxH = 0;
  3420. // identique à TD
  3421. $this->c_TD($param);
  3422. }
  3423. /**
  3424. * balise : IMG
  3425. * mode : OUVERTURE
  3426. *
  3427. * @param array paramètres de l'élément de parsing
  3428. * @return null
  3429. */
  3430. function o_IMG($param)
  3431. {
  3432. // analyse du style
  3433. $src = str_replace('&amp;', '&', $param['src']);
  3434. $this->style->save();
  3435. $this->style->value['width'] = 0;
  3436. $this->style->value['height'] = 0;
  3437. $this->style->value['border'] = array(
  3438. 'type' => 'none',
  3439. 'width' => 0,
  3440. 'color' => array(0, 0, 0),
  3441. );
  3442. $this->style->value['background'] = array(
  3443. 'color' => null,
  3444. 'image' => null,
  3445. 'position' => null,
  3446. 'repeat' => null
  3447. );
  3448. $this->style->analyse('img', $param);
  3449. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  3450. $this->style->FontSet();
  3451. // affichage de l'image
  3452. $this->Image($src, isset($param['sub_li']));
  3453. // restauration du style
  3454. $this->style->load();
  3455. $this->style->FontSet();
  3456. }
  3457. /**
  3458. * balise : SELECT
  3459. * mode : OUVERTURE
  3460. *
  3461. * @param array paramètres de l'élément de parsing
  3462. * @return null
  3463. */
  3464. function o_SELECT($param)
  3465. {
  3466. // preparation du champs
  3467. if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
  3468. $param['name'] = strtolower($param['name']);
  3469. if (isset($this->champs[$param['name']]))
  3470. $this->champs[$param['name']]++;
  3471. else
  3472. $this->champs[$param['name']] = 1;
  3473. $this->style->save();
  3474. $this->style->analyse('select', $param);
  3475. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  3476. $this->style->FontSet();
  3477. $this->lstSelect = array();
  3478. $this->lstSelect['name'] = $param['name'];
  3479. $this->lstSelect['multi'] = isset($param['multiple']) ? true : false;
  3480. $this->lstSelect['size'] = isset($param['size']) ? $param['size'] : 1;
  3481. $this->lstSelect['options'] = array();
  3482. if ($this->lstSelect['multi'] && $this->lstSelect['size']<3) $this->lstSelect['size'] = 3;
  3483. }
  3484. /**
  3485. * balise : OPTION
  3486. * mode : OUVERTURE
  3487. *
  3488. * @param array paramètres de l'élément de parsing
  3489. * @return null
  3490. */
  3491. function o_OPTION($param)
  3492. {
  3493. // on extrait tout ce qui est contenu dans l'option
  3494. $res = $this->parsing->getLevel($this->parse_pos);
  3495. $this->parse_pos = $res[0]-2;
  3496. $texte = $res[1];
  3497. $value = isset($param['value']) ? $param['value'] : 'auto_opt_'.(count($this->lstSelect)+1);
  3498. $this->lstSelect['options'][$value] = $texte;
  3499. }
  3500. /**
  3501. * balise : OPTION
  3502. * mode : FERMETURE
  3503. *
  3504. * @param array paramètres de l'élément de parsing
  3505. * @return null
  3506. */
  3507. function c_OPTION($param) { }
  3508. /**
  3509. * balise : SELECT
  3510. * mode : FERMETURE
  3511. *
  3512. * @param array paramètres de l'élément de parsing
  3513. * @return null
  3514. */
  3515. function c_SELECT()
  3516. {
  3517. // position d'affichage
  3518. $x = $this->pdf->getX();
  3519. $y = $this->pdf->getY();
  3520. $f = 1.08*$this->style->value['font-size'];
  3521. $w = $this->style->value['width']; if (!$w) $w = 50;
  3522. $h = ($f*1.07*$this->lstSelect['size'] + 1);
  3523. $prop = array();
  3524. if ($this->lstSelect['multi']) $prop['multipleSelection'] = true;
  3525. $this->pdf->form_Select($this->lstSelect['name'], $x, $y, $w, $h, $this->lstSelect['options'], $this->lstSelect['size']>1, $prop);
  3526. $this->maxX = max($this->maxX, $x+$w);
  3527. $this->maxY = max($this->maxY, $y+$h);
  3528. $this->maxH = max($this->maxH, $h);
  3529. $this->pdf->setX($x+$w);
  3530. $this->style->load();
  3531. $this->style->FontSet();
  3532. $this->lstSelect = array();
  3533. }
  3534. /**
  3535. * balise : TEXTAREA
  3536. * mode : OUVERTURE
  3537. *
  3538. * @param array paramètres de l'élément de parsing
  3539. * @return null
  3540. */
  3541. function o_TEXTAREA($param)
  3542. {
  3543. // preparation du champs
  3544. if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
  3545. $param['name'] = strtolower($param['name']);
  3546. if (isset($this->champs[$param['name']]))
  3547. $this->champs[$param['name']]++;
  3548. else
  3549. $this->champs[$param['name']] = 1;
  3550. $this->style->save();
  3551. $this->style->analyse('textarea', $param);
  3552. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  3553. $this->style->FontSet();
  3554. // position d'affichage
  3555. $x = $this->pdf->getX();
  3556. $y = $this->pdf->getY();
  3557. $fx = 0.65*$this->style->value['font-size'];
  3558. $fy = 1.08*$this->style->value['font-size'];
  3559. // on extrait tout ce qui est contenu dans le textarea
  3560. $res = $this->parsing->getLevel($this->parse_pos);
  3561. $this->parse_pos = $res[0]-2;
  3562. $texte = $res[1];
  3563. $w = $fx*(isset($param['cols']) ? $param['cols'] : 22)+1;
  3564. $h = $fy*1.07*(isset($param['rows']) ? $param['rows'] : 3)+3;
  3565. // if ($this->style->value['width']) $w = $this->style->value['width'];
  3566. // if ($this->style->value['height']) $h = $this->style->value['height'];
  3567. $prop = array();
  3568. $prop['value'] = $texte;
  3569. $prop['multiline'] = true;
  3570. $this->pdf->form_InputText($param['name'], $x, $y, $w, $h, $prop);
  3571. $this->maxX = max($this->maxX, $x+$w);
  3572. $this->maxY = max($this->maxY, $y+$h);
  3573. $this->maxH = max($this->maxH, $h);
  3574. $this->pdf->setX($x+$w);
  3575. }
  3576. /**
  3577. * balise : TEXTAREA
  3578. * mode : FERMETURE
  3579. *
  3580. * @param array paramètres de l'élément de parsing
  3581. * @return null
  3582. */
  3583. function c_TEXTAREA()
  3584. {
  3585. $this->style->load();
  3586. $this->style->FontSet();
  3587. }
  3588. /**
  3589. * balise : INPUT
  3590. * mode : OUVERTURE
  3591. *
  3592. * @param array paramètres de l'élément de parsing
  3593. * @return null
  3594. */
  3595. function o_INPUT($param)
  3596. {
  3597. // preparation du champs
  3598. if (!isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->lstChamps)+1);
  3599. if (!isset($param['value'])) $param['value'] = '';
  3600. if (!isset($param['type'])) $param['type'] = 'text';
  3601. $param['name'] = strtolower($param['name']);
  3602. $param['type'] = strtolower($param['type']);
  3603. if (!in_array($param['type'], array('text', 'checkbox', 'radio', 'hidden', 'submit', 'reset', 'button'))) $param['type'] = 'text';
  3604. if (isset($this->champs[$param['name']]))
  3605. $this->champs[$param['name']]++;
  3606. else
  3607. $this->champs[$param['name']] = 1;
  3608. $this->style->save();
  3609. $this->style->analyse('input', $param);
  3610. $this->style->setPosition($this->pdf->x, $this->pdf->y);
  3611. $this->style->FontSet();
  3612. $name = $param['name'];
  3613. // position d'affichage
  3614. $x = $this->pdf->getX();
  3615. $y = $this->pdf->getY();
  3616. $f = 1.08*$this->style->value['font-size'];
  3617. switch($param['type'])
  3618. {
  3619. case 'checkbox':
  3620. $w = 3;
  3621. $h = $w;
  3622. if ($h<$f) $y+= ($f-$h)*0.5;
  3623. $this->pdf->form_InputCheckBox($name, $x, $y, $w, isset($param['checked']));
  3624. break;
  3625. case 'radio':
  3626. $w = 3;
  3627. $h = $w;
  3628. if ($h<$f) $y+= ($f-$h)*0.5;
  3629. $this->pdf->form_InputRadio($name, $x, $y, $w);
  3630. break;
  3631. case 'hidden':
  3632. $w = 0;
  3633. $h = 0;
  3634. $this->pdf->form_InputHidden($name, $param['value']);
  3635. break;
  3636. case 'text':
  3637. $w = $this->style->value['width']; if (!$w) $w = 40;
  3638. $h = $f*1.3;
  3639. $prop = array();
  3640. $prop['value'] = $param['value'];
  3641. $this->pdf->form_InputText($name, $x, $y, $w, $h, $prop);
  3642. break;
  3643. case 'submit':
  3644. case 'reset':
  3645. case 'button':
  3646. $action = isset($param['onclick']) ? $param['onclick'] : '';
  3647. $w = $this->style->value['width']; if (!$w) $w = 40;
  3648. $h = $this->style->value['height']; if (!$h) $h = $f*1.3;
  3649. $prop = array();
  3650. $this->pdf->form_InputButton($name, $x, $y, $w, $h, $param['value'], $action, $prop);
  3651. break;
  3652. default:
  3653. $w = 0;
  3654. $h = 0;
  3655. break;
  3656. }
  3657. $this->maxX = max($this->maxX, $x+$w);
  3658. $this->maxY = max($this->maxY, $y+$h);
  3659. $this->maxH = max($this->maxH, $h);
  3660. $this->pdf->setX($x+$w);
  3661. $this->style->load();
  3662. $this->style->FontSet();
  3663. }
  3664. function textLOAD($langue)
  3665. {
  3666. if (!preg_match('/^([a-z0-9]+)$/isU', $langue))
  3667. {
  3668. echo 'ERROR : language code <b>'.$langue.'</b> incorrect.';
  3669. exit;
  3670. }
  3671. $file = dirname(__FILE__).'/langues/'.strtolower($langue).'.txt';
  3672. if (!is_file($file))
  3673. {
  3674. echo 'ERROR : language code <b>'.$langue.'</b> unknown.<br>';
  3675. echo 'You can create the translation file <b>'.$file.'</b> and send it to me in order to integrate it into a future version.';
  3676. exit;
  3677. }
  3678. $texte = array();
  3679. $infos = file($file);
  3680. foreach($infos as $val)
  3681. {
  3682. $val = trim($val);
  3683. $val = explode("\t", $val);
  3684. if (count($val)<2) continue;
  3685. $t_k = trim($val[0]); unset($val[0]);
  3686. $t_v = trim(implode(' ', $val));
  3687. if ($t_k && $t_v) $texte[$t_k] = $t_v;
  3688. }
  3689. global $HTML2PDF_TEXTE_FILE;
  3690. $HTML2PDF_TEXTE_FILE = $texte;
  3691. }
  3692. function textGET($key)
  3693. {
  3694. global $HTML2PDF_TEXTE_FILE;
  3695. if (!isset($HTML2PDF_TEXTE_FILE[$key])) return '######';
  3696. return $HTML2PDF_TEXTE_FILE[$key];
  3697. }
  3698. function makeError($err, $file, $line, $other = null)
  3699. {
  3700. $msg = '';
  3701. switch($err)
  3702. {
  3703. case 1:
  3704. $msg = (HTML2PDF::textGET('err01'));
  3705. $msg = str_replace('[[OTHER]]', $other, $msg);
  3706. break;
  3707. case 2:
  3708. $msg = (HTML2PDF::textGET('err02'));
  3709. $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
  3710. $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
  3711. $msg = str_replace('[[OTHER_2]]', $other[2], $msg);
  3712. break;
  3713. case 3:
  3714. $msg = (HTML2PDF::textGET('err03'));
  3715. $msg = str_replace('[[OTHER]]', $other, $msg);
  3716. break;
  3717. case 4:
  3718. $msg = (HTML2PDF::textGET('err04'));
  3719. $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
  3720. break;
  3721. case 5:
  3722. $msg = (HTML2PDF::textGET('err05'));
  3723. $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
  3724. break;
  3725. case 6:
  3726. $msg = (HTML2PDF::textGET('err06'));
  3727. $msg = str_replace('[[OTHER]]', $other, $msg);
  3728. break;
  3729. case 7:
  3730. $msg = (HTML2PDF::textGET('err07'));
  3731. break;
  3732. }
  3733. echo '<span style="color: #AA0000; font-weight: bold;">'.(HTML2PDF::textGET('txt01')).$err.'</span><br>';
  3734. echo (HTML2PDF::textGET('txt02')).' '.$file.'<br>';
  3735. echo (HTML2PDF::textGET('txt03')).' '.$line.'<br>';
  3736. echo '<br>';
  3737. echo $msg;
  3738. exit;
  3739. }
  3740. }
  3741. }