Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni authored Sep 6, 2023
2 parents 7d76401 + 128b268 commit 1499838
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions include/barcodes/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 25 additions & 25 deletions include/tcpdf_fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions include/tcpdf_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<string,float[]>
*/
public static $page_formats = array(
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ parameters:
- ./
excludePaths:
- vendor/
# remove once https://github.com/phpstan/phpstan/issues/7955 is fixed
- fonts/
- tests/

scanFiles:
Expand Down
12 changes: 8 additions & 4 deletions tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,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);
Expand Down Expand Up @@ -4104,6 +4104,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
Expand All @@ -4120,6 +4121,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)
Expand Down Expand Up @@ -6411,7 +6413,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
Expand Down Expand Up @@ -6874,6 +6876,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;
Expand Down Expand Up @@ -9927,7 +9931,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 ';
Expand Down Expand Up @@ -22057,7 +22061,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) {
Expand Down
6 changes: 3 additions & 3 deletions tcpdf_barcodes_1d.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand All @@ -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);
}
Expand Down

0 comments on commit 1499838

Please sign in to comment.