From ea49e80f4b784e37791ac38bdf1c218a908b705c Mon Sep 17 00:00:00 2001 From: nicolaasuni Date: Sun, 27 Feb 2011 11:43:29 +0100 Subject: [PATCH] 5.9.059 --- CHANGELOG.TXT | 3 + README.TXT | 4 +- tcpdf.php | 153 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 96 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index d85ce87..ebfd313 100755 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -1,3 +1,6 @@ +5.9.059 (2011-02-27) + - Default Header() method was improved to reduce document size. + 5.9.058 (2011-02-25) - Image() method was improved to cache images with transparency layers (thanks to Korneliusz Jarzębski for reporting this problem). diff --git a/README.TXT b/README.TXT index 30a7cde..7a07e67 100755 --- a/README.TXT +++ b/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 5.9.058 -Release date: 2011-02-25 +Version: 5.9.059 +Release date: 2011-02-27 Author: Nicola Asuni Copyright (c) 2002-2011: diff --git a/tcpdf.php b/tcpdf.php index 57b4e8f..5d4c865 100755 --- a/tcpdf.php +++ b/tcpdf.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 5.9.058 + * @version 5.9.059 */ // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file. @@ -146,7 +146,7 @@ require_once(dirname(__FILE__).'/config/tcpdf_config.php'); * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.
* @package com.tecnick.tcpdf * @brief PHP class for generating PDF documents without requiring external extensions. - * @version 5.9.058 + * @version 5.9.059 * @author Nicola Asuni - info@tecnick.com */ class TCPDF { @@ -157,7 +157,7 @@ class TCPDF { * Current TCPDF version. * @private */ - private $tcpdf_version = '5.9.058'; + private $tcpdf_version = '5.9.059'; // Protected properties @@ -566,6 +566,12 @@ class TCPDF { */ protected $PDFVersion = '1.7'; + /** + * ID of the stored default header template (-1 = not set). + * @protected + */ + protected $header_xobjid = -1; + /** * Minimum distance between header and top page margin. * @protected @@ -4003,47 +4009,71 @@ class TCPDF { * @public */ public function Header() { - $ormargins = $this->getOriginalMargins(); - $headerfont = $this->getHeaderFont(); - $headerdata = $this->getHeaderData(); - if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) { - $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']); - if (($imgtype == 'eps') OR ($imgtype == 'ai')) { - $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); - } elseif ($imgtype == 'svg') { - $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); + if ($this->header_xobjid < 0) { + // start a new XObject Template + $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin - $this->header_margin); + $headerfont = $this->getHeaderFont(); + $headerdata = $this->getHeaderData(); + $this->y = $this->header_margin; + if ($this->rtl) { + $this->x = $this->w - $this->original_rMargin; } else { - $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); + $this->x = $this->original_lMargin; } - $imgy = $this->getImageRBY(); - } else { - $imgy = $this->GetY(); + if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) { + $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']); + if (($imgtype == 'eps') OR ($imgtype == 'ai')) { + $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); + } elseif ($imgtype == 'svg') { + $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); + } else { + $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); + } + $imgy = $this->getImageRBY(); + } else { + $imgy = $this->y; + } + $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2); + // set starting margin for text data cell + if ($this->getRTL()) { + $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1); + } else { + $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1); + } + $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1); + $this->SetTextColor(0, 0, 0); + // header title + $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1); + $this->SetX($header_x); + $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0); + // header string + $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]); + $this->SetX($header_x); + $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false); + // print an ending header line + $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); + $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY())); + if ($this->rtl) { + $this->SetX($this->original_rMargin); + } else { + $this->SetX($this->original_lMargin); + } + $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C'); + $this->endTemplate(); } - $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2); - // set starting margin for text data cell - if ($this->getRTL()) { - $header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1); - } else { - $header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1); + // print header template + $x = 0; + $dx = 0; + if ($this->booklet AND (($this->page % 2) == 0)) { + // adjust margins for booklet mode + $dx = ($this->original_lMargin - $this->original_rMargin); } - $this->SetTextColor(0, 0, 0); - // header title - $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1); - $this->SetX($header_x); - $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0); - // header string - $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]); - $this->SetX($header_x); - $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false); - // print an ending header line - $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); - $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY())); - if ($this->getRTL()) { - $this->SetX($ormargins['right']); + if ($this->rtl) { + $x = $this->w + $dx; } else { - $this->SetX($ormargins['left']); + $x = 0 + $dx; } - $this->Cell(0, 0, '', 'T', 0, 'C'); + $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false); } /** @@ -4052,17 +4082,16 @@ class TCPDF { * @public */ public function Footer() { - $cur_y = $this->GetY(); - $ormargins = $this->getOriginalMargins(); + $cur_y = $this->y; $this->SetTextColor(0, 0, 0); //set style for cell border - $line_width = 0.85 / $this->getScaleFactor(); + $line_width = 0.85 / $this->k; $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); //print document barcode $barcode = $this->getBarcode(); if (!empty($barcode)) { $this->Ln($line_width); - $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right']) / 3); + $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3); $style = array( 'position' => $this->rtl?'R':'L', 'align' => $this->rtl?'R':'L', @@ -4075,7 +4104,7 @@ class TCPDF { 'bgcolor' => false, 'text' => false ); - $this->write1DBarcode($barcode, 'C128B', '', $cur_y + $line_width, '', (($this->getFooterMargin() / 3) - $line_width), 0.3, $style, ''); + $this->write1DBarcode($barcode, 'C128B', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, ''); } if (empty($this->pagegroups)) { $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); @@ -4085,10 +4114,10 @@ class TCPDF { $this->SetY($cur_y); //Print page number if ($this->getRTL()) { - $this->SetX($ormargins['right']); + $this->SetX($this->original_rMargin); $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L'); } else { - $this->SetX($ormargins['left']); + $this->SetX($this->original_lMargin); $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R'); } } @@ -5267,7 +5296,7 @@ class TCPDF { public function AcceptPageBreak() { if ($this->num_columns > 1) { // multi column mode - if($this->current_column < ($this->num_columns - 1)) { + if ($this->current_column < ($this->num_columns - 1)) { // go to next column $this->selectColumn($this->current_column + 1); } else { @@ -7569,7 +7598,7 @@ class TCPDF { * @since 4.6.025 (2009-08-17) */ public function set_mqr($mqr) { - if(!defined('PHP_VERSION_ID')) { + if (!defined('PHP_VERSION_ID')) { $version = PHP_VERSION; define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4})); } @@ -7584,7 +7613,7 @@ class TCPDF { * @since 4.6.025 (2009-08-17) */ public function get_mqr() { - if(!defined('PHP_VERSION_ID')) { + if (!defined('PHP_VERSION_ID')) { $version = PHP_VERSION; define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4})); } @@ -8355,7 +8384,7 @@ class TCPDF { for ($n=1; $n <= $nb; ++$n) { $temppage = $this->getPageBuffer($n); if (!empty($this->pagegroups)) { - if(isset($this->newpagegroup[$n])) { + if (isset($this->newpagegroup[$n])) { $pagegroupnum = 0; } ++$pagegroupnum; @@ -8842,7 +8871,7 @@ class TCPDF { break; } case 'link': { - if(is_string($pl['txt'])) { + if (is_string($pl['txt'])) { // external URI link $annots .= ' /A <_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>'; } else { @@ -9874,7 +9903,7 @@ class TCPDF { $this->_newobj(); $s = '< $fdv) { - if(is_float($fdv)) { + if (is_float($fdv)) { $fdv = sprintf('%.3F', $fdv); } $s .= ' /'.$fdk.' '.$fdv.''; @@ -10235,7 +10264,7 @@ class TCPDF { $out = '<< /Type /FontDescriptor'; $out .= ' /FontName /'.$fontname; foreach ($font['desc'] as $key => $value) { - if(is_float($value)) { + if (is_float($value)) { $value = sprintf('%.3F', $value); } $out .= ' /'.$key.' '.$value; @@ -10346,7 +10375,7 @@ class TCPDF { $s = '< $v) { if ($k != 'Style') { - if(is_float($v)) { + if (is_float($v)) { $v = sprintf('%.3F', $v); } $s .= ' /'.$k.' '.$v.''; @@ -14463,7 +14492,7 @@ class TCPDF { $x = $x - $w; } // the followind avoid fields duplication after saving the document - $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {"; + $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {"; $k = $this->k; $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n"; $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n"; @@ -22357,7 +22386,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } elseif ($listtype == '#') { // set default list type for ordered list $listtype = 'decimal'; - } elseif(substr($listtype, 0, 4) == 'img|') { + } elseif (substr($listtype, 0, 4) == 'img|') { // custom image type ('img|type|width|height|image.ext') $img = explode('|', $listtype); $listtype = 'img'; @@ -23698,7 +23727,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: public function selectColumn($col='') { if (is_string($col)) { $col = $this->current_column; - } elseif($col >= $this->num_columns) { + } elseif ($col >= $this->num_columns) { $col = 0; } $xshift = 0; @@ -23918,8 +23947,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } $inserted = 0; $maxpos = $numchars - $rightmin; - for($i = $leftmin; $i <= $maxpos; ++$i) { - if(isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) { + for ($i = $leftmin; $i <= $maxpos; ++$i) { + if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) { // 173 = soft hyphen character array_splice($word, $i + $inserted, 0, 173); ++$inserted; @@ -24895,7 +24924,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // sets the character data handler function for the XML parser xml_set_character_data_handler($this->parser, 'segSVGContentHandler'); // start parsing an XML document - if(!xml_parse($this->parser, $svgdata)) { + if (!xml_parse($this->parser, $svgdata)) { $error_message = sprintf("SVG Error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)); $this->Error($error_message); } @@ -25129,7 +25158,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) { $objstyle = ''; $minlen = (0.01 / $this->k); // minimum acceptable lenght (3 point) - if(!isset($svgstyle['opacity'])) { + if (!isset($svgstyle['opacity'])) { return $objstyle; } // clip-path