Update TCPDF.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
//============================================================+
|
||||
// File name : tcpdf_fonts.php
|
||||
// Version : 1.0.013
|
||||
// Version : 1.1.0
|
||||
// Begin : 2008-01-01
|
||||
// Last Update : 2014-05-23
|
||||
// Last Update : 2014-12-10
|
||||
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
|
||||
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
|
||||
// -------------------------------------------------------------------
|
||||
@@ -42,7 +42,7 @@
|
||||
* @class TCPDF_FONTS
|
||||
* Font methods for TCPDF library.
|
||||
* @package com.tecnick.tcpdf
|
||||
* @version 1.0.013
|
||||
* @version 1.1.0
|
||||
* @author Nicola Asuni - info@tecnick.com
|
||||
*/
|
||||
class TCPDF_FONTS {
|
||||
@@ -70,7 +70,7 @@ class TCPDF_FONTS {
|
||||
* @public static
|
||||
*/
|
||||
public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false, $link=false) {
|
||||
if (!file_exists($fontfile)) {
|
||||
if (!TCPDF_STATIC::file_exists($fontfile)) {
|
||||
// Could not find file
|
||||
return false;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class TCPDF_FONTS {
|
||||
$outpath = self::_getfontpath();
|
||||
}
|
||||
// check if this font already exist
|
||||
if (@file_exists($outpath.$font_name.'.php')) {
|
||||
if (@TCPDF_STATIC::file_exists($outpath.$font_name.'.php')) {
|
||||
// this font already exist (delete it from fonts folder to rebuild it)
|
||||
return $font_name;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class TCPDF_FONTS {
|
||||
$enc_target = TCPDF_FONT_DATA::$encmap[$enc];
|
||||
$last = 0;
|
||||
for ($i = 32; $i <= 255; ++$i) {
|
||||
if ($enc_target != $enc_ref[$i]) {
|
||||
if ($enc_target[$i] != $enc_ref[$i]) {
|
||||
if ($i != ($last + 1)) {
|
||||
$fmetric['diff'] .= $i.' ';
|
||||
}
|
||||
@@ -186,7 +186,7 @@ class TCPDF_FONTS {
|
||||
$data .= $encrypted;
|
||||
// store compressed font
|
||||
$fmetric['file'] .= '.z';
|
||||
$fp = fopen($outpath.$fmetric['file'], 'wb');
|
||||
$fp = TCPDF_STATIC::fopenLocal($outpath.$fmetric['file'], 'wb');
|
||||
fwrite($fp, gzcompress($data));
|
||||
fclose($fp);
|
||||
// get font info
|
||||
@@ -354,6 +354,11 @@ class TCPDF_FONTS {
|
||||
$fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths));
|
||||
} else {
|
||||
// ---------- TRUE TYPE ----------
|
||||
$offset = 0; // offset position of the font data
|
||||
if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
|
||||
// sfnt version must be 0x00010000 for TrueType version 1.0.
|
||||
return false;
|
||||
}
|
||||
if ($fmetric['type'] != 'cidfont0') {
|
||||
if ($link) {
|
||||
// creates a symbolic link to the existing font
|
||||
@@ -361,16 +366,11 @@ class TCPDF_FONTS {
|
||||
} else {
|
||||
// store compressed font
|
||||
$fmetric['file'] .= '.z';
|
||||
$fp = fopen($outpath.$fmetric['file'], 'wb');
|
||||
$fp = TCPDF_STATIC::fopenLocal($outpath.$fmetric['file'], 'wb');
|
||||
fwrite($fp, gzcompress($font));
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
$offset = 0; // offset position of the font data
|
||||
if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
|
||||
// sfnt version must be 0x00010000 for TrueType version 1.0.
|
||||
return false;
|
||||
}
|
||||
$offset += 4;
|
||||
// get number of tables
|
||||
$numTables = TCPDF_STATIC::_getUSHORT($font, $offset);
|
||||
@@ -435,6 +435,10 @@ class TCPDF_FONTS {
|
||||
$tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
|
||||
for ($i = 0; $i < $tot_num_glyphs; ++$i) {
|
||||
$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
|
||||
if (isset($indexToLoc[($i - 1)]) && ($indexToLoc[$i] == $indexToLoc[($i - 1)])) {
|
||||
// the last glyph didn't have an outline
|
||||
unset($indexToLoc[($i - 1)]);
|
||||
}
|
||||
$offset += 2;
|
||||
}
|
||||
} else {
|
||||
@@ -442,6 +446,10 @@ class TCPDF_FONTS {
|
||||
$tot_num_glyphs = floor($table['loca']['length'] / 4); // numGlyphs + 1
|
||||
for ($i = 0; $i < $tot_num_glyphs; ++$i) {
|
||||
$indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
|
||||
if (isset($indexToLoc[($i - 1)]) && ($indexToLoc[$i] == $indexToLoc[($i - 1)])) {
|
||||
// the last glyph didn't have an outline
|
||||
unset($indexToLoc[($i - 1)]);
|
||||
}
|
||||
$offset += 4;
|
||||
}
|
||||
}
|
||||
@@ -657,7 +665,7 @@ class TCPDF_FONTS {
|
||||
$glyphIdArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
|
||||
$offset += 2;
|
||||
}
|
||||
for ($k = 0; $k < $segCount; ++$k) {
|
||||
for ($k = 0; $k < $segCount - 1; ++$k) {
|
||||
for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
|
||||
if ($idRangeOffset[$k] == 0) {
|
||||
$g = ($idDelta[$k] + $c) % 65536;
|
||||
@@ -877,7 +885,7 @@ class TCPDF_FONTS {
|
||||
$cidtogidmap = self::updateCIDtoGIDmap($cidtogidmap, $cid, $ctg[$cid]);
|
||||
}
|
||||
// store compressed CIDToGIDMap
|
||||
$fp = fopen($outpath.$fmetric['ctg'], 'wb');
|
||||
$fp = TCPDF_STATIC::fopenLocal($outpath.$fmetric['ctg'], 'wb');
|
||||
fwrite($fp, gzcompress($cidtogidmap));
|
||||
fclose($fp);
|
||||
}
|
||||
@@ -903,7 +911,7 @@ class TCPDF_FONTS {
|
||||
$pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n";
|
||||
$pfile .= '// --- EOF ---'."\n";
|
||||
// store file
|
||||
$fp = fopen($outpath.$font_name.'.php', 'w');
|
||||
$fp = TCPDF_STATIC::fopenLocal($outpath.$font_name.'.php', 'w');
|
||||
fwrite($fp, $pfile);
|
||||
fclose($fp);
|
||||
// return TCPDF font name
|
||||
@@ -1482,6 +1490,171 @@ class TCPDF_FONTS {
|
||||
return '/W ['.$w.' ]';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update the CIDToGIDMap string with a new value.
|
||||
* @param $map (string) CIDToGIDMap.
|
||||
* @param $cid (int) CID value.
|
||||
* @param $gid (int) GID value.
|
||||
* @return (string) CIDToGIDMap.
|
||||
* @author Nicola Asuni
|
||||
* @since 5.9.123 (2011-09-29)
|
||||
* @public static
|
||||
*/
|
||||
public static function updateCIDtoGIDmap($map, $cid, $gid) {
|
||||
if (($cid >= 0) AND ($cid <= 0xFFFF) AND ($gid >= 0)) {
|
||||
if ($gid > 0xFFFF) {
|
||||
$gid -= 0x10000;
|
||||
}
|
||||
$map[($cid * 2)] = chr($gid >> 8);
|
||||
$map[(($cid * 2) + 1)] = chr($gid & 0xFF);
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return fonts path
|
||||
* @return string
|
||||
* @public static
|
||||
*/
|
||||
public static function _getfontpath() {
|
||||
if (!defined('K_PATH_FONTS') AND is_dir($fdir = realpath(dirname(__FILE__).'/../fonts'))) {
|
||||
if (substr($fdir, -1) != '/') {
|
||||
$fdir .= '/';
|
||||
}
|
||||
define('K_PATH_FONTS', $fdir);
|
||||
}
|
||||
return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return font full path
|
||||
* @param $file (string) Font file name.
|
||||
* @param $fontdir (string) Font directory (set to false fto search on default directories)
|
||||
* @return string Font full path or empty string
|
||||
* @author Nicola Asuni
|
||||
* @since 6.0.025
|
||||
* @public static
|
||||
*/
|
||||
public static function getFontFullPath($file, $fontdir=false) {
|
||||
$fontfile = '';
|
||||
// search files on various directories
|
||||
if (($fontdir !== false) AND @TCPDF_STATIC::file_exists($fontdir.$file)) {
|
||||
$fontfile = $fontdir.$file;
|
||||
} elseif (@TCPDF_STATIC::file_exists(self::_getfontpath().$file)) {
|
||||
$fontfile = self::_getfontpath().$file;
|
||||
} elseif (@TCPDF_STATIC::file_exists($file)) {
|
||||
$fontfile = $file;
|
||||
}
|
||||
return $fontfile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a reference font size.
|
||||
* @param $size (string) String containing font size value.
|
||||
* @param $refsize (float) Reference font size in points.
|
||||
* @return float value in points
|
||||
* @public static
|
||||
*/
|
||||
public static function getFontRefSize($size, $refsize=12) {
|
||||
switch ($size) {
|
||||
case 'xx-small': {
|
||||
$size = ($refsize - 4);
|
||||
break;
|
||||
}
|
||||
case 'x-small': {
|
||||
$size = ($refsize - 3);
|
||||
break;
|
||||
}
|
||||
case 'small': {
|
||||
$size = ($refsize - 2);
|
||||
break;
|
||||
}
|
||||
case 'medium': {
|
||||
$size = $refsize;
|
||||
break;
|
||||
}
|
||||
case 'large': {
|
||||
$size = ($refsize + 2);
|
||||
break;
|
||||
}
|
||||
case 'x-large': {
|
||||
$size = ($refsize + 4);
|
||||
break;
|
||||
}
|
||||
case 'xx-large': {
|
||||
$size = ($refsize + 6);
|
||||
break;
|
||||
}
|
||||
case 'smaller': {
|
||||
$size = ($refsize - 3);
|
||||
break;
|
||||
}
|
||||
case 'larger': {
|
||||
$size = ($refsize + 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ====================================================================================================================
|
||||
// REIMPLEMENTED
|
||||
// ====================================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the unicode caracter specified by the value
|
||||
* @param $c (int) UTF-8 value
|
||||
@@ -1491,6 +1664,7 @@ class TCPDF_FONTS {
|
||||
* @public static
|
||||
*/
|
||||
public static function unichr($c, $unicode=true) {
|
||||
$c = intval($c);
|
||||
if (!$unicode) {
|
||||
return chr($c);
|
||||
} elseif ($c <= 0x7F) {
|
||||
@@ -1655,64 +1829,6 @@ class TCPDF_FONTS {
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the CIDToGIDMap string with a new value.
|
||||
* @param $map (string) CIDToGIDMap.
|
||||
* @param $cid (int) CID value.
|
||||
* @param $gid (int) GID value.
|
||||
* @return (string) CIDToGIDMap.
|
||||
* @author Nicola Asuni
|
||||
* @since 5.9.123 (2011-09-29)
|
||||
* @public static
|
||||
*/
|
||||
public static function updateCIDtoGIDmap($map, $cid, $gid) {
|
||||
if (($cid >= 0) AND ($cid <= 0xFFFF) AND ($gid >= 0)) {
|
||||
if ($gid > 0xFFFF) {
|
||||
$gid -= 0x10000;
|
||||
}
|
||||
$map[($cid * 2)] = chr($gid >> 8);
|
||||
$map[(($cid * 2) + 1)] = chr($gid & 0xFF);
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return fonts path
|
||||
* @return string
|
||||
* @public static
|
||||
*/
|
||||
public static function _getfontpath() {
|
||||
if (!defined('K_PATH_FONTS') AND is_dir($fdir = realpath(dirname(__FILE__).'/../fonts'))) {
|
||||
if (substr($fdir, -1) != '/') {
|
||||
$fdir .= '/';
|
||||
}
|
||||
define('K_PATH_FONTS', $fdir);
|
||||
}
|
||||
return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return font full path
|
||||
* @param $file (string) Font file name.
|
||||
* @param $fontdir (string) Font directory (set to false fto search on default directories)
|
||||
* @return string Font full path or empty string
|
||||
* @author Nicola Asuni
|
||||
* @since 6.0.025
|
||||
* @public static
|
||||
*/
|
||||
public static function getFontFullPath($file, $fontdir=false) {
|
||||
$fontfile = '';
|
||||
// search files on various directories
|
||||
if (($fontdir !== false) AND @file_exists($fontdir.$file)) {
|
||||
$fontfile = $fontdir.$file;
|
||||
} elseif (@file_exists(self::_getfontpath().$file)) {
|
||||
$fontfile = self::_getfontpath().$file;
|
||||
} elseif (@file_exists($file)) {
|
||||
$fontfile = $file;
|
||||
}
|
||||
return $fontfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts UTF-8 characters array to array of Latin1 characters array<br>
|
||||
* @param $unicode (array) array containing UTF-8 unicode values
|
||||
@@ -1888,7 +2004,11 @@ class TCPDF_FONTS {
|
||||
$chars = str_split($str);
|
||||
$carr = array_map('ord', $chars);
|
||||
}
|
||||
$currentfont['subsetchars'] += array_fill_keys($carr, true);
|
||||
if (is_array($currentfont['subsetchars']) && is_array($carr)) {
|
||||
$currentfont['subsetchars'] += array_fill_keys($carr, true);
|
||||
} else {
|
||||
$currentfont['subsetchars'] = array_merge($currentfont['subsetchars'], $carr);
|
||||
}
|
||||
return $carr;
|
||||
}
|
||||
|
||||
@@ -2527,55 +2647,6 @@ class TCPDF_FONTS {
|
||||
return $ordarray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference font size.
|
||||
* @param $size (string) String containing font size value.
|
||||
* @param $refsize (float) Reference font size in points.
|
||||
* @return float value in points
|
||||
* @public static
|
||||
*/
|
||||
public static function getFontRefSize($size, $refsize=12) {
|
||||
switch ($size) {
|
||||
case 'xx-small': {
|
||||
$size = ($refsize - 4);
|
||||
break;
|
||||
}
|
||||
case 'x-small': {
|
||||
$size = ($refsize - 3);
|
||||
break;
|
||||
}
|
||||
case 'small': {
|
||||
$size = ($refsize - 2);
|
||||
break;
|
||||
}
|
||||
case 'medium': {
|
||||
$size = $refsize;
|
||||
break;
|
||||
}
|
||||
case 'large': {
|
||||
$size = ($refsize + 2);
|
||||
break;
|
||||
}
|
||||
case 'x-large': {
|
||||
$size = ($refsize + 4);
|
||||
break;
|
||||
}
|
||||
case 'xx-large': {
|
||||
$size = ($refsize + 6);
|
||||
break;
|
||||
}
|
||||
case 'smaller': {
|
||||
$size = ($refsize - 3);
|
||||
break;
|
||||
}
|
||||
case 'larger': {
|
||||
$size = ($refsize + 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
|
||||
} // END OF TCPDF_FONTS CLASS
|
||||
|
||||
//============================================================+
|
||||
|
||||
Reference in New Issue
Block a user