PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_virtuemart/classes/pdf/html2fpdf.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 2926 lines | 2458 code | 94 blank | 374 comment | 553 complexity | b143a1b1e84efd8712ce08255eb401c1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

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

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

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