Skip to content

Commit

Permalink
php 8+ edge cases fixes (#630)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
  • Loading branch information
bruno-farias and nicolaasuni authored Sep 6, 2023
1 parent 35e4147 commit de332db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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
4 changes: 3 additions & 1 deletion tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit de332db

Please sign in to comment.