30
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-05-31 21:30:47 +00:00

5.9.167 (2012-06-22)

- Thai language rendering was fixed and improved.
- Method isCharDefined() was improved.
- Protected method replaceChar() was added.
- Font kerning word was corrected to tracking.
This commit is contained in:
nick 2012-06-22 08:14:47 +01:00
parent 9ea87e1c44
commit 5ca264c68d
5 changed files with 93 additions and 54 deletions

View File

@ -1,3 +1,9 @@
5.9.167 (2012-06-22)
- Thai language rendering was fixed and improved.
- Method isCharDefined() was improved.
- Protected method replaceChar() was added.
- Font "kerning" word was corrected to "tracking".
5.9.166 (2012-06-21) 5.9.166 (2012-06-21)
- Array to string conversion on file_id creation was fixed. - Array to string conversion on file_id creation was fixed.
- Thai language rendering was fixed (thanks to Atsawin Chaowanakritsanakul). - Thai language rendering was fixed (thanks to Atsawin Chaowanakritsanakul).
@ -601,7 +607,7 @@
- The problem of blank page for nobr table higher than a single page was fixed. - The problem of blank page for nobr table higher than a single page was fixed.
5.9.000 (2010-10-06) 5.9.000 (2010-10-06)
- Support for text stretching and spacing (kerning) was added, see example n. 63 and methods setFontStretching(), getFontStretching(), setFontSpacing(), getFontSpacing(). - Support for text stretching and spacing (tracking) was added, see example n. 63 and methods setFontStretching(), getFontStretching(), setFontSpacing(), getFontSpacing().
- Support for CSS properties 'font-stretch' and 'letter-spacing' was added (see example n. 63). - Support for CSS properties 'font-stretch' and 'letter-spacing' was added (see example n. 63).
- The cMargin state was replaced by cell_padding array that can be set/get using setCellPadding() and getCellPadding() methods. - The cMargin state was replaced by cell_padding array that can be set/get using setCellPadding() and getCellPadding() methods.
- Methods getCellPaddings() and setCellPaddings() were added to fine tune cell paddings (see example n. 5). - Methods getCellPaddings() and setCellPaddings() were added to fine tune cell paddings (see example n. 5).

View File

@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076
------------------------------------------------------------ ------------------------------------------------------------
Name: TCPDF Name: TCPDF
Version: 5.9.166 Version: 5.9.167
Release date: 2012-06-21 Release date: 2012-06-22
Author: Nicola Asuni Author: Nicola Asuni
Copyright (c) 2002-2012: Copyright (c) 2002-2012:
@ -47,7 +47,7 @@ Main Features:
* no-write page regions; * no-write page regions;
* bookmarks, named destinations and table of content; * bookmarks, named destinations and table of content;
* text hyphenation; * text hyphenation;
* text stretching and spacing (tracking/kerning); * text stretching and spacing (tracking);
* automatic page break, line break and text alignments including justification; * automatic page break, line break and text alignments including justification;
* automatic page numbering and page groups; * automatic page numbering and page groups;
* move and delete pages; * move and delete pages;

View File

@ -66,6 +66,9 @@ $pdf->setLanguageArray($l);
// --------------------------------------------------------- // ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// set font // set font
$pdf->SetFont('freeserif', '', 12); $pdf->SetFont('freeserif', '', 12);

View File

@ -2,10 +2,10 @@
//============================================================+ //============================================================+
// File name : example_063.php // File name : example_063.php
// Begin : 2010-09-29 // Begin : 2010-09-29
// Last Update : 2010-10-05 // Last Update : 2012-06-21
// //
// Description : Example 063 for TCPDF class // Description : Example 063 for TCPDF class
// Text stretching and spacing (tracking/kerning) // Text stretching and spacing (tracking)
// //
// Author: Nicola Asuni // Author: Nicola Asuni
// //
@ -22,7 +22,7 @@
/** /**
* Creates an example PDF TEST document using TCPDF * Creates an example PDF TEST document using TCPDF
* @package com.tecnick.tcpdf * @package com.tecnick.tcpdf
* @abstract TCPDF - Example: Text stretching and spacing (tracking/kerning) * @abstract TCPDF - Example: Text stretching and spacing (tracking)
* @author Nicola Asuni * @author Nicola Asuni
* @since 2010-09-29 * @since 2010-09-29
*/ */
@ -72,10 +72,10 @@ $pdf->SetFont('helvetica', 'B', 16);
// add a page // add a page
$pdf->AddPage(); $pdf->AddPage();
$pdf->Write(0, 'Example of Text Stretching and Spacing (tracking/kerning)', '', 0, 'L', true, 0, false, false, 0); $pdf->Write(0, 'Example of Text Stretching and Spacing (tracking)', '', 0, 'L', true, 0, false, false, 0);
$pdf->Ln(5); $pdf->Ln(5);
// create several cells to display all cases of stretching and kerning combinations. // create several cells to display all cases of stretching and spacing combinations.
$fonts = array('times', 'dejavuserif'); $fonts = array('times', 'dejavuserif');
$alignments = array('L' => 'LEFT', 'C' => 'CENTER', 'R' => 'RIGHT', 'J' => 'JUSTIFY'); $alignments = array('L' => 'LEFT', 'C' => 'CENTER', 'R' => 'RIGHT', 'J' => 'JUSTIFY');

