/webcore/ext/pdf/webcore.pdf.php
# · PHP · 2552 lines · 2307 code · 128 blank · 117 comment · 501 complexity · 0f2431773e64bb248890c925c715e39e MD5 · raw file
Large files are truncated click here to view the full file
- <?php
- require_once "webcore.pdf.base.php";
-
- /**
- * Class to write a PDF using a HTML
- *
- * @package WebCore
- * @subpackage Pdf
- * @author original work Renato A.C. webcore implementation Geo Perez
- */
- class PdfWriter extends PdfGenerator
- {
- protected $pgwidth;
- protected $fontlist;
- protected $issetcolor;
- protected $titulo;
- protected $oldx;
- protected $oldy;
- protected $B;
- protected $U;
- protected $I;
-
- protected $tablestart;
- protected $tdbegin;
- protected $table;
- protected $cell;
- protected $col;
- protected $row;
-
- protected $divSettings;
-
- protected $listlvl;
- protected $listnum;
- protected $listtype;
- protected $listoccur;
- protected $listlist;
- protected $listitem;
-
- protected $buffer_on;
- protected $pbegin;
- protected $pjustfinished;
- protected $blockjustfinished;
- protected $SUP;
- protected $SUB;
- protected $toupper;
- protected $tolower;
- protected $dash_on;
- protected $dotted_on;
- protected $strike;
-
- protected $CSS;
- protected $cssbegin;
- protected $backupcss;
- protected $textbuffer;
- protected $currentstyle;
- protected $currentfont;
- protected $colorarray;
- protected $bgcolorarray;
- protected $enabledtags;
-
- protected $lineheight;
- protected $basepath;
- protected $outlineparam;
- protected $outline_on;
- protected $specialcontent;
- protected $selectoption;
-
- public function __construct($orientation='P', $unit='mm', $format='letter')
- {
- parent::__construct($orientation, $unit, $format);
- $this->AliasNbPages();
- $this->enabledtags = "<option><outline><span><newpage><page_break><s><strike><del><ins><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>";
-
- $this->setFont('Arial', '', 11);
- $this->lineheight = 5;
- $this->pgwidth = $this->fw - $this->lMargin - $this->rMargin ;
- $this->setFillColor(255);
- $this->titulo='';
- $this->oldx=-1;
- $this->oldy=-1;
- $this->B=0;
- $this->U=0;
- $this->I=0;
- $this->listlvl=0;
- $this->listnum=0;
- $this->listtype='';
- $this->listoccur=array();
- $this->listlist=array();
- $this->listitem=array();
- $this->tablestart=false;
- $this->tdbegin=false;
- $this->table=array();
- $this->cell=array();
- $this->col=-1;
- $this->row=-1;
-
- $divSettings = array ("divbegin" => false,
- "divalign" => "L",
- "divwidth" => 0,
- "divheight" => 0,
- "divbgcolor" => false,
- "divcolor" => false,
- "divborder" => 0);
-
- $this->divSettings = new KeyedCollectionWrapper($divSettings, false);
-
- $this->fontlist=array("arial","times","courier","helvetica","symbol","monospace","serif","sans");
- $this->issetcolor=false;
- $this->pbegin=false;
- $this->pjustfinished=false;
- $this->blockjustfinished = true;
- $this->toupper=false;
- $this->tolower=false;
- $this->dash_on=false;
- $this->dotted_on=false;
- $this->SUP=false;
- $this->SUB=false;
- $this->buffer_on=false;
- $this->strike=false;
- $this->currentfont='';
- $this->currentstyle='';
- $this->colorarray=array();
- $this->bgcolorarray=array();
- $this->cssbegin=false;
- $this->textbuffer=array();
- $this->CSS=array();
- $this->backupcss=array();
- $this->basepath = "";
- $this->outlineparam = array();
- $this->outline_on = false;
- $this->specialcontent = '';
- $this->selectoption = array();
- }
-
- public function setBasePath($str)
- {
- $this->basepath = dirname($str) . "/";
- $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
- }
-
- public function header($content='')
- {
- if ($content == '')
- return;
-
- $y = $this->y;
-
- foreach($content as $tableheader)
- {
- $this->y = $y;
-
- $x = $tableheader['x'];
- $w = $tableheader['w'];
- $h = $tableheader['h'];
- $va = $tableheader['va'];
- $mih = $tableheader['mih'];
- $border = $tableheader['border'];
- $align = $tableheader['a'];
-
- $this->divalign=$align;
- $this->x = $x;
-
- if (!isset($va) || $va=='M')
- $this->y += ($h-$mih)/2;
- elseif (isset($va) && $va=='B')
- $this->y += $h-$mih;
-
- if (isset($border) and $border != 'all')
- $this->_tableRect($x, $y, $w, $h, $border);
- elseif (isset($border) && $border == 'all')
- $this->Rect($x, $y, $w, $h);
-
- $value = $w-2;
- $this->divSettings->setValue("divwidth", $value);
- $this->divheight = 1.1*$this->lineheight;
- $textbuffer = $tableheader['textbuffer'];
-
- if (!empty($textbuffer))
- $this->printbuffer($textbuffer,false,true/*inside a table*/);
-
- $textbuffer = array();
- }
-
- $this->y = $y + $h;
- }
-
- public function footer()
- {
- $this->setY(-10);
- $this->setFont('Arial', 'B', 9);
- $this->setTextColor(0);
- $this->setFont('Arial','I',9);
- $this->Cell(0,10,$this->PageNo().'/{nb}', 0, 0, 'C');
- $this->setFont('Arial','',11);
- }
-
- public function writeHTML($html)
- {
- if($this->page==0) $this->addPage();
-
- $html = $this->adjustHtml($html);
- $html = $this->readCss($html);
-
- $html = str_replace('<?','< ',$html);
- $html = strip_tags($html,$this->enabledtags);
-
- $a = preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
-
- foreach($a as $i => $e)
- {
- if($i%2==0)
- {
- if (strpos($e,"&") !== false)
- {
- if (strpos($e,"#") !== false)
- $e = $this->value_entity_decode($e);
-
- $e = html_entity_decode($e,ENT_QUOTES,'cp1252');
- }
-
- $e = str_replace(chr(160),chr(32),$e);
-
- if (strlen($e) == 0)
- continue;
-
- if ($this->toupper) $e = strtoupper($e);
- if ($this->tolower) $e = strtolower($e);
-
- if($this->titulo)
- $this->setTitle($e);
- elseif($this->specialcontent)
- {
- if ($this->specialcontent == "type=select" and $this->selectoption['ACTIVE'] == true)
- {
- $stringwidth = $this->GetStringWidth($e);
-
- if (!isset($this->selectoption['MAXWIDTH']) or $stringwidth > $this->selectoption['MAXWIDTH'])
- $this->selectoption['MAXWIDTH'] = $stringwidth;
-
- if (!isset($this->selectoption['SELECTED']) or $this->selectoption['SELECTED'] == '')
- $this->selectoption['SELECTED'] = $e;
- }
- else
- $this->textbuffer[] = array("»¤¬"/*identifier*/.$this->specialcontent."»¤¬".$e);
- }
- elseif($this->tablestart)
- {
- if($this->tdbegin)
- {
- $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,'',$this->currentstyle,
- $this->colorarray,$this->currentfont,
- $this->SUP,$this->SUB,'',$this->strike,
- $this->outlineparam,$this->bgcolorarray);
- $this->cell[$this->row][$this->col]['text'][] = $e;
- $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e);
- }
- }
- elseif($this->pbegin or $this->divSettings->getValue("divbegin") or $this->SUP or $this->SUB or $this->strike or $this->buffer_on)
- {
- $this->textbuffer[] = array($e, '',$this->currentstyle,$this->colorarray,$this->currentfont,
- $this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,
- $this->bgcolorarray);
- }
- else
- {
- if ($this->blockjustfinished) $e = ltrim($e);
-
- if ($e != '')
- {
- $this->Write($this->lineheight,$e);
- if ($this->pjustfinished) $this->pjustfinished = false;
- }
- }
- }
- else
- {
- if ($e{0} == '/')
- {
- $this->CloseTag(strtoupper(substr($e,1)));
- }
- else
- {
- $e = preg_replace('|=\'(.*?)\'|s', "=\"\$1\"", $e);
- $e = preg_replace('| (\\w+?)=([^\\s>"]+)|si', " \$1=\"\$2\"", $e);
-
- if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) )
- {
- $regexp = '/ (href|src)="(.*?)"/i';
- preg_match($regexp,$e,$auxiliararray);
- $path = $auxiliararray[2];
- $path = str_replace("\\","/",$path); //If on Windows
-
- $regexp = '|^./|';
- $path = preg_replace($regexp,'',$path);
- if($path{0} != '#') //It is not an Internal Link
- {
- if (strpos($path,"../") !== false ) //It is a Relative Link
- {
- $backtrackamount = substr_count($path,"../");
- $maxbacktrack = substr_count($this->basepath,"/") - 1;
- $filepath = str_replace("../",'',$path);
- $path = $this->basepath;
- //If it is an invalid relative link, then make it go to directory root
- if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
- //Backtrack some directories
- for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
- $path = $path . "/" . $filepath; //Make it an absolute path
- }
- elseif( strpos($path,":/") === false) //It is a Local Link
- {
- $path = $this->basepath . $path;
- }
- }
-
- $e = preg_replace('/ (href|src)="(.*?)"/i',' \\1="'.$path.'"',$e);
- }
-
- $contents=array();
-
- preg_match_all('/\\S*=["\'][^"\']*["\']/',$e,$contents);
- preg_match('/\\S+/',$e,$a2);
-
- $tag=strtoupper($a2[0]);
- $attr=array();
-
- if (!empty($contents))
- {
- foreach($contents[0] as $v)
- {
- if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
- $attr[strtoupper($a3[1])]=$a3[2];
- }
- }
-
- $this->openTag($tag,$attr);
- }
- }
- }
- }
-
- private function openTag($tag,$attr)
- {
- $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','middle'=>'M','bottom'=>'B','justify'=>'J');
- $this->blockjustfinished=false;
-
- switch($tag)
- {
- case 'PAGE_BREAK':
- case 'NEWPAGE':
- $this->blockjustfinished = true;
- $this->addPage();
- break;
- case 'S':
- case 'STRIKE':
- case 'DEL':
- $this->strike=true;
- break;
- case 'SUB':
- $this->SUB=true;
- break;
- case 'SUP':
- $this->SUP=true;
- break;
- case 'TABLE':
- if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
-
- $this->tablestart = true;
- $this->table['nc'] = $this->table['nr'] = 0;
-
- if (isset($attr['WIDTH'])) $this->table['w'] = $this->convertSize($attr['WIDTH'],$this->pgwidth);
- if (isset($attr['HEIGHT'])) $this->table['h'] = $this->convertSize($attr['HEIGHT'],$this->pgwidth);
- if (isset($attr['ALIGN'])) $this->table['a'] = $align[strtolower($attr['ALIGN'])];
- if (isset($attr['BORDER'])) $this->table['border'] = $attr['BORDER'];
- break;
- case 'TR':
- $this->row++;
- $this->table['nr']++;
- $this->col = -1;
- break;
- case 'TH':
- $this->setStyle('B',true);
- if (!isset($attr['ALIGN'])) $attr['ALIGN'] = "center";
- case 'TD':
- $this->tdbegin = true;
- $this->col++;
- while (isset($this->cell[$this->row][$this->col]))
- $this->col++;
-
- if ($this->table['nc'] < $this->col+1)
- $this->table['nc'] = $this->col+1;
-
- $this->cell[$this->row][$this->col] = array();
- $this->cell[$this->row][$this->col]['text'] = array();
- $this->cell[$this->row][$this->col]['s'] = 3;
-
- if (isset($attr['WIDTH'])) $this->cell[$this->row][$this->col]['w'] = $this->convertSize($attr['WIDTH'],$this->pgwidth);
- if (isset($attr['HEIGHT'])) $this->cell[$this->row][$this->col]['h'] = $this->convertSize($attr['HEIGHT'],$this->pgwidth);
- if (isset($attr['ALIGN'])) $this->cell[$this->row][$this->col]['a'] = $align[strtolower($attr['ALIGN'])];
- if (isset($attr['VALIGN'])) $this->cell[$this->row][$this->col]['va'] = $align[strtolower($attr['VALIGN'])];
- if (isset($attr['BORDER'])) $this->cell[$this->row][$this->col]['border'] = $attr['BORDER'];
-
- $cs = $rs = 1;
-
- if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $this->cell[$this->row][$this->col]['colspan'] = $attr['COLSPAN'];
- if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $this->cell[$this->row][$this->col]['rowspan'] = $attr['ROWSPAN'];
-
- for ($k=$this->row ; $k < $this->row+$rs ;$k++)
- {
- for($l=$this->col; $l < $this->col+$cs ;$l++)
- {
- if ($k-$this->row || $l-$this->col)
- $this->cell[$k][$l] = 0;
- }
- }
-
- if (isset($attr['NOWRAP'])) $this->cell[$this->row][$this->col]['nowrap']= 1;
- break;
- case 'OL':
- if (!isset($attr['TYPE']) or $attr['TYPE'] == '')
- $this->listtype = '1';
- else
- $this->listtype = $attr['TYPE'];
- case 'UL':
- if ((!isset($attr['TYPE']) or $attr['TYPE'] == '') and $tag=='UL')
- {
- //Insert UL defaults
- if ($this->listlvl == 0) $this->listtype = 'disc';
- elseif ($this->listlvl == 1) $this->listtype = 'circle';
- else $this->listtype = 'square';
- }
- elseif (isset($attr['TYPE']) and $tag=='UL') $this->listtype = $attr['TYPE'];
- $this->buffer_on = false;
- if ($this->listlvl == 0)
- {
- if (!$this->pjustfinished)
- {
- if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
- $this->Ln($this->lineheight);
- }
- $this->oldx = $this->x;
- $this->listlvl++; // first depth level
- $this->listnum = 0; // reset
- $this->listoccur[$this->listlvl] = 1;
- $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
- }
- else
- {
- if (!empty($this->textbuffer))
- {
- $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
- $this->listnum++;
- }
- $this->textbuffer = array();
- $occur = $this->listoccur[$this->listlvl];
- $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
- $this->listlvl++;
- $this->listnum = 0; // reset
-
- if ($this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
- else $this->listoccur[$this->listlvl]++;
- $occur = $this->listoccur[$this->listlvl];
- $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
- }
- break;
- case 'LI':
- if ($this->listlvl == 0)
- {
- if (!$this->pjustfinished and $this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
- $this->oldx = $this->x;
- $this->listlvl++; // first depth level
- $this->listnum = 0; // reset
- $this->listoccur[$this->listlvl] = 1;
- $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
- }
- if ($this->listnum == 0)
- {
- $this->buffer_on = true; //activate list 'bufferization'
- $this->listnum++;
- $this->textbuffer = array();
- }
- else
- {
- $this->buffer_on = true; //activate list 'bufferization'
- if (!empty($this->textbuffer))
- {
- $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
- $this->listnum++;
- }
- $this->textbuffer = array();
- }
- break;
- case 'H1': // 2 * fontsize
- case 'H2': // 1.5 * fontsize
- case 'H3': // 1.17 * fontsize
- case 'H4': // 1 * fontsize
- case 'H5': // 0.83 * fontsize
- case 'H6': // 0.67 * fontsize
- $this->buffer_on = true;
- if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
- elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
- $this->setStyle('B',true);
- switch($tag)
- {
- case 'H1':
- $this->setFontSize(2*$this->FontSizePt);
- $this->lineheight *= 2;
- break;
- case 'H2':
- $this->setFontSize(1.5*$this->FontSizePt);
- $this->lineheight *= 1.5;
- break;
- case 'H3':
- $this->setFontSize(1.17*$this->FontSizePt);
- $this->lineheight *= 1.17;
- break;
- case 'H4':
- $this->setFontSize($this->FontSizePt);
- break;
- case 'H5':
- $this->setFontSize(0.83*$this->FontSizePt);
- $this->lineheight *= 0.83;
- break;
- case 'H6':
- $this->setFontSize(0.67*$this->FontSizePt);
- $this->lineheight *= 0.67;
- break;
- }
- break;
- case 'HR':
- if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
- $this->Ln(0.2*$this->lineheight);
- $hrwidth = $this->pgwidth;
- $this->setDrawColor(200, 200, 200);
- $x = $this->x;
- $y = $this->y;
- $empty = $this->pgwidth - $hrwidth;
- $empty /= 2;
- $x += $empty;
- $oldlinewidth = $this->LineWidth;
- $this->setLineWidth(0.3);
- $this->Line($x,$y,$x+$hrwidth,$y);
- $this->setLineWidth($oldlinewidth);
- $this->Ln(0.2*$this->lineheight);
- $this->setDrawColor(0);
- $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
- break;
- case 'INS':
- $this->setStyle('U',true);
- break;
- case 'TITLE':
- $this->titulo = true;
- break;
- case 'B':
- case 'I':
- case 'U':
- if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
- {
- $this->cssbegin=true;
- if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
- elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
- //Read Inline CSS
- if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
- //Look for name in the $this->CSS array
- $this->backupcss = $properties;
- if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
- }
- $this->setStyle($tag,true);
- break;
- case 'A':
- if (isset($attr['NAME']) and $attr['NAME'] != '')
- $this->textbuffer[] = array('','','',array(),'',false,false,$attr['NAME']); //an internal link (adds a space for recognition)
- break;
- case 'DIV':
- if ($this->listlvl > 0) // We are closing (omitted) OL/UL tag(s)
- {
- $this->buffer_on = false;
- if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
- $this->textbuffer = array();
- $this->listlvl--;
- $this->printlistbuffer();
- $this->pjustfinished = true; //act as if a paragraph just ended
- }
- $this->divSettings->setValue("divbegin", true);
- if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
- if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
- {
- $this->cssbegin=true;
- if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
- elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
- //Read Inline CSS
- if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
- //Look for name in the $this->CSS array
- if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
- }
- break;
- case 'IMG':
- if(!empty($this->textbuffer) and !$this->tablestart)
- {
- $olddivwidth = $this->divSettings->getValue("divwidth");
- $olddivheight = $this->divSettings->getValue("divheight");
-
- if ( $olddivwidth == 0) $this->divwidth = $this->pgwidth - $x + $this->lMargin;
- if ( $olddivheight == 0) $this->divheight = $this->lineheight;
- //Print content
- $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
- $this->textbuffer=array();
-
- $this->divSettings->setValue("divwidth", $olddivwidth);
- $this->divSettings->setValue("divheight", $olddivheight);
-
- $this->textbuffer=array();
- $this->Ln($this->lineheight);
- }
- if(isset($attr['SRC']))
- {
- $srcpath = $attr['SRC'];
- if(!isset($attr['WIDTH'])) $attr['WIDTH'] = 0;
- else $attr['WIDTH'] = $this->convertSize($attr['WIDTH'],$this->pgwidth);//$attr['WIDTH'] /= 4;
- if(!isset($attr['HEIGHT'])) $attr['HEIGHT'] = 0;
- else $attr['HEIGHT'] = $this->convertSize($attr['HEIGHT'],$this->pgwidth);//$attr['HEIGHT'] /= 4;
- if ($this->tdbegin)
- {
- $bak_x = $this->x;
- $bak_y = $this->y;
-
- $f_exists = @fopen($srcpath,"rb");
- if (!$f_exists)
- break;
- $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'','',false);
- $this->y = $bak_y;
- $this->x = $bak_x;
- }
- elseif($this->pbegin or $this->divSettings->getValue("divbegin"))
- {
- $ypos = 0;
- $bak_x = $this->x;
- $bak_y = $this->y;
-
- $f_exists = @fopen($srcpath,"rb");
- if (!$f_exists)
- break;
-
- $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'','',false);
- $this->y = $bak_y;
- $this->x = $bak_x;
- $xpos = '';
- switch($this->divalign)
- {
- case "C":
- $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
- $empty = ($this->pgwidth - $sizesarray['WIDTH'])/2;
- $xpos = 'xpos='.$empty.',';
- break;
- case "R":
- $spacesize = $this->CurrentFont[ 'cw' ][ ' ' ] * ( $this->FontSizePt / 1000 );
- $empty = ($this->pgwidth - $sizesarray['WIDTH']);
- $xpos = 'xpos='.$empty.',';
- break;
- default: break;
- }
- $numberoflines = (integer)ceil($sizesarray['HEIGHT']/$this->lineheight) ;
- $ypos = $numberoflines * $this->lineheight;
- $this->textbuffer[] = array("»¤¬"/*identifier*/."type=image,ypos=$ypos,{$xpos}width=".$sizesarray['WIDTH'].",height=".$sizesarray['HEIGHT']."»¤¬".$sizesarray['OUTPUT']);
-
- while($numberoflines)
- {
- $this->textbuffer[] = array("\n", '' ,$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);$numberoflines--;
- }
- }
- else
- {
- $imgborder = 0;
- if (isset($attr['BORDER'])) $imgborder = $this->convertSize($attr['BORDER'],$this->pgwidth);
-
- $f_exists = @fopen($srcpath,"rb");
- if (!$f_exists) //Show 'image not found' icon instead
- {
- $srcpath = str_replace("\\","/",dirname(__FILE__)) . "/";
- $srcpath .= 'no_img.gif';
- }
- $sizesarray = $this->Image($srcpath, $this->GetX(), $this->GetY(), $attr['WIDTH'], $attr['HEIGHT'],'', ''); //Output Image
- $ini_x = $sizesarray['X'];
- $ini_y = $sizesarray['Y'];
- if ($imgborder)
- {
- $oldlinewidth = $this->LineWidth;
- $this->setLineWidth($imgborder);
- $this->Rect($ini_x,$ini_y,$sizesarray['WIDTH'],$sizesarray['HEIGHT']);
- $this->setLineWidth($oldlinewidth);
- }
- }
- if ($sizesarray['X'] < $this->x) $this->x = $this->lMargin;
- if ($this->tablestart)
- {
- $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=image,width=".$sizesarray['WIDTH'].",height=".$sizesarray['HEIGHT']."»¤¬".$sizesarray['OUTPUT']);
- $this->cell[$this->row][$this->col]['s'] += $sizesarray['WIDTH'] + 1;// +1 == margin
- $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
- if (!isset($this->cell[$this->row][$this->col]['w'])) $this->cell[$this->row][$this->col]['w'] = $sizesarray['WIDTH'] + 3;
- if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $sizesarray['HEIGHT'] + 3;
- }
- }
- break;
- case 'BLOCKQUOTE':
- case 'BR':
- if($this->tablestart)
- {
- $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n", '',$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
- $this->cell[$this->row][$this->col]['text'][] = "\n";
- 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
- 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
- $this->cell[$this->row][$this->col]['s'] = 0;// reset
- }
- elseif($this->divSettings->getValue("divbegin") or $this->pbegin or $this->buffer_on) $this->textbuffer[] = array("\n", '',$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
- else {$this->Ln($this->lineheight);$this->blockjustfinished = true;}
- break;
- case 'P':
- //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
- if ($this->listlvl > 0) // We are closing (omitted) OL/UL tag(s)
- {
- $this->buffer_on = false;
- if (!empty($this->textbuffer)) $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl]);
- $this->textbuffer = array();
- $this->listlvl--;
- $this->printlistbuffer();
- $this->pjustfinished = true; //act as if a paragraph just ended
- }
- if ($this->tablestart)
- {
- $this->cell[$this->row][$this->col]['textbuffer'][] = array($e, '',$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
- $this->cell[$this->row][$this->col]['text'][] = "\n";
- break;
- }
- $this->pbegin=true;
- if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
- elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
- //Save x,y coords in case we need to print borders...
- $this->oldx = $this->x;
- $this->oldy = $this->y;
- if(isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
- {
- $this->cssbegin=true;
- if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
- elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
- //Read Inline CSS
- if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
- $this->backupcss = $properties;
- if (!empty($properties)) $this->setCSS($properties); //name(id/class/style) found in the CSS array!
- }
- break;
- case 'SPAN':
- $this->buffer_on = true;
- //Save x,y coords in case we need to print borders...
- $this->oldx = $this->x;
- $this->oldy = $this->y;
- if( isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
- {
- $this->cssbegin=true;
- if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
- elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
- //Read Inline CSS
- if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
- //Look for name in the $this->CSS array
- $this->backupcss = $properties;
- if (!empty($properties)) $this->setCSS($properties); //name found in the CSS array!
- }
- break;
- case 'PRE':
- if($this->tablestart)
- {
- $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n", '',$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
- $this->cell[$this->row][$this->col]['text'][] = "\n";
- }
- elseif($this->divSettings->getValue("divbegin") or $this->pbegin or $this->buffer_on) $this->textbuffer[] = array("\n", '',$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
- else
- {
- if ($this->x != $this->lMargin) $this->Ln(2*$this->lineheight);
- elseif (!$this->pjustfinished) $this->Ln($this->lineheight);
- $this->buffer_on = true;
- $this->oldx = $this->x;
- $this->oldy = $this->y;
- if(isset($attr['CLASS']) or isset($attr['ID']) or isset($attr['STYLE']) )
- {
- $this->cssbegin=true;
- if (isset($attr['CLASS'])) $properties = $this->CSS[$attr['CLASS']];
- elseif (isset($attr['ID'])) $properties = $this->CSS[$attr['ID']];
- //Read Inline CSS
- if (isset($attr['STYLE'])) $properties = $this->readInlineCSS($attr['STYLE']);
- //Look for name in the $this->CSS array
- $this->backupcss = $properties;
- if (!empty($properties)) $this->setCSS($properties); //name(id/class/style) found in the CSS array!
- }
- }
- case 'CODE':
- $this->setFont('courier');
- $this->currentfont='courier';
- break;
- case 'TEXTAREA':
- $this->buffer_on = true;
- $colsize = 20; //HTML default value
- $rowsize = 2; //HTML default value
- if (isset($attr['COLS'])) $colsize = $attr['COLS'];
- if (isset($attr['ROWS'])) $rowsize = $attr['ROWS'];
- if (!$this->tablestart)
- {
- if ($this->x != $this->lMargin) $this->Ln($this->lineheight);
- $this->col = $colsize;
- $this->row = $rowsize;
- }
- else //it is inside a table
- {
- $this->specialcontent = "type=textarea,lines=$rowsize,width=".((2.2*$colsize) + 3); //Activate form info in order to paint FORM elements within table
- $this->cell[$this->row][$this->col]['s'] += (2.2*$colsize) + 6;// +6 == margin
- if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = 1.1*$this->lineheight*$rowsize + 2.5;
- }
- break;
- case 'SELECT':
- $this->specialcontent = "type=select"; //Activate form info in order to paint FORM elements within table
- break;
- case 'OPTION':
- $this->selectoption['ACTIVE'] = true;
- if (empty($this->selectoption))
- {
- $this->selectoption['MAXWIDTH'] = '';
- $this->selectoption['SELECTED'] = '';
- }
- if (isset($attr['SELECTED'])) $this->selectoption['SELECTED'] = '';
- break;
- case 'FORM':
- if($this->tablestart)
- {
- $this->cell[$this->row][$this->col]['textbuffer'][] = array($e, '',$this->currentstyle,$this->colorarray,$this->currentfont,$this->SUP,$this->SUB,''/*internal link*/,$this->strike,$this->outlineparam,$this->bgcolorarray);
- $this->cell[$this->row][$this->col]['text'][] = "\n";
- }
- elseif ($this->x != $this->lMargin) $this->Ln($this->lineheight); //Skip a line, if needed
- break;
- case 'INPUT':
- if (!isset($attr['TYPE'])) $attr['TYPE'] == ''; //in order to allow default 'TEXT' form (in case of malformed HTML code)
- if (!$this->tablestart)
- {
- switch(strtoupper($attr['TYPE'])){
- case 'CHECKBOX': //Draw Checkbox
- $checked = false;
- if (isset($attr['CHECKED'])) $checked = true;
- $this->setFillColor(235,235,235);
- $this->x += 3;
- $this->Rect($this->x,$this->y+1,3,3,'DF');
- if ($checked)
- {
- $this->Line($this->x,$this->y+1,$this->x+3,$this->y+1+3);
- $this->Line($this->x,$this->y+1+3,$this->x+3,$this->y+1);
- }
- $this->setFillColor(255);
- $this->x += 3.5;
- break;
- case 'RADIO': //Draw Radio button
- $checked = false;
- if (isset($attr['CHECKED'])) $checked = true;
- $this->x += 4;
- $this->Circle($this->x,$this->y+2.2,1,'D');
- $this->_out('0.000 g');
- if ($checked) $this->Circle($this->x,$this->y+2.2,0.4,'DF');
- $this->Write(5,$texto,$this->x);
- $this->x += 2;
- break;
- case 'BUTTON':
- case 'SUBMIT':
- case 'RESET':
- $texto='';
- if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
- $nihil = 2.5;
- $this->x += 2;
- $this->setFillColor(190,190,190);
- $this->Rect($this->x,$this->y,$this->GetStringWidth($texto)+2*$nihil,4.5,'DF'); // 4.5 in order to avoid overlapping
- $this->x += $nihil;
- $this->Write(5,$texto,$this->x);
- $this->x += $nihil;
- $this->setFillColor(255);
- break;
- case 'PASSWORD':
- if (isset($attr['VALUE']))
- {
- $num_stars = strlen($attr['VALUE']);
- $attr['VALUE'] = str_repeat('*',$num_stars);
- }
- case 'TEXT': //Draw TextField
- default: //default == TEXT
- $texto='';
- if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
- $tamanho = 20;
- if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $tamanho = $attr['SIZE'];
- $this->setFillColor(235,235,235);
- $this->x += 2;
- $this->Rect($this->x,$this->y,2*$tamanho,4.5,'DF');// 4.5 in order to avoid overlapping
- if ($texto != '')
- {
- $this->x += 1;
- $this->Write(5,$texto,$this->x);
- $this->x -= $this->GetStringWidth($texto);
- }
- $this->setFillColor(255);
- $this->x += 2*$tamanho;
- break;
- }
- }
- else //we are inside a table
- {
- $this->cell[$this->row][$this->col]['form'] = true; // in order to make some width adjustments later
- $type = '';
- $text = '';
- $height = 0;
- $width = 0;
- switch(strtoupper($attr['TYPE'])){
- case 'CHECKBOX': //Draw Checkbox
- $checked = false;
- if (isset($attr['CHECKED'])) $checked = true;
- $text = $checked;
- $type = 'CHECKBOX';
- $width = 4;
- $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
- $this->cell[$this->row][$this->col]['s'] += $width;
- if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight;
- break;
- case 'RADIO': //Draw Radio button
- $checked = false;
- if (isset($attr['CHECKED'])) $checked = true;
- $text = $checked;
- $type = 'RADIO';
- $width = 3;
- $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
- $this->cell[$this->row][$this->col]['s'] += $width;
- if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight;
- break;
- case 'BUTTON': $type = 'BUTTON'; // Draw a button
- case 'SUBMIT': if ($type == '') $type = 'SUBMIT';
- case 'RESET': if ($type == '') $type = 'RESET';
- $texto='';
- if (isset($attr['VALUE'])) $texto = " " . $attr['VALUE'] . " ";
- $text = $texto;
- $width = $this->GetStringWidth($texto)+3;
- $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
- $this->cell[$this->row][$this->col]['s'] += $width;
- if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight + 2;
- break;
- case 'PASSWORD':
- if (isset($attr['VALUE']))
- {
- $num_stars = strlen($attr['VALUE']);
- $attr['VALUE'] = str_repeat('*',$num_stars);
- }
- $type = 'PASSWORD';
- case 'TEXT': //Draw TextField
- default: //default == TEXT
- $texto='';
- if (isset($attr['VALUE'])) $texto = $attr['VALUE'];
- $tamanho = 20;
- if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $tamanho = $attr['SIZE'];
- $text = $texto;
- $width = 2*$tamanho;
- if ($type == '') $type = 'TEXT';
- $this->cell[$this->row][$this->col]['textbuffer'][] = array("»¤¬"/*identifier*/."type=input,subtype=$type,width=$width,height=$height"."»¤¬".$text);
- $this->cell[$this->row][$this->col]['s'] += $width;
- if (!isset($this->cell[$this->row][$this->col]['h'])) $this->cell[$this->row][$this->col]['h'] = $this->lineheight + 2;
- break;
- }
- }
- break;
- }
-
- $this->pjustfinished=false;
- }
-
- function CloseTag($tag)
- {
- if($tag=='OPTION') $this->selectoption['ACTIVE'] = false;
- if($tag=='INS') $tag='U';
- if($tag=='STRONG') $tag='B';
- if($tag=='EM' or $tag=='CITE') $tag='I';
- if($tag=='OUTLINE')
- {
- if(!$this->pbegin and !$this->divSettings->getValue("divbegin") and !$this->tablestart)
- {
- $this->setTextOutline(false);
- $this->outlineparam=array();
- //Save x,y coords ???
- $x = $this->x;
- $y = $this->y;
- //Set some default values
- $this->divSettings->setValue("divwidth", $this->pgwidth - $x + $this->lMargin);
- //Print content
- $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
- $this->textbuffer=array();
- //Reset values
- $this->Reset();
- $this->buffer_on=false;
- }
- $this->setTextOutline(false);
- $this->outlineparam=array();
- }
- if($tag=='A')
- {
- if(!$this->pbegin and !$this->divSettings->getValue("divbegin") and !$this->tablestart and !$this->buffer_on)
- {
- //Save x,y coords ???
- $x = $this->x;
- $y = $this->y;
- //Set some default values
- $this->divSettings->setValue("divwidth", $this->pgwidth - $x + $this->lMargin);
- //Print content
- $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
- $this->textbuffer=array();
- //Reset values
- $this->Reset();
- }
- }
- if($tag=='TH') $this->setStyle('B',false);
- if($tag=='TH' or $tag=='TD') $this->tdbegin = false;
- if($tag=='SPAN')
- {
- if(!$this->pbegin and !$this->divSettings->getValue("divbegin") and !$this->tablestart)
- {
- if($this->cssbegin)
- {
- //Check if we have borders to print
- if ($this->cssbegin and ($this->divborder or $this->dash_on or $this->dotted_on or $this->divbgcolor))
- {
- $texto='';
- foreach($this->textbuffer as $vetor) $texto.=$vetor[0];
- $tempx = $this->x;
- if($this->divbgcolor) $this->Cell($this->GetStringWidth($texto),$this->lineheight,'',$this->divborder,'','L',$this->divbgcolor);
- if ($this->dash_on) $this->Rect($this->oldx,$this->oldy,$this->GetStringWidth($texto),$this->lineheight);
- if ($this->dotted_on) $this->DottedRect($this->x - $this->GetStringWidth($texto),$this->y,$this->GetStringWidth($texto),$this->lineheight);
- $this->x = $tempx;
- $this->x -= 1; //adjust alignment
- }
- $this->cssbegin=false;
- $this->backupcss=array();
- }
- //Save x,y coords ???
- $x = $this->x;
- $y = $this->y;
- //Set some default values
- $this->divSettings->setValue("divwidth", $this->pgwidth - $x + $this->lMargin);
- //Print content
- $this->printbuffer($this->textbuffer,true/*is out of a block (e.g. DIV,P etc.)*/);
- $this->textbuffer=array();
- //Reset values
- $this->Reset();
- }
- $this->buffer_on=false;
- }
- if($tag=='P' or $tag=='DIV') //CSS in BLOCK mode
- {
- $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
- if(!$this->tablestart)
- {
- if ($this->divSettings->getValue("divwidth") == 0) $this->divSettings->setValue("divwidth", $this->pgwidth);
- if ($tag=='P')
- {
- $this->pbegin=false;
- $this->pjustfinished=true;
- }
- else $this->divSettings->setValue("divbegin", false);
- $content='';
- foreach($this->textbuffer as $aux) $content .= $aux[0];
- $numlines = $this->WordWrap($content, $this->divSettings->getValue("divwidth"));
- if ($this->divheight == 0) $this->divheight = $numlines * 5;
- //Print content
- $this->printbuffer($this->textbuffer);
- $this->textbuffer=array();
- if ($tag=='P') $this->Ln($this->lineheight);
- }//end of 'if (!this->tablestart)'
- //Reset values
- $this->Reset();
- $this->cssbegin=false;
- $this->backupcss=array();
- }
- if($tag=='TABLE') { // TABLE-END
- $this->blockjustfinished = true; //Eliminate exceeding left-side spaces
- $this->table['cells'] = $this->cell;
- $this->table['wc'] = array_pad(array(),$this->table['nc'],array('miw'=>0,'maw'=>0));
- $this->table['hr'] = array_pad(array(),$this->table['nr'],0);
- $this->_tableColumnWidth($this->table);
- $this->_tableWidth($this->table);
- $this->_tableHeight($this->table);
-
- $this->_tableWrite($this->table);
-
- //Reset values
- $this->tablestart=false; //bool
- $this->table=array(); //array
- $this->cell=array(); //array
- $this->col=-1; //int
- $this->row=-1; //int
- $this->Reset();
- $this->Ln(0.5*$this->lineheight);
- }
- if(($tag=='UL') or ($tag=='OL')) {
- if ($this->buffer_on == false) $this->listnum--;
- if ($this->listlvl == 1) // We are…