32
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-11-22 12:55:10 +00:00
This commit is contained in:
nicolaasuni 2011-02-27 11:43:29 +01:00
parent af7f105c46
commit ea49e80f4b
3 changed files with 96 additions and 64 deletions

View File

@ -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) 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). - Image() method was improved to cache images with transparency layers (thanks to Korneliusz Jarzębski for reporting this problem).

View File

@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076
------------------------------------------------------------ ------------------------------------------------------------
Name: TCPDF Name: TCPDF
Version: 5.9.058 Version: 5.9.059
Release date: 2011-02-25 Release date: 2011-02-27
Author: Nicola Asuni Author: Nicola Asuni
Copyright (c) 2002-2011: Copyright (c) 2002-2011:

153
tcpdf.php
View File

@ -1,9 +1,9 @@
<?php <?php
//============================================================+ //============================================================+
// File name : tcpdf.php // File name : tcpdf.php
// Version : 5.9.058 // Version : 5.9.059
// Begin : 2002-08-03 // Begin : 2002-08-03
// Last Update : 2011-02-25 // Last Update : 2011-02-27
// Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com // Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
// License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS. // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS.
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -134,7 +134,7 @@
* Tools to encode your unicode fonts are on fonts/utils directory.</p> * Tools to encode your unicode fonts are on fonts/utils directory.</p>
* @package com.tecnick.tcpdf * @package com.tecnick.tcpdf
* @author Nicola Asuni * @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. // 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.<br> * 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.<br>
* @package com.tecnick.tcpdf * @package com.tecnick.tcpdf
* @brief PHP class for generating PDF documents without requiring external extensions. * @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 * @author Nicola Asuni - info@tecnick.com
*/ */
class TCPDF { class TCPDF {
@ -157,7 +157,7 @@ class TCPDF {
* Current TCPDF version. * Current TCPDF version.
* @private * @private
*/ */
private $tcpdf_version = '5.9.058'; private $tcpdf_version = '5.9.059';
// Protected properties // Protected properties
@ -566,6 +566,12 @@ class TCPDF {
*/ */
protected $PDFVersion = '1.7'; 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. * Minimum distance between header and top page margin.
* @protected * @protected
@ -4003,47 +4009,71 @@ class TCPDF {
* @public * @public
*/ */
public function Header() { public function Header() {
$ormargins = $this->getOriginalMargins(); if ($this->header_xobjid < 0) {
$headerfont = $this->getHeaderFont(); // start a new XObject Template
$headerdata = $this->getHeaderData(); $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin - $this->header_margin);
if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) { $headerfont = $this->getHeaderFont();
$imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']); $headerdata = $this->getHeaderData();
if (($imgtype == 'eps') OR ($imgtype == 'ai')) { $this->y = $this->header_margin;
$this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); if ($this->rtl) {
} elseif ($imgtype == 'svg') { $this->x = $this->w - $this->original_rMargin;
$this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
} else { } else {
$this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); $this->x = $this->original_lMargin;
} }
$imgy = $this->getImageRBY(); if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
} else { $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
$imgy = $this->GetY(); 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); // print header template
// set starting margin for text data cell $x = 0;
if ($this->getRTL()) { $dx = 0;
$header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1); if ($this->booklet AND (($this->page % 2) == 0)) {
} else { // adjust margins for booklet mode
$header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1); $dx = ($this->original_lMargin - $this->original_rMargin);
} }
$this->SetTextColor(0, 0, 0); if ($this->rtl) {
// header title $x = $this->w + $dx;
$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']);
} else { } 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
*/ */
public function Footer() { public function Footer() {
$cur_y = $this->GetY(); $cur_y = $this->y;
$ormargins = $this->getOriginalMargins();
$this->SetTextColor(0, 0, 0); $this->SetTextColor(0, 0, 0);
//set style for cell border //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))); $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
//print document barcode //print document barcode
$barcode = $this->getBarcode(); $barcode = $this->getBarcode();
if (!empty($barcode)) { if (!empty($barcode)) {
$this->Ln($line_width); $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( $style = array(
'position' => $this->rtl?'R':'L', 'position' => $this->rtl?'R':'L',
'align' => $this->rtl?'R':'L', 'align' => $this->rtl?'R':'L',
@ -4075,7 +4104,7 @@ class TCPDF {
'bgcolor' => false, 'bgcolor' => false,
'text' => 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)) { if (empty($this->pagegroups)) {
$pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
@ -4085,10 +4114,10 @@ class TCPDF {
$this->SetY($cur_y); $this->SetY($cur_y);
//Print page number //Print page number
if ($this->getRTL()) { if ($this->getRTL()) {
$this->SetX($ormargins['right']); $this->SetX($this->original_rMargin);
$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L'); $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
} else { } else {
$this->SetX($ormargins['left']); $this->SetX($this->original_lMargin);
$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R'); $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
} }
} }
@ -5267,7 +5296,7 @@ class TCPDF {
public function AcceptPageBreak() { public function AcceptPageBreak() {
if ($this->num_columns > 1) { if ($this->num_columns > 1) {
// multi column mode // multi column mode
if($this->current_column < ($this->num_columns - 1)) { if ($this->current_column < ($this->num_columns - 1)) {
// go to next column // go to next column
$this->selectColumn($this->current_column + 1); $this->selectColumn($this->current_column + 1);
} else { } else {
@ -7569,7 +7598,7 @@ class TCPDF {
* @since 4.6.025 (2009-08-17) * @since 4.6.025 (2009-08-17)
*/ */
public function set_mqr($mqr) { public function set_mqr($mqr) {
if(!defined('PHP_VERSION_ID')) { if (!defined('PHP_VERSION_ID')) {
$version = PHP_VERSION; $version = PHP_VERSION;
define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4})); 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) * @since 4.6.025 (2009-08-17)
*/ */
public function get_mqr() { public function get_mqr() {
if(!defined('PHP_VERSION_ID')) { if (!defined('PHP_VERSION_ID')) {
$version = PHP_VERSION; $version = PHP_VERSION;
define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4})); define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
} }
@ -8355,7 +8384,7 @@ class TCPDF {
for ($n=1; $n <= $nb; ++$n) { for ($n=1; $n <= $nb; ++$n) {
$temppage = $this->getPageBuffer($n); $temppage = $this->getPageBuffer($n);
if (!empty($this->pagegroups)) { if (!empty($this->pagegroups)) {
if(isset($this->newpagegroup[$n])) { if (isset($this->newpagegroup[$n])) {
$pagegroupnum = 0; $pagegroupnum = 0;
} }
++$pagegroupnum; ++$pagegroupnum;
@ -8842,7 +8871,7 @@ class TCPDF {
break; break;
} }
case 'link': { case 'link': {
if(is_string($pl['txt'])) { if (is_string($pl['txt'])) {
// external URI link // external URI link
$annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>'; $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
} else { } else {
@ -9874,7 +9903,7 @@ class TCPDF {
$this->_newobj(); $this->_newobj();
$s = '<</Type /FontDescriptor /FontName /'.$name; $s = '<</Type /FontDescriptor /FontName /'.$name;
foreach ($font['desc'] as $fdk => $fdv) { foreach ($font['desc'] as $fdk => $fdv) {
if(is_float($fdv)) { if (is_float($fdv)) {
$fdv = sprintf('%.3F', $fdv); $fdv = sprintf('%.3F', $fdv);
} }
$s .= ' /'.$fdk.' '.$fdv.''; $s .= ' /'.$fdk.' '.$fdv.'';
@ -10235,7 +10264,7 @@ class TCPDF {
$out = '<< /Type /FontDescriptor'; $out = '<< /Type /FontDescriptor';
$out .= ' /FontName /'.$fontname; $out .= ' /FontName /'.$fontname;
foreach ($font['desc'] as $key => $value) { foreach ($font['desc'] as $key => $value) {
if(is_float($value)) { if (is_float($value)) {
$value = sprintf('%.3F', $value); $value = sprintf('%.3F', $value);
} }
$out .= ' /'.$key.' '.$value; $out .= ' /'.$key.' '.$value;
@ -10346,7 +10375,7 @@ class TCPDF {
$s = '<</Type /FontDescriptor /FontName /'.$name; $s = '<</Type /FontDescriptor /FontName /'.$name;
foreach ($font['desc'] as $k => $v) { foreach ($font['desc'] as $k => $v) {
if ($k != 'Style') { if ($k != 'Style') {
if(is_float($v)) { if (is_float($v)) {
$v = sprintf('%.3F', $v); $v = sprintf('%.3F', $v);
} }
$s .= ' /'.$k.' '.$v.''; $s .= ' /'.$k.' '.$v.'';
@ -14463,7 +14492,7 @@ class TCPDF {
$x = $x - $w; $x = $x - $w;
} }
// the followind avoid fields duplication after saving the document // 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; $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 .= 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"; $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 == '#') { } elseif ($listtype == '#') {
// set default list type for ordered list // set default list type for ordered list
$listtype = 'decimal'; $listtype = 'decimal';
} elseif(substr($listtype, 0, 4) == 'img|') { } elseif (substr($listtype, 0, 4) == 'img|') {
// custom image type ('img|type|width|height|image.ext') // custom image type ('img|type|width|height|image.ext')
$img = explode('|', $listtype); $img = explode('|', $listtype);
$listtype = 'img'; $listtype = 'img';
@ -23698,7 +23727,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
public function selectColumn($col='') { public function selectColumn($col='') {
if (is_string($col)) { if (is_string($col)) {
$col = $this->current_column; $col = $this->current_column;
} elseif($col >= $this->num_columns) { } elseif ($col >= $this->num_columns) {
$col = 0; $col = 0;
} }
$xshift = 0; $xshift = 0;
@ -23918,8 +23947,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
} }
$inserted = 0; $inserted = 0;
$maxpos = $numchars - $rightmin; $maxpos = $numchars - $rightmin;
for($i = $leftmin; $i <= $maxpos; ++$i) { for ($i = $leftmin; $i <= $maxpos; ++$i) {
if(isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) { if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
// 173 = soft hyphen character // 173 = soft hyphen character
array_splice($word, $i + $inserted, 0, 173); array_splice($word, $i + $inserted, 0, 173);
++$inserted; ++$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 // sets the character data handler function for the XML parser
xml_set_character_data_handler($this->parser, 'segSVGContentHandler'); xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
// start parsing an XML document // 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)); $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); $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()) { protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
$objstyle = ''; $objstyle = '';
$minlen = (0.01 / $this->k); // minimum acceptable lenght (3 point) $minlen = (0.01 / $this->k); // minimum acceptable lenght (3 point)
if(!isset($svgstyle['opacity'])) { if (!isset($svgstyle['opacity'])) {
return $objstyle; return $objstyle;
} }
// clip-path // clip-path