From: <rc...@us...> - 2014-08-04 20:16:17
|
Revision: 6803 http://sourceforge.net/p/web-erp/reponame/6803 Author: rchacon Date: 2014-08-04 20:16:08 +0000 (Mon, 04 Aug 2014) Log Message: ----------- class.pdf.php: Adds comments and regroups AddText and AddTextWarp. Modified Paths: -------------- trunk/includes/class.pdf.php Modified: trunk/includes/class.pdf.php =================================================================== --- trunk/includes/class.pdf.php 2014-08-02 05:07:53 UTC (rev 6802) +++ trunk/includes/class.pdf.php 2014-08-04 20:16:08 UTC (rev 6803) @@ -71,13 +71,103 @@ TCPDF::Line ($x1,$this->h-$y1,$x2,$this->h-$y2,$style); } - function addText($xb,$YPos,$size,$text)//,$angle=0,$wordSpaceAdjust=0) - { + function addText($xb,$YPos,$size,$text/*,$angle=0,$wordSpaceAdjust=0*/) { // Javier $text = html_entity_decode($text); $this->SetFontSize($size); $this->Text($xb, $this->h-$YPos, $text); } + function addTextWrap($XPos, $YPos, $Width, $Height, $Text, $Align='J', $border=0, $fill=0) { + // R&OS version 0.12.2: "addTextWrap function is no more, use addText instead". + /* Returns the balance of the string that could not fit in the width + * XPos = pdf horizontal coordinate + * YPos = pdf vertical coordiante + */ + //some special characters are html encoded + //this code serves to make them appear human readable in pdf file + $Text = html_entity_decode($Text, ENT_QUOTES, 'UTF-8'); + + $this->x = $XPos; + $this->y = $this->h - $YPos - $Height;//RChacon: This -$Height is the difference in yPos between AddText() and AddTextWarp(). + + switch($Align) { + case 'right': + $Align = 'R'; break; + case 'center': + $Align = 'C'; break; + default: + $Align = 'L'; + } + $this->SetFontSize($Height); + + if($Width==0) { + $Width=$this->w-$this->rMargin-$this->x; + } + $wmax=($Width-2*$this->cMargin); + $s=str_replace("\r",'',$Text); + $s=str_replace("\n",' ',$s); + $s = trim($s).' '; + $nb=mb_strlen($s); + $b=0; + if ($border) { + if ($border==1) { + $border='LTRB'; + $b='LRT'; + $b2='LR'; + } else { + $b2=''; + if(is_int(mb_strpos($border,'L'))) { + $b2.='L'; + } + if(is_int(mb_strpos($border,'R'))) { + $b2.='R'; + } + $b=is_int(mb_strpos($border,'T')) ? $b2.'T' : $b2; + } + } + $sep=-1; + $i=0; + $l= $ls=0; + $ns=0; + $cw = $this->GetStringWidth($s, '', '', 0, true); + while($i<$nb) { + $c=$s{$i}; + if($c==' ' AND $i>0) { + $sep=$i; + $ls=$l; + $ns++; + } + if (isset($cw[$i])) { + $l += $cw[$i]; + } + if($l>$wmax){ + break; + } else { + $i++; + } + } + if($sep==-1) { + if($i==0) { + $i++; + } + + if(isset($this->ws) and $this->ws>0) { + $this->ws=0; + $this->_out('0 Tw'); + } + $sep = $i; + } else { + if($Align=='J') { + $this->ws=($ns>1) ? ($wmax-$ls)/($ns-1) : 0; + $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); + } + } + + $this->Cell($Width,$Height,mb_substr($s,0,$sep),$b,2,$Align,$fill); + $this->x=$this->lMargin; + return mb_substr($s, $sep); + }// End function addTextWrap. + function addInfo($label, $value) { if ($label == 'Creator') { @@ -239,96 +329,6 @@ $this->partEllipse($XPos+$Width-$RadiusX, $YPos-$Height+$RadiusY, 270, 360, $RadiusX, $RadiusY);// Bottom right corner. } - function addTextWrap($XPos, $YPos, $Width, $Height, $Text, $Align='J', $border=0, $fill=0) { - /* Returns the balance of the string that could not fit in the width - * XPos = pdf horizontal coordinate - * YPos = pdf vertical coordiante - */ - //some special characters are html encoded - //this code serves to make them appear human readable in pdf file - $Text = html_entity_decode($Text, ENT_QUOTES, 'UTF-8'); - - $this->x = $XPos; - $this->y = $this->h - $YPos - $Height; - - switch($Align) { - case 'right': - $Align = 'R'; break; - case 'center': - $Align = 'C'; break; - default: - $Align = 'L'; - } - $this->SetFontSize($Height); - - if($Width==0) { - $Width=$this->w-$this->rMargin-$this->x; - } - $wmax=($Width-2*$this->cMargin); - $s=str_replace("\r",'',$Text); - $s=str_replace("\n",' ',$s); - $s = trim($s).' '; - $nb=mb_strlen($s); - $b=0; - if ($border) { - if ($border==1) { - $border='LTRB'; - $b='LRT'; - $b2='LR'; - } else { - $b2=''; - if(is_int(mb_strpos($border,'L'))) { - $b2.='L'; - } - if(is_int(mb_strpos($border,'R'))) { - $b2.='R'; - } - $b=is_int(mb_strpos($border,'T')) ? $b2.'T' : $b2; - } - } - $sep=-1; - $i=0; - $l= $ls=0; - $ns=0; - $cw = $this->GetStringWidth($s, '', '', 0, true); - while($i<$nb) { - $c=$s{$i}; - if($c==' ' AND $i>0) { - $sep=$i; - $ls=$l; - $ns++; - } - if (isset($cw[$i])) { - $l += $cw[$i]; - } - if($l>$wmax){ - break; - } else { - $i++; - } - } - if($sep==-1) { - if($i==0) { - $i++; - } - - if(isset($this->ws) and $this->ws>0) { - $this->ws=0; - $this->_out('0 Tw'); - } - $sep = $i; - } else { - if($Align=='J') { - $this->ws=($ns>1) ? ($wmax-$ls)/($ns-1) : 0; - $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); - } - } - - $this->Cell($Width,$Height,mb_substr($s,0,$sep),$b,2,$Align,$fill); - $this->x=$this->lMargin; - return mb_substr($s, $sep); - } //end function addTextWrap - } // end of class } //end if Cpdf class exists already ?> |