From f7b000d23cc401825be2967edef619a7da273da1 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Wed, 6 Sep 2023 09:51:45 +0200 Subject: [PATCH 01/12] Fix SPDX license ID (#591) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f06c7337..b5a64873 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "homepage": "http://www.tcpdf.org/", "version": "6.6.2", - "license": "LGPL-3.0-only", + "license": "LGPL-3.0-or-later", "authors": [ { "name": "Nicola Asuni", From 70b63fa124f818ddc1f2203bad63b8cc9e2c145f Mon Sep 17 00:00:00 2001 From: Robert Kosmac Date: Wed, 6 Sep 2023 15:55:27 +0800 Subject: [PATCH 02/12] Applied fix found by BrainforgeUK in Issue #564 (#620) Tested and confirmed working in PHP 7.4 and PHP 8.2 --- tcpdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcpdf.php b/tcpdf.php index 667b004f..688a985b 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -2461,7 +2461,7 @@ public function setLastH($h) { */ public function getCellHeight($fontsize, $padding=TRUE) { $height = ($fontsize * $this->cell_height_ratio); - if ($padding) { + if ($padding && !empty($this->cell_padding)) { $height += ($this->cell_padding['T'] + $this->cell_padding['B']); } return round($height, 6); From fc6faf6935c84469ebc0aa285333e4ee5523e384 Mon Sep 17 00:00:00 2001 From: Ruben Barkow-Kuder Date: Wed, 6 Sep 2023 09:56:29 +0200 Subject: [PATCH 03/12] README: tone down the warning about tc-lib-pdf (#589) * README: tone down the warning about tc-lib-pdf Signed-off-by: Ruben Barkow-Kuder * Update README.md Co-authored-by: William Desportes --------- Signed-off-by: Ruben Barkow-Kuder Co-authored-by: William Desportes --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cf843227..567ad5bd 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,8 @@ * **source** https://github.com/tecnickcom/TCPDF -## IMPORTANT -A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this version will not receive any additional development or support. -This version should be considered obsolete, new projects should use the new version as soon it will become stable. +## NOTE +A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this library is in support only mode. From 7734617956dd441dca573302f63d3d691c0b1d04 Mon Sep 17 00:00:00 2001 From: Robert Johnson Nallori Date: Wed, 6 Sep 2023 13:27:19 +0530 Subject: [PATCH 04/12] Fix of Deprecation warning with php 8.1 #614 (#615) * Fix of Deprecation warning with php 8.1 #614 * Update include/barcodes/qrcode.php Co-authored-by: William Desportes --------- Co-authored-by: Robert Johnson Nallori Co-authored-by: johnson361 Co-authored-by: William Desportes --- include/barcodes/qrcode.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/barcodes/qrcode.php b/include/barcodes/qrcode.php index 322cace3..1a64a4cb 100644 --- a/include/barcodes/qrcode.php +++ b/include/barcodes/qrcode.php @@ -888,6 +888,7 @@ protected function getCode() { if ($col >= $this->rsblocks[0]['dataLength']) { $row += $this->b1; } + $row = (int) $row; $ret = $this->rsblocks[$row]['data'][$col]; } elseif ($this->count < $this->dataLength + $this->eccLength) { $row = ($this->count - $this->dataLength) % $this->blocks; From 35e41474e574187b372d4bbf157bb0a9d63a76c1 Mon Sep 17 00:00:00 2001 From: Sagehen Studio Date: Wed, 6 Sep 2023 01:01:36 -0700 Subject: [PATCH 05/12] Fixes for PHP 8.2 in tcpdf_fonts.php - fixes #632 (#633) * Update tcpdf_fonts.php Fixes "use of "self" in callables is deprecated" warning is arising from tcpdf_fonts.php when using PHP >= 8.2 * Update tcpdf_fonts.php for PHP 5.3-8.2 compatibility PHP 8.2 "use of "self" in callables is deprecated" yet some ways of fixing this breaks for PHP 5.3. This approach works, tested PHP 5.3.29 - 8.2.0 * Update tcpdf_fonts.php Spaces added back in before arguments * Update tcpdf_fonts.php using get_called_class() Maneuvers compatibility of callables inside array_map() between PHP 5.3 and 8.2 - tested. --------- Co-authored-by: Nicola Asuni --- include/tcpdf_fonts.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/tcpdf_fonts.php b/include/tcpdf_fonts.php index 30053d3e..a04d5144 100644 --- a/include/tcpdf_fonts.php +++ b/include/tcpdf_fonts.php @@ -1780,9 +1780,9 @@ public static function arrUTF8ToUTF16BE($unicode, $setbom=false) { */ public static function UTF8ArrayToUniArray($ta, $isunicode=true) { if ($isunicode) { - return array_map(array('TCPDF_FONTS', 'unichrUnicode'), $ta); + return array_map(get_called_class().'::unichrUnicode', $ta); } - return array_map(array('TCPDF_FONTS', 'unichrASCII'), $ta); + return array_map(get_called_class().'::unichrASCII', $ta); } /** @@ -2002,7 +2002,7 @@ public static function UTF8StringToArray($str, $isunicode, &$currentfont) { if ($isunicode) { // requires PCRE unicode support turned on $chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY); - $carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars); + $carr = array_map(get_called_class().'::uniord', $chars); } else { $chars = str_split($str); $carr = array_map('ord', $chars); From de332dba065ca74d4dc12245c171e28700f11528 Mon Sep 17 00:00:00 2001 From: Bruno Farias Date: Wed, 6 Sep 2023 10:03:03 +0200 Subject: [PATCH 06/12] php 8+ edge cases fixes (#630) Co-authored-by: Nicola Asuni --- include/tcpdf_static.php | 4 ++-- tcpdf.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/tcpdf_static.php b/include/tcpdf_static.php index 57006552..81805054 100644 --- a/include/tcpdf_static.php +++ b/include/tcpdf_static.php @@ -1780,7 +1780,7 @@ public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $f if ($ret === false) { return array(); } - return $ret; + return is_array($ret) ? $ret : array(); } // preg_split is bugged - try alternative solution $ret = array(); @@ -2124,7 +2124,7 @@ public static function _freadint($f) { * Array of page formats * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4) * @public static - * + * * @var array */ public static $page_formats = array( diff --git a/tcpdf.php b/tcpdf.php index 688a985b..25a00d67 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -6409,7 +6409,7 @@ public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $st // calculate maximum width for a single character on string $chrw = $this->GetArrStringWidth($chars, '', '', 0, true); array_walk($chrw, array($this, 'getRawCharWidth')); - $maxchwidth = max($chrw); + $maxchwidth = ((is_array($chrw) || $chrw instanceof Countable) && count($chrw) > 0) ? max($chrw) : 0; // get array of chars $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode); // get the number of characters @@ -6872,6 +6872,8 @@ protected function fitBlock($w, $h, $x, $y, $fitonpage=false) { } // resize the block to be contained on the remaining available page or column space if ($fitonpage) { + // fallback to avoid division by zero + $h = $h == 0 ? 1 : $h; $ratio_wh = ($w / $h); if (($y + $h) > $this->PageBreakTrigger) { $h = $this->PageBreakTrigger - $y; From 7e3fb6f3b6931687d77482e6f6e7b30641ae2502 Mon Sep 17 00:00:00 2001 From: ren1244 Date: Wed, 6 Sep 2023 16:07:57 +0800 Subject: [PATCH 07/12] Fix composite glyph output (#581) * Fix composite glyph output * Pad zeros before checksum calulation --------- Co-authored-by: Nicola Asuni --- include/tcpdf_fonts.php | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/include/tcpdf_fonts.php b/include/tcpdf_fonts.php index a04d5144..a71c84b7 100644 --- a/include/tcpdf_fonts.php +++ b/include/tcpdf_fonts.php @@ -1323,43 +1323,43 @@ public static function _getTrueTypeFontSubset($font, $subsetchars) { // set the checkSumAdjustment to 0 $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12); } - $pad = 4 - ($table[$tag]['length'] % 4); - if ($pad != 4) { - // the length of a table must be a multiple of four bytes - $table[$tag]['length'] += $pad; - $table[$tag]['data'] .= str_repeat("\x0", $pad); - } $table[$tag]['offset'] = $offset; $offset += $table[$tag]['length']; + $numPad = ($offset + 3 & ~3) - $offset; + if($numPad > 0) { + $table[$tag]['data'] .= str_repeat("\x0", $numPad); + $offset += $numPad; + } // check sum is not changed (so keep the following line commented) - //$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']); + //$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length'] + $numPad); } else { unset($table[$tag]); } } // add loca + $table['loca'] = array(); $table['loca']['data'] = $loca; $table['loca']['length'] = strlen($loca); - $pad = 4 - ($table['loca']['length'] % 4); - if ($pad != 4) { - // the length of a table must be a multiple of four bytes - $table['loca']['length'] += $pad; - $table['loca']['data'] .= str_repeat("\x0", $pad); - } $table['loca']['offset'] = $offset; - $table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']); $offset += $table['loca']['length']; + $numPad = ($offset + 3 & ~3) - $offset; + if($numPad > 0) { + $table['loca']['data'] .= str_repeat("\x0", $numPad); + $offset += $numPad; + } + $table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length'] + $numPad); // add glyf + $table['glyf'] = array(); $table['glyf']['data'] = $glyf; $table['glyf']['length'] = strlen($glyf); - $pad = 4 - ($table['glyf']['length'] % 4); - if ($pad != 4) { - // the length of a table must be a multiple of four bytes - $table['glyf']['length'] += $pad; - $table['glyf']['data'] .= str_repeat("\x0", $pad); - } $table['glyf']['offset'] = $offset; - $table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']); + $offset += $table['glyf']['length']; + $numPad = ($offset + 3 & ~3) - $offset; + if($numPad > 0) { + $table['glyf']['data'] .= str_repeat("\x0", $numPad); + $offset += $numPad; + } + $table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length'] + $numPad); // rebuild font $font = ''; $font .= pack('N', 0x10000); // sfnt version @@ -1383,7 +1383,7 @@ public static function _getTrueTypeFontSubset($font, $subsetchars) { } // set checkSumAdjustment on head table $checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font)); - $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12); + $font = substr($font, 0, $table['head']['offset'] + $offset + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + $offset + 12); return $font; } From 9c7982de49b879d1a1c58236996fa13c277d5b34 Mon Sep 17 00:00:00 2001 From: simonbuehler Date: Wed, 6 Sep 2023 10:15:01 +0200 Subject: [PATCH 08/12] fix for #583 (#584) * fix for #583 * fix fix --------- Co-authored-by: Nicola Asuni --- tcpdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcpdf.php b/tcpdf.php index 25a00d67..23194bd2 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -9927,7 +9927,7 @@ protected function _putcatalog() { } $out .= ' >> >>'; } - $font = $this->getFontBuffer('helvetica'); + $font = $this->getFontBuffer((($this->pdfa_mode) ? 'pdfa' : '') .'helvetica'); $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)'; $out .= ' /Q '.(($this->rtl)?'2':'0'); //$out .= ' /XFA '; From b142eba80f5e0bd7cee180d2f045d79367a5bad9 Mon Sep 17 00:00:00 2001 From: Daniel Salerno Date: Wed, 6 Sep 2023 10:20:02 +0200 Subject: [PATCH 09/12] Fix non-numeric value warning (#627) * Fix non-numeric value warning Fixes this warning on generating PDF: Warning: A non-numeric value encountered in /tcpdf/tcpdf.php on line 5473 * Better fix for non-numeric value warning Fixes this warning on generating PDF after calling `Text` with a non-numeric value for `$fstroke`: Warning: A non-numeric value encountered in /tcpdf/tcpdf.php on line 5470 * Update tcpdf.php Co-authored-by: William Desportes --------- Co-authored-by: William Desportes Co-authored-by: Nicola Asuni --- tcpdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcpdf.php b/tcpdf.php index 23194bd2..057182a8 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -22057,7 +22057,7 @@ public function getNumberOfColumns() { public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) { // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode // convert text rendering parameters - if ($stroke < 0) { + if ($stroke < 0 || !is_numeric($stroke)) { $stroke = 0; } if ($fill === true) { From 26d2eed8dbe65b55676391fa8fb37aa0809ea121 Mon Sep 17 00:00:00 2001 From: theonlytruth Date: Wed, 6 Sep 2023 10:24:18 +0200 Subject: [PATCH 10/12] Fixed problems with S25 barcode (#611) This was already fixed in tc-lib-barcode. --- tcpdf_barcodes_1d.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tcpdf_barcodes_1d.php b/tcpdf_barcodes_1d.php index 10a79a72..45d35616 100644 --- a/tcpdf_barcodes_1d.php +++ b/tcpdf_barcodes_1d.php @@ -828,7 +828,7 @@ protected function barcode_s25($code, $checksum=false) { $chr['5'] = '11101011101010'; $chr['6'] = '10111011101010'; $chr['7'] = '10101011101110'; - $chr['8'] = '10101110111010'; + $chr['8'] = '11101010111010'; $chr['9'] = '10111010111010'; if ($checksum) { // add checksum @@ -838,7 +838,7 @@ protected function barcode_s25($code, $checksum=false) { // add leading zero if code-length is odd $code = '0'.$code; } - $seq = '11011010'; + $seq = '1110111010'; $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { $digit = $code[$i]; @@ -848,7 +848,7 @@ protected function barcode_s25($code, $checksum=false) { } $seq .= $chr[$digit]; } - $seq .= '1101011'; + $seq .= '111010111'; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); return $this->binseq_to_array($seq, $bararray); } From 548c0f22e08b0aa34b56e2d6d03d0455ead71dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 6 Sep 2023 10:29:19 +0200 Subject: [PATCH 11/12] Check fonts files with phpstan too (#575) --- .github/workflows/tests.yml | 2 +- phpstan.neon.dist | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a70e0fe2..ecfd73a5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -132,4 +132,4 @@ jobs: - name: Install phpstan run: composer require --dev phpstan/phpstan - name: Analyse files - run: ./vendor/bin/phpstan --memory-limit=2G + run: ./vendor/bin/phpstan --memory-limit=6G diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a5e7a433..3f7bb1bd 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,8 +4,6 @@ parameters: - ./ excludePaths: - vendor/ - # remove once https://github.com/phpstan/phpstan/issues/7955 is fixed - - fonts/ - tests/ scanFiles: From 128b2687937cb16d19e4bcd36f19536f400af1cb Mon Sep 17 00:00:00 2001 From: survik1 Date: Wed, 6 Sep 2023 10:30:14 +0200 Subject: [PATCH 12/12] Fix return type annotation (#613) * Fix return type annotation * BC with tools that do not support PHPStan annotations Co-authored-by: William Desportes --------- Co-authored-by: William Desportes Co-authored-by: Nicola Asuni --- tcpdf.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tcpdf.php b/tcpdf.php index 057182a8..a90b2489 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -4102,6 +4102,7 @@ public function setTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, * @param float $fontsize Font size in points. The default value is the current size. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length. * @return float[]|float total string length or array of characted widths + * @phpstan-return ($getarray is true ? float[] : float) total string length or array of characted widths * @author Nicola Asuni * @public * @since 1.2 @@ -4118,6 +4119,7 @@ public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $ge * @param float $fontsize Font size in points. The default value is the current size. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length. * @return float[]|float total string length or array of characted widths + * @phpstan-return ($getarray is true ? float[] : float) total string length or array of characted widths * @author Nicola Asuni * @public * @since 2.4.000 (2008-03-06)