From: <rc...@us...> - 2015-02-20 16:12:24
|
Revision: 7160 http://sourceforge.net/p/web-erp/reponame/7160 Author: rchacon Date: 2015-02-20 16:12:16 +0000 (Fri, 20 Feb 2015) Log Message: ----------- Right version. Sorry. Modified Paths: -------------- trunk/includes/class.pdf.php Modified: trunk/includes/class.pdf.php =================================================================== --- trunk/includes/class.pdf.php 2015-02-20 16:08:13 UTC (rev 7159) +++ trunk/includes/class.pdf.php 2015-02-20 16:12:16 UTC (rev 7160) @@ -71,90 +71,113 @@ TCPDF::Line ($x1,$this->h-$y1,$x2,$this->h-$y2,$style); } - function addText($xb,$YPos,$size,$text/*,$angle=0,$wordSpaceAdjust=0*/) { + function addText($XPos,$YPos,$fontsize,$text/*,$angle=0,$wordSpaceAdjust=0*/) { + // $XPos = cell horizontal coordinate from page left side to cell left side in dpi (72dpi = 25.4mm). + // $YPos = cell vertical coordinate from page bottom side to cell top side in dpi (72dpi = 25.4mm). + // $fontsize = font size in dpi (72dpi = 25.4mm). // Javier $text = html_entity_decode($text); - $this->SetFontSize($size);// Public function SetFontSize() in ~/includes/tcpdf/tcpdf.php. - $this->Text($xb, $this->h-$YPos, $text);// Public function Text() in ~/includes/tcpdf/tcpdf.php. + $this->SetFontSize($fontsize);// Public function SetFontSize() in ~/includes/tcpdf/tcpdf.php. + $this->Text($XPos, $this->h-$YPos, $text);// Public function Text() in ~/includes/tcpdf/tcpdf.php. } -//------------------------------------------------------------------------------ -public function addTextWrap($xpos, $ypos, $linewidth, $fontsize, $text, $justification='left', $angle=0, $test=0) { -// Adds text to the page, but ensure that it fits within a certain width. If it does not fit then put in as much as possible, splitting at white space or soft hyphen character and return the remainder. Justification can also be specified for the text. It use UTF-8 encoding. -// $xpos = cell horizontal coordinate from page left side to cell left side in dpi (72dpi = 25.4mm). -// $ypos = cell vertical coordinate from page bottom side to cell bottom? side in dpi (72dpi = 25.4mm). -// $linewidth = cell (line) width in dpi (72dpi = 25.4mm). -// $fontsize = font size in dpi (72dpi = 25.4mm). -// $text = text to be split in portion to be add to the page and the remainder to be returned. -// $justification = 'left', 'right', 'center', 'centre' or 'full'. -// Ignores $angle and $test. -// @access public. + 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 = cell horizontal coordinate from page left side to cell left side in dpi (72dpi = 25.4mm). + // $YPos = cell vertical coordinate from page bottom side to cell bottom side in dpi (72dpi = 25.4mm). + */ + //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'); -if($linewidth == 0) { - $linewidth = $this->w -$this->rMargin -$xpos;// Line_width = Page_width - Right_margin - Cell_horizontal_coordinate. -} + $this->x = $XPos; + $this->y = $this->h - $YPos - $Height;//RChacon: This -$Height is the difference in yPos between AddText() and AddTextWarp(). -$this->SetFontSize($fontsize);// Public function SetFontSize() in ~/includes/tcpdf/tcpdf.php. + switch($Align) { + case 'right': + $Align = 'R'; break; + case 'center': + $Align = 'C'; break; + default: + $Align = 'L'; + } + $this->SetFontSize($Height); -$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');// Convert all HTML entities to their applicable characters. + 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};*/ + $c=mb_substr($s, $i, 1, 'UTF-8'); + 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++; + } -switch($justification) {// Translate from Pdf-Creator to TCPDF. - case 'left': - $justification = 'L'; break; - case 'right': - $justification = 'R'; break; - case 'center': - $justification = 'C'; break; - case 'centre': - $justification = 'C'; break; - case 'full': - $justification = 'J'; break; - default: - $justification = 'L'; break; -} + 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->MultiCell($linewidth, $fontsize, $text, 0, $justification, false, 1, $xpos, $this->h - $ypos - $fontsize);// COMMENT: In "$this->h -$ypos -$fontsize", "-$fontsize" is the difference in the yPos between AddText() and AddTextWarp(). It is better "$this->h -$ypos", but that requires to recode all the pdf generator scripts. -} -//------------------------------------------------------------------------------ -function TextWrap($xpos, $ypos, $linewidth, $fontsize, $text, $justification='left', $angle=0, $test=0) { - // Adds text to the page, but ensure that it fits within a certain width. If it does not fit then put in as much as possible, splitting at white space or soft hyphen character and return the remainder. Justification can also be specified for the text. It use UTF-8 encoding. - // $xpos = cell horizontal coordinate from page left side to cell left side in dpi (72dpi = 25.4mm). - // $ypos = cell vertical coordinate from page bottom side to cell bottom? side in dpi (72dpi = 25.4mm). - // $linewidth = cell (line) width in dpi (72dpi = 25.4mm). - // $fontsize = font size in dpi (72dpi = 25.4mm). - // $text = text to be split in portion to be add to the page and the remainder to be returned. - // $justification = 'left', 'right', 'center', 'centre' or 'full'. - // Ignores $angle and $test. - // @access public. - if($linewidth == 0) { - $linewidth = $this->w -$this->rMargin -$xpos;// Line_width = Page_width - Right_margin - Cell_horizontal_coordinate. - } - $this->SetFontSize($fontsize);// Public function SetFontSize() in ~/includes/tcpdf/tcpdf.php. - $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');// Convert all HTML entities to their applicable characters. - switch($justification) {// Translate from Pdf-Creator to TCPDF. - case 'left': - $justification = 'L'; break; - case 'right': - $justification = 'R'; break; - case 'center': - $justification = 'C'; break; - case 'centre': - $justification = 'C'; break; - case 'full': - $justification = 'J'; break; - default: - $justification = 'L'; break; - } - $this->MultiCell($linewidth, $fontsize, $text, 0, $justification, false, 1, $xpos, $this->h - $ypos); - return $this->h - $this->y;// yPos is the same as in addText(). -} -//=========================================================================================== + $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') { /* Javier: Some scripts set the creator to be WebERP like this $pdf->addInfo('Creator', 'WebERP http://www.weberp.org'); - But the Creator is TCPDF by Nicola Asuni, PDF_CREATOR is defined as 'TCPDF' in ~/includes/tcpdf/config/tcpdfconfig.php + But the Creator is TCPDF by Nicola Asuni, PDF_CREATOR is defined as 'TCPDF' in tcpdf/config/tcpdfconfig.php */ $this->SetCreator(PDF_CREATOR); } if ($label == 'Author') { @@ -175,7 +198,7 @@ } function addJpegFromFile($img,$XPos,$YPos,$Width=0,$Height=0,$Type=''){ - $this->Image($img, $x=$XPos, $y=$this->h-$YPos/*-$Height*/, $w=$Width, $h=$Height,$type=$Type); + $this->Image($img, $x=$XPos, $y=$this->h-$YPos-$Height, $w=$Width, $h=$Height,$type=$Type); } /* |