Skip to content

Commit fe94384

Browse files
committed
Ignore warnings about float to int casting on tcpdf_fonts
The warning is being thrown in PHP 8.5, and it's breaking PDF generation in some cases, caught in tests executed on armhf systems. Fixes: #856
1 parent 7a27012 commit fe94384

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

include/tcpdf_fonts.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,12 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
930930
* @public static
931931
*/
932932
public static function _getTTFtableChecksum($table, $length) {
933+
// Suppress warning about casting on armhf
934+
if (PHP_INT_SIZE == 4) {
935+
set_error_handler(function($errno, $errstr) {
936+
return strpos($errstr, 'is not representable as an int') !== false;
937+
}, E_WARNING);
938+
}
933939
$sum = 0;
934940
$tlen = ($length / 4);
935941
$offset = 0;
@@ -939,6 +945,9 @@ public static function _getTTFtableChecksum($table, $length) {
939945
$offset += 4;
940946
}
941947
$sum = unpack('Ni', pack('N', $sum));
948+
if (PHP_INT_SIZE == 4) {
949+
restore_error_handler();
950+
}
942951
return $sum['i'];
943952
}
944953

@@ -1382,9 +1391,18 @@ public static function _getTrueTypeFontSubset($font, $subsetchars) {
13821391
foreach ($table as $data) {
13831392
$font .= $data['data'];
13841393
}
1394+
// Suppress warning about casting on armhf
1395+
if (PHP_INT_SIZE == 4) {
1396+
set_error_handler(function($errno, $errstr) {
1397+
return strpos($errstr, 'is not representable as an int') !== false;
1398+
}, E_WARNING);
1399+
}
13851400
// set checkSumAdjustment on head table
13861401
$checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font));
13871402
$font = substr($font, 0, $table['head']['offset'] + $offset + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + $offset + 12);
1403+
if (PHP_INT_SIZE == 4) {
1404+
restore_error_handler();
1405+
}
13881406
return $font;
13891407
}
13901408

0 commit comments

Comments
 (0)