PageRenderTime 172ms CodeModel.GetById 34ms RepoModel.GetById 2ms app.codeStats 3ms

/sites/all/modules/table_export/formats/export_pdf/pdf/html2fpdf.php

https://bitbucket.org/norvin/mingen-dts-server
PHP | 2910 lines | 2457 code | 94 blank | 359 comment | 551 complexity | c5d9c9cfc8d5762e2d0691e281fe2d75 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. *** General-use version
  4. DEBUG HINT:
  5. - Inside function printbuffer make $fill=1
  6. - Inside function Cell make:
  7. if($fill==1 or $border==1)
  8. {
  9. // if ($fill==1) $op=($border==1) ? 'B' : 'f';
  10. // else $op='S';
  11. $op='S';
  12. - Following these 2 steps you will be able to see the cell's boundaries
  13. WARNING: When adding a new tag support, also add its name inside the function DisableTags()'s very long string
  14. ODDITIES (?):
  15. . It seems like saved['border'] and saved['bgcolor'] are useless inside the FlowingBlock...
  16. These 2 attributes do the same thing?!?:
  17. . $this->currentfont - mine
  18. . $this->CurrentFont - fpdf's
  19. TODO (in the future...):
  20. - Make font-family, font-size, lineheight customizable
  21. - Increase number of HTML/CSS tags/properties, Image/Font Types, recognized/supported
  22. - allow BMP support? (tried with http://phpthumb.sourceforge.net/ but failed)
  23. - Improve CSS support
  24. - support image side-by-side or one-below-another or both?
  25. - Improve code clarity even more (modularize and get better var names like on textbuffer array's indexes for example)
  26. //////////////////////////////////////////////////////////////////////////////
  27. //////////////DO NOT MODIFY THE CONTENTS OF THIS BOX//////////////////////////
  28. //////////////////////////////////////////////////////////////////////////////
  29. // //
  30. // HTML2FPDF is a php script to read a HTML text and generate a PDF file. //
  31. // Copyright (C) 2004-2005 Renato Coelho //
  32. // This script may be distributed as long as the following files are kept //
  33. // together: //
  34. // //
  35. // fpdf.php, html2fpdf.php, gif.php,htmltoolkit.php,license.txt,credits.txt //
  36. // //
  37. //////////////////////////////////////////////////////////////////////////////
  38. Misc. Observations:
  39. - CSS + align = bug! (?)
  40. OBS1: para textos de mais de 1 página, talvez tenha que juntar varios $texto_artigo
  41. antes de mandar gerar o PDF, para que o PDF gerado seja completo.
  42. OBS2: there are 2 types of spaces 32 and 160 (ascii values)
  43. OBS3: //! is a special comment to be used with source2doc.php, a script I created
  44. in order to generate the doc on the site html2fpdf.sf.net
  45. OBS4: var $LineWidth; // line width in user unit - use this to make css thin/medium/thick work
  46. OBS5: Images and Textareas: when they are inserted you can only type below them (==display:block)
  47. OBS6: Optimized to 'A4' paper (default font: Arial , normal , size 11 )
  48. OBS7: Regexp + Perl ([preg]accepts non-greedy quantifiers while PHP[ereg] does not)
  49. Perl: '/regexp/x' where x == option ( x = i:ignore case , x = s: DOT gets \n as well)
  50. ========================END OF INITIAL COMMENTS=================================
  51. */
  52. define('HTML2FPDF_VERSION','3.0(beta)');
  53. if (!defined('RELATIVE_PATH')) define('RELATIVE_PATH','');
  54. if (!defined('FPDF_FONTPATH')) define('FPDF_FONTPATH','font/');
  55. require_once(RELATIVE_PATH.'fpdf.php');
  56. require_once(RELATIVE_PATH.'htmltoolkit.php');
  57. class HTML2FPDF extends FPDF
  58. {
  59. //internal attributes
  60. var $HREF; //! string
  61. var $pgwidth; //! float
  62. var $fontlist; //! array
  63. var $issetfont; //! bool
  64. var $issetcolor; //! bool
  65. var $titulo; //! string
  66. var $oldx; //! float
  67. var $oldy; //! float
  68. var $B; //! int
  69. var $U; //! int
  70. var $I; //! int
  71. var $tablestart; //! bool
  72. var $tdbegin; //! bool
  73. var $table; //! array
  74. var $cell; //! array
  75. var $col; //! int
  76. var $row; //! int
  77. var $divbegin; //! bool
  78. var $divalign; //! char
  79. var $divwidth; //! float
  80. var $divheight; //! float
  81. var $divbgcolor; //! bool
  82. var $divcolor; //! bool
  83. var $divborder; //! int
  84. var $divrevert; //! bool
  85. var $listlvl; //! int
  86. var $listnum; //! int
  87. var $listtype; //! string
  88. //array(lvl,# of occurrences)
  89. var $listoccur; //! array
  90. //array(lvl,occurrence,type,maxnum)
  91. var $listlist; //! array
  92. //array(lvl,num,content,type)
  93. var $listitem; //! array
  94. var $buffer_on; //! bool
  95. var $pbegin; //! bool
  96. var $pjustfinished; //! bool
  97. var $blockjustfinished; //! bool
  98. var $SUP; //! bool
  99. var $SUB; //! bool
  100. var $toupper; //! bool
  101. var $tolower; //! bool
  102. var $dash_on; //! bool
  103. var $dotted_on; //! bool
  104. var $strike; //! bool
  105. var $CSS; //! array
  106. var $cssbegin; //! bool
  107. var $backupcss; //! array
  108. var $textbuffer; //! array
  109. var $currentstyle; //! string
  110. var $currentfont; //! string
  111. var $colorarray; //! array
  112. var $bgcolorarray; //! array
  113. var $internallink; //! array
  114. var $enabledtags; //! string
  115. var $lineheight; //! int
  116. var $basepath; //! string
  117. // array('COLOR','WIDTH','OLDWIDTH')
  118. var $outlineparam; //! array
  119. var $outline_on; //! bool
  120. var $specialcontent; //! string
  121. var $selectoption; //! array
  122. //options attributes
  123. var $usecss; //! bool
  124. var $usepre; //! bool
  125. var $usetableheader; //! bool
  126. var $shownoimg; //! bool
  127. function HTML2FPDF($orientation='P',$unit='mm',$format='A4')
  128. {
  129. //! @desc Constructor
  130. //! @return An object (a class instance)
  131. //Call parent constructor
  132. $this->FPDF($orientation,$unit,$format);
  133. //To make the function Footer() work properly
  134. $this->AliasNbPages();
  135. //Enable all tags as default
  136. $this->DisableTags();
  137. //Set default display preferences
  138. $this->DisplayPreferences('');
  139. //Initialization of the attributes
  140. $this->SetFont('Arial','',11); // Changeable?(not yet...)
  141. $this->lineheight = 5; // Related to FontSizePt == 11
  142. $this->pgwidth = $this->fw - $this->lMargin - $this->rMargin ;
  143. $this->SetFillColor(255);
  144. $this->HREF='';
  145. $this->titulo='';
  146. $this->oldx=-1;
  147. $this->oldy=-1;
  148. $this->B=0;
  149. $this->U=0;
  150. $this->I=0;
  151. $this->listlvl=0;
  152. $this->listnum=0;
  153. $this->listtype='';
  154. $this->listoccur=array();
  155. $this->listlist=array();
  156. $this->listitem=array();
  157. $this->tablestart=false;
  158. $this->tdbegin=false;
  159. $this->table=array();
  160. $this->cell=array();
  161. $this->col=-1;
  162. $this->row=-1;
  163. $this->divbegin=false;
  164. $this->divalign="L";
  165. $this->divwidth=0;
  166. $this->divheight=0;
  167. $this->divbgcolor=false;
  168. $this->divcolor=false;
  169. $this->divborder=0;
  170. $this->divrevert=false;
  171. $this->fontlist=array("arial","times","courier","helvetica","symbol","monospace","serif","sans");
  172. $this->issetfont=false;
  173. $this->issetcolor=false;
  174. $this->pbegin=false;
  175. $this->pjustfinished=false;
  176. $this->blockjustfinished = true; //in order to eliminate exceeding left-side spaces
  177. $this->toupper=false;
  178. $this->tolower=false;
  179. $this->dash_on=false;
  180. $this->dotted_on=false;
  181. $this->SUP=false;
  182. $this->SUB=false;
  183. $this->buffer_on=false;
  184. $this->strike=false;
  185. $this->currentfont='';
  186. $this->currentstyle='';
  187. $this->colorarray=array();
  188. $this->bgcolorarray=array();
  189. $this->cssbegin=false;
  190. $this->textbuffer=array();
  191. $this->CSS=array();
  192. $this->backupcss=array();
  193. $this->internallink=array();
  194. $this->basepath = "";
  195. $this->outlineparam = array();
  196. $this->outline_on = false;
  197. $this->specialcontent = '';
  198. $this->selectoption = array();
  199. $this->shownoimg=false;
  200. $this->usetableheader=false;
  201. $this->usecss=true;
  202. $this->usepre=true;
  203. }
  204. function setBasePath($str)
  205. {
  206. //! @desc Inform the script where the html file is (full path - e.g. http://www.google.com/dir1/dir2/dir3/file.html ) in order to adjust HREF and SRC links. No-Parameter: The directory where this script is.
  207. //! @return void
  208. $this->basepath = dirname($str) . "/";
  209. $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
  210. }
  211. function ShowNOIMG_GIF($opt=true)
  212. {
  213. //! @desc Enable/Disable Displaying the no_img.gif when an image is not found. No-Parameter: Enable
  214. //! @return void
  215. $this->shownoimg=$opt;
  216. }
  217. function UseCSS($opt=true)
  218. {
  219. //! @desc Enable/Disable CSS recognition. No-Parameter: Enable
  220. //! @return void
  221. $this->usecss=$opt;
  222. }
  223. function UseTableHeader($opt=true)
  224. {
  225. //! @desc Enable/Disable Table Header to appear every new page. No-Parameter: Enable
  226. //! @return void
  227. $this->usetableheader=$opt;
  228. }
  229. function UsePRE($opt=true)
  230. {
  231. //! @desc Enable/Disable pre tag recognition. No-Parameter: Enable
  232. //! @return void
  233. $this->usepre=$opt;
  234. }
  235. //Page header
  236. function Header($content='')
  237. {
  238. //! @return void
  239. //! @desc The header is printed in every page.
  240. if($this->usetableheader and $content != '')
  241. {
  242. $y = $this->y;
  243. foreach($content as $tableheader)
  244. {
  245. $this->y = $y;
  246. //Set some cell values
  247. $x = $tableheader['x'];
  248. $w = $tableheader['w'];
  249. $h = $tableheader['h'];
  250. $va = $tableheader['va'];
  251. $mih = $tableheader['mih'];
  252. $fill = $tableheader['bgcolor'];
  253. $border = $tableheader['border'];
  254. $align = $tableheader['a'];
  255. //Align
  256. $this->divalign=$align;
  257. $this->x = $x;
  258. //Vertical align
  259. if (!isset($va) || $va=='M') $this->y += ($h-$mih)/2;
  260. elseif (isset($va) && $va=='B') $this->y += $h-$mih;
  261. if ($fill)
  262. {
  263. $color = ConvertColor($fill);
  264. $this->SetFillColor($color['R'],$color['G'],$color['B']);
  265. $this->Rect($x, $y, $w, $h, 'F');
  266. }
  267. //Border
  268. if (isset($border) and $border != 'all') $this->_tableRect($x, $y, $w, $h, $border);
  269. elseif (isset($border) && $border == 'all') $this->Rect($x, $y, $w, $h);
  270. //Print cell content
  271. $this->divwidth = $w-2;
  272. $this->divheight = 1.1*$this->lineheight;
  273. $textbuffer = $tableheader['textbuffer'];
  274. if (!empty($textbuffer)) $this->printbuffer($textbuffer,false,true/*inside a table*/);
  275. $textbuffer = array();
  276. }
  277. $this->y = $y + $h; //Update y coordinate
  278. }//end of 'if usetableheader ...'
  279. }
  280. //Page footer
  281. function Footer()
  282. {
  283. //! @return void
  284. //! @desc The footer is printed in every page!
  285. //Position at 1.0 cm from bottom
  286. $this->SetY(-10);
  287. //Copyright //especial para esta vers?o
  288. $this->SetFont('Arial','B',9);
  289. $this->SetTextColor(0);
  290. //Arial italic 9
  291. $this->SetFont('Arial','I',9);
  292. //Page number
  293. $this->Cell(0,10,$this->PageNo().'/{nb}',0,0,'C');
  294. //Return Font to normal
  295. $this->SetFont('Arial','',11);
  296. }
  297. ///////////////////
  298. /// HTML parser ///
  299. ///////////////////
  300. function WriteHTML($html)
  301. {
  302. //! @desc HTML parser
  303. //! @return void
  304. /* $e == content */
  305. $this->ReadMetaTags($html);
  306. $html = AdjustHTML($html,$this->usepre); //Try to make HTML look more like XHTML
  307. if ($this->usecss) $html = $this->ReadCSS($html);
  308. //Add new supported tags in the DisableTags function
  309. $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word
  310. $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string
  311. //Explode the string in order to parse the HTML code
  312. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  313. foreach($a as $i => $e)
  314. {
  315. if($i%2==0)
  316. {
  317. //TEXT
  318. //Adjust lineheight
  319. // $this->lineheight = (5*$this->FontSizePt)/11; //should be inside printbuffer?
  320. //Adjust text, if needed
  321. if (strpos($e,"&") !== false) //HTML-ENTITIES decoding
  322. {
  323. if (strpos($e,"#") !== false) $e = value_entity_decode($e); // Decode value entities
  324. //Avoid crashing the script on PHP 4.0
  325. $version = phpversion();
  326. $version = str_replace('.','',$version);
  327. if ($version >= 430) $e = html_entity_decode($e,ENT_QUOTES,'cp1252'); // changes &nbsp; and the like by their respective char
  328. else $e = lesser_entity_decode($e);
  329. }
  330. $e = str_replace(chr(160),chr(32),$e); //unify ascii code of spaces (in order to recognize all of them correctly)
  331. if (strlen($e) == 0) continue;
  332. if ($this->divrevert) $e = strrev($e);
  333. if ($this->toupper) $e = strtoupper($e);
  334. if ($this->tolower) $e = strtolower($e);
  335. //Start of 'if/elseif's
  336. if($this->titulo) $this->SetTitle($e);
  337. elseif($this->specialcontent)
  338. {
  339. if ($this->specialcontent == "type=select" and $this->selectoption['ACTIVE'] == true) //SELECT tag (form element)
  340. {
  341. $stringwidth = $this->GetStringWidth($e);
  342. if (!isset($this->selectoption['MAXWIDTH']) or $stringwidth > $this->selectoption['MAXWIDTH']) $this->selectoption['MAXWIDTH'] = $stringwidth;
  343. if (!isset($this->selectoption['SELECTED']) or $this->selectoption['SELECTED'] == '') $this->selectoption['SELECTED'] = $e;
  344. }
  345. else $this->textbuffer[] = array("?¤?"/*identifier*/.$this->specialcontent."?¤?".$e);
  346. }
  347. elseif($this->tablestart)
  348. {
  349. if($this->tdbegin)
  350. {
  351. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
  352. $this->cell[$this->row][$this->col]['text'][] = $e;
  353. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e);
  354. }
  355. //Ignore content between <table>,<tr> and a <td> tag (this content is usually only a bunch of spaces)
  356. }
  357. elseif($this->pbegin or $this->HREF or $this->divbegin or $this->SUP or $this->SUB or $this->strike or $this->buffer_on) $this->textbuffer[] = array($e,$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray); //Accumulate text on buffer
  358. else
  359. {
  360. if ($this->blockjustfinished) $e = ltrim($e);
  361. if ($e != '')
  362. {
  363. $this->Write($this->lineheight,$e); //Write text directly in the PDF
  364. if ($this->pjustfinished) $this->pjustfinished = false;
  365. }
  366. }
  367. }
  368. else
  369. {
  370. //Tag
  371. if($e{0}=='/') $this->CloseTag(strtoupper(substr($e,1)));
  372. else
  373. {
  374. $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any
  375. $e = preg_replace($regexp,"=\"\$1\"",$e);
  376. $regexp = '| (\\w+?)=([^\\s>"]+)|si'; // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
  377. $e = preg_replace($regexp," \$1=\"\$2\"",$e);
  378. //Fix path values, if needed
  379. if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) )
  380. {
  381. $regexp = '/ (href|src)="(.*?)"/i';
  382. preg_match($regexp,$e,$auxiliararray);
  383. $path = $auxiliararray[2];
  384. $path = str_replace("\\","/",$path); //If on Windows
  385. //Get link info and obtain its absolute path
  386. $regexp = '|^./|';
  387. $path = preg_replace($regexp,'',$path);
  388. if($path{0} != '#') //It is not an Internal Link
  389. {
  390. if (strpos($path,"../") !== false ) //It is a Relative Link
  391. {
  392. $backtrackamount = substr_count($path,"../");
  393. $maxbacktrack = substr_count($this->basepath,"/") - 1;
  394. $filepath = str_replace("../",'',$path);
  395. $path = $this->basepath;
  396. //If it is an invalid relative link, then make it go to directory root
  397. if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
  398. //Backtrack some directories
  399. for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
  400. $path = $path . "/" . $filepath; //Make it an absolute path
  401. }
  402. elseif( strpos($path,":/") === false) //It is a Local Link
  403. {
  404. $path = $this->basepath . $path;
  405. }
  406. //Do nothing if it is an Absolute Link
  407. }
  408. $regexp = '/ (href|src)="(.*?)"/i';
  409. $e = preg_replace($regexp,' \\1="'.$path.'"',$e);
  410. }//END of Fix path values
  411. //Extract attributes
  412. $contents=array();
  413. preg_match_all('/\\S*=["\'][^"\']*["\']/',$e,$contents);
  414. preg_match('/\\S+/',$e,$a2);
  415. $tag=strtoupper($a2[0]);
  416. $attr=array();
  417. if (!empty($contents))
  418. {
  419. foreach($contents[0] as $v)
  420. {
  421. if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
  422. {
  423. $attr[strtoupper($a3[1])]=$a3[2];
  424. }
  425. }
  426. }
  427. $this->OpenTag($tag,$attr);
  428. }
  429. }
  430. }//end of foreach($a as $i=>$e)
  431. //Create Internal Links, if needed
  432. if (!empty($this->internallink) )
  433. {
  434. foreach($this->internallink as $k=>$v)
  435. {
  436. if (strpos($k,"#") !== false ) continue; //ignore
  437. $ypos = $v['Y'];
  438. $pagenum = $v['PAGE'];
  439. $sharp = "#";
  440. while (array_key_exists($sharp.$k,$this->internallink))
  441. {
  442. $internallink = $this->internallink[$sharp.$k];
  443. $this->SetLink($internallink,$ypos,$pagenum);
  444. $sharp .= "#";
  445. }
  446. }
  447. }
  448. }
  449. function OpenTag($tag,$attr)
  450. {
  451. //! @return void
  452. // What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here>
  453. $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','middle'=>'M','bottom'=>'B','justify'=>'J');
  454. $this->blockjustfinished=false;
  455. //Opening tag
  456. switch($tag){
  457. case 'PAGE_BREAK': //custom-tag
  458. case 'NEWPAGE': //custom-tag
  459. $this->blockjustfinished = true;
  460. $this->AddPage();
  461. break;
  462. case 'OUTLINE': //custom-tag (CSS2 property - browsers don't support it yet - Jan2005)
  463. //Usage: (default: width=normal color=white)
  464. //<outline width="(thin|medium|thick)" color="(usualcolorformat)" >Text</outline>
  465. //Mix this tag with the <font color="(usualcolorformat)"> tag to get mixed colors on outlined text!
  466. $this->buffer_on = true;
  467. if (isset($attr['COLOR'])) $this->outlineparam['COLOR'] = ConvertColor($attr['COLOR']);
  468. else $this->outlineparam['COLOR'] = array('R'=>255,'G'=>255,'B'=>255); //white
  469. $this->outlineparam['OLDWIDTH'] = $this->LineWidth;
  470. if (isset($attr['WIDTH']))
  471. {
  472. switch(strtoupper($attr['WIDTH']))
  473. {
  474. case 'THIN': $this->outlineparam['WIDTH'] = 0.75*$this->LineWidth; break;
  475. case 'MEDIUM': $this->outlineparam['WIDTH'] = $this->LineWidth; break;
  476. case 'THICK': $this->outlineparam['WIDTH'] = 1.75*$this->LineWidth; break;
  477. }
  478. }
  479. else $this->outlineparam['WIDTH'] = $this->LineWidth; //width == oldwidth
  480. break;
  481. case 'BDO':
  482. if (isset($attr['DIR']) and (strtoupper($attr['DIR']) == 'RTL' )) $this->divrevert = true;
  483. break;
  484. case 'S':
  485. case 'STRIKE':
  486. case 'DEL':
  487. $this->strike=true;
  488. break;
  489. case 'SUB':
  490. $this->SUB=true;
  491. break;
  492. case 'SUP':
  493. $this->SUP=true;
  494. break;
  495. case 'CENTER':
  496. $this->buffer_on = true;
  497. if ($this->tdbegin) $this->cell[$this->row][$this->col]['a'] = $align['center'];
  498. else
  499. {
  500. $this->divalign = $align['center'];
  501. if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
  502. }
  503. break;
  504. case 'ADDRESS':
  505. $this->buffer_on = true;
  506. $this->SetStyle('I',true);
  507. if (!$this->tdbegin and $this->x != $this->lMargin) $this->Ln($this->lineheight);
  508. break;
  509. case 'TABLE': // TABLE-BEGIN
  510. if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
  511. $this->tablestart = true;
  512. $this->table['nc'] = $this->table['nr'] = 0;
  513. if (isset($attr['REPEAT_HEADER']) and $attr['REPEAT_HEADER'] == true) $this->UseTableHeader(true);
  514. if (isset($attr['WIDTH'])) $this->table['w'] = ConvertSize($attr['WIDTH'],$this->pgwidth);
  515. if (isset($attr['HEIGHT'])) $this->table['h'] = ConvertSize($attr['HEIGHT'],$this->pgwidth);
  516. if (isset($attr['ALIGN'])) $this->table['a'] = $align[strtolower($attr['ALIGN'])];
  517. if (isset($attr['BORDER'])) $this->table['border'] = $attr['BORDER'];
  518. if (isset($attr['BGCOLOR'])) $this->table['bgcolor'][-1] = $attr['BGCOLOR'];
  519. break;
  520. case 'TR':
  521. $this->row++;
  522. $this->table['nr']++;
  523. $this->col = -1;
  524. if (isset($attr['BGCOLOR']))$this->table['bgcolor'][$this->row] = $attr['BGCOLOR'];
  525. break;
  526. case 'TH':
  527. $this->SetStyle('B',true);
  528. if (!isset($attr['ALIGN'])) $attr['ALIGN'] = "center";
  529. case 'TD':
  530. $this->tdbegin = true;
  531. $this->col++;
  532. while (isset($this->cell[$this->row][$this->col])) $this->col++;
  533. //Update number column
  534. if ($this->table['nc'] < $this->col+1) $this->table['nc'] = $this->col+1;
  535. $this->cell[$this->row][$this->col] = array();
  536. $this->cell[$this->row][$this->col]['text'] = array();
  537. $this->cell[$this->row][$this->col]['s'] = 3;
  538. if (isset($attr['WIDTH'])) $this->cell[$this->row][$this->col]['w'] = ConvertSize($attr['WIDTH'],$this->pgwidth);
  539. if (isset($attr['HEIGHT'])) $this->cell[$this->row][$this->col]['h'] = ConvertSize($attr['HEIGHT'],$this->pgwidth);
  540. if (isset($attr['ALIGN'])) $this->cell[$this->row][$this->col]['a'] = $align[strtolower($attr['ALIGN'])];
  541. if (isset($attr['VALIGN'])) $this->cell[$this->row][$this->col]['va'] = $align[strtolower($attr['VALIGN'])];
  542. if (isset($attr['BORDER'])) $this->cell[$this->row][$this->col]['border'] = $attr['BORDER'];
  543. if (isset($attr['BGCOLOR'])) $this->cell[$this->row][$this->col]['bgcolor'] = $attr['BGCOLOR'];
  544. $cs = $rs = 1;
  545. if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $this->cell[$this->row][$this->col]['colspan'] = $attr['COLSPAN'];
  546. if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $this->cell[$this->row][$this->col]['rowspan'] = $attr['ROWSPAN'];
  547. //Chiem dung vi tri de danh cho cell span (?mais hein?)
  548. for ($k=$this->row ; $k < $this->row+$rs ;$k++)
  549. for($l=$this->col; $l < $this->col+$cs ;$l++)
  550. {
  551. if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0;
  552. }
  553. if (isset($attr['NOWRAP'])) $this->cell[$this->row][$this->col]['nowrap']= 1;
  554. break;
  555. case 'OL':
  556. if ( !isset($attr['TYPE']) or $attr['TYPE'] == '' ) $this->listtype = '1'; //OL default == '1'
  557. else $this->listtype = $attr['TYPE']; // ol and ul types are mixed here
  558. case 'UL':
  559. if ( (!isset($attr['TYPE']) or $attr['TYPE'] == '') and $tag=='UL')
  560. {
  561. //Insert UL defaults
  562. if ($this->listlvl == 0) $this->listtype = 'disc';
  563. elseif ($this->listlvl == 1) $this->listtype = 'circle';
  564. else $this->listtype = 'square';
  565. }
  566. elseif (isset($attr['TYPE']) and $tag=='UL') $this->listtype = $attr['TYPE'];
  567. $this->buffer_on = false;
  568. if ($this->listlvl == 0)
  569. {
  570. //First of all, skip a line
  571. if (!$this->pjustfinished)
  572. {
  573. if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
  574. $this->Ln($this->lineheight);
  575. }
  576. $this->oldx = $this->x;
  577. $this->listlvl++; // first depth level
  578. $this->listnum = 0; // reset
  579. $this->listoccur[$this->listlvl] = 1;
  580. $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  581. }
  582. else
  583. {
  584. if (!empty($this->textbuffer))
  585. {
  586. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
  587. $this->listnum++;
  588. }
  589. $this->textbuffer = array();
  590. $occur = $this->listoccur[$this->listlvl];
  591. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  592. $this->listlvl++;
  593. $this->listnum = 0; // reset
  594. if ($this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
  595. else $this->listoccur[$this->listlvl]++;
  596. $occur = $this->listoccur[$this->listlvl];
  597. $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  598. }
  599. break;
  600. case 'LI':
  601. //Observation: </LI> is ignored
  602. if ($this->listlvl == 0) //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  603. {
  604. //First of all, skip a line
  605. if (!$this->pjustfinished and $this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
  606. $this->oldx = $this->x;
  607. $this->listlvl++; // first depth level
  608. $this->listnum = 0; // reset
  609. $this->listoccur[$this->listlvl] = 1;
  610. $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  611. }
  612. if ($this->listnum == 0)
  613. {
  614. $this->buffer_on = true; //activate list 'bufferization'
  615. $this->listnum++;
  616. $this->textbuffer = array();
  617. }
  618. else
  619. {
  620. $this->buffer_on = true; //activate list 'bufferization'
  621. if (!empty($this->textbuffer))
  622. {
  623. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
  624. $this->listnum++;
  625. }
  626. $this->textbuffer = array();
  627. }
  628. break;
  629. case 'H1': // 2 * fontsize
  630. case 'H2': // 1.5 * fontsize
  631. case 'H3': // 1.17 * fontsize
  632. case 'H4': // 1 * fontsize
  633. case 'H5': // 0.83 * fontsize
  634. case 'H6': // 0.67 * fontsize
  635. //Values obtained from: http://www.w3.org/TR/REC-CSS2/sample.html
  636. if(isset($attr['ALIGN'])) $this->divalign = $align[strtolower($attr['ALIGN'])];
  637. $this->buffer_on = true;
  638. if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
  639. elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
  640. $this->SetStyle('B',true);
  641. switch($tag)
  642. {
  643. case 'H1':
  644. $this->SetFontSize(2*$this->FontSizePt);
  645. $this->lineheight *= 2;
  646. break;
  647. case 'H2':
  648. $this->SetFontSize(1.5*$this->FontSizePt);
  649. $this->lineheight *= 1.5;
  650. break;
  651. case 'H3':
  652. $this->SetFontSize(1.17*$this->FontSizePt);
  653. $this->lineheight *= 1.17;
  654. break;
  655. case 'H4':
  656. $this->SetFontSize($this->FontSizePt);
  657. break;
  658. case 'H5':
  659. $this->SetFontSize(0.83*$this->FontSizePt);
  660. $this->lineheight *= 0.83;
  661. break;
  662. case 'H6':
  663. $this->SetFontSize(0.67*$this->FontSizePt);
  664. $this->lineheight *= 0.67;
  665. break;
  666. }
  667. break;
  668. case 'HR': //Default values: width=100% align=center color=gray
  669. //Skip a line, if needed
  670. if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
  671. $this->Ln(0.2*$this->lineheight);
  672. $hrwidth = $this->pgwidth;
  673. $hralign = 'C';
  674. $hrcolor = array('R'=>200,'G'=>200,'B'=>200);
  675. if($attr['WIDTH'] != '') $hrwidth = ConvertSize($attr['WIDTH'],$this->pgwidth);
  676. if($attr['ALIGN'] != '') $hralign = $align[strtolower($attr['ALIGN'])];
  677. if($attr['COLOR'] != '') $hrcolor = ConvertColor($attr['COLOR']);
  678. $this->SetDrawColor($hrcolor['R'],$hrcolor['G'],$hrcolor['B']);
  679. $x = $this->x;
  680. $y = $this->y;
  681. switch($hralign)
  682. {
  683. case 'L':
  684. case 'J':
  685. break;
  686. case 'C':
  687. $empty = $this->pgwidth - $hrwidth;
  688. $empty /= 2;
  689. $x += $empty;
  690. break;
  691. case 'R':
  692. $empty = $this->pgwidth - $hrwidth;
  693. $x += $empty;
  694. break;
  695. }
  696. $oldlinewidth = $this->LineWidth;
  697. $this->SetLineWidth(0.3);
  698. $this->Line($x,$y,$x+$hrwidth,$y);
  699. $this->SetLineWidth($oldlinewidth);
  700. $this->Ln(0.2*$this->lineheight);
  701. $this->SetDrawColor(0);
  702. $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
  703. break;
  704. case 'INS':
  705. $this->SetStyle('U',true);
  706. break;
  707. case 'SMALL':
  708. $newsize = $this->FontSizePt - 1;
  709. $this->SetFontSize($newsize);
  710. break;
  711. case 'BIG':
  712. $newsize = $this->FontSizePt + 1;
  713. $this->SetFontSize($newsize);
  714. case 'STRONG':
  715. $this->SetStyle('B',true);
  716. break;
  717. case 'CITE':
  718. case 'EM':
  719. $this->SetStyle('I',true);
  720. break;
  721. case 'TITLE':
  722. $this->titulo = true;
  723. break;
  724. case 'B':
  725. case 'I':
  726. case 'U':
  727. if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
  728. {
  729. $this->cssbegin=true;
  730. if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
  731. elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
  732. //Read Inline CSS
  733. if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
  734. //Look for name in the $this->CSS array
  735. $this->backupcss = $properties;
  736. if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
  737. }
  738. $this->SetStyle($tag,true);
  739. break;
  740. case 'A':
  741. if (isset($attr['NAME']) and $attr['NAME'] != '') $this->textbuffer[] = array('','','',array(),'',false,false,$attr['NAME']); //an internal link (adds a space for recognition)
  742. if (isset($attr['HREF'])) $this->HREF=$attr['HREF'];
  743. break;
  744. case 'DIV':
  745. //in case of malformed HTML code. Example:(...)</div><li>Content</li><div>DIV1</div>(...)
  746. if ($this->listlvl > 0) // We are closing (omitted) OL/UL tag(s)
  747. {
  748. $this->buffer_on = false;
  749. if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
  750. $this->textbuffer = array();
  751. $this->listlvl--;
  752. $this->printlistbuffer();
  753. $this->pjustfinished = true; //act as if a paragraph just ended
  754. }
  755. $this->divbegin=true;
  756. if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
  757. if( isset($attr['ALIGN']) and $attr['ALIGN'] != '' ) $this->divalign = $align[strtolower($attr['ALIGN'])];
  758. if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
  759. {
  760. $this->cssbegin=true;
  761. if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
  762. elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
  763. //Read Inline CSS
  764. if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
  765. //Look for name in the $this->CSS array
  766. if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
  767. }
  768. break;
  769. case 'IMG':
  770. if(!empty($this->textbuffer) and !$this->tablestart)
  771. {
  772. //Output previously buffered content and output image below
  773. //Set some default values
  774. $olddivwidth = $this->divwidth;
  775. $olddivheight = $this->divheight;
  776. if ( $this->divwidth == 0) $this->divwidth = $this->pgwidth - $x + $this->lMargin;
  777. if ( $this->divheight == 0) $this->divheight = $this->lineheight;
  778. //Print content
  779. $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
  780. $this->textbuffer=array();
  781. //Reset values
  782. $this->divwidth = $olddivwidth;
  783. $this->divheight = $olddivheight;
  784. $this->textbuffer=array();
  785. $this->Ln($this->lineheight);
  786. }
  787. if(isset($attr['SRC']))
  788. {
  789. $srcpath = $attr['SRC'];
  790. if(!isset($attr['WIDTH'])) $attr['WIDTH'] = 0;
  791. else $attr['WIDTH'] = ConvertSize($attr['WIDTH'],$this->pgwidth);//$attr['WIDTH'] /= 4;
  792. if(!isset($attr['HEIGHT'])) $attr['HEIGHT'] = 0;
  793. else $attr['HEIGHT'] = ConvertSize($attr['HEIGHT'],$this->pgwidth);//$attr['HEIGHT'] /= 4;
  794. if ($this->tdbegin)
  795. {
  796. $bak_x = $this->x;
  797. $bak_y = $this->y;
  798. //Check whether image exists locally or on the URL
  799. $f_exists = @fopen($srcpath,"rb");
  800. if (!$f_exists) //Show 'image not found' icon instead
  801. {
  802. if(!$this->shownoimg) break;
  803. $srcpath = str_replace("\\","/",dirname(__FILE__)) . "/";
  804. $srcpath .= 'no_img.gif';
  805. }
  806. $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'','',false);
  807. $this->y = $bak_y;
  808. $this->x = $bak_x;
  809. }
  810. elseif($this->pbegin or $this->divbegin)
  811. {
  812. //In order to support <div align='center'><img ...></div>
  813. $ypos = 0;
  814. $bak_x = $this->x;
  815. $bak_y = $this->y;
  816. //Check whether image exists locally or on the URL
  817. $f_exists = @fopen($srcpath,"rb");
  818. if (!$f_exists) //Show 'image not found' icon instead
  819. {
  820. if(!$this->shownoimg) break;
  821. $srcpath = str_replace("\\","/",dirname(__FILE__)) . "/";
  822. $srcpath .= 'no_img.gif';
  823. }
  824. $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'','',false);
  825. $this->y = $bak_y;
  826. $this->x = $bak_x;
  827. $xpos = '';
  828. switch($this->divalign)
  829. {
  830. case "C":
  831. $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
  832. $empty = ($this->pgwidth - $sizesarray['WIDTH'])/2;
  833. $xpos = 'xpos='.$empty.',';
  834. break;
  835. case "R":
  836. $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
  837. $empty = ($this->pgwidth - $sizesarray['WIDTH']);
  838. $xpos = 'xpos='.$empty.',';
  839. break;
  840. default: break;
  841. }
  842. $numberoflines = (integer)ceil($sizesarray['HEIGHT']/$this->lineheight) ;
  843. $ypos = $numberoflines * $this->lineheight;
  844. $this->textbuffer[] = array("?¤?"/*identifier*/."type=image,ypos=$ypos,{$xpos}width=".$sizesarray['WIDTH'].",height=".$sizesarray['HEIGHT']."?¤?".$sizesarray['OUTPUT']);
  845. while($numberoflines) {$this->textbuffer[] = array("\n",$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);$numberoflines--;}
  846. }
  847. else
  848. {
  849. $imgborder = 0;
  850. if (isset($attr['BORDER'])) $imgborder = ConvertSize($attr['BORDER'],$this->pgwidth);
  851. //Check whether image exists locally or on the URL
  852. $f_exists = @fopen($srcpath,"rb");
  853. if (!$f_exists) //Show 'image not found' icon instead
  854. {
  855. $srcpath = str_replace("\\","/",dirname(__FILE__)) . "/";
  856. $srcpath .= 'no_img.gif';
  857. }
  858. $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'',$this->HREF); //Output Image
  859. $ini_x = $sizesarray['X'];
  860. $ini_y = $sizesarray['Y'];
  861. if ($imgborder)
  862. {
  863. $oldlinewidth = $this->LineWidth;
  864. $this->SetLineWidth($imgborder);
  865. $this->Rect($ini_x,$ini_y,$sizesarray['WIDTH'],$sizesarray['HEIGHT']);
  866. $this->SetLineWidth($oldlinewidth);
  867. }
  868. }
  869. if ($sizesarray['X'] < $this->x) $this->x = $this->lMargin;
  870. if ($this->tablestart)
  871. {
  872. $this->cell[$this->row][$this->col]['textbuffer'][] = array("?¤?"/*identifier*/."type=image,width=".$sizesarray['WIDTH'].",height=".$sizesarray['HEIGHT']."?¤?".$sizesarray['OUTPUT']);
  873. $this->cell[$this->row][$this->col]['s'] += $sizesarray['WIDTH'] + 1;// +1 == margin
  874. $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
  875. if (!isset($this->cell[$this->row][$this->col]['w'])) $this->cell[$this->row][$this->col]['w'] = $sizesarray['WIDTH'] + 3;
  876. if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $sizesarray['HEIGHT'] + 3;
  877. }
  878. }
  879. break;
  880. case 'BLOCKQUOTE':
  881. case 'BR':
  882. if($this->tablestart)
  883. {
  884. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
  885. $this->cell[$this->row][$this->col]['text'][] = "\n";
  886. if (!isset($this->cell[$this->row][$this->col]['maxs'])) $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'] +2; //+2 == margin
  887. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']+2;//+2 == margin
  888. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  889. }
  890. elseif($this->divbegin or $this->pbegin or $this->buffer_on) $this->textbuffer[] = array("\n",$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
  891. else {$this->Ln($this->lineheight);$this->blockjustfinished = true;}
  892. break;
  893. case 'P':
  894. //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  895. if ($this->listlvl > 0) // We are closing (omitted) OL/UL tag(s)
  896. {
  897. $this->buffer_on = false;
  898. if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
  899. $this->textbuffer = array();
  900. $this->listlvl--;
  901. $this->printlistbuffer();
  902. $this->pjustfinished = true; //act as if a paragraph just ended
  903. }
  904. if ($this->tablestart)
  905. {
  906. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
  907. $this->cell[$this->row][$this->col]['text'][] = "\n";
  908. break;
  909. }
  910. $this->pbegin=true;
  911. if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
  912. elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
  913. //Save x,y coords in case we need to print borders...
  914. $this->oldx = $this->x;
  915. $this->oldy = $this->y;
  916. if(isset($attr['ALIGN'])) $this->divalign = $align[strtolower($attr['ALIGN'])];
  917. if(isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
  918. {
  919. $this->cssbegin=true;
  920. if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
  921. elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
  922. //Read Inline CSS
  923. if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
  924. //Look for name in the $this->CSS array
  925. $this->backupcss = $properties;
  926. if (!empty($properties)) $this->setCSS($properties); //name(id/class/style) found in the CSS array!
  927. }
  928. break;
  929. case 'SPAN':
  930. $this->buffer_on = true;
  931. //Save x,y coords in case we need to print borders...
  932. $this->oldx = $this->x;
  933. $this->oldy = $this->y;
  934. if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
  935. {
  936. $this->cssbegin=true;
  937. if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
  938. elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
  939. //Read Inline CSS
  940. if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
  941. //Look for name in the $this->CSS array
  942. $this->backupcss = $properties;
  943. if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
  944. }
  945. break;
  946. case 'PRE':
  947. if($this->tablestart)
  948. {
  949. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
  950. $this->cell[$this->row][$this->col]['text'][] = "\n";
  951. }
  952. elseif($this->divbegin or $this->pbegin or $this->buffer_on) $this->textbuffer[] = array("\n",$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
  953. else
  954. {
  955. if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
  956. elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
  957. $this->buffer_on = true;
  958. //Save x,y coords in case we need to print borders...
  959. $this->oldx = $this->x;
  960. $this->oldy = $this->y;
  961. if(isset($attr['ALIGN'])) $this->divalign = $align[strtolower($attr['ALIGN'])];
  962. if(isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
  963. {
  964. $this->cssbegin=true;
  965. if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
  966. elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
  967. //Read Inline CSS
  968. if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
  969. //Look for name in the $this->CSS array
  970. $this->backupcss = $properties;
  971. if (!empty($properties)) $this->setCSS($properties); //name(id/class/style) found in the CSS array!
  972. }
  973. }
  974. case 'TT':
  975. case 'KBD':
  976. case 'SAMP':
  977. case 'CODE':
  978. $this->SetFont('courier');
  979. $this->currentfont='courier';
  980. break;
  981. case 'TEXTAREA':
  982. $this->buffer_on = true;
  983. $colsize = 20; //HTML default value
  984. $rowsize = 2; //HTML default value
  985. if (isset($attr['COLS'])) $colsize = $attr['COLS'];
  986. if (isset($attr['ROWS'])) $rowsize = $attr['ROWS'];
  987. if (!$this->tablestart)
  988. {
  989. if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
  990. $this->col = $colsize;
  991. $this->row = $rowsize;
  992. }
  993. else //it is inside a table
  994. {
  995. $this->specialcontent = "type=textarea,lines=$rowsize,width=".((2.2*$colsize) + 3); //Activate form info in order to paint FORM elements within table
  996. $this->cell[$this->row][$this->col]['s'] += (2.2*$colsize) + 6;// +6 == margin
  997. if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = 1.1*$this->lineheight*$rowsize + 2.5;
  998. }
  999. break;
  1000. case 'SELECT':
  1001. $this->specialcontent = "type=select"; //Activate form info in order to paint FORM elements within table
  1002. break;
  1003. case 'OPTION':
  1004. $this->selectoption['ACTIVE'] = true;
  1005. if (empty($this->selectoption))
  1006. {
  1007. $this->selectoption['MAXWIDTH'] = '';
  1008. $this->selectoption['SELECTED'] = '';
  1009. }
  1010. if (isset($attr['SELECTED'])) $this->selectoption['SELECTED'] = '';
  1011. break;
  1012. case 'FORM':
  1013. if($this->tablestart)
  1014. {
  1015. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
  1016. $this->cell[$this->row][$this->col]['text'][] = "\n";
  1017. }
  1018. elseif ($this->x != $this->lMargin) $this->Ln($this->lineheight); //Skip a line, if needed
  1019. break;
  1020. case 'INPUT':
  1021. if (!isset($attr['TYPE'])) $attr['TYPE'] == ''; //in order to allow default 'TEXT' form (in case of malformed HTML code)
  1022. if (!$this->tablestart)
  1023. {
  1024. switch(strtoupper($attr['TYPE'])){
  1025. case 'CHECKBOX': //Draw Checkbox
  1026. $checked = false;
  1027. if (isset($attr['CHECKED'])) $checked = true;
  1028. $this->SetFillColor(235,235,235);
  1029. $this->x += 3;
  1030. $this->Rect($this->x,$this->y+1,3,3,'DF');
  1031. if ($checked)
  1032. {
  1033. $this->Line($this->x,$this->y+1,$this->x+3,$this->y+1+3);
  1034. $this->Line($this->x,$this->y+1+3,$this->x+3,$this->y+1);
  1035. }
  1036. $this->SetFillColor(255);
  1037. $this->x += 3.5;
  1038. break;
  1039. case 'RADIO': //Draw Radio button
  1040. $checked = false;
  1041. if (isset($attr['CHECKED'])) $checked = true;
  1042. $this->x += 4;
  1043. $this->Circle($this->x,$this->y+2.2,1,'D');
  1044. $this->_out('0.000 g');
  1045. if ($checked) $this->Circle($this->x,$this->y+2.2,0.4,'DF');
  1046. $this->Write(5,$texto,$this->x);
  1047. $this->x += 2;
  1048. break;
  1049. case 'BUTTON': // Draw a button
  1050. case 'SUBMIT':
  1051. case 'RESET':
  1052. $texto='';
  1053. if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
  1054. $nihil = 2.5;
  1055. $this->x += 2;
  1056. $this->SetFillColor(190,190,190);
  1057. $this->Rect($this->x,$this->y,$this->GetStringWidth($texto)+2*$nihil,4.5,'DF'); // 4.5 in order to avoid overlapping
  1058. $this->x += $nihil;
  1059. $this->Write(5,$texto,$this->x);
  1060. $this->x += $nihil;
  1061. $this->SetFillColor(255);
  1062. break;
  1063. case 'PASSWORD':
  1064. if (isset($attr['VALUE']))
  1065. {
  1066. $num_stars = strlen($attr['VALUE']);
  1067. $attr['VALUE'] = str_repeat('*',$num_stars);
  1068. }
  1069. case 'TEXT': //Draw TextField
  1070. default: //default == TEXT
  1071. $texto='';
  1072. if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
  1073. $tamanho = 20;
  1074. if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $tamanho = $attr['SIZE'];
  1075. $this->SetFillColor(235,235,235);
  1076. $this->x += 2;
  1077. $this->Rect($this->x,$this->y,2*$tamanho,4.5,'DF');// 4.5 in order to avoid overlapping
  1078. if ($texto != '')
  1079. {
  1080. $this->x += 1;
  1081. $this->Write(5,$texto,$this->x);
  1082. $this->x -= $this->GetStringWidth($texto);
  1083. }
  1084. $this->SetFillColor(255);
  1085. $this->x += 2*$tamanho;
  1086. break;
  1087. }
  1088. }
  1089. else //we are inside a table
  1090. {
  1091. $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
  1092. $type = '';
  1093. $text = '';
  1094. $height = 0;
  1095. $width = 0;
  1096. switch(strtoupper($attr['TYPE'])){
  1097. case 'CHECKBOX': //Draw Checkbox
  1098. $checked = false;
  1099. if (isset($attr['CHECKED'])) $checked = true;
  1100. $text = $checked;
  1101. $type = 'CHECKBOX';
  1102. $width = 4;
  1103. $this->cell[$this->row][$this->col]['textbuffer'][] = array("?¤?"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."?¤?".$text);
  1104. $this->cell[$this->row][$this->col]['s'] += $width;
  1105. if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight;
  1106. break;
  1107. case 'RADIO': //Draw Radio button
  1108. $checked = false;
  1109. if (isset($attr['CHECKED'])) $checked = true;
  1110. $text = $checked;
  1111. $type = 'RADIO';
  1112. $width = 3;
  1113. $this->cell[$this->row][$this->col]['textbuffer'][] = array("?¤?"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."?¤?".$text);
  1114. $this->cell[$this->row][$this->col]['s'] += $width;
  1115. if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight;
  1116. break;
  1117. case 'BUTTON': $type = 'BUTTON'; // Draw a button
  1118. case 'SUBMIT': if ($type == '') $type = 'SUBMIT';
  1119. case 'RESET': if ($type == '') $type = 'RESET';
  1120. $texto='';
  1121. if (isset($attr['VALUE'])) $texto = " " . $attr['VALUE'] . " ";
  1122. $text = $texto;
  1123. $width = $this->GetStringWidth($texto)+3;
  1124. $this->cell[$this->row][$this->col]['textbuffer'][] = array("?¤?"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."?¤?".$text);
  1125. $this->cell[$this->row][$this->col]['s'] += $width;
  1126. if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight + 2;
  1127. break;
  1128. case 'PASSWORD':
  1129. if (isset($attr['VALUE']))
  1130. {
  1131. $num_stars = strlen($attr['VALUE']);
  1132. $attr['VALUE'] = str_repeat('*',$num_stars);
  1133. }
  1134. $type = 'PASSWORD';
  1135. case 'TEXT': //Draw TextField
  1136. default: //default == TEXT
  1137. $texto='';
  1138. if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
  1139. $tamanho = 20;
  1140. if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $tamanho = $attr['SIZE'];
  1141. $text = $texto;
  1142. $width = 2*$tamanho;
  1143. if ($type == '') $type = 'TEXT';
  1144. $this->cell[$this->row][$this->col]['textbuffer'][] = array("?¤?"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."?¤?".$text);
  1145. $this->cell[$this->row][$this->col]['s'] += $width;
  1146. if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight + 2;
  1147. break;
  1148. }
  1149. }
  1150. break;
  1151. case 'FONT':
  1152. //Font size is ignored for now
  1153. if (isset($attr['COLOR']) and $attr['COLOR']!='')
  1154. {
  1155. $cor = ConvertColor($attr['COLOR']);
  1156. //If something goes wrong switch color to black
  1157. $cor['R'] = (isset($cor['R'])?$cor['R']:0);
  1158. $cor['G'] = (isset($cor['G'])?$cor['G']:0);
  1159. $cor['B'] = (isset($cor['B'])?$cor['B']:0);
  1160. $this->colorarray = $cor;
  1161. $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
  1162. $this->issetcolor = true;
  1163. }
  1164. if (isset($attr['FACE']) and in_array(strtolower($attr['FACE']), $this->fontlist))
  1165. {
  1166. $this->SetFont(strtolower($attr['FACE']));
  1167. $this->issetfont=true;
  1168. }
  1169. //'If' disabled in this version due lack of testing (you may enable it if you want)
  1170. // if (isset($attr['FACE']) and in_array(strtolower($attr['FACE']), $this->fontlist) and isset($attr['SIZE']) and $attr['SIZE']!='') {
  1171. // $this->SetFont(strtolower($attr['FACE']),'',$attr['SIZE']);
  1172. // $this->issetfont=true;
  1173. // }
  1174. break;
  1175. }//end of switch
  1176. $this->pjustfinished=false;
  1177. }
  1178. function CloseTag($tag)
  1179. {
  1180. //! @return void
  1181. //Closing tag
  1182. if($tag=='OPTION') $this->selectoptio…

Large files files are truncated, but you can click here to view the full file