· 8 years ago · Nov 22, 2017, 01:52 PM
1<?php
2/*
3*** General-use version
4
5DEBUG HINT:
6- Inside function printbuffer make $fill=1
7- Inside function Cell make:
8if($fill==1 or $border==1)
9{
10// if ($fill==1) $op=($border==1) ? 'B' : 'f';
11// else $op='S';
12$op='S';
13- Following these 2 steps you will be able to see the cell's boundaries
14
15WARNING: When adding a new tag support, also add its name inside the function DisableTags()'s very long string
16
17ODDITIES (?):
18. It seems like saved['border'] and saved['bgcolor'] are useless inside the FlowingBlock...
19These 2 attributes do the same thing?!?:
20. $this->currentfont - mine
21. $this->CurrentFont - fpdf's
22
23TODO (in the future...):
24- Make font-family, font-size, lineheight customizable
25- Increase number of HTML/CSS tags/properties, Image/Font Types, recognized/supported
26- allow BMP support? (tried with http://phpthumb.sourceforge.net/ but failed)
27- Improve CSS support
28- support image side-by-side or one-below-another or both?
29- Improve code clarity even more (modularize and get better var names like on textbuffer array's indexes for example)
30
31//////////////////////////////////////////////////////////////////////////////
32//////////////DO NOT MODIFY THE CONTENTS OF THIS BOX//////////////////////////
33//////////////////////////////////////////////////////////////////////////////
34// //
35// HTML2FPDF is a php script to read a HTML text and generate a PDF file. //
36// Copyright (C) 2004-2005 Renato Coelho //
37// This script may be distributed as long as the following files are kept //
38// together: //
39// //
40// fpdf.php, html2fpdf.php, gif.php,htmltoolkit.php,license.txt,credits.txt //
41// //
42//////////////////////////////////////////////////////////////////////////////
43
44Misc. Observations:
45- CSS + align = bug! (?)
46OBS1: para textos de mais de 1 página, talvez tenha que juntar varios $texto_artigo
47antes de mandar gerar o PDF, para que o PDF gerado seja completo.
48OBS2: there are 2 types of spaces 32 and 160 (ascii values)
49OBS3: //! is a special comment to be used with source2doc.php, a script I created
50in order to generate the doc on the site html2fpdf.sf.net
51OBS4: var $LineWidth; // line width in user unit - use this to make css thin/medium/thick work
52OBS5: Images and Textareas: when they are inserted you can only type below them (==display:block)
53OBS6: Optimized to 'A4' paper (default font: Arial , normal , size 11 )
54OBS7: Regexp + Perl ([preg]accepts non-greedy quantifiers while PHP[ereg] does not)
55Perl: '/regexp/x' where x == option ( x = i:ignore case , x = s: DOT gets \n as well)
56========================END OF INITIAL COMMENTS=================================
57*/
58
59define('HTML2FPDF_VERSION','3.0(beta)');
60if (!defined('RELATIVE_PATH')) define('RELATIVE_PATH','');
61if (!defined('FPDF_FONTPATH')) define('FPDF_FONTPATH','font/');
62require_once(RELATIVE_PATH.'fpdf.php');
63require_once(RELATIVE_PATH.'htmltoolkit.php');
64
65class html2fpdf extends FPDF
66{
67//internal attributes
68var $HREF; //! string
69var $pgwidth; //! float
70var $fontlist; //! array
71var $issetfont; //! bool
72var $issetcolor; //! bool
73var $titulo; //! string
74var $oldx; //! float
75var $oldy; //! float
76var $B; //! int
77var $U; //! int
78var $I; //! int
79
80var $tablestart; //! bool
81var $tdbegin; //! bool
82var $table; //! array
83var $cell; //! array
84var $col; //! int
85var $row; //! int
86
87var $divbegin; //! bool
88var $divalign; //! char
89var $divwidth; //! float
90var $divheight; //! float
91var $divbgcolor; //! bool
92var $divcolor; //! bool
93var $divborder; //! int
94var $divrevert; //! bool
95
96var $listlvl; //! int
97var $listnum; //! int
98var $listtype; //! string
99//array(lvl,# of occurrences)
100var $listoccur; //! array
101//array(lvl,occurrence,type,maxnum)
102var $listlist; //! array
103//array(lvl,num,content,type)
104var $listitem; //! array
105
106var $buffer_on; //! bool
107var $pbegin; //! bool
108var $pjustfinished; //! bool
109var $blockjustfinished; //! bool
110var $SUP; //! bool
111var $SUB; //! bool
112var $toupper; //! bool
113var $tolower; //! bool
114var $dash_on; //! bool
115var $dotted_on; //! bool
116var $strike; //! bool
117
118var $CSS; //! array
119var $cssbegin; //! bool
120var $backupcss; //! array
121var $textbuffer; //! array
122var $currentstyle; //! string
123var $currentfont; //! string
124var $colorarray; //! array
125var $bgcolorarray; //! array
126var $internallink; //! array
127var $enabledtags; //! string
128
129var $lineheight; //! int
130var $basepath; //! string
131// array('COLOR','WIDTH','OLDWIDTH')
132var $outlineparam; //! array
133var $outline_on; //! bool
134
135var $specialcontent; //! string
136var $selectoption; //! array
137
138//options attributes
139var $usecss; //! bool
140var $usepre; //! bool
141var $usetableheader; //! bool
142var $shownoimg; //! bool
143//---Código inserido
144 private $pagInicial;
145 private $tipoBol;
146 private $nrBi;
147 private $dataBi;
148 private $pGradAssina;
149 private $militarAssina;
150 private $funcaoAssina;
151 private $boletim;
152
153 public function html2fpdf($orientation='P',$unit='mm',$format='a4')
154 //, $pagInicial, $tipoBol, $boletim,
155 // $pGradAssina, $militarAssina, $funcaoAssina, $boletim)
156 { FPDF::FPDF($orientation, $unit, $format);
157 $this->pagInicial = $pagInicial;
158 //$this->tipoBol = $tipoBol->getAbreviatura();
159 //Call parent constructor
160 $this->FPDF($orientation,$unit,$format);
161 //To make the function Footer() work properly
162 $this->AliasNbPages();
163 //Enable all tags as default
164 $this->DisableTags();
165 //Set default display preferences
166 $this->DisplayPreferences('');
167 //Initialization of the attributes
168 $this->SetFont('Times','',12); // Changeable?(not yet...)
169 $this->lineheight = 5; // Related to FontSizePt == 11
170 $this->pgwidth = $this->fw - ($this->lMargin + $this->rMargin) - 10 ;
171 $this->SetFillColor(255);
172 $this->HREF='';
173 $this->titulo='';
174 $this->oldx=-1;
175 $this->oldy=-1;
176 $this->B=0;
177 $this->U=0;
178 $this->I=0;
179
180 $this->listlvl=0;
181 $this->listnum=0;
182 $this->listtype='';
183 $this->listoccur=array();
184 $this->listlist=array();
185 $this->listitem=array();
186
187 $this->tablestart=false;
188 $this->tdbegin=false;
189 $this->table=array();
190 $this->cell=array();
191 $this->col=-1;
192 $this->row=-1;
193
194 $this->divbegin=false;
195 $this->divalign="L";
196 $this->divwidth=0;
197 $this->divheight=0;
198 $this->divbgcolor=false;
199 $this->divcolor=false;
200 $this->divborder=0;
201 $this->divrevert=false;
202
203 $this->fontlist=array("arial","times","courier","helvetica","symbol","monospace","serif","sans");
204 $this->issetfont=false;
205 $this->issetcolor=false;
206
207 $this->pbegin=false;
208 $this->pjustfinished=false;
209 $this->blockjustfinished = true; //in order to eliminate exceeding left-side spaces
210 $this->toupper=false;
211 $this->tolower=false;
212 $this->dash_on=false;
213 $this->dotted_on=false;
214 $this->SUP=false;
215 $this->SUB=false;
216 $this->buffer_on=false;
217 $this->strike=false;
218
219 $this->currentfont='';
220 $this->currentstyle='';
221 $this->colorarray=array();
222 $this->bgcolorarray=array();
223 $this->cssbegin=false;
224 $this->textbuffer=array();
225 $this->CSS=array();
226 $this->backupcss=array();
227 $this->internallink=array();
228
229 $this->basepath = "";
230
231 $this->outlineparam = array();
232 $this->outline_on = false;
233
234 $this->specialcontent = '';
235 $this->selectoption = array();
236
237 $this->shownoimg=false;
238 $this->usetableheader=false;
239 $this->usecss=true;
240 $this->usepre=true;
241}
242
243function setBasePath($str)
244{
245//! @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.
246//! @return void
247 $this->basepath = dirname($str) . "/";
248 $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
249}
250
251function ShowNOIMG_GIF($opt=true)
252{
253//! @desc Enable/Disable Displaying the no_img.gif when an image is not found. No-Parameter: Enable
254//! @return void
255 $this->shownoimg=$opt;
256}
257
258function UseCSS($opt=true)
259{
260//! @desc Enable/Disable CSS recognition. No-Parameter: Enable
261//! @return void
262 $this->usecss=$opt;
263}
264
265function UseTableHeader($opt=true)
266{
267//! @desc Enable/Disable Table Header to appear every new page. No-Parameter: Enable
268//! @return void
269 $this->usetableheader=$opt;
270}
271
272function UsePRE($opt=true)
273{
274//! @desc Enable/Disable pre tag recognition. No-Parameter: Enable
275//! @return void
276 $this->usepre=$opt;
277}
278
279//Page header
280function Header($content='')
281{
282/* $this->SetFont('Times','',12);
283 $this->SetY(15);
284 if ($this->PageNo() <> 1)
285 {
286 //Vai para 1.5 cm da borda superior
287 $this->SetY(6);
288 $this->Cell(150,5,'(Continuação do ' . $this->tipoBol . ' Nr ' . $this->nrBi . ', de ' . $this->dataBi .
289 ')',0,0,'L');
290 $this->Cell(30,5,'Pag Nr ' . ($this->PageNo()+ $this->pagInicial),0,0,'R');
291 $this->SetY(18);
292 }else{
293 $this->Cell(180,5,'Pag Nr ' . ($this->PageNo()+ $this->pagInicial),0,0,'R');
294 }
295*/
296//! @return void
297//! @desc The header is printed in every page.
298
299 /* Comentei o default ate ---
300 if($this->usetableheader and $content != '')
301 {
302 $y = $this->y;
303 foreach($content as $tableheader)
304 {
305 $this->y = $y;
306 //Set some cell values
307 $x = $tableheader['x'];
308 $w = $tableheader['w'];
309 $h = $tableheader['h'];
310 $va = $tableheader['va'];
311 $mih = $tableheader['mih'];
312 $fill = $tableheader['bgcolor'];
313 $border = $tableheader['border'];
314 $align = $tableheader['a'];
315 //Align
316 $this->divalign=$align;
317 $this->x = $x;
318 //Vertical align
319 if (!isset($va) || $va=='M') $this->y += ($h-$mih)/2;
320 elseif (isset($va) && $va=='B') $this->y += $h-$mih;
321 if ($fill)
322 {
323 $color = ConvertColor($fill);
324 $this->SetFillColor($color['R'],$color['G'],$color['B']);
325 $this->Rect($x, $y, $w, $h, 'F');
326 }
327 //Border
328 if (isset($border) and $border != 'all') $this->_tableRect($x, $y, $w, $h, $border);
329 elseif (isset($border) && $border == 'all') $this->Rect($x, $y, $w, $h);
330 //Print cell content
331 $this->divwidth = $w-2;
332 $this->divheight = 1.1*$this->lineheight;
333 $textbuffer = $tableheader['textbuffer'];
334 if (!empty($textbuffer)) $this->printbuffer($textbuffer,false,true);
335 $textbuffer = array();
336 }
337 $this->y = $y + $h; //Update y coordinate
338 }//end of 'if usetableheader ...' ----*/
339
340}
341
342//Page footer
343/*
344function Footer()
345{
346//! @return void
347//! @desc The footer is printed in every page!
348 //Position at 1.0 cm from bottom
349 $this->SetY(-10);
350 //Copyright //especial para esta versão
351 $this->SetFont('Times','B',12);
352 $this->SetTextColor(0);
353 //Arial italic 9
354 $this->SetFont('Arial','I',9);
355 //Page number
356 $this->Cell(0,10,$this->PageNo().'/{nb}',0,0,'C');
357 //Return Font to normal
358 $this->SetFont('Times','',12);
359} */
360
361private function imprimirCampoAssinatura($pGradAssina, $militarAssina, $funcaoAssina)
362 {
363 $linha = '_______';
364 $this->SetFont('Times','B',8);
365 if (($pGradAssina->getCodigo == 1) or ($pGradAssina->getCodigo == 2) or ($pGradAssina->getCodigo == 3))
366 { $texto = $pGradAssina->getDescricao() . ' ' . $militarAssina->getNome();
367 }
368 else
369 {
370 $texto = $militarAssina->getNome() . ' - ' . $pGradAssina->getDescricao();
371 }
372 while (round($this->GetStringWidth($linha)) < round($this->GetStringWidth($texto))+4)
373 { $linha = $linha.'_';
374 }
375 //1-imprimir linha centralizada para assinatura
376 $this->Cell(60,3,$linha,0,1,'C');
377
378 //2-imprimir posto/nome da autoridade que assina
379 $this->Cell(120,3,'',0,0,'C');
380 $this->Cell(60,3,$texto,0,1,'C');
381
382 //3-imprimir funcao da autoridade que assina
383 $this->SetFont('Times','',8);
384 $this->Cell(120,3,'',0,0,'C');
385 $this->Cell(60,3,$funcaoAssina->getDescricao(),0,1,'C');
386 $this->SetFont('Times','',12);
387 }
388
389
390function Footer()
391 {
392 //To be implemented in your own inherited class
393 //Vai para 1.5 cm da borda inferior
394 $this->SetLeftMargin(15);
395 $this->SetY(-20);
396/* //imprime o status do boletim
397 $this->SetFont('Times','',8);
398 if (($this->boletim->getAprovado() == "N") and ($this->boletim->getAssinado() == "N"))
399 { $this->Cell(90,5,'Boletim em elaboração! Gerado em ' . date('d/m/Y - H:i:s').'.',0,1,'L');
400 }else{
401 if ($this->boletim->getAssinado() == "N")
402 { $this->Cell(90,5,'Boletim aprovado e ainda não assinado! Gerado em ' . date('d/m/Y - H:i:s').'.',0,1,'L');
403 }else
404 { $this->Cell(90,5,'Gerado em '.date('d/m/Y - H:i:s').'.',0,1,'L');
405 }
406 }*/
407 if ($this->res){
408 $this->SetY(-10);
409 $this->SetFont('Times','B',12);
410 $this->SetTextColor(255,0,0);
411 $this->SetDrawColor(255,0,0);
412 $this->SetLineWidth(0.5);
413 $this->Cell(70,7,'',0,0,'L');
414 $this->Cell(40,7,'RESERVADO',1,0,'C');
415 $this->Cell(70,7,'',0,0,'L');
416 $this->SetTextColor(0,0,0);
417 $this->SetDrawColor(0,0,0);
418 $this->SetLineWidth(0.2);
419 }
420 $this->SetFont('Times','',12);
421 }
422
423///////////////////
424/// HTML parser ///
425///////////////////
426function WriteHTML($html)
427{
428//! @desc HTML parser
429//! @return void
430/* $e == content */
431
432 $this->ReadMetaTags($html);
433 $html = AdjustHTML($html,$this->usepre); //Try to make HTML look more like XHTML
434 if ($this->usecss) $html = $this->ReadCSS($html);
435 //Add new supported tags in the DisableTags function
436 $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word
437 $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string
438 //Explode the string in order to parse the HTML code
439 $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
440
441 foreach($a as $i => $e)
442 {
443
444 if($i%2==0)
445 {
446 //TEXT
447
448 //Adjust lineheight
449 // $this->lineheight = (5*$this->FontSizePt)/11; //should be inside printbuffer?
450 //Adjust text, if needed
451 if (strpos($e,"&") !== false) //HTML-ENTITIES decoding
452 {
453 if (strpos($e,"#") !== false) $e = value_entity_decode($e); // Decode value entities
454 //Avoid crashing the script on PHP 4.0
455 $version = phpversion();
456 $version = str_replace('.','',$version);
457 if ($version >= 430) $e = html_entity_decode($e,ENT_QUOTES,'cp1252'); // changes and the like by their respective char
458 else $e = lesser_entity_decode($e);
459 }
460 $e = str_replace(chr(160),chr(32),$e); //unify ascii code of spaces (in order to recognize all of them correctly)
461 if (strlen($e) == 0) continue;
462 if ($this->divrevert) $e = strrev($e);
463 if ($this->toupper) $e = strtoupper($e);
464 if ($this->tolower) $e = strtolower($e);
465 //Start of 'if/elseif's
466 if($this->titulo) $this->SetTitle($e);
467 elseif($this->specialcontent)
468 {
469 if ($this->specialcontent == "type=select" and $this->selectoption['ACTIVE'] == true) //SELECT tag (form element)
470 {
471 $stringwidth = $this->GetStringWidth($e);
472 if (!isset($this->selectoption['MAXWIDTH']) or $stringwidth > $this->selectoption['MAXWIDTH']) $this->selectoption['MAXWIDTH'] = $stringwidth;
473 if (!isset($this->selectoption['SELECTED']) or $this->selectoption['SELECTED'] == '') $this->selectoption['SELECTED'] = $e;
474 }
475 else $this->textbuffer[] = array("»¤¬"/*identifier*/.$this->specialcontent."»¤¬".$e);
476 }
477 elseif($this->tablestart)
478 {
479 if($this->tdbegin)
480 {
481 $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);
482 $this->cell[$this->row][$this->col]['text'][] = $e;
483 $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e);
484 }
485 //Ignore content between <table>,<tr> and a <td> tag (this content is usually only a bunch of spaces)
486 }
487 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
488 else
489 {
490 if ($this->blockjustfinished) $e = ltrim($e);
491 if ($e != '')
492 {
493 $this->Write($this->lineheight,$e); //Write text directly in the PDF
494 if ($this->pjustfinished) $this->pjustfinished = false;
495 }
496 }
497 }
498 else
499 {
500 //Tag
501 if($e{0}=='/') $this->CloseTag(strtoupper(substr($e,1)));
502 else
503 {
504 $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any
505 $e = preg_replace($regexp,"=\"\$1\"",$e);
506 $regexp = '| (\\w+?)=([^\\s>"]+)|si'; // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
507 $e = preg_replace($regexp," \$1=\"\$2\"",$e);
508 //Fix path values, if needed
509 if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) )
510 {
511 $regexp = '/ (href|src)="(.*?)"/i';
512 preg_match($regexp,$e,$auxiliararray);
513 $path = $auxiliararray[2];
514 $path = str_replace("\\","/",$path); //If on Windows
515 //Get link info and obtain its absolute path
516 $regexp = '|^./|';
517 $path = preg_replace($regexp,'',$path);
518 if($path{0} != '#') //It is not an Internal Link
519 {
520 if (strpos($path,"../") !== false ) //It is a Relative Link
521 {
522 $backtrackamount = substr_count($path,"../");
523 $maxbacktrack = substr_count($this->basepath,"/") - 1;
524 $filepath = str_replace("../",'',$path);
525 $path = $this->basepath;
526 //If it is an invalid relative link, then make it go to directory root
527 if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
528 //Backtrack some directories
529 for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
530 $path = $path . "/" . $filepath; //Make it an absolute path
531 }
532 elseif( strpos($path,":/") === false) //It is a Local Link
533 {
534 $path = $this->basepath . $path;
535 }
536 //Do nothing if it is an Absolute Link
537 }
538 $regexp = '/ (href|src)="(.*?)"/i';
539 $e = preg_replace($regexp,' \\1="'.$path.'"',$e);
540 }//END of Fix path values
541 //Extract attributes
542 $contents=array();
543 preg_match_all('/\\S*=["\'][^"\']*["\']/',$e,$contents);
544 preg_match('/\\S+/',$e,$a2);
545 $tag=strtoupper($a2[0]);
546 $attr=array();
547 if (!empty($contents))
548 {
549 foreach($contents[0] as $v)
550 {
551 if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
552 {
553 $attr[strtoupper($a3[1])]=$a3[2];
554 }
555 }
556 }
557 $this->OpenTag($tag,$attr);
558 }
559 }
560 }//end of foreach($a as $i=>$e)
561 //Create Internal Links, if needed
562 if (!empty($this->internallink) )
563 {
564 foreach($this->internallink as $k=>$v)
565 {
566 if (strpos($k,"#") !== false ) continue; //ignore
567 $ypos = $v['Y'];
568 $pagenum = $v['PAGE'];
569 $sharp = "#";
570 while (array_key_exists($sharp.$k,$this->internallink))
571 {
572 $internallink = $this->internallink[$sharp.$k];
573 $this->SetLink($internallink,$ypos,$pagenum);
574 $sharp .= "#";
575 }
576 }
577 }
578}
579
580function OpenTag($tag,$attr)
581{
582//! @return void
583// What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here>
584
585 $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','middle'=>'M','bottom'=>'B','justify'=>'J');
586
587 $this->blockjustfinished=false;
588 //Opening tag
589 switch($tag){
590 case 'PAGE_BREAK': //custom-tag
591 case 'NEWPAGE': //custom-tag
592 $this->blockjustfinished = true;
593 $this->AddPage();
594 break;
595 case 'OUTLINE': //custom-tag (CSS2 property - browsers don't support it yet - Jan2005)
596 //Usage: (default: width=normal color=white)
597 //<outline width="(thin|medium|thick)" color="(usualcolorformat)" >Text</outline>
598 //Mix this tag with the <font color="(usualcolorformat)"> tag to get mixed colors on outlined text!
599 $this->buffer_on = true;
600 if (isset($attr['COLOR'])) $this->outlineparam['COLOR'] = ConvertColor($attr['COLOR']);
601 else $this->outlineparam['COLOR'] = array('R'=>255,'G'=>255,'B'=>255); //white
602 $this->outlineparam['OLDWIDTH'] = $this->LineWidth;
603 if (isset($attr['WIDTH']))
604 {
605 switch(strtoupper($attr['WIDTH']))
606 {
607 case 'THIN': $this->outlineparam['WIDTH'] = 0.75*$this->LineWidth; break;
608 case 'MEDIUM': $this->outlineparam['WIDTH'] = $this->LineWidth; break;
609 case 'THICK': $this->outlineparam['WIDTH'] = 1.75*$this->LineWidth; break;
610 }
611 }
612 else $this->outlineparam['WIDTH'] = $this->LineWidth; //width == oldwidth
613 break;
614 case 'BDO':
615 if (isset($attr['DIR']) and (strtoupper($attr['DIR']) == 'RTL' )) $this->divrevert = true;
616 break;
617 case 'S':
618 case 'STRIKE':
619 case 'DEL':
620 $this->strike=true;
621 break;
622 case 'SUB':
623 $this->SUB=true;
624 break;
625 case 'SUP':
626 $this->SUP=true;
627 break;
628 case 'CENTER':
629 $this->buffer_on = true;
630 if ($this->tdbegin) $this->cell[$this->row][$this->col]['a'] = $align['center'];
631 else
632 {
633 $this->divalign = $align['center'];
634 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
635 }
636 break;
637 case 'ADDRESS':
638 $this->buffer_on = true;
639 $this->SetStyle('I',true);
640 if (!$this->tdbegin and $this->x != $this->lMargin) $this->Ln($this->lineheight);
641 break;
642 case 'TABLE': // TABLE-BEGIN
643 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
644 $this->tablestart = true;
645 $this->table['nc'] = $this->table['nr'] = 0;
646 if (isset($attr['REPEAT_HEADER']) and $attr['REPEAT_HEADER'] == true) $this->UseTableHeader(true);
647 if (isset($attr['WIDTH'])) $this->table['w'] = ConvertSize($attr['WIDTH'],$this->pgwidth) - 20;
648 if (isset($attr['HEIGHT'])) $this->table['h'] = ConvertSize($attr['HEIGHT'],$this->pgwidth);
649 if (isset($attr['ALIGN'])) $this->table['a'] = $align[strtolower($attr['ALIGN'])];
650 if (isset($attr['BORDER'])) $this->table['border'] = $attr['BORDER'];
651 if (isset($attr['BGCOLOR'])) $this->table['bgcolor'][-1] = $attr['BGCOLOR'];
652 break;
653 case 'TR':
654 $this->row++;
655 $this->table['nr']++;
656 $this->col = -1;
657 if (isset($attr['BGCOLOR']))$this->table['bgcolor'][$this->row] = $attr['BGCOLOR'];
658 break;
659 case 'TH':
660 $this->SetStyle('B',true);
661 if (!isset($attr['ALIGN'])) $attr['ALIGN'] = "center";
662 case 'TD':
663 $this->tdbegin = true;
664 $this->col++;
665 while (isset($this->cell[$this->row][$this->col])) $this->col++;
666 //Update number column
667 if ($this->table['nc'] < $this->col+1) $this->table['nc'] = $this->col+1;
668 $this->cell[$this->row][$this->col] = array();
669 $this->cell[$this->row][$this->col]['text'] = array();
670 $this->cell[$this->row][$this->col]['s'] = 3;
671 if (isset($attr['WIDTH'])) $this->cell[$this->row][$this->col]['w'] = ConvertSize($attr['WIDTH'],$this->pgwidth) - 20;
672 if (isset($attr['HEIGHT'])) $this->cell[$this->row][$this->col]['h'] = ConvertSize($attr['HEIGHT'],$this->pgwidth);
673 if (isset($attr['ALIGN'])) $this->cell[$this->row][$this->col]['a'] = $align[strtolower($attr['ALIGN'])];
674 if (isset($attr['VALIGN'])) $this->cell[$this->row][$this->col]['va'] = $align[strtolower($attr['VALIGN'])];
675 if (isset($attr['BORDER'])) $this->cell[$this->row][$this->col]['border'] = $attr['BORDER'];
676 if (isset($attr['BGCOLOR'])) $this->cell[$this->row][$this->col]['bgcolor'] = $attr['BGCOLOR'];
677 $cs = $rs = 1;
678 if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $this->cell[$this->row][$this->col]['colspan'] = $attr['COLSPAN'];
679 if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $this->cell[$this->row][$this->col]['rowspan'] = $attr['ROWSPAN'];
680 //Chiem dung vi tri de danh cho cell span (¿mais hein?)
681 for ($k=$this->row ; $k < $this->row+$rs ;$k++)
682 for($l=$this->col; $l < $this->col+$cs ;$l++)
683 {
684 if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0;
685 }
686 if (isset($attr['NOWRAP'])) $this->cell[$this->row][$this->col]['nowrap']= 1;
687 break;
688 case 'OL':
689 if ( !isset($attr['TYPE']) or $attr['TYPE'] == '' ) $this->listtype = '1'; //OL default == '1'
690 else $this->listtype = $attr['TYPE']; // ol and ul types are mixed here
691 case 'UL':
692 if ( (!isset($attr['TYPE']) or $attr['TYPE'] == '') and $tag=='UL')
693 {
694 //Insert UL defaults
695 if ($this->listlvl == 0) $this->listtype = 'disc';
696 elseif ($this->listlvl == 1) $this->listtype = 'circle';
697 else $this->listtype = 'square';
698 }
699 elseif (isset($attr['TYPE']) and $tag=='UL') $this->listtype = $attr['TYPE'];
700 $this->buffer_on = false;
701 if ($this->listlvl == 0)
702 {
703 //First of all, skip a line
704 if (!$this->pjustfinished)
705 {
706 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
707 $this->Ln($this->lineheight);
708 }
709 $this->oldx = $this->x;
710 $this->listlvl++; // first depth level
711 $this->listnum = 0; // reset
712 $this->listoccur[$this->listlvl] = 1;
713 $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
714 }
715 else
716 {
717 if (!empty($this->textbuffer))
718 {
719 $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
720 $this->listnum++;
721 }
722 $this->textbuffer = array();
723 $occur = $this->listoccur[$this->listlvl];
724 $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
725 $this->listlvl++;
726 $this->listnum = 0; // reset
727
728 if ($this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
729 else $this->listoccur[$this->listlvl]++;
730 $occur = $this->listoccur[$this->listlvl];
731 $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
732 }
733 break;
734 case 'LI':
735 //Observation: </LI> is ignored
736 if ($this->listlvl == 0) //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
737 {
738 //First of all, skip a line
739 if (!$this->pjustfinished and $this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
740 $this->oldx = $this->x;
741 $this->listlvl++; // first depth level
742 $this->listnum = 0; // reset
743 $this->listoccur[$this->listlvl] = 1;
744 $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
745 }
746 if ($this->listnum == 0)
747 {
748 $this->buffer_on = true; //activate list 'bufferization'
749 $this->listnum++;
750 $this->textbuffer = array();
751 }
752 else
753 {
754 $this->buffer_on = true; //activate list 'bufferization'
755 if (!empty($this->textbuffer))
756 {
757 $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
758 $this->listnum++;
759 }
760 $this->textbuffer = array();
761 }
762 break;
763 case 'H1': // 2 * fontsize
764 case 'H2': // 1.5 * fontsize
765 case 'H3': // 1.17 * fontsize
766 case 'H4': // 1 * fontsize
767 case 'H5': // 0.83 * fontsize
768 case 'H6': // 0.67 * fontsize
769 //Values obtained from: http://www.w3.org/TR/REC-CSS2/sample.html
770 if(isset($attr['ALIGN'])) $this->divalign = $align[strtolower($attr['ALIGN'])];
771 $this->buffer_on = true;
772 if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
773 elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
774 $this->SetStyle('B',true);
775 switch($tag)
776 {
777 case 'H1':
778 $this->SetFontSize(2*$this->FontSizePt);
779 $this->lineheight *= 2;
780 break;
781 case 'H2':
782 $this->SetFontSize(1.5*$this->FontSizePt);
783 $this->lineheight *= 1.5;
784 break;
785 case 'H3':
786 $this->SetFontSize(1.17*$this->FontSizePt);
787 $this->lineheight *= 1.17;
788 break;
789 case 'H4':
790 $this->SetFontSize($this->FontSizePt);
791 break;
792 case 'H5':
793 $this->SetFontSize(0.83*$this->FontSizePt);
794 $this->lineheight *= 0.83;
795 break;
796 case 'H6':
797 $this->SetFontSize(0.67*$this->FontSizePt);
798 $this->lineheight *= 0.67;
799 break;
800 }
801 break;
802 case 'HR': //Default values: width=100% align=center color=gray
803 //Skip a line, if needed
804 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
805 $this->Ln(0.2*$this->lineheight);
806 $hrwidth = $this->pgwidth;
807 $hralign = 'C';
808 $hrcolor = array('R'=>200,'G'=>200,'B'=>200);
809 if($attr['WIDTH'] != '') $hrwidth = ConvertSize($attr['WIDTH'],$this->pgwidth);
810 if($attr['ALIGN'] != '') $hralign = $align[strtolower($attr['ALIGN'])];
811 if($attr['COLOR'] != '') $hrcolor = ConvertColor($attr['COLOR']);
812 $this->SetDrawColor($hrcolor['R'],$hrcolor['G'],$hrcolor['B']);
813 $x = $this->x;
814 $y = $this->y;
815 switch($hralign)
816 {
817 case 'L':
818 case 'J':
819 break;
820 case 'C':
821 $empty = $this->pgwidth - $hrwidth;
822 $empty /= 2;
823 $x += $empty;
824 break;
825 case 'R':
826 $empty = $this->pgwidth - $hrwidth;
827 $x += $empty;
828 break;
829 }
830 $oldlinewidth = $this->LineWidth;
831 $this->SetLineWidth(0.3);
832 $this->Line($x,$y,$x+$hrwidth,$y);
833 $this->SetLineWidth($oldlinewidth);
834 $this->Ln(0.2*$this->lineheight);
835 $this->SetDrawColor(0);
836 $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
837 break;
838 case 'INS':
839 $this->SetStyle('U',true);
840 break;
841 case 'SMALL':
842 $newsize = $this->FontSizePt - 1;
843 $this->SetFontSize($newsize);
844 break;
845 case 'BIG':
846 $newsize = $this->FontSizePt + 1;
847 $this->SetFontSize($newsize);
848 case 'STRONG':
849 $this->SetStyle('B',true);
850 break;
851 case 'CITE':
852 case 'EM':
853 $this->SetStyle('I',true);
854 break;
855 case 'TITLE':
856 $this->titulo = true;
857 break;
858 case 'B':
859 case 'I':
860 case 'U':
861 if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
862 {
863 $this->cssbegin=true;
864 if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
865 elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
866 //Read Inline CSS
867 if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
868 //Look for name in the $this->CSS array
869 $this->backupcss = $properties;
870 if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
871 }
872 $this->SetStyle($tag,true);
873 break;
874 case 'A':
875 if (isset($attr['NAME']) and $attr['NAME'] != '') $this->textbuffer[] = array('','','',array(),'',false,false,$attr['NAME']); //an internal link (adds a space for recognition)
876 if (isset($attr['HREF'])) $this->HREF=$attr['HREF'];
877 break;
878 case 'DIV':
879 //in case of malformed HTML code. Example:(...)</div><li>Content</li><div>DIV1</div>(...)
880 if ($this->listlvl > 0) // We are closing (omitted) OL/UL tag(s)
881 {
882 $this->buffer_on = false;
883 if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
884 $this->textbuffer = array();
885 $this->listlvl--;
886 $this->printlistbuffer();
887 $this->pjustfinished = true; //act as if a paragraph just ended
888 }
889 $this->divbegin=true;
890 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
891 if( isset($attr['ALIGN']) and $attr['ALIGN'] != '' ) $this->divalign = $align[strtolower($attr['ALIGN'])];
892 if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
893 {
894 $this->cssbegin=true;
895 if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
896 elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
897 //Read Inline CSS
898 if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
899 //Look for name in the $this->CSS array
900 if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
901 }
902 break;
903 case 'IMG':
904 if(!empty($this->textbuffer) and !$this->tablestart)
905 {
906 //Output previously buffered content and output image below
907 //Set some default values
908 $olddivwidth = $this->divwidth;
909 $olddivheight = $this->divheight;
910 if ( $this->divwidth == 0) $this->divwidth = $this->pgwidth - $x + $this->lMargin;
911 if ( $this->divheight == 0) $this->divheight = $this->lineheight;
912 //Print content
913 $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
914 $this->textbuffer=array();
915 //Reset values
916 $this->divwidth = $olddivwidth;
917 $this->divheight = $olddivheight;
918 $this->textbuffer=array();
919 $this->Ln($this->lineheight);
920 }
921 if(isset($attr['SRC']))
922 {
923 $srcpath = $attr['SRC'];
924 if(!isset($attr['WIDTH'])) $attr['WIDTH'] = 0;
925 else $attr['WIDTH'] = ConvertSize($attr['WIDTH'],$this->pgwidth);//$attr['WIDTH'] /= 4;
926 if(!isset($attr['HEIGHT'])) $attr['HEIGHT'] = 0;
927 else $attr['HEIGHT'] = ConvertSize($attr['HEIGHT'],$this->pgwidth);//$attr['HEIGHT'] /= 4;
928 if ($this->tdbegin)
929 {
930 $bak_x = $this->x;
931 $bak_y = $this->y;
932 //Check whether image exists locally or on the URL
933 $f_exists = @fopen($srcpath,"rb");
934 if (!$f_exists) //Show 'image not found' icon instead
935 {
936 if(!$this->shownoimg) break;
937 $srcpath = str_replace("\\","/",dirname(__FILE__)) . "/";
938 $srcpath .= 'no_img.gif';
939 }
940 $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'','',false);
941 $this->y = $bak_y;
942 $this->x = $bak_x;
943 }
944 elseif($this->pbegin or $this->divbegin)
945 {
946 //In order to support <div align='center'><img ...></div>
947 $ypos = 0;
948 $bak_x = $this->x;
949 $bak_y = $this->y;
950 //Check whether image exists locally or on the URL
951 $f_exists = @fopen($srcpath,"rb");
952 if (!$f_exists) //Show 'image not found' icon instead
953 {
954 if(!$this->shownoimg) break;
955 $srcpath = str_replace("\\","/",dirname(__FILE__)) . "/";
956 $srcpath .= 'no_img.gif';
957 }
958 $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'','',false);
959 $this->y = $bak_y;
960 $this->x = $bak_x;
961 $xpos = '';
962 switch($this->divalign)
963 {
964 case "C":
965 $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
966 $empty = ($this->pgwidth - $sizesarray['WIDTH'])/2;
967 $xpos = 'xpos='.$empty.',';
968 break;
969 case "R":
970 $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
971 $empty = ($this->pgwidth - $sizesarray['WIDTH']);
972 $xpos = 'xpos='.$empty.',';
973 break;
974 default: break;
975 }
976 $numberoflines = (integer)ceil($sizesarray['HEIGHT']/$this->lineheight) ;
977 $ypos = $numberoflines * $this->lineheight;
978 $this->textbuffer[] = array("»¤¬"/*identifier*/."type=image,ypos=$ypos,{$xpos}width=".$sizesarray['WIDTH'].",height=".$sizesarray['HEIGHT']."»¤¬".$sizesarray['OUTPUT']);
979 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--;}
980 }
981 else
982 {
983 $imgborder = 0;
984 if (isset($attr['BORDER'])) $imgborder = ConvertSize($attr['BORDER'],$this->pgwidth);
985 //Check whether image exists locally or on the URL
986 $f_exists = @fopen($srcpath,"rb");
987 if (!$f_exists) //Show 'image not found' icon instead
988 {
989 $srcpath = str_replace("\\","/",dirname(__FILE__)) . "/";
990 $srcpath .= 'no_img.gif';
991 }
992 $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'',$this->HREF); //Output Image
993 $ini_x = $sizesarray['X'];
994 $ini_y = $sizesarray['Y'];
995 if ($imgborder)
996 {
997 $oldlinewidth = $this->LineWidth;
998 $this->SetLineWidth($imgborder);
999 $this->Rect($ini_x,$ini_y,$sizesarray['WIDTH'],$sizesarray['HEIGHT']);
1000 $this->SetLineWidth($oldlinewidth);
1001 }
1002 }
1003 if ($sizesarray['X'] < $this->x) $this->x = $this->lMargin;
1004 if ($this->tablestart)
1005 {
1006 $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=image,width=".$sizesarray['WIDTH'].",height=".$sizesarray['HEIGHT']."»¤¬".$sizesarray['OUTPUT']);
1007 $this->cell[$this->row][$this->col]['s'] += $sizesarray['WIDTH'] + 1;// +1 == margin
1008 $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
1009 if (!isset($this->cell[$this->row][$this->col]['w'])) $this->cell[$this->row][$this->col]['w'] = $sizesarray['WIDTH'] + 3;
1010 if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $sizesarray['HEIGHT'] + 3;
1011 }
1012 }
1013 break;
1014 case 'BLOCKQUOTE':
1015 $this->cell[$this->row][$this->col]['text'][] = " ";
1016 case 'BR':
1017 if($this->tablestart)
1018 {
1019 $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);
1020 $this->cell[$this->row][$this->col]['text'][] = "\n";
1021 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
1022 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
1023 $this->cell[$this->row][$this->col]['s'] = 0;// reset
1024 }
1025 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);
1026 else {$this->Ln($this->lineheight);$this->blockjustfinished = true;}
1027 break;
1028 case 'P':
1029 //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
1030 if ($this->listlvl > 0) // We are closing (omitted) OL/UL tag(s)
1031 {
1032 $this->buffer_on = false;
1033 if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
1034 $this->textbuffer = array();
1035 $this->listlvl--;
1036 $this->printlistbuffer();
1037 $this->pjustfinished = true; //act as if a paragraph just ended
1038 }
1039 if ($this->tablestart)
1040 {
1041 $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);
1042 $this->cell[$this->row][$this->col]['text'][] = "\n";
1043 break;
1044 }
1045 $this->pbegin=true;
1046 if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
1047 elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
1048 //Save x,y coords in case we need to print borders...
1049 $this->oldx = $this->x;
1050 $this->oldy = $this->y;
1051 if(isset($attr['ALIGN'])) $this->divalign = $align[strtolower($attr['ALIGN'])];
1052 if(isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
1053 {
1054 $this->cssbegin=true;
1055 if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
1056 elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
1057 //Read Inline CSS
1058 if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
1059 //Look for name in the $this->CSS array
1060 $this->backupcss = $properties;
1061 if (!empty($properties)) $this->setCSS($properties); //name(id/class/style) found in the CSS array!
1062 }
1063 break;
1064 case 'SPAN':
1065 $this->buffer_on = true;
1066 //Save x,y coords in case we need to print borders...
1067 $this->oldx = $this->x;
1068 $this->oldy = $this->y;
1069 if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
1070 {
1071 $this->cssbegin=true;
1072 if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
1073 elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
1074 //Read Inline CSS
1075 if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
1076 //Look for name in the $this->CSS array
1077 $this->backupcss = $properties;
1078 if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
1079 }
1080 break;
1081 case 'PRE':
1082 if($this->tablestart)
1083 {
1084 $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);
1085 $this->cell[$this->row][$this->col]['text'][] = "\n";
1086 }
1087 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);
1088 else
1089 {
1090 if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
1091 elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
1092 $this->buffer_on = true;
1093 //Save x,y coords in case we need to print borders...
1094 $this->oldx = $this->x;
1095 $this->oldy = $this->y;
1096 if(isset($attr['ALIGN'])) $this->divalign = $align[strtolower($attr['ALIGN'])];
1097 if(isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
1098 {
1099 $this->cssbegin=true;
1100 if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
1101 elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
1102 //Read Inline CSS
1103 if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
1104 //Look for name in the $this->CSS array
1105 $this->backupcss = $properties;
1106 if (!empty($properties)) $this->setCSS($properties); //name(id/class/style) found in the CSS array!
1107 }
1108 }
1109 case 'TT':
1110 case 'KBD':
1111 case 'SAMP':
1112 case 'CODE':
1113 $this->SetFont('courier');
1114 $this->currentfont='courier';
1115 break;
1116 case 'TEXTAREA':
1117 $this->buffer_on = true;
1118 $colsize = 20; //HTML default value
1119 $rowsize = 2; //HTML default value
1120 if (isset($attr['COLS'])) $colsize = $attr['COLS'];
1121 if (isset($attr['ROWS'])) $rowsize = $attr['ROWS'];
1122 if (!$this->tablestart)
1123 {
1124 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
1125 $this->col = $colsize;
1126 $this->row = $rowsize;
1127 }
1128 else //it is inside a table
1129 {
1130 $this->specialcontent = "type=textarea,lines=$rowsize,width=".((2.2*$colsize) + 3); //Activate form info in order to paint FORM elements within table
1131 $this->cell[$this->row][$this->col]['s'] += (2.2*$colsize) + 6;// +6 == margin
1132 if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = 1.1*$this->lineheight*$rowsize + 2.5;
1133 }
1134 break;
1135 case 'SELECT':
1136 $this->specialcontent = "type=select"; //Activate form info in order to paint FORM elements within table
1137 break;
1138 case 'OPTION':
1139 $this->selectoption['ACTIVE'] = true;
1140 if (empty($this->selectoption))
1141 {
1142 $this->selectoption['MAXWIDTH'] = '';
1143 $this->selectoption['SELECTED'] = '';
1144 }
1145 if (isset($attr['SELECTED'])) $this->selectoption['SELECTED'] = '';
1146 break;
1147 case 'FORM':
1148 if($this->tablestart)
1149 {
1150 $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);
1151 $this->cell[$this->row][$this->col]['text'][] = "\n";
1152 }
1153 elseif ($this->x != $this->lMargin) $this->Ln($this->lineheight); //Skip a line, if needed
1154 break;
1155 case 'INPUT':
1156 if (!isset($attr['TYPE'])) $attr['TYPE'] == ''; //in order to allow default 'TEXT' form (in case of malformed HTML code)
1157 if (!$this->tablestart)
1158 {
1159 switch(strtoupper($attr['TYPE'])){
1160 case 'CHECKBOX': //Draw Checkbox
1161 $checked = false;
1162 if (isset($attr['CHECKED'])) $checked = true;
1163 $this->SetFillColor(235,235,235);
1164 $this->x += 3;
1165 $this->Rect($this->x,$this->y+1,3,3,'DF');
1166 if ($checked)
1167 {
1168 $this->Line($this->x,$this->y+1,$this->x+3,$this->y+1+3);
1169 $this->Line($this->x,$this->y+1+3,$this->x+3,$this->y+1);
1170 }
1171 $this->SetFillColor(255);
1172 $this->x += 3.5;
1173 break;
1174 case 'RADIO': //Draw Radio button
1175 $checked = false;
1176 if (isset($attr['CHECKED'])) $checked = true;
1177 $this->x += 4;
1178 $this->Circle($this->x,$this->y+2.2,1,'D');
1179 $this->_out('0.000 g');
1180 if ($checked) $this->Circle($this->x,$this->y+2.2,0.4,'DF');
1181 $this->Write(5,$texto,$this->x);
1182 $this->x += 2;
1183 break;
1184 case 'BUTTON': // Draw a button
1185 case 'SUBMIT':
1186 case 'RESET':
1187 $texto='';
1188 if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
1189 $nihil = 2.5;
1190 $this->x += 2;
1191 $this->SetFillColor(190,190,190);
1192 $this->Rect($this->x,$this->y,$this->GetStringWidth($texto)+2*$nihil,4.5,'DF'); // 4.5 in order to avoid overlapping
1193 $this->x += $nihil;
1194 $this->Write(5,$texto,$this->x);
1195 $this->x += $nihil;
1196 $this->SetFillColor(255);
1197 break;
1198 case 'PASSWORD':
1199 if (isset($attr['VALUE']))
1200 {
1201 $num_stars = strlen($attr['VALUE']);
1202 $attr['VALUE'] = str_repeat('*',$num_stars);
1203 }
1204 case 'TEXT': //Draw TextField
1205 default: //default == TEXT
1206 $texto='';
1207 if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
1208 $tamanho = 20;
1209 if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $tamanho = $attr['SIZE'];
1210 $this->SetFillColor(235,235,235);
1211 $this->x += 2;
1212 $this->Rect($this->x,$this->y,2*$tamanho,4.5,'DF');// 4.5 in order to avoid overlapping
1213 if ($texto != '')
1214 {
1215 $this->x += 1;
1216 $this->Write(5,$texto,$this->x);
1217 $this->x -= $this->GetStringWidth($texto);
1218 }
1219 $this->SetFillColor(255);
1220 $this->x += 2*$tamanho;
1221 break;
1222 }
1223 }
1224 else //we are inside a table
1225 {
1226 $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
1227 $type = '';
1228 $text = '';
1229 $height = 0;
1230 $width = 0;
1231 switch(strtoupper($attr['TYPE'])){
1232 case 'CHECKBOX': //Draw Checkbox
1233 $checked = false;
1234 if (isset($attr['CHECKED'])) $checked = true;
1235 $text = $checked;
1236 $type = 'CHECKBOX';
1237 $width = 4;
1238 $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
1239 $this->cell[$this->row][$this->col]['s'] += $width;
1240 if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight;
1241 break;
1242 case 'RADIO': //Draw Radio button
1243 $checked = false;
1244 if (isset($attr['CHECKED'])) $checked = true;
1245 $text = $checked;
1246 $type = 'RADIO';
1247 $width = 3;
1248 $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
1249 $this->cell[$this->row][$this->col]['s'] += $width;
1250 if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight;
1251 break;
1252 case 'BUTTON': $type = 'BUTTON'; // Draw a button
1253 case 'SUBMIT': if ($type == '') $type = 'SUBMIT';
1254 case 'RESET': if ($type == '') $type = 'RESET';
1255 $texto='';
1256 if (isset($attr['VALUE'])) $texto = " " . $attr['VALUE'] . " ";
1257 $text = $texto;
1258 $width = $this->GetStringWidth($texto)+3;
1259 $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
1260 $this->cell[$this->row][$this->col]['s'] += $width;
1261 if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight + 2;
1262 break;
1263 case 'PASSWORD':
1264 if (isset($attr['VALUE']))
1265 {
1266 $num_stars = strlen($attr['VALUE']);
1267 $attr['VALUE'] = str_repeat('*',$num_stars);
1268 }
1269 $type = 'PASSWORD';
1270 case 'TEXT': //Draw TextField
1271 default: //default == TEXT
1272 $texto='';
1273 if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
1274 $tamanho = 20;
1275 if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $tamanho = $attr['SIZE'];
1276 $text = $texto;
1277 $width = 2*$tamanho;
1278 if ($type == '') $type = 'TEXT';
1279 $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
1280 $this->cell[$this->row][$this->col]['s'] += $width;
1281 if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight + 2;
1282 break;
1283 }
1284 }
1285 break;
1286 case 'FONT':
1287//Font size is ignored for now
1288 if (isset($attr['COLOR']) and $attr['COLOR']!='')
1289 {
1290 $cor = ConvertColor($attr['COLOR']);
1291 //If something goes wrong switch color to black
1292 $cor['R'] = (isset($cor['R'])?$cor['R']:0);
1293 $cor['G'] = (isset($cor['G'])?$cor['G']:0);
1294 $cor['B'] = (isset($cor['B'])?$cor['B']:0);
1295 $this->colorarray = $cor;
1296 $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
1297 $this->issetcolor = true;
1298 }
1299 if (isset($attr['FACE']) and in_array(strtolower($attr['FACE']), $this->fontlist))
1300 {
1301 $this->SetFont(strtolower($attr['FACE']));
1302 $this->issetfont=true;
1303 }
1304 //'If' disabled in this version due lack of testing (you may enable it if you want)
1305 if (isset($attr['FACE']) and in_array(strtolower($attr['FACE']), $this->fontlist) and isset($attr['SIZE']) and $attr['SIZE']!='') {
1306 $this->SetFont(strtolower($attr['FACE']),'',$attr['SIZE']);
1307 $this->issetfont=true;
1308 }
1309 break;
1310 }//end of switch
1311 $this->pjustfinished=false;
1312}
1313
1314function CloseTag($tag)
1315{
1316//! @return void
1317 //Closing tag
1318 if($tag=='OPTION') $this->selectoption['ACTIVE'] = false;
1319 if($tag=='BDO') $this->divrevert = false;
1320 if($tag=='INS') $tag='U';
1321 if($tag=='STRONG') $tag='B';
1322 if($tag=='EM' or $tag=='CITE') $tag='I';
1323 if($tag=='OUTLINE')
1324 {
1325 if(!$this->pbegin and !$this->divbegin and !$this->tablestart)
1326 {
1327 //Deactivate $this->outlineparam for its info is already stored inside $this->textbuffer
1328 //if (isset($this->outlineparam['OLDWIDTH'])) $this->SetTextOutline($this->outlineparam['OLDWIDTH']);
1329 $this->SetTextOutline(false);
1330 $this->outlineparam=array();
1331 //Save x,y coords ???
1332 $x = $this->x;
1333 $y = $this->y;
1334 //Set some default values
1335 $this->divwidth = $this->pgwidth - $x + $this->lMargin;
1336 //Print content
1337 $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
1338 $this->textbuffer=array();
1339 //Reset values
1340 $this->Reset();
1341 $this->buffer_on=false;
1342 }
1343 $this->SetTextOutline(false);
1344 $this->outlineparam=array();
1345 }
1346 if($tag=='A')
1347 {
1348 if(!$this->pbegin and !$this->divbegin and !$this->tablestart and !$this->buffer_on)
1349 {
1350 //Deactivate $this->HREF for its info is already stored inside $this->textbuffer
1351 $this->HREF='';
1352 //Save x,y coords ???
1353 $x = $this->x;
1354 $y = $this->y;
1355 //Set some default values
1356 $this->divwidth = $this->pgwidth - $x + $this->lMargin;
1357 //Print content
1358 $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
1359 $this->textbuffer=array();
1360 //Reset values
1361 $this->Reset();
1362 }
1363 $this->HREF='';
1364 }
1365 if($tag=='TH') $this->SetStyle('B',false);
1366 if($tag=='TH' or $tag=='TD') $this->tdbegin = false;
1367 if($tag=='SPAN')
1368 {
1369 if(!$this->pbegin and !$this->divbegin and !$this->tablestart)
1370 {
1371 if($this->cssbegin)
1372 {
1373 //Check if we have borders to print
1374 if ($this->cssbegin and ($this->divborder or $this->dash_on or $this->dotted_on or $this->divbgcolor))
1375 {
1376 $texto='';
1377 foreach($this->textbuffer as $vetor) $texto.=$vetor[0];
1378 $tempx = $this->x;
1379 if($this->divbgcolor) $this->Cell($this->GetStringWidth($texto),$this->lineheight,'',$this->divborder,'','L',$this->divbgcolor);
1380 if ($this->dash_on) $this->Rect($this->oldx,$this->oldy,$this->GetStringWidth($texto),$this->lineheight);
1381 if ($this->dotted_on) $this->DottedRect($this->x - $this->GetStringWidth($texto),$this->y,$this->GetStringWidth($texto),$this->lineheight);
1382 $this->x = $tempx;
1383 $this->x -= 1; //adjust alignment
1384 }
1385 $this->cssbegin=false;
1386 $this->backupcss=array();
1387 }
1388 //Save x,y coords ???
1389 $x = $this->x;
1390 $y = $this->y;
1391 //Set some default values
1392 $this->divwidth = $this->pgwidth - $x + $this->lMargin;
1393 //Print content
1394 $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
1395 $this->textbuffer=array();
1396 //Reset values
1397 $this->Reset();
1398 }
1399 $this->buffer_on=false;
1400 }
1401 if($tag=='P' or $tag=='DIV') //CSS in BLOCK mode
1402 {
1403 $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
1404 if(!$this->tablestart)
1405 {
1406 if ($this->divwidth == 0) $this->divwidth = $this->pgwidth;
1407 if ($tag=='P')
1408 {
1409 $this->pbegin=false;
1410 $this->pjustfinished=true;
1411 }
1412 else $this->divbegin=false;
1413 $content='';
1414 foreach($this->textbuffer as $aux) $content .= $aux[0];
1415 $numlines = $this->WordWrap($content,$this->divwidth);
1416 if ($this->divheight == 0) $this->divheight = $numlines * 5;
1417 //Print content
1418 $this->printbuffer($this->textbuffer);
1419 $this->textbuffer=array();
1420 if ($tag=='P') $this->Ln($this->lineheight);
1421 }//end of 'if (!this->tablestart)'
1422 //Reset values
1423 $this->Reset();
1424 $this->cssbegin=false;
1425 $this->backupcss=array();
1426 }
1427 if($tag=='TABLE') { // TABLE-END
1428 $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
1429 $this->table['cells'] = $this->cell;
1430 $this->table['wc'] = array_pad(array(),$this->table['nc'],array('miw'=>0,'maw'=>0));
1431 $this->table['hr'] = array_pad(array(),$this->table['nr'],0);
1432 $this->_tableColumnWidth($this->table);
1433 $this->_tableWidth($this->table);
1434 $this->_tableHeight($this->table);
1435
1436 //Output table on PDF
1437 $this->_tableWrite($this->table);
1438
1439 //Reset values
1440 $this->tablestart=false; //bool
1441 $this->table=array(); //array
1442 $this->cell=array(); //array
1443 $this->col=-1; //int
1444 $this->row=-1; //int
1445 $this->Reset();
1446 $this->Ln(0.5*$this->lineheight);
1447 }
1448 if(($tag=='UL') or ($tag=='OL')) {
1449 if ($this->buffer_on == false) $this->listnum--;//Adjust minor BUG (this happens when there are two </OL> together)
1450 if ($this->listlvl == 1) // We are closing the last OL/UL tag
1451 {
1452 $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
1453 $this->buffer_on = false;
1454 if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
1455 $this->textbuffer = array();
1456 $this->listlvl--;
1457 $this->printlistbuffer();
1458 }
1459 else // returning one level
1460 {
1461 if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
1462 $this->textbuffer = array();
1463 $occur = $this->listoccur[$this->listlvl];
1464 $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
1465 $this->listlvl--;
1466 $occur = $this->listoccur[$this->listlvl];
1467 $this->listnum = $this->listlist[$this->listlvl][$occur]['MAXNUM']; // recover previous level's number
1468 $this->listtype = $this->listlist[$this->listlvl][$occur]['TYPE']; // recover previous level's type
1469 $this->buffer_on = false;
1470 }
1471 }
1472 if($tag=='H1' or $tag=='H2' or $tag=='H3' or $tag=='H4' or $tag=='H5' or $tag=='H6')
1473 {
1474 $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
1475 if(!$this->pbegin and !$this->divbegin and !$this->tablestart)
1476 {
1477 //These 2 codelines are useless?
1478 $texto='';
1479 foreach($this->textbuffer as $vetor) $texto.=$vetor[0];
1480 //Save x,y coords ???
1481 $x = $this->x;
1482 $y = $this->y;
1483 //Set some default values
1484 $this->divwidth = $this->pgwidth;
1485 //Print content
1486 $this->printbuffer($this->textbuffer);
1487 $this->textbuffer=array();
1488 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
1489 //Reset values
1490 $this->Reset();
1491 }
1492 $this->buffer_on=false;
1493 $this->lineheight = 5;
1494 $this->Ln($this->lineheight);
1495 $this->SetFontSize(11);
1496 $this->SetStyle('B',false);
1497 }
1498 if($tag=='TITLE') {$this->titulo=false; $this->blockjustfinished = true;}
1499 if($tag=='FORM') $this->Ln($this->lineheight);
1500 if($tag=='PRE')
1501 {
1502 if(!$this->pbegin and !$this->divbegin and !$this->tablestart)
1503 {
1504 if ($this->divwidth == 0) $this->divwidth = $this->pgwidth;
1505 $content='';
1506 foreach($this->textbuffer as $aux) $content .= $aux[0];
1507 $numlines = $this->WordWrap($content,$this->divwidth);
1508 if ($this->divheight == 0) $this->divheight = $numlines * 5;
1509 //Print content
1510 $this->textbuffer[0][0] = ltrim($this->textbuffer[0][0]); //Remove exceeding left-side space
1511 $this->printbuffer($this->textbuffer);
1512 $this->textbuffer=array();
1513 if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
1514 //Reset values
1515 $this->Reset();
1516 $this->Ln(1.1*$this->lineheight);
1517 }
1518 if($this->tablestart)
1519 {
1520 $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);
1521 $this->cell[$this->row][$this->col]['text'][] = "\n";
1522 }
1523 if($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);
1524 $this->cssbegin=false;
1525 $this->backupcss=array();
1526 $this->buffer_on = false;
1527 $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
1528 $this->pjustfinished = true; //behaves the same way
1529 }
1530 if($tag=='CODE' or $tag=='PRE' or $tag=='TT' or $tag=='KBD' or $tag=='SAMP')
1531 {
1532 $this->currentfont='';
1533 $this->SetFont('Times');
1534 }
1535 if($tag=='B' or $tag=='I' or $tag=='U')
1536 {
1537 $this->SetStyle($tag,false);
1538 if ($this->cssbegin and !$this->divbegin and !$this->pbegin and !$this->buffer_on)
1539 {
1540 //Reset values
1541 $this->Reset();
1542 $this->cssbegin=false;
1543 $this->backupcss=array();
1544 }
1545 }
1546 if($tag=='TEXTAREA')
1547 {
1548 if (!$this->tablestart) //not inside a table
1549 {
1550 //Draw arrows too?
1551 $texto = '';
1552 foreach($this->textbuffer as $v) $texto .= $v[0];
1553 $this->SetFillColor(235,235,235);
1554 $this->SetFont('Times');
1555 $this->x +=3;
1556 $linesneeded = $this->WordWrap($texto,($this->col*2.2)+3);
1557 if ( $linesneeded > $this->row ) //Too many words inside textarea
1558 {
1559 $textoaux = explode("\n",$texto);
1560 $texto = '';
1561 for($i=0;$i < $this->row;$i++)
1562 {
1563 if ($i == $this->row-1) $texto .= $textoaux[$i];
1564 else $texto .= $textoaux[$i] . "\n";
1565 }
1566 //Inform the user that some text has been truncated
1567 $texto{strlen($texto)-1} = ".";
1568 $texto{strlen($texto)-2} = ".";
1569 $texto{strlen($texto)-3} = ".";
1570 }
1571 $backup_y = $this->y;
1572 $this->Rect($this->x,$this->y,(2.2*$this->col)+6,5*$this->row,'DF');
1573 if ($texto != '') $this->MultiCell((2.2*$this->col)+6,$this->lineheight,$texto);
1574 $this->y = $backup_y + $this->row*$this->lineheight;
1575 $this->SetFont('Times');
1576 }
1577 else //inside a table
1578 {
1579 $this->cell[$this->row][$this->col]['textbuffer'][] = $this->textbuffer[0];
1580 $this->cell[$this->row][$this->col]['text'][] = $this->textbuffer[0];
1581 $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
1582 $this->specialcontent = '';
1583 }
1584 $this->SetFillColor(255);
1585 $this->textbuffer=array();
1586 $this->buffer_on = false;
1587 }
1588 if($tag=='SELECT')
1589 {
1590 $texto = '';
1591 $tamanho = 0;
1592 if (isset($this->selectoption['MAXWIDTH'])) $tamanho = $this->selectoption['MAXWIDTH'];
1593 if ($this->tablestart)
1594 {
1595 $texto = "»¤¬".$this->specialcontent."»¤¬".$this->selectoption['SELECTED'];
1596 $aux = explode("»¤¬",$texto);
1597 $texto = $aux[2];
1598 $texto = "»¤¬".$aux[1].",width=$tamanho,height=".($this->lineheight + 2)."»¤¬".$texto;
1599 $this->cell[$this->row][$this->col]['s'] += $tamanho + 7; // margin + arrow box
1600 $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
1601
1602 if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight + 2;
1603 $this->cell[$this->row][$this->col]['textbuffer'][] = array($texto);
1604 $this->cell[$this->row][$this->col]['text'][] = '';
1605
1606 }
1607 else //not inside a table
1608 {
1609 $texto = $this->selectoption['SELECTED'];
1610 $this->SetFillColor(235,235,235);
1611 $this->x += 2;
1612 $this->Rect($this->x,$this->y,$tamanho+2,5,'DF');//+2 margin
1613 $this->x += 1;
1614 if ($texto != '') $this->Write(5,$texto,$this->x);
1615 $this->x += $tamanho - $this->GetStringWidth($texto) + 2;
1616 $this->SetFillColor(190,190,190);
1617 $this->Rect($this->x-1,$this->y,5,5,'DF'); //Arrow Box
1618 $this->SetFont('zapfdingbats');
1619 $this->Write(5,chr(116),$this->x); //Down arrow
1620 $this->SetFont('Times');
1621 $this->SetFillColor(255);
1622 $this->x += 1;
1623 }
1624 $this->selectoption = array();
1625 $this->specialcontent = '';
1626 $this->textbuffer = array();
1627 }
1628 if($tag=='SUB' or $tag=='SUP') //subscript or superscript
1629 {
1630 if(!$this->pbegin and !$this->divbegin and !$this->tablestart and !$this->buffer_on and !$this->strike)
1631 {
1632 //Deactivate $this->SUB/SUP for its info is already stored inside $this->textbuffer
1633 $this->SUB=false;
1634 $this->SUP=false;
1635 //Save x,y coords ???
1636 $x = $this->x;
1637 $y = $this->y;
1638 //Set some default values
1639 $this->divwidth = $this->pgwidth - $x + $this->lMargin;
1640 //Print content
1641 $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
1642 $this->textbuffer=array();
1643 //Reset values
1644 $this->Reset();
1645 }
1646 $this->SUB=false;
1647 $this->SUP=false;
1648 }
1649 if($tag=='S' or $tag=='STRIKE' or $tag=='DEL')
1650 {
1651 if(!$this->pbegin and !$this->divbegin and !$this->tablestart)
1652 {
1653 //Deactivate $this->strike for its info is already stored inside $this->textbuffer
1654 $this->strike=false;
1655 //Save x,y coords ???
1656 $x = $this->x;
1657 $y = $this->y;
1658 //Set some default values
1659 $this->divwidth = $this->pgwidth - $x + $this->lMargin;
1660 //Print content
1661 $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
1662 $this->textbuffer=array();
1663 //Reset values
1664 $this->Reset();
1665 }
1666 $this->strike=false;
1667 }
1668 if($tag=='ADDRESS' or $tag=='CENTER') // <ADDRESS> or <CENTER> tag
1669 {
1670 $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
1671 if(!$this->pbegin and !$this->divbegin and !$this->tablestart)
1672 {
1673 //Save x,y coords ???
1674 $x = $this->x;
1675 $y = $this->y;
1676 //Set some default values
1677 $this->divwidth = $this->pgwidth - $x + $this->lMargin;
1678 //Print content
1679 $this->printbuffer($this->textbuffer);
1680 $this->textbuffer=array();
1681 //Reset values
1682 $this->Reset();
1683 }
1684 $this->buffer_on=false;
1685 if ($tag == 'ADDRESS') $this->SetStyle('I',false);
1686 }
1687 if($tag=='BIG')
1688 {
1689 $newsize = $this->FontSizePt - 1;
1690 $this->SetFontSize($newsize);
1691 $this->SetStyle('B',false);
1692 }
1693 if($tag=='SMALL')
1694 {
1695 $newsize = $this->FontSizePt + 1;
1696 $this->SetFontSize($newsize);
1697 }
1698 if($tag=='FONT')
1699 {
1700 if ($this->issetcolor == true)
1701 {
1702 $this->colorarray = array();
1703 $this->SetTextColor(0);
1704 $this->issetcolor = false;
1705 }
1706 if ($this->issetfont)
1707 {
1708 $this->SetFont('Times');
1709 $this->issetfont=false;
1710 }
1711 if ($this->cssbegin)
1712 {
1713 //Get some attributes back!
1714 $this->setCSS($this->backupcss);
1715 }
1716 }
1717}
1718
1719function printlistbuffer()
1720{
1721//! @return void
1722//! @desc Prints all list-related buffered info
1723
1724 //Save x coordinate
1725 $x = $this->oldx;
1726 foreach($this->listitem as $item)
1727 {
1728 //Set default width & height values
1729 $this->divwidth = $this->pgwidth;
1730 $this->divheight = $this->lineheight;
1731 //Get list's buffered data
1732 $lvl = $item[0];
1733 $num = $item[1];
1734 $this->textbuffer = $item[2];
1735 $occur = $item[3];
1736 $type = $this->listlist[$lvl][$occur]['TYPE'];
1737 $maxnum = $this->listlist[$lvl][$occur]['MAXNUM'];
1738 switch($type) //Format type
1739 {
1740 case 'A':
1741 $num = dec2alpha($num,true);
1742 $maxnum = dec2alpha($maxnum,true);
1743 $type = str_pad($num,strlen($maxnum),' ',STR_PAD_LEFT) . ".";
1744 break;
1745 case 'a':
1746 $num = dec2alpha($num,false);
1747 $maxnum = dec2alpha($maxnum,false);
1748 $type = str_pad($num,strlen($maxnum),' ',STR_PAD_LEFT) . ".";
1749 break;
1750 case 'I':
1751 $num = dec2roman($num,true);
1752 $maxnum = dec2roman($maxnum,true);
1753 $type = str_pad($num,strlen($maxnum),' ',STR_PAD_LEFT) . ".";
1754 break;
1755 case 'i':
1756 $num = dec2roman($num,false);
1757 $maxnum = dec2roman($maxnum,false);
1758 $type = str_pad($num,strlen($maxnum),' ',STR_PAD_LEFT) . ".";
1759 break;
1760 case '1':
1761 $type = str_pad($num,strlen($maxnum),' ',STR_PAD_LEFT) . ".";
1762 break;
1763 case 'disc':
1764 $type = chr(149);
1765 break;
1766 case 'square':
1767 $type = chr(110); //black square on Zapfdingbats font
1768 break;
1769 case 'circle':
1770 $type = chr(186);
1771 break;
1772 default: break;
1773 }
1774 $this->x = (5*$lvl) + $x; //Indent list
1775 //Get bullet width including margins
1776 $oldsize = $this->FontSize * $this->k;
1777 if ($type == chr(110)) $this->SetFont('zapfdingbats','',5);
1778 $type .= ' ';
1779 $blt_width = $this->GetStringWidth($type)+$this->cMargin*2;
1780 //Output bullet
1781 $this->Cell($blt_width,5,$type,'','','L');
1782 $this->SetFont('Times','',$oldsize);
1783 $this->divwidth = $this->divwidth + $this->lMargin - $this->x;
1784 //Print content
1785 $this->printbuffer($this->textbuffer);
1786 $this->textbuffer=array();
1787 }
1788 //Reset all used values
1789 $this->listoccur = array();
1790 $this->listitem = array();
1791 $this->listlist = array();
1792 $this->listlvl = 0;
1793 $this->listnum = 0;
1794 $this->listtype = '';
1795 $this->textbuffer = array();
1796 $this->divwidth = 0;
1797 $this->divheight = 0;
1798 $this->oldx = -1;
1799 //At last, but not least, skip a line
1800 $this->Ln($this->lineheight);
1801}
1802
1803function printbuffer($arrayaux,$outofblock=false,$is_table=false)
1804{
1805//! @return headache
1806//! @desc Prepares buffered text to be printed with FlowingBlock()
1807
1808 //Save some previous parameters
1809 $save = array();
1810 $save['strike'] = $this->strike;
1811 $save['SUP'] = $this->SUP;
1812 $save['SUB'] = $this->SUB;
1813 $save['DOTTED'] = $this->dotted_on;
1814 $save['DASHED'] = $this->dash_on;
1815 $this->SetDash(); //restore to no dash
1816 $this->dash_on = false;
1817 $this->dotted_on = false;
1818
1819 $bak_y = $this->y;
1820 $bak_x = $this->x;
1821 $align = $this->divalign;
1822 $oldpage = $this->page;
1823
1824 //Overall object size == $old_height
1825 //Line height == $this->divheight
1826 $old_height = $this->divheight;
1827 if ($is_table)
1828 {
1829 $this->divheight = 1.1*$this->lineheight;
1830 $fill = 0;
1831 }
1832 else
1833 {
1834 $this->divheight = $this->lineheight;
1835 if ($this->FillColor == '1.000 g') $fill = 0; //avoid useless background painting (1.000 g == white background color)
1836 else $fill = 1;
1837 }
1838
1839 $this->newFlowingBlock( $this->divwidth,$this->divheight,$this->divborder,$align,$fill,$is_table);
1840
1841 $array_size = count($arrayaux);
1842 for($i=0;$i < $array_size; $i++)
1843 {
1844 $vetor = $arrayaux[$i];
1845 if ($i == 0 and $vetor[0] != "\n") $vetor[0] = ltrim($vetor[0]);
1846 if (empty($vetor[0]) and empty($vetor[7])) continue; //Ignore empty text and not carrying an internal link
1847 //Activating buffer properties
1848 if(isset($vetor[10]) and !empty($vetor[10])) //Background color
1849 {
1850 $cor = $vetor[10];
1851 $this->SetFillColor($cor['R'],$cor['G'],$cor['B']);
1852 $this->divbgcolor = true;
1853 }
1854 if(isset($vetor[9]) and !empty($vetor[9])) // Outline parameters
1855 {
1856 $cor = $vetor[9]['COLOR'];
1857 $outlinewidth = $vetor[9]['WIDTH'];
1858 $this->SetTextOutline($outlinewidth,$cor['R'],$cor['G'],$cor['B']);
1859 $this->outline_on = true;
1860 }
1861 if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text
1862 {
1863 $this->strike = true;
1864 }
1865 if(isset($vetor[7]) and $vetor[7] != '') // internal link: <a name="anyvalue">
1866 {
1867 $this->internallink[$vetor[7]] = array("Y"=>$this->y,"PAGE"=>$this->page );
1868 $this->Bookmark($vetor[7]." (pg. $this->page)",0,$this->y);
1869 if (empty($vetor[0])) continue; //Ignore empty text
1870 }
1871 if(isset($vetor[6]) and $vetor[6] === true) // Subscript
1872 {
1873 $this->SUB = true;
1874 $this->SetFontSize(6);
1875 }
1876 if(isset($vetor[5]) and $vetor[5] === true) // Superscript
1877 {
1878 $this->SUP = true;
1879 $this->SetFontSize(6);
1880 }
1881 if(isset($vetor[4]) and $vetor[4] != '') $this->SetFont($vetor[4]); // Font Family
1882 if (!empty($vetor[3])) //Font Color
1883 {
1884 $cor = $vetor[3];
1885 $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
1886 }
1887 if(isset($vetor[2]) and $vetor[2] != '') //Bold,Italic,Underline styles
1888 {
1889 if (strpos($vetor[2],"B") !== false) $this->SetStyle('B',true);
1890 if (strpos($vetor[2],"I") !== false) $this->SetStyle('I',true);
1891 if (strpos($vetor[2],"U") !== false) $this->SetStyle('U',true);
1892 }
1893 if(isset($vetor[1]) and $vetor[1] != '') //LINK
1894 {
1895 if (strpos($vetor[1],".") === false) //assuming every external link has a dot indicating extension (e.g: .html .txt .zip www.somewhere.com etc.)
1896 {
1897 //Repeated reference to same anchor?
1898 while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
1899 $this->internallink[$vetor[1]] = $this->AddLink();
1900 $vetor[1] = $this->internallink[$vetor[1]];
1901 }
1902 $this->HREF = $vetor[1];
1903 $this->SetTextColor(0,0,255);
1904 $this->SetStyle('U',true);
1905 }
1906 //Print-out special content
1907 if (isset($vetor[0]) and $vetor[0]{0} == '»' and $vetor[0]{1} == '¤' and $vetor[0]{2} == '¬') //identifier has been identified!
1908 {
1909 $content = explode("»¤¬",$vetor[0]);
1910 $texto = $content[2];
1911 $content = explode(",",$content[1]);
1912 foreach($content as $value)
1913 {
1914 $value = explode("=",$value);
1915 $specialcontent[$value[0]] = $value[1];
1916 }
1917 if ($this->flowingBlockAttr[ 'contentWidth' ] > 0) // Print out previously accumulated content
1918 {
1919 $width_used = $this->flowingBlockAttr[ 'contentWidth' ] / $this->k;
1920 //Restart Flowing Block
1921 $this->finishFlowingBlock($outofblock);
1922 $this->x = $bak_x + ($width_used % $this->divwidth) + 0.5;// 0.5 == margin
1923 $this->y -= ($this->lineheight + 0.5);
1924 $extrawidth = 0; //only to be used in case $specialcontent['width'] does not contain all used width (e.g. Select Box)
1925 if ($specialcontent['type'] == 'select') $extrawidth = 7; //arrow box + margin
1926 if(($this->x - $bak_x) + $specialcontent['width'] + $extrawidth > $this->divwidth )
1927 {
1928 $this->x = $bak_x;
1929 $this->y += $this->lineheight - 1;
1930 }
1931 $this->newFlowingBlock( $this->divwidth,$this->divheight,$this->divborder,$align,$fill,$is_table );
1932 }
1933 switch(strtoupper($specialcontent['type']))
1934 {
1935 case 'IMAGE':
1936 //xpos and ypos used in order to support: <div align='center'><img ...></div>
1937 $xpos = 0;
1938 $ypos = 0;
1939 if (isset($specialcontent['ypos']) and $specialcontent['ypos'] != '') $ypos = (float)$specialcontent['ypos'];
1940 if (isset($specialcontent['xpos']) and $specialcontent['xpos'] != '') $xpos = (float)$specialcontent['xpos'];
1941 $width_used = (($this->x - $bak_x) + $specialcontent['width'])*$this->k; //in order to adjust x coordinate later
1942 //Is this the best way of fixing x,y coordinates?
1943 $fix_x = ($this->x+2) * $this->k + ($xpos*$this->k); //+2 margin
1944 $fix_y = ($this->h - (($this->y+2) + $specialcontent['height'])) * $this->k;//+2 margin
1945 $imgtemp = explode(" ",$texto);
1946 $imgtemp[5]=$fix_x; // x
1947 $imgtemp[6]=$fix_y; // y
1948 $texto = implode(" ",$imgtemp);
1949 $this->_out($texto);
1950 //Readjust x coordinate in order to allow text to be placed after this form element
1951 $this->x = $bak_x;
1952 $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
1953 $spacenum = (integer)ceil(($width_used / $spacesize));
1954 //Consider the space used so far in this line as a bunch of spaces
1955 if ($ypos != 0) $this->Ln($ypos);
1956 else $this->WriteFlowingBlock(str_repeat(' ',$spacenum));
1957 break;
1958 case 'INPUT':
1959 switch($specialcontent['subtype'])
1960 {
1961 case 'PASSWORD':
1962 case 'TEXT': //Draw TextField
1963 $width_used = (($this->x - $bak_x) + $specialcontent['width'])*$this->k; //in order to adjust x coordinate later
1964 $this->SetFillColor(235,235,235);
1965 $this->x += 1;
1966 $this->y += 1;
1967 $this->Rect($this->x,$this->y,$specialcontent['width'],4.5,'DF');// 4.5 in order to avoid overlapping
1968 if ($texto != '')
1969 {
1970 $this->x += 1;
1971 $this->Write(5,$texto,$this->x);
1972 $this->x -= $this->GetStringWidth($texto);
1973 }
1974 $this->SetFillColor(255);
1975 $this->y -= 1;
1976 //Readjust x coordinate in order to allow text to be placed after this form element
1977 $this->x = $bak_x;
1978 $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
1979 $spacenum = (integer)ceil(($width_used / $spacesize));
1980 //Consider the space used so far in this line as a bunch of spaces
1981 $this->WriteFlowingBlock(str_repeat(' ',$spacenum));
1982 break;
1983 case 'CHECKBOX': //Draw Checkbox
1984 $width_used = (($this->x - $bak_x) + $specialcontent['width'])*$this->k; //in order to adjust x coordinate later
1985 $checked = $texto;
1986 $this->SetFillColor(235,235,235);
1987 $this->y += 1;
1988 $this->x += 1;
1989 $this->Rect($this->x,$this->y,3,3,'DF');
1990 if ($checked)
1991 {
1992 $this->Line($this->x,$this->y,$this->x+3,$this->y+3);
1993 $this->Line($this->x,$this->y+3,$this->x+3,$this->y);
1994 }
1995 $this->SetFillColor(255);
1996 $this->y -= 1;
1997 //Readjust x coordinate in order to allow text to be placed after this form element
1998 $this->x = $bak_x;
1999 $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
2000 $spacenum = (integer)ceil(($width_used / $spacesize));
2001 //Consider the space used so far in this line as a bunch of spaces
2002 $this->WriteFlowingBlock(str_repeat(' ',$spacenum));
2003 break;
2004 case 'RADIO': //Draw Radio button
2005 $width_used = (($this->x - $bak_x) + $specialcontent['width']+0.5)*$this->k; //in order to adjust x coordinate later
2006 $checked = $texto;
2007 $this->x += 2;
2008 $this->y += 1.5;
2009 $this->Circle($this->x,$this->y+1.2,1,'D');
2010 $this->_out('0.000 g');
2011 if ($checked) $this->Circle($this->x,$this->y+1.2,0.4,'DF');
2012 $this->y -= 1.5;
2013 //Readjust x coordinate in order to allow text to be placed after this form element
2014 $this->x = $bak_x;
2015 $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
2016 $spacenum = (integer)ceil(($width_used / $spacesize));
2017 //Consider the space used so far in this line as a bunch of spaces
2018 $this->WriteFlowingBlock(str_repeat(' ',$spacenum));
2019 break;
2020 case 'BUTTON': // Draw a button
2021 case 'SUBMIT':
2022 case 'RESET':
2023 $nihil = ($specialcontent['width']-$this->GetStringWidth($texto))/2;
2024 $this->x += 1.5;
2025 $this->y += 1;
2026 $this->SetFillColor(190,190,190);
2027 $this->Rect($this->x,$this->y,$specialcontent['width'],4.5,'DF'); // 4.5 in order to avoid overlapping
2028 $this->x += $nihil;
2029 $this->Write(5,$texto,$this->x);
2030 $this->x += $nihil;
2031 $this->SetFillColor(255);
2032 $this->y -= 1;
2033 break;
2034 default: break;
2035 }
2036 break;
2037 case 'SELECT':
2038 $width_used = (($this->x - $bak_x) + $specialcontent['width'] + 8)*$this->k; //in order to adjust x coordinate later
2039 $this->SetFillColor(235,235,235); //light gray
2040 $this->x += 1.5;
2041 $this->y += 1;
2042 $this->Rect($this->x,$this->y,$specialcontent['width']+2,$this->lineheight,'DF'); // +2 == margin
2043 $this->x += 1;
2044 if ($texto != '') $this->Write($this->lineheight,$texto,$this->x); //the combobox content
2045 $this->x += $specialcontent['width'] - $this->GetStringWidth($texto) + 2;
2046 $this->SetFillColor(190,190,190); //dark gray
2047 $this->Rect($this->x-1,$this->y,5,5,'DF'); //Arrow Box
2048 $this->SetFont('zapfdingbats');
2049 $this->Write($this->lineheight,chr(116),$this->x); //Down arrow
2050 $this->SetFont('Times');
2051 $this->SetFillColor(255);
2052 //Readjust x coordinate in order to allow text to be placed after this form element
2053 $this->x = $bak_x;
2054 $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
2055 $spacenum = (integer)ceil(($width_used / $spacesize));
2056 //Consider the space used so far in this line as a bunch of spaces
2057 $this->WriteFlowingBlock(str_repeat(' ',$spacenum));
2058 break;
2059 case 'TEXTAREA':
2060 //Setup TextArea properties
2061 $this->SetFillColor(235,235,235);
2062 $this->SetFont('courier');
2063 $this->currentfont='courier';
2064 $ta_lines = $specialcontent['lines'];
2065 $ta_height = 1.1*$this->lineheight*$ta_lines;
2066 $ta_width = $specialcontent['width'];
2067 //Adjust x,y coordinates
2068 $this->x += 1.5;
2069 $this->y += 1.5;
2070 $linesneeded = $this->WordWrap($texto,$ta_width);
2071 if ( $linesneeded > $ta_lines ) //Too many words inside textarea
2072 {
2073 $textoaux = explode("\n",$texto);
2074 $texto = '';
2075 for($i=0;$i<$ta_lines;$i++)
2076 {
2077 if ($i == $ta_lines-1) $texto .= $textoaux[$i];
2078 else $texto .= $textoaux[$i] . "\n";
2079 }
2080 //Inform the user that some text has been truncated
2081 $texto{strlen($texto)-1} = ".";
2082 $texto{strlen($texto)-2} = ".";
2083 $texto{strlen($texto)-3} = ".";
2084 }
2085 $backup_y = $this->y;
2086 $backup_x = $this->x;
2087 $this->Rect($this->x,$this->y,$ta_width+3,$ta_height,'DF');
2088 if ($texto != '') $this->MultiCell($ta_width+3,$this->lineheight,$texto);
2089 $this->y = $backup_y - 1.5;
2090 $this->x = $backup_x + $ta_width + 2.5;
2091 $this->SetFillColor(255);
2092 $this->SetFont('Times');
2093 $this->currentfont='';
2094 break;
2095 default: break;
2096 }
2097 }
2098 else //THE text
2099 {
2100 if ($vetor[0] == "\n") //We are reading a <BR> now turned into newline ("\n")
2101 {
2102 //Restart Flowing Block
2103 $this->finishFlowingBlock($outofblock);
2104 if($outofblock) $this->Ln($this->lineheight);
2105 $this->x = $bak_x;
2106 $this->newFlowingBlock( $this->divwidth,$this->divheight,$this->divborder,$align,$fill,$is_table );
2107 }
2108 else $this->WriteFlowingBlock( $vetor[0] , $outofblock );
2109 }
2110 //Check if it is the last element. If so then finish printing the block
2111 if ($i == ($array_size-1)) $this->finishFlowingBlock($outofblock);
2112 //Now we must deactivate what we have used
2113 if( (isset($vetor[1]) and $vetor[1] != '') or $this->HREF != '')
2114 {
2115 $this->SetTextColor(0);
2116 $this->SetStyle('U',false);
2117 $this->HREF = '';
2118 }
2119 if(isset($vetor[2]) and $vetor[2] != '')
2120 {
2121 $this->SetStyle('B',false);
2122 $this->SetStyle('I',false);
2123 $this->SetStyle('U',false);
2124 }
2125 if(isset($vetor[3]) and $vetor[3] != '')
2126 {
2127 unset($cor);
2128 $this->SetTextColor(0);
2129 }
2130 if(isset($vetor[4]) and $vetor[4] != '') $this->SetFont('Times');
2131 if(isset($vetor[5]) and $vetor[5] === true)
2132 {
2133 $this->SUP = false;
2134 $this->SetFontSize(11);
2135 }
2136 if(isset($vetor[6]) and $vetor[6] === true)
2137 {
2138 $this->SUB = false;
2139 $this->SetFontSize(11);
2140 }
2141 //vetor7-internal links
2142 if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text
2143 {
2144 $this->strike = false;
2145 }
2146 if(isset($vetor[9]) and !empty($vetor[9])) // Outline parameters
2147 {
2148 $this->SetTextOutline(false);
2149 $this->outline_on = false;
2150 }
2151 if(isset($vetor[10]) and !empty($vetor[10])) //Background color
2152 {
2153 $this->SetFillColor(255);
2154 $this->divbgcolor = false;
2155 }
2156 }//end of for(i=0;i<arraysize;i++)
2157
2158 //Restore some previously set parameters
2159 $this->strike = $save['strike'];
2160 $this->SUP = $save['SUP'];
2161 $this->SUB = $save['SUB'];
2162 $this->dotted_on = $save['DOTTED'];
2163 $this->dash_on = $save['DASHED'];
2164 if ($this->dash_on) $this->SetDash(2,2);
2165 //Check whether we have borders to paint or not
2166 //(only works 100% if whole content spans only 1 page)
2167 if ($this->cssbegin and ($this->divborder or $this->dash_on or $this->dotted_on or $this->divbgcolor))
2168 {
2169 if ($oldpage != $this->page)
2170 {
2171 //Only border on last page is painted (known bug)
2172 $x = $this->lMargin;
2173 $y = $this->tMargin;
2174 $old_height = $this->y - $y;
2175 }
2176 else
2177 {
2178 if ($this->oldx < 0) $x = $this->x;
2179 else $x = $this->oldx;
2180 if ($this->oldy < 0) $y = $this->y - $old_height;
2181 else $y = $this->oldy;
2182 }
2183 if ($this->divborder) $this->Rect($x,$y,$this->divwidth,$old_height);
2184 if ($this->dash_on) $this->Rect($x,$y,$this->divwidth,$old_height);
2185 if ($this->dotted_on) $this->DottedRect($x,$y,$this->divwidth,$old_height);
2186 $this->x = $bak_x;
2187 }
2188}
2189
2190function Reset()
2191{
2192//! @return void
2193//! @desc Resets several class attributes
2194
2195// if ( $this->issetcolor !== true )
2196// {
2197 $this->SetTextColor(0);
2198 $this->SetDrawColor(0);
2199 $this->SetFillColor(255);
2200 $this->colorarray = array();
2201 $this->bgcolorarray = array();
2202$this->issetcolor = false;
2203// }
2204$this->HREF = '';
2205$this->SetTextOutline(false);
2206
2207//$this->strike = false;
2208
2209 $this->SetFontSize(11);
2210 $this->SetStyle('B',false);
2211 $this->SetStyle('I',false);
2212 $this->SetStyle('U',false);
2213 $this->SetFont('');
2214// $this->SetFont('Times');
2215 $this->divwidth = 0;
2216 $this->divheight = 0;
2217 $this->divalign = "L";
2218 $this->divrevert = false;
2219 $this->divborder = 0;
2220 $this->divbgcolor = false;
2221 $this->toupper = false;
2222 $this->tolower = false;
2223 $this->SetDash(); //restore to no dash
2224 $this->dash_on = false;
2225 $this->dotted_on = false;
2226 $this->oldx = -1;
2227 $this->oldy = -1;
2228}
2229
2230function ReadMetaTags($html)
2231{
2232//! @return void
2233//! @desc Pass meta tag info to PDF file properties
2234 $regexp = '/ (\\w+?)=([^\\s>"]+)/si'; // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
2235 $html = preg_replace($regexp," \$1=\"\$2\"",$html);
2236 $regexp = '/<meta .*?(name|content)="(.*?)" .*?(name|content)="(.*?)".*?>/si';
2237 preg_match_all($regexp,$html,$aux);
2238
2239 $firstattr = $aux[1];
2240 $secondattr = $aux[3];
2241 for( $i = 0 ; $i < count($aux[0]) ; $i++)
2242 {
2243
2244 $name = ( strtoupper($firstattr[$i]) == "NAME" )? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]);
2245 $content = ( strtoupper($firstattr[$i]) == "CONTENT" )? $aux[2][$i] : $aux[4][$i];
2246 switch($name)
2247 {
2248 case "KEYWORDS": $this->SetKeywords($content); break;
2249 case "AUTHOR": $this->SetAuthor($content); break;
2250 case "DESCRIPTION": $this->SetSubject($content); break;
2251 }
2252 }
2253 //Comercial do Aplicativo usado (no caso um script):
2254 $this->SetCreator("HTML2FPDF >> http://html2fpdf.sf.net");
2255}
2256
2257//////////////////
2258/// CSS parser ///
2259//////////////////
2260function ReadCSS($html)
2261{
2262//! @desc CSS parser
2263//! @return string
2264
2265/*
2266* This version ONLY supports: .class {...} / #id { .... }
2267* It does NOT support: body{...} / a#hover { ... } / p.right { ... } / other mixed names
2268* This function must read the CSS code (internal or external) and order its value inside $this->CSS.
2269*/
2270
2271 $match = 0; // no match for instance
2272 $regexp = ''; // This helps debugging: showing what is the REAL string being processed
2273
2274 //CSS inside external files
2275 $regexp = '/<link rel="stylesheet".*?href="(.+?)"\\s*?\/?>/si';
2276 $match = preg_match_all($regexp,$html,$CSSext);
2277 $ind = 0;
2278
2279 while($match){
2280 //Fix path value
2281 $path = $CSSext[1][$ind];
2282 $path = str_replace("\\","/",$path); //If on Windows
2283 //Get link info and obtain its absolute path
2284 $regexp = '|^./|';
2285 $path = preg_replace($regexp,'',$path);
2286 if (strpos($path,"../") !== false ) //It is a Relative Link
2287 {
2288 $backtrackamount = substr_count($path,"../");
2289 $maxbacktrack = substr_count($this->basepath,"/") - 1;
2290 $filepath = str_replace("../",'',$path);
2291 $path = $this->basepath;
2292 //If it is an invalid relative link, then make it go to directory root
2293 if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
2294 //Backtrack some directories
2295 for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
2296 $path = $path . "/" . $filepath; //Make it an absolute path
2297 }
2298 elseif( strpos($path,":/") === false) //It is a Local Link
2299 {
2300 $path = $this->basepath . $path;
2301 }
2302 //Do nothing if it is an Absolute Link
2303 //END of fix path value
2304 $CSSextblock = file_get_contents($path);
2305
2306 //Get class/id name and its characteristics from $CSSblock[1]
2307 $regexp = '/[.# ]([^.]+?)\\s*?\{(.+?)\}/s'; // '/s' PCRE_DOTALL including \n
2308 preg_match_all( $regexp, $CSSextblock, $extstyle);
2309
2310 //Make CSS[Name-of-the-class] = array(key => value)
2311 $regexp = '/\\s*?(\\S+?):(.+?);/si';
2312
2313 for($i=0; $i < count($extstyle[1]) ; $i++)
2314 {
2315 preg_match_all( $regexp, $extstyle[2][$i], $extstyleinfo);
2316 $extproperties = $extstyleinfo[1];
2317 $extvalues = $extstyleinfo[2];
2318 for($j = 0; $j < count($extproperties) ; $j++)
2319 {
2320 //Array-properties and Array-values must have the SAME SIZE!
2321 $extclassproperties[strtoupper($extproperties[$j])] = trim($extvalues[$j]);
2322 }
2323 $this->CSS[$extstyle[1][$i]] = $extclassproperties;
2324 $extproperties = array();
2325 $extvalues = array();
2326 $extclassproperties = array();
2327 }
2328 $match--;
2329 $ind++;
2330 } //end of match
2331
2332 $match = 0; // reset value, if needed
2333
2334 //CSS internal
2335 //Get content between tags and order it, using regexp
2336 $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
2337 $match = preg_match($regexp,$html,$CSSblock);
2338
2339 if ($match) {
2340 //Get class/id name and its characteristics from $CSSblock[1]
2341 $regexp = '/[.#]([^.]+?)\\s*?\{(.+?)\}/s'; // '/s' PCRE_DOTALL including \n
2342 preg_match_all( $regexp, $CSSblock[1], $style);
2343
2344 //Make CSS[Name-of-the-class] = array(key => value)
2345 $regexp = '/\\s*?(\\S+?):(.+?);/si';
2346
2347 for($i=0; $i < count($style[1]) ; $i++)
2348 {
2349 preg_match_all( $regexp, $style[2][$i], $styleinfo);
2350 $properties = $styleinfo[1];
2351 $values = $styleinfo[2];
2352 for($j = 0; $j < count($properties) ; $j++)
2353 {
2354 //Array-properties and Array-values must have the SAME SIZE!
2355 $classproperties[strtoupper($properties[$j])] = trim($values[$j]);
2356 }
2357 $this->CSS[$style[1][$i]] = $classproperties;
2358 $properties = array();
2359 $values = array();
2360 $classproperties = array();
2361 }
2362 } // end of match
2363
2364 //Remove CSS (tags and content), if any
2365 $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
2366 $html = preg_replace($regexp,'',$html);
2367
2368 return $html;
2369}
2370
2371function readInlineCSS($html)
2372{
2373//! @return array
2374//! @desc Reads inline CSS and returns an array of properties
2375
2376 //Fix incomplete CSS code
2377 $size = strlen($html)-1;
2378 if ($html{$size} != ';') $html .= ';';
2379 //Make CSS[Name-of-the-class] = array(key => value)
2380 $regexp = '|\\s*?(\\S+?):(.+?);|i';
2381 preg_match_all( $regexp, $html, $styleinfo);
2382 $properties = $styleinfo[1];
2383 $values = $styleinfo[2];
2384 //Array-properties and Array-values must have the SAME SIZE!
2385 $classproperties = array();
2386 for($i = 0; $i < count($properties) ; $i++) $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
2387
2388 return $classproperties;
2389}
2390
2391function setCSS($arrayaux)
2392{
2393//! @return void
2394//! @desc Change some class attributes according to CSS properties
2395 if (!is_array($arrayaux)) return; //Removes PHP Warning
2396 foreach($arrayaux as $k => $v)
2397 {
2398 switch($k){
2399 case 'WIDTH':
2400 $this->divwidth = ConvertSize($v,$this->pgwidth);
2401 break;
2402 case 'HEIGHT':
2403 $this->divheight = ConvertSize($v,$this->pgwidth);
2404 break;
2405 case 'BORDER': // width style color (width not supported correctly - it is always considered as normal)
2406 $prop = explode(' ',$v);
2407 if ( count($prop) != 3 ) break; // Not supported: borders not fully declared
2408 //style: dashed dotted none (anything else => solid )
2409 if (strnatcasecmp($prop[1],"dashed") == 0) //found "dashed"! (ignores case)
2410 {
2411 $this->dash_on = true;
2412 $this->SetDash(2,2); //2mm on, 2mm off
2413 }
2414 elseif (strnatcasecmp($prop[1],"dotted") == 0) //found "dotted"! (ignores case)
2415 {
2416 $this->dotted_on = true;
2417 }
2418 elseif (strnatcasecmp($prop[1],"none") == 0) $this->divborder = 0;
2419 else $this->divborder = 1;
2420 //color
2421 $coul = ConvertColor($prop[2]);
2422 $this->SetDrawColor($coul['R'],$coul['G'],$coul['B']);
2423 $this->issetcolor=true;
2424 break;
2425 case 'FONT-FAMILY': // one of the $this->fontlist fonts
2426 //If it is a font list, get all font types
2427 $aux_fontlist = explode(",",$v);
2428 $fontarraysize = count($aux_fontlist);
2429 for($i=0;$i<$fontarraysize;$i++)
2430 {
2431 $fonttype = $aux_fontlist[$i];
2432 $fonttype = trim($fonttype);
2433 //If font is found, set it, and exit loop
2434 if ( in_array(strtolower($fonttype), $this->fontlist) ) {$this->SetFont(strtolower($fonttype));break;}
2435 //If font = "courier new" for example, try simply looking for "courier"
2436 $fonttype = explode(" ",$fonttype);
2437 $fonttype = $fonttype[0];
2438 if ( in_array(strtolower($fonttype), $this->fontlist) ) {$this->SetFont(strtolower($fonttype));break;}
2439 }
2440 break;
2441 case 'FONT-SIZE': //Does not support: smaller, larger
2442 if(is_numeric($v{0}))
2443 {
2444 $mmsize = ConvertSize($v,$this->pgwidth);
2445 $this->SetFontSize( $mmsize*(72/25.4) ); //Get size in points (pt)
2446 }
2447 else{
2448 $v = strtoupper($v);
2449 switch($v)
2450 {
2451 //Values obtained from http://www.w3schools.com/html/html_reference.asp
2452 case 'XX-SMALL': $this->SetFontSize( (0.7)* 11);
2453 break;
2454 case 'X-SMALL': $this->SetFontSize( (0.77) * 11);
2455 break;
2456 case 'SMALL': $this->SetFontSize( (0.86)* 11);
2457 break;
2458 case 'MEDIUM': $this->SetFontSize(11);
2459 break;
2460 case 'LARGE': $this->SetFontSize( (1.2)*11);
2461 break;
2462 case 'X-LARGE': $this->SetFontSize( (1.5)*11);
2463 break;
2464 case 'XX-LARGE': $this->SetFontSize( 2*11);
2465 break;
2466 }
2467 }
2468 break;
2469 case 'FONT-STYLE': // italic normal oblique
2470 switch (strtoupper($v))
2471 {
2472 case 'ITALIC':
2473 case 'OBLIQUE':
2474 $this->SetStyle('I',true);
2475 break;
2476 case 'NORMAL': break;
2477 }
2478 break;
2479 case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100)
2480 switch (strtoupper($v))
2481 {
2482 case 'BOLD':
2483 $this->SetStyle('B',true);
2484 break;
2485 case 'NORMAL': break;
2486 }
2487 break;
2488 case 'TEXT-DECORATION': // none underline //Does not support: overline, blink
2489 switch (strtoupper($v))
2490 {
2491 case 'LINE-THROUGH':
2492 $this->strike = true;
2493 break;
2494 case 'UNDERLINE':
2495 $this->SetStyle('U',true);
2496 break;
2497 case 'NONE': break;
2498 }
2499 case 'TEXT-TRANSFORM': // none uppercase lowercase //Does not support: capitalize
2500 switch (strtoupper($v)) //Not working 100%
2501 {
2502 case 'UPPERCASE':
2503 $this->toupper=true;
2504 break;
2505 case 'LOWERCASE':
2506 $this->tolower=true;
2507 break;
2508 case 'NONE': break;
2509 }
2510 case 'TEXT-ALIGN': //left right center justify
2511 switch (strtoupper($v))
2512 {
2513 case 'LEFT':
2514 $this->divalign="L";
2515 break;
2516 case 'CENTER':
2517 $this->divalign="C";
2518 break;
2519 case 'RIGHT':
2520 $this->divalign="R";
2521 break;
2522 case 'JUSTIFY':
2523 $this->divalign="J";
2524 break;
2525 }
2526 break;
2527 case 'DIRECTION': //ltr(default) rtl
2528 if (strtolower($v) == 'rtl') $this->divrevert = true;
2529 break;
2530 case 'BACKGROUND': // bgcolor only
2531 $cor = ConvertColor($v);
2532 $this->bgcolorarray = $cor;
2533 $this->SetFillColor($cor['R'],$cor['G'],$cor['B']);
2534 $this->divbgcolor = true;
2535 break;
2536 case 'COLOR': // font color
2537 $cor = ConvertColor($v);
2538 $this->colorarray = $cor;
2539 $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
2540 $this->issetcolor=true;
2541 break;
2542 }//end of switch($k)
2543 }//end of foreach
2544}
2545
2546function SetStyle($tag,$enable)
2547{
2548//! @return void
2549//! @desc Enables/Disables B,I,U styles
2550 //Modify style and select corresponding font
2551 $this->$tag+=($enable ? 1 : -1);
2552 $style='';
2553 //Fix some SetStyle misuse
2554 if ($this->$tag < 0) $this->$tag = 0;
2555 if ($this->$tag > 1) $this->$tag = 1;
2556 foreach(array('B','I','U') as $s)
2557 if($this->$s>0)
2558 $style.=$s;
2559
2560 $this->currentstyle=$style;
2561 $this->SetFont('',$style);
2562}
2563
2564function DisableTags($str='')
2565{
2566//! @return void
2567//! @desc Disable some tags using ',' as separator. Enable all tags calling this function without parameters.
2568 if ($str == '') //enable all tags
2569 {
2570 //Insert new supported tags in the long string below.
2571 $this->enabledtags = "<tt><kbd><samp><option><outline><span><newpage><page_break><s><strike><del><bdo><big><small><address><ins><cite><font><center><sup><sub><input><select><option><textarea><title><form><ol><ul><li><h1><h2><h3><h4><h5><h6><pre><b><u><i><a><img><p><br><strong><em><code><th><tr><blockquote><hr><td><tr><table><div>";
2572 }
2573 else
2574 {
2575 $str = explode(",",$str);
2576 foreach($str as $v) $this->enabledtags = str_replace(trim($v),'',$this->enabledtags);
2577 }
2578}
2579
2580////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
2581//Thanks to vietcom (vncommando at yahoo dot com)
2582/* Modified by Renato Coelho
2583 in order to print tables that span more than 1 page and to allow
2584 bold,italic and the likes inside table cells (and alignment now works with styles!)
2585*/
2586
2587//table Array of (w, h, bc, nr, wc, hr, cells)
2588//w Width of table
2589//h Height of table
2590//nc Number column
2591//nr Number row
2592//hr List of height of each row
2593//wc List of width of each column
2594//cells List of cells of each rows, cells[i][j] is a cell in the table
2595function _tableColumnWidth(&$table){
2596//! @return void
2597 $cs = &$table['cells'];
2598 $mw = $this->getStringWidth('W');
2599 $nc = $table['nc'];
2600 $nr = $table['nr'];
2601 $listspan = array();
2602 //Xac dinh do rong cua cac cell va cac cot tuong ung
2603 for($j = 0 ; $j < $nc ; $j++ ) //columns
2604 {
2605 $wc = &$table['wc'][$j];
2606 for($i = 0 ; $i < $nr ; $i++ ) //rows
2607 {
2608 if (isset($cs[$i][$j]) && $cs[$i][$j])
2609 {
2610 $c = &$cs[$i][$j];
2611 $miw = $mw;
2612 if (isset($c['maxs']) and $c['maxs'] != '') $c['s'] = $c['maxs'];
2613 $c['maw'] = $c['s'];
2614 if (isset($c['nowrap'])) $miw = $c['maw'];
2615 if (isset($c['w']))
2616 {
2617 if ($miw<$c['w']) $c['miw'] = $c['w'];
2618 if ($miw>$c['w']) $c['miw'] = $c['w'] = $miw;
2619 if (!isset($wc['w'])) $wc['w'] = 1;
2620 }
2621 else $c['miw'] = $miw;
2622 if ($c['maw'] < $c['miw']) $c['maw'] = $c['miw'];
2623 if (!isset($c['colspan']))
2624 {
2625 if ($wc['miw'] < $c['miw']) $wc['miw'] = $c['miw'];
2626 if ($wc['maw'] < $c['maw']) $wc['maw'] = $c['maw'];
2627 }
2628 else $listspan[] = array($i,$j);
2629 //Check if minimum width of the whole column is big enough for a huge word to fit
2630 $auxtext = implode("",$c['text']);
2631 $minwidth = $this->WordWrap($auxtext,$wc['miw']-2);// -2 == margin
2632 if ($minwidth < 0 and (-$minwidth) > $wc['miw']) $wc['miw'] = (-$minwidth) +2; //increase minimum width
2633 if ($wc['miw'] > $wc['maw']) $wc['maw'] = $wc['miw']; //update maximum width, if needed
2634 }
2635 }//rows
2636 }//columns
2637 //Xac dinh su anh huong cua cac cell colspan len cac cot va nguoc lai
2638 $wc = &$table['wc'];
2639 foreach ($listspan as $span)
2640 {
2641 list($i,$j) = $span;
2642 $c = &$cs[$i][$j];
2643 $lc = $j + $c['colspan'];
2644 if ($lc > $nc) $lc = $nc;
2645
2646 $wis = $wisa = 0;
2647 $was = $wasa = 0;
2648 $list = array();
2649 for($k=$j;$k<$lc;$k++)
2650 {
2651 $wis += $wc[$k]['miw'];
2652 $was += $wc[$k]['maw'];
2653 if (!isset($c['w']))
2654 {
2655 $list[] = $k;
2656 $wisa += $wc[$k]['miw'];
2657 $wasa += $wc[$k]['maw'];
2658 }
2659 }
2660 if ($c['miw'] > $wis)
2661 {
2662 if (!$wis)
2663 {//Cac cot chua co kich thuoc => chia deu
2664 for($k=$j;$k<$lc;$k++) $wc[$k]['miw'] = $c['miw']/$c['colspan'];
2665 }
2666 elseif(!count($list))
2667 {//Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca
2668 $wi = $c['miw'] - $wis;
2669 for($k=$j;$k<$lc;$k++) $wc[$k]['miw'] += ($wc[$k]['miw']/$wis)*$wi;
2670 }
2671 else
2672 {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto
2673 $wi = $c['miw'] - $wis;
2674 foreach ($list as $k) $wc[$k]['miw'] += ($wc[$k]['miw']/$wisa)*$wi;
2675 }
2676 }
2677 if ($c['maw'] > $was)
2678 {
2679 if (!$wis)
2680 {//Cac cot chua co kich thuoc => chia deu
2681 for($k=$j;$k<$lc;$k++) $wc[$k]['maw'] = $c['maw']/$c['colspan'];
2682 }
2683 elseif (!count($list))
2684 {
2685 //Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca
2686 $wi = $c['maw'] - $was;
2687 for($k=$j;$k<$lc;$k++) $wc[$k]['maw'] += ($wc[$k]['maw']/$was)*$wi;
2688 }
2689 else
2690 {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto
2691 $wi = $c['maw'] - $was;
2692 foreach ($list as $k) $wc[$k]['maw'] += ($wc[$k]['maw']/$wasa)*$wi;
2693 }
2694 }
2695 }
2696}
2697
2698function _tableWidth(&$table){
2699//! @return void
2700//! @desc Calculates the Table Width
2701// @desc Xac dinh chieu rong cua table
2702 $widthcols = &$table['wc'];
2703 $numcols = $table['nc'];
2704 $tablewidth = 0;
2705 for ( $i = 0 ; $i < $numcols ; $i++ )
2706 {
2707 $tablewidth += isset($widthcols[$i]['w']) ? $widthcols[$i]['miw'] : $widthcols[$i]['maw'];
2708 }
2709 if ($tablewidth > $this->pgwidth) $table['w'] = $this->pgwidth;
2710 if (isset($table['w']))
2711 {
2712 $wis = $wisa = 0;
2713 $list = array();
2714 for( $i = 0 ; $i < $numcols ; $i++ )
2715 {
2716 $wis += $widthcols[$i]['miw'];
2717 if (!isset($widthcols[$i]['w'])){ $list[] = $i;$wisa += $widthcols[$i]['miw'];}
2718 }
2719 if ($table['w'] > $wis)
2720 {
2721 if (!count($list))
2722 {//Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca
2723 //http://www.ksvn.com/anhviet_new.htm - translating comments...
2724 //bent shrink essence move size measure automatic => divide against give as a whole
2725 //$wi = $table['w'] - $wis;
2726 $wi = ($table['w'] - $wis)/$numcols;
2727 for($k=0;$k<$numcols;$k++)
2728 //$widthcols[$k]['miw'] += ($widthcols[$k]['miw']/$wis)*$wi;
2729 $widthcols[$k]['miw'] += $wi;
2730 }
2731 else
2732 {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto
2733 //$wi = $table['w'] - $wis;
2734 $wi = ($table['w'] - $wis)/count($list);
2735 foreach ($list as $k)
2736 //$widthcols[$k]['miw'] += ($widthcols[$k]['miw']/$wisa)*$wi;
2737 $widthcols[$k]['miw'] += $wi;
2738 }
2739 }
2740 for ($i=0;$i<$numcols;$i++)
2741 {
2742 $tablewidth = $widthcols[$i]['miw'];
2743 unset($widthcols[$i]);
2744 $widthcols[$i] = $tablewidth;
2745 }
2746 }
2747 else //table has no width defined
2748 {
2749 $table['w'] = $tablewidth;
2750 for ( $i = 0 ; $i < $numcols ; $i++)
2751 {
2752 $tablewidth = isset($widthcols[$i]['w']) ? $widthcols[$i]['miw'] : $widthcols[$i]['maw'];
2753 unset($widthcols[$i]);
2754 $widthcols[$i] = $tablewidth;
2755 }
2756 }
2757}
2758
2759function _tableHeight(&$table){
2760//! @return void
2761//! @desc Calculates the Table Height
2762 $cells = &$table['cells'];
2763 $numcols = $table['nc'];
2764 $numrows = $table['nr'];
2765 $listspan = array();
2766 for( $i = 0 ; $i < $numrows ; $i++ )//rows
2767 {
2768 $heightrow = &$table['hr'][$i];
2769 for( $j = 0 ; $j < $numcols ; $j++ ) //columns
2770 {
2771 if (isset($cells[$i][$j]) && $cells[$i][$j])
2772 {
2773 $c = &$cells[$i][$j];
2774 list($x,$cw) = $this->_tableGetWidth($table, $i,$j);
2775 //Check whether width is enough for this cells' text
2776 $auxtext = implode("",$c['text']);
2777 $auxtext2 = $auxtext; //in case we have text with styles
2778 $nostyles_size = $this->GetStringWidth($auxtext) + 3; // +3 == margin
2779 $linesneeded = $this->WordWrap($auxtext,$cw-2);// -2 == margin
2780 if ($c['s'] > $nostyles_size and !isset($c['form'])) //Text with styles
2781 {
2782 $auxtext = $auxtext2; //recover original characteristics (original /n placements)
2783 $diffsize = $c['s'] - $nostyles_size; //with bold et al. char width gets a bit bigger than plain char
2784 if ($linesneeded == 0) $linesneeded = 1; //to avoid division by zero
2785 $diffsize /= $linesneeded;
2786 $linesneeded = $this->WordWrap($auxtext,$cw-2-$diffsize);//diffsize used to wrap text correctly
2787 }
2788 if (isset($c['form']))
2789 {
2790 $linesneeded = ceil(($c['s']-3)/($cw-2)); //Text + form in a cell
2791 //Presuming the use of styles
2792 if ( ($this->GetStringWidth($auxtext) + 3) > ($cw-2) ) $linesneeded++;
2793 }
2794 $ch = $linesneeded * 1.1 * $this->lineheight;
2795 //If height is bigger than page height...
2796 if ($ch > ($this->fh - $this->bMargin - $this->tMargin)) $ch = ($this->fh - $this->bMargin - $this->tMargin);
2797 //If height is defined and it is bigger than calculated $ch then update values
2798 if (isset($c['h']) && $c['h'] > $ch)
2799 {
2800 $c['mih'] = $ch; //in order to keep valign working
2801 $ch = $c['h'];
2802 }
2803 else $c['mih'] = $ch;
2804 if (isset($c['rowspan'])) $listspan[] = array($i,$j);
2805 elseif ($heightrow < $ch) $heightrow = $ch;
2806 if (isset($c['form'])) $c['mih'] = $ch;
2807 }
2808 }//end of columns
2809 }//end of rows
2810 $heightrow = &$table['hr'];
2811 foreach ($listspan as $span)
2812 {
2813 list($i,$j) = $span;
2814 $c = &$cells[$i][$j];
2815 $lr = $i + $c['rowspan'];
2816 if ($lr > $numrows) $lr = $numrows;
2817 $hs = $hsa = 0;
2818 $list = array();
2819 for($k=$i;$k<$lr;$k++)
2820 {
2821 $hs += $heightrow[$k];
2822 if (!isset($c['h']))
2823 {
2824 $list[] = $k;
2825 $hsa += $heightrow[$k];
2826 }
2827 }
2828 if ($c['mih'] > $hs)
2829 {
2830 if (!$hs)
2831 {//Cac dong chua co kich thuoc => chia deu
2832 for($k=$i;$k<$lr;$k++) $heightrow[$k] = $c['mih']/$c['rowspan'];
2833 }
2834 elseif (!count($list))
2835 {//Khong co dong nao co kich thuoc auto => chia deu phan du cho tat ca
2836 $hi = $c['mih'] - $hs;
2837 for($k=$i;$k<$lr;$k++) $heightrow[$k] += ($heightrow[$k]/$hs)*$hi;
2838 }
2839 else
2840 {//Co mot so dong co kich thuoc auto => chia deu phan du cho cac dong auto
2841 $hi = $c['mih'] - $hsa;
2842 foreach ($list as $k) $heightrow[$k] += ($heightrow[$k]/$hsa)*$hi;
2843 }
2844 }
2845 }
2846}
2847
2848function _tableGetWidth(&$table, $i,$j){
2849//! @return array(x,w)
2850// @desc Xac dinh toa do va do rong cua mot cell
2851
2852 $cell = &$table['cells'][$i][$j];
2853 if ($cell)
2854 {
2855 if (isset($cell['x0'])) return array($cell['x0'], $cell['w0']);
2856 $x = 0;
2857 $widthcols = &$table['wc'];
2858 for( $k = 0 ; $k < $j ; $k++ ) $x += $widthcols[$k];
2859 $w = $widthcols[$j];
2860 if (isset($cell['colspan']))
2861 {
2862 for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) $w += $widthcols[$k];
2863 }
2864 $cell['x0'] = $x;
2865 $cell['w0'] = $w;
2866 return array($x, $w);
2867 }
2868 return array(0,0);
2869}
2870
2871function _tableGetHeight(&$table, $i,$j){
2872//! @return array(y,h)
2873 $cell = &$table['cells'][$i][$j];
2874 if ($cell){
2875 if (isset($cell['y0'])) return array($cell['y0'], $cell['h0']);
2876 $y = 0;
2877 $heightrow = &$table['hr'];
2878 for ($k=0;$k<$i;$k++) $y += $heightrow[$k];
2879 $h = $heightrow[$i];
2880 if (isset($cell['rowspan'])){
2881 for ($k=$i+$cell['rowspan']-1;$k>$i;$k--)
2882 $h += $heightrow[$k];
2883 }
2884 $cell['y0'] = $y;
2885 $cell['h0'] = $h;
2886 return array($y, $h);
2887 }
2888 return array(0,0);
2889}
2890
2891function _tableRect($x, $y, $w, $h, $type=1){
2892//! @return void
2893 if ($type==1) $this->Rect($x, $y, $w, $h);
2894 elseif (strlen($type)==4){
2895 $x2 = $x + $w; $y2 = $y + $h;
2896 if (intval($type{0})) $this->Line($x , $y , $x2, $y );
2897 if (intval($type{1})) $this->Line($x2, $y , $x2, $y2);
2898 if (intval($type{2})) $this->Line($x , $y2, $x2, $y2);
2899 if (intval($type{3})) $this->Line($x , $y , $x , $y2);
2900 }
2901}
2902
2903function _tableWrite(&$table){
2904//! @desc Main table function
2905//! @return void
2906 $cells = &$table['cells'];
2907 $numcols = $table['nc'];
2908 $numrows = $table['nr'];
2909 $x0 = $this->x;
2910 $y0 = $this->y;
2911 $right = $this->pgwidth - $this->rMargin;
2912 if (isset($table['a']) and ($table['w'] != $this->pgwidth))
2913 {
2914 if ($table['a']=='C') $x0 += (($right-$x0) - $table['w'])/2;
2915 elseif ($table['a']=='R') $x0 = $right - $table['w'];
2916 }
2917 $returny = 0;
2918 $tableheader = array();
2919 //Draw Table Contents and Borders
2920 for( $i = 0 ; $i < $numrows ; $i++ ) //Rows
2921 {
2922 $skippage = false;
2923 for( $j = 0 ; $j < $numcols ; $j++ ) //Columns
2924 {
2925 if (isset($cells[$i][$j]) && $cells[$i][$j])
2926 {
2927 $cell = &$cells[$i][$j];
2928 list($x,$w) = $this->_tableGetWidth($table, $i, $j);
2929 list($y,$h) = $this->_tableGetHeight($table, $i, $j);
2930 $x += $x0;
2931 $y += $y0;
2932 $y -= $returny;
2933 if ((($y + $h) > ($this->fh - $this->bMargin)) && ($y0 >0 || $x0 > 0))
2934 {
2935 if (!$skippage)
2936 {
2937 $y -= $y0;
2938 $returny += $y;
2939 $this->AddPage();
2940 if ($this->usetableheader) $this->Header($tableheader);
2941 if ($this->usetableheader) $y0 = $this->y;
2942 else $y0 = $this->tMargin;
2943 $y = $y0;
2944 }
2945 $skippage = true;
2946 }
2947 //Align
2948 $this->x = $x; $this->y = $y;
2949 $align = isset($cell['a'])? $cell['a'] : 'L';
2950 //Vertical align
2951 if (!isset($cell['va']) || $cell['va']=='M') $this->y += ($h-$cell['mih'])/2;
2952 elseif (isset($cell['va']) && $cell['va']=='B') $this->y += $h-$cell['mih'];
2953 //Fill
2954 $fill = isset($cell['bgcolor']) ? $cell['bgcolor']
2955 : (isset($table['bgcolor'][$i]) ? $table['bgcolor'][$i]
2956 : (isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0));
2957 if ($fill)
2958 {
2959 $color = ConvertColor($fill);
2960 $this->SetFillColor($color['R'],$color['G'],$color['B']);
2961 $this->Rect($x, $y, $w, $h, 'F');
2962 }
2963 //Border
2964 if (isset($cell['border'])) $this->_tableRect($x, $y, $w, $h, $cell['border']);
2965 elseif (isset($table['border']) && $table['border']) $this->Rect($x, $y, $w, $h);
2966 $this->divalign=$align;
2967 $this->divwidth=$w-2;
2968 //Get info of first row == table header
2969 if ($this->usetableheader and $i == 0 )
2970 {
2971 $tableheader[$j]['x'] = $x;
2972 $tableheader[$j]['y'] = $y;
2973 $tableheader[$j]['h'] = $h;
2974 $tableheader[$j]['w'] = $w;
2975 $tableheader[$j]['text'] = $cell['text'];
2976 $tableheader[$j]['textbuffer'] = $cell['textbuffer'];
2977 $tableheader[$j]['a'] = isset($cell['a'])? $cell['a'] : 'L';
2978 $tableheader[$j]['va'] = $cell['va'];
2979 $tableheader[$j]['mih'] = $cell['mih'];
2980 $tableheader[$j]['bgcolor'] = $fill;
2981 if ($table['border']) $tableheader[$j]['border'] = 'all';
2982 elseif (isset($cell['border'])) $tableheader[$j]['border'] = $cell['border'];
2983 }
2984 if (!empty($cell['textbuffer'])) $this->printbuffer($cell['textbuffer'],false,true/*inside a table*/);
2985 //Reset values
2986 $this->Reset();
2987 }//end of (if isset(cells)...)
2988 }// end of columns
2989 if ($i == $numrows-1) $this->y = $y + $h; //last row jump (update this->y position)
2990 }// end of rows
2991}//END OF FUNCTION _tableWrite()
2992
2993/////////////////////////END OF TABLE CODE//////////////////////////////////
2994
2995}//end of Class
2996
2997/*
2998---- JUNK(?)/OLD CODE: ------
2999// <? <- this fixes HIGHLIGHT PSPAD bug ...
3000
3001*/
3002
3003?>