120
tcpdf.php
View File

@ -1,9 +1,9 @@
<?php <?php
//============================================================+ //============================================================+
// File name : tcpdf.php // File name : tcpdf.php
// Version : 5.9.166 // Version : 5.9.167
// Begin : 2002-08-03 // Begin : 2002-08-03
// Last Update : 2012-06-21 // Last Update : 2012-06-22
// Author : Nicola Asuni - Tecnick.com LTD - Manor Coach House, Church Hill, Aldershot, Hants, GU12 4RQ, UK - www.tecnick.com - info@tecnick.com // Author : Nicola Asuni - Tecnick.com LTD - Manor Coach House, Church Hill, Aldershot, Hants, GU12 4RQ, UK - www.tecnick.com - info@tecnick.com
// License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -57,7 +57,7 @@
// * no-write page regions; // * no-write page regions;
// * bookmarks, named destinations and table of content; // * bookmarks, named destinations and table of content;
// * text hyphenation; // * text hyphenation;
// * text stretching and spacing (tracking/kerning); // * text stretching and spacing (tracking);
// * automatic page break, line break and text alignments including justification; // * automatic page break, line break and text alignments including justification;
// * automatic page numbering and page groups; // * automatic page numbering and page groups;
// * move and delete pages; // * move and delete pages;
@ -125,7 +125,7 @@
* <li>no-write page regions;</li> * <li>no-write page regions;</li>
* <li>bookmarks, named destinations and table of content;</li> * <li>bookmarks, named destinations and table of content;</li>
* <li>text hyphenation;</li> * <li>text hyphenation;</li>
* <li>text stretching and spacing (tracking/kerning);</li> * <li>text stretching and spacing (tracking);</li>
* <li>automatic page break, line break and text alignments including justification;</li> * <li>automatic page break, line break and text alignments including justification;</li>
* <li>automatic page numbering and page groups;</li> * <li>automatic page numbering and page groups;</li>
* <li>move and delete pages;</li> * <li>move and delete pages;</li>
@ -137,7 +137,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.166 * @version 5.9.167
*/ */
// 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.
@ -149,7 +149,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.166 * @version 5.9.167
* @author Nicola Asuni - info@tecnick.com * @author Nicola Asuni - info@tecnick.com
*/ */
class TCPDF { class TCPDF {
@ -160,7 +160,7 @@ class TCPDF {
* Current TCPDF version. * Current TCPDF version.
* @private * @private
*/ */
private $tcpdf_version = '5.9.166'; private $tcpdf_version = '5.9.167';
// Protected properties // Protected properties
@ -1596,7 +1596,7 @@ class TCPDF {
protected $font_stretching = 100; protected $font_stretching = 100;
/** /**
* Increases or decreases the space between characters in a text by the specified amount (tracking/kerning). * Increases or decreases the space between characters in a text by the specified amount (tracking).
* @protected * @protected
* @since 5.9.000 (2010-09-29) * @since 5.9.000 (2010-09-29)
*/ */
@ -4933,7 +4933,7 @@ class TCPDF {
} }
/** /**
* Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking/kerning). * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
* @param $char (int) The char code whose length is to be returned * @param $char (int) The char code whose length is to be returned
* @param $notlast (boolean) set to false for the latest character on string, true otherwise (default) * @param $notlast (boolean) set to false for the latest character on string, true otherwise (default)
* @return float char width * @return float char width
@ -5414,7 +5414,7 @@ class TCPDF {
} }
/** /**
* Return the font ascent value * Return the font ascent value.
* @param $font (string) font name * @param $font (string) font name
* @param $style (string) font style * @param $style (string) font style
* @param $size (float) The size (in points) * @param $size (float) The size (in points)
@ -5435,7 +5435,7 @@ class TCPDF {
} }
/** /**
* Return the font descent value * Return true in the character is present in the specified font.
* @param $char (mixed) Character to check (integer value or string) * @param $char (mixed) Character to check (integer value or string)
* @param $font (string) Font name (family name). * @param $font (string) Font name (family name).
* @param $style (string) Font style. * @param $style (string) Font style.
@ -5450,6 +5450,9 @@ class TCPDF {
$char = $char[0]; $char = $char[0];
} }
if ($this->empty_string($font)) { if ($this->empty_string($font)) {
if ($this->empty_string($style)) {
return (isset($this->CurrentFont['cw'][intval($char)]));
}
$font = $this->FontFamily; $font = $this->FontFamily;
} }
$fontdata = $this->AddFont($font, $style); $fontdata = $this->AddFont($font, $style);
@ -6063,71 +6066,57 @@ class TCPDF {
// sara um // sara um
if (in_array($ch1, $longtail)) { if (in_array($ch1, $longtail)) {
// tonemark at upper left // tonemark at upper left
$newchr = (0xf713 + $ch0 - 0x0e48); $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
$output[] = $newchr;
$this->CurrentFont['subsetchars'][$newchr] = true;
} else { } else {
// tonemark at upper right (normal position) // tonemark at upper right (normal position)
$output[] = $ch0; $output[] = $ch0;
} }
} elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) { } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
// tonemark at lower left // tonemark at lower left
$newchr = (0xf705 + $ch0 - 0x0e48); $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
$output[] = $newchr;
$this->CurrentFont['subsetchars'][$newchr] = true;
} elseif (in_array($ch1, $upvowel)) { } elseif (in_array($ch1, $upvowel)) {
if (in_array($ch2, $longtail)) { if (in_array($ch2, $longtail)) {
// tonemark at upper left // tonemark at upper left
$newchr = (0xf713 + $ch0 - 0x0e48); $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
$output[] = $newchr;
$this->CurrentFont['subsetchars'][$newchr] = true;
} else { } else {
// tonemark at upper right (normal position) // tonemark at upper right (normal position)
$output[] = $ch0; $output[] = $ch0;
} }
} else { } else {
// tonemark at lower right // tonemark at lower right
$newchr = (0xf70a + $ch0 - 0x0e48); $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
$output[] = $newchr;
$this->CurrentFont['subsetchars'][$newchr] = true;
} }
} elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) { } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
// add lower left nikhahit and sara aa // add lower left nikhahit and sara aa
$output[] = 0xf711; if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
$this->CurrentFont['subsetchars'][0xf711] = true; $output[] = 0xf711;
$output[] = 0x0e32; $output[] = 0x0e32;
$this->CurrentFont['subsetchars'][0x0e32] = true; } else {
$output[] = $ch0;
}
} elseif (in_array($ch1, $longtail)) { } elseif (in_array($ch1, $longtail)) {
if ($ch0 == 0x0e31) { if ($ch0 == 0x0e31) {
// lower left mai hun arkad // lower left mai hun arkad
$output[] = 0xf710; $output[] = $this->replaceChar($ch0, 0xf710);
$this->CurrentFont['subsetchars'][0xf710] = true;
} elseif (in_array($ch0, $upvowel)) { } elseif (in_array($ch0, $upvowel)) {
// lower left // lower left
$newchr = (0xf701 + $ch0 - 0x0e34); $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
$output[] = $newchr;
$this->CurrentFont['subsetchars'][$newchr] = true;
} elseif ($ch0 == 0x0e47) { } elseif ($ch0 == 0x0e47) {
// lower left mai tai koo // lower left mai tai koo
$output[] = 0xf712; $output[] = $this->replaceChar($ch0, 0xf712);
$this->CurrentFont['subsetchars'][0xf712] = true;
} else { } else {
// normal character // normal character
$output[] = $ch0; $output[] = $ch0;
} }
} elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) { } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
// lower vowel // lower vowel
$newchr = (0xf718 + $ch0 - 0x0e38); $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
$output[] = $newchr;
$this->CurrentFont['subsetchars'][$newchr] = true;
} elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) { } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
// yo ying without lower part // yo ying without lower part
$output[] = 0xf70f; $output[] = $this->replaceChar($ch0, 0xf70f);
$this->CurrentFont['subsetchars'][0xf70f] = true;
} elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) { } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
// tho santan without lower part // tho santan without lower part
$output[] = 0xf700; $output[] = $this->replaceChar($ch0, 0xf700);
$this->CurrentFont['subsetchars'][0xf700] = true;
} else { } else {
$output[] = $ch0; $output[] = $ch0;
} }
@ -6136,6 +6125,7 @@ class TCPDF {
$output[] = $unicode[$i]; $output[] = $unicode[$i];
} }
} }
$unicode = $output;
} // end of K_THAI_TOPCHARS } // end of K_THAI_TOPCHARS
$txt2 = $this->arrUTF8ToUTF16BE($unicode, false); $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
} }
@ -6253,6 +6243,27 @@ class TCPDF {
$xdk = $xdx * $k; $xdk = $xdx * $k;
// print text // print text
$s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2); $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
if (isset($uniblock)) {
// print overlapping characters as separate string
$xshift = 0; // horizontal shift
$ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
$spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
foreach ($uniblock as $uk => $uniarr) {
if (($uk % 2) == 0) {
// x space to skip
if ($spacewidth != 0) {
// justification shift
$xshift += (count(array_keys($uniarr, 32)) * $spw);
}
$xshift += $this->GetArrStringWidth($uniarr); // + shift justification
} else {
// character to print
$topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
$topchr = $this->_escape($topchr);
$s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
}
}
}
if ($this->underline) { if ($this->underline) {
$s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width); $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
} }
@ -6315,6 +6326,25 @@ class TCPDF {
return $rs; return $rs;
} }
/**
* Replace a char if is defined on the current font.
* @param $oldchar (int) Integer code (unicode) of the character to replace.
* @param $newchar (int) Integer code (unicode) of the new character.
* @return int the replaced char or the old char in case the new char i not defined
* @protected
* @since 5.9.167 (2012-06-22)
*/
protected function replaceChar($oldchar, $newchar) {
if ($this->isCharDefined($newchar)) {
// add the new char on the subset list
$this->CurrentFont['subsetchars'][$newchar] = true;
// return the new char
return $newchr;
}
// return the old char
return $oldchar;
}
/** /**
* Returns the code to draw the cell border * Returns the code to draw the cell border
* @param $x (float) X coordinate. * @param $x (float) X coordinate.
@ -20970,7 +21000,7 @@ class TCPDF {
/** /**
* Returns the letter-spacing value from CSS value * Returns the letter-spacing value from CSS value
* @param $spacing (string) letter-spacing value * @param $spacing (string) letter-spacing value
* @param $parent (float) font spacing (tracking/kerning) value of the parent element * @param $parent (float) font spacing (tracking) value of the parent element
* @return float quantity to increases or decreases the space between characters in a text. * @return float quantity to increases or decreases the space between characters in a text.
* @protected * @protected
* @since 5.9.000 (2010-10-02) * @since 5.9.000 (2010-10-02)
@ -21918,7 +21948,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
$curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize); $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
$curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize); $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
$curfontstretcing = $this->font_stretching; $curfontstretcing = $this->font_stretching;
$curfontkerning = $this->font_spacing; $curfonttracking = $this->font_spacing;
$this->newline = true; $this->newline = true;
$newline = true; $newline = true;
$startlinepage = $this->page; $startlinepage = $this->page;
@ -22057,7 +22087,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
$this_method_vars['curfontascent'] = $curfontascent; $this_method_vars['curfontascent'] = $curfontascent;
$this_method_vars['curfontdescent'] = $curfontdescent; $this_method_vars['curfontdescent'] = $curfontdescent;
$this_method_vars['curfontstretcing'] = $curfontstretcing; $this_method_vars['curfontstretcing'] = $curfontstretcing;
$this_method_vars['curfontkerning'] = $curfontkerning; $this_method_vars['curfonttracking'] = $curfonttracking;
$this_method_vars['minstartliney'] = $minstartliney; $this_method_vars['minstartliney'] = $minstartliney;
$this_method_vars['maxbottomliney'] = $maxbottomliney; $this_method_vars['maxbottomliney'] = $maxbottomliney;
$this_method_vars['yshift'] = $yshift; $this_method_vars['yshift'] = $yshift;
@ -27453,7 +27483,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
/** /**
* Get the amount to increase or decrease the space between characters in a text. * Get the amount to increase or decrease the space between characters in a text.
* @return int font spacing (tracking/kerning) value * @return int font spacing (tracking) value
* @author Nicola Asuni * @author Nicola Asuni
* @public * @public
* @since 5.9.000 (2010-09-29) * @since 5.9.000 (2010-09-29)