diff --git a/examples/example_012.php b/examples/example_012.php index 0767d0f..4b17819 100644 --- a/examples/example_012.php +++ b/examples/example_012.php @@ -91,7 +91,7 @@ $pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3)); // Curve $pdf->Text(5, 34, 'Curve examples'); -$pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6); +$pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, '', $style6); $pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, 'F', $style6); $pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 200)); @@ -99,18 +99,18 @@ $pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 2 $pdf->Text(5, 79, 'Circle and ellipse examples'); $pdf->setLineStyle($style5); $pdf->Circle(25,105,20); -$pdf->Circle(25,105,10, 90, 180, null, $style6); +$pdf->Circle(25,105,10, 90, 180, '', $style6); $pdf->Circle(25,105,10, 270, 360, 'F'); $pdf->Circle(25,105,10, 270, 360, 'C', $style6); $pdf->setLineStyle($style5); $pdf->Ellipse(100,103,40,20); -$pdf->Ellipse(100,105,20,10, 0, 90, 180, null, $style6); +$pdf->Ellipse(100,105,20,10, 0, 90, 180, '', $style6); $pdf->Ellipse(100,105,20,10, 0, 270, 360, 'DF', $style6); $pdf->setLineStyle($style5); $pdf->Ellipse(175,103,30,15,45); -$pdf->Ellipse(175,105,15,7.50, 45, 90, 180, null, $style6); +$pdf->Ellipse(175,105,15,7.50, 45, 90, 180, '', $style6); $pdf->Ellipse(175,105,15,7.50, 45, 270, 360, 'F', $style6, array(220, 200, 200)); // Polygon @@ -130,9 +130,9 @@ $pdf->Text(5, 169, 'Regular polygon examples'); $pdf->setLineStyle($style5); $pdf->RegularPolygon(20, 190, 15, 6, 0, 1, 'F'); $pdf->RegularPolygon(55, 190, 15, 6); -$pdf->RegularPolygon(55, 190, 10, 6, 45, 0, 'DF', array($style6, 0, $style7, 0, $style7, $style7)); -$pdf->RegularPolygon(90, 190, 15, 3, 0, 1, 'DF', array('all' => $style5), array(200, 220, 200), 'F', array(255, 200, 200)); -$pdf->RegularPolygon(125, 190, 15, 4, 30, 1, null, array('all' => $style5), null, null, $style6); +$pdf->RegularPolygon(55, 190, 10, 6, 45, false, 'DF', array($style6, 0, $style7, 0, $style7, $style7)); +$pdf->RegularPolygon(90, 190, 15, 3, 0, true, 'DF', array('all' => $style5), array(200, 220, 200), 'F', array(255, 200, 200)); +$pdf->RegularPolygon(125, 190, 15, 4, 30, true, '', array('all' => $style5), array(), '', $style6); $pdf->RegularPolygon(160, 190, 15, 10); // Star polygon @@ -140,9 +140,9 @@ $pdf->Text(5, 209, 'Star polygon examples'); $pdf->setLineStyle($style5); $pdf->StarPolygon(20, 230, 15, 20, 3, 0, 1, 'F'); $pdf->StarPolygon(55, 230, 15, 12, 5); -$pdf->StarPolygon(55, 230, 7, 12, 5, 45, 0, 'DF', array('all' => $style7), array(220, 220, 200), 'F', array(255, 200, 200)); -$pdf->StarPolygon(90, 230, 15, 20, 6, 0, 1, 'DF', array('all' => $style5), array(220, 220, 200), 'F', array(255, 200, 200)); -$pdf->StarPolygon(125, 230, 15, 5, 2, 30, 1, null, array('all' => $style5), null, null, $style6); +$pdf->StarPolygon(55, 230, 7, 12, 5, 45, false, 'DF', array('all' => $style7), array(220, 220, 200), 'F', array(255, 200, 200)); +$pdf->StarPolygon(90, 230, 15, 20, 6, 0, true, 'DF', array('all' => $style5), array(220, 220, 200), 'F', array(255, 200, 200)); +$pdf->StarPolygon(125, 230, 15, 5, 2, 30, true, '', array('all' => $style5), array(), '', $style6); $pdf->StarPolygon(160, 230, 15, 10, 3); $pdf->StarPolygon(160, 230, 7, 50, 26); @@ -151,7 +151,7 @@ $pdf->Text(5, 249, 'Rounded rectangle examples'); $pdf->setLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); $pdf->RoundedRect(5, 255, 40, 30, 3.50, '1111', 'DF'); $pdf->RoundedRect(50, 255, 40, 30, 6.50, '1000'); -$pdf->RoundedRect(95, 255, 40, 30, 10.0, '1111', null, $style6); +$pdf->RoundedRect(95, 255, 40, 30, 10.0, '1111', '', $style6); $pdf->RoundedRect(140, 255, 40, 30, 8.0, '0101', 'DF', $style6, array(200, 200, 200)); // Arrows diff --git a/examples/example_050.php b/examples/example_050.php index 45f9186..0647be6 100644 --- a/examples/example_050.php +++ b/examples/example_050.php @@ -160,7 +160,7 @@ $pdf->Text(20, 205, 'QRCODE H'); o5 = File Size (numeric); o6 = Checksum (numeric). - Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. + Parameters t, s and f are required for a Macro Control Block, all other parameters are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff". */ diff --git a/examples/tcpdf_include.php b/examples/tcpdf_include.php index 26e23a8..40d9f75 100644 --- a/examples/tcpdf_include.php +++ b/examples/tcpdf_include.php @@ -28,7 +28,8 @@ require_once('config/tcpdf_config_alt.php'); // Include the main TCPDF library (search the library on the following directories). $tcpdf_include_dirs = array( - realpath('../tcpdf.php'), + realpath(dirname(__FILE__) . '/../tcpdf.php'),// True source file + realpath('../tcpdf.php'),// Relative from $PWD '/usr/share/php/tcpdf/tcpdf.php', '/usr/share/tcpdf/tcpdf.php', '/usr/share/php-tcpdf/tcpdf.php', diff --git a/include/tcpdf_static.php b/include/tcpdf_static.php index 10e8192..7f41538 100644 --- a/include/tcpdf_static.php +++ b/include/tcpdf_static.php @@ -506,7 +506,7 @@ class TCPDF_STATIC { return $out; } if ($last_enc_key != $key) { - $k = str_repeat($key, ((256 / strlen($key)) + 1)); + $k = str_repeat($key, (int) ((256 / strlen($key)) + 1)); $rc4 = range(0, 255); $j = 0; for ($i = 0; $i < 256; ++$i) { diff --git a/tcpdf.php b/tcpdf.php index fabba04..375f0ca 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -7409,9 +7409,9 @@ class TCPDF { if (!isset($this->gdgammacache['#'.$c])) { $colors = imagecolorsforindex($img, $c); // GD alpha is only 7 bit (0 -> 127) - $this->gdgammacache['#'.$c] = (((127 - $colors['alpha']) / 127) * 255); + $this->gdgammacache['#'.$c] = (int) (((127 - $colors['alpha']) / 127) * 255); // correct gamma - $this->gdgammacache['#'.$c] = (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255); + $this->gdgammacache['#'.$c] = (int) (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255); // store the latest values on cache to improve performances if (count($this->gdgammacache) > 8) { // remove one element from the cache array @@ -14529,8 +14529,8 @@ class TCPDF { if ($patch_array[$i]['points'][$j] > $bpcd) { $patch_array[$i]['points'][$j] = $bpcd; } - $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256)); - $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256)); + $this->gradients[$n]['stream'] .= chr((int) floor($patch_array[$i]['points'][$j] / 256)); + $this->gradients[$n]['stream'] .= chr((int) floor(intval($patch_array[$i]['points'][$j]) % 256)); } $count_cols = count($patch_array[$i]['colors']); for ($j=0; $j < $count_cols; ++$j) { @@ -15324,7 +15324,7 @@ class TCPDF { // create new barcode object $barcodeobj = new TCPDFBarcode($code, $type); $arrcode = $barcodeobj->getBarcodeArray(); - if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) { + if (empty($arrcode) OR ($arrcode['maxw'] <= 0)) { $this->Error('Error in 1D barcode string'); } if ($arrcode['maxh'] <= 0) { @@ -15642,7 +15642,7 @@ class TCPDF { // create new barcode object $barcodeobj = new TCPDF2DBarcode($code, $type); $arrcode = $barcodeobj->getBarcodeArray(); - if (($arrcode === false) OR empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) { + if (empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) { $this->Error('Error in 2D barcode string'); } // set default values diff --git a/tcpdf_barcodes_1d.php b/tcpdf_barcodes_1d.php index 7fc9648..10a79a7 100644 --- a/tcpdf_barcodes_1d.php +++ b/tcpdf_barcodes_1d.php @@ -53,7 +53,7 @@ class TCPDFBarcode { * Array representation of barcode. * @protected */ - protected $barcode_array; + protected $barcode_array = array(); /** * This is the class constructor. @@ -373,7 +373,7 @@ class TCPDFBarcode { break; } default: { - $this->barcode_array = false; + $this->barcode_array = array(); $arrcode = false; break; } diff --git a/tcpdf_barcodes_2d.php b/tcpdf_barcodes_2d.php index 9b35689..730361b 100644 --- a/tcpdf_barcodes_2d.php +++ b/tcpdf_barcodes_2d.php @@ -53,7 +53,7 @@ class TCPDF2DBarcode { * Array representation of barcode. * @protected */ - protected $barcode_array = false; + protected $barcode_array = array(); /** * This is the class constructor. @@ -63,7 +63,7 @@ class TCPDF2DBarcode { *
  • $arrcode['num_cols'] required number of columns
  • *
  • $arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)
  • * @param string $code code to print - * @param string $type type of barcode: + * @param string $type type of barcode: */ public function __construct($code, $type) { $this->setBarcode($code, $type); @@ -246,7 +246,7 @@ class TCPDF2DBarcode { /** * Set the barcode. * @param string $code code to print - * @param string $type type of barcode: + * @param string $type type of barcode: * @return void */ public function setBarcode($code, $type) { @@ -338,7 +338,7 @@ class TCPDF2DBarcode { break; } default: { - $this->barcode_array = false; + $this->barcode_array = array(); } } } diff --git a/tests/launch.sh b/tests/launch.sh index 78ecf46..6798991 100755 --- a/tests/launch.sh +++ b/tests/launch.sh @@ -22,10 +22,12 @@ EXAMPLE_BARCODE_FILES="$(find examples/barcodes -type f -name 'example*.php' \ TEMP_FOLDER="$(mktemp -d /tmp/TCPDF-tests.XXXXXXXXX)" OUTPUT_FILE="${TEMP_FOLDER}/output.pdf" OUTPUT_FILE_ERROR="${TEMP_FOLDER}/errors.txt" -ROOT_DIR="$(php -r 'echo realpath(__DIR__);')" +# Allows you to use PHP_BINARY="php8.1" ./tests/launch.sh +PHP_BINARY="${PHP_BINARY:-php}" +ROOT_DIR="$(${PHP_BINARY} -r 'echo realpath(__DIR__);')" TESTS_DIR="${ROOT_DIR}/tests/" -PHP_EXT_DIR="$(php -r 'echo ini_get("extension_dir");')" +PHP_EXT_DIR="$(${PHP_BINARY} -r 'echo ini_get("extension_dir");')" echo "php extension dir: ${PHP_EXT_DIR}" @@ -36,32 +38,28 @@ COVERAGE_EXTENSION="-d extension=pcov.so" IMAGICK_OR_GD="-dextension=gd.so" JSON_EXT="-dextension=json.so" XML_EXT="-dextension=xml.so" -if [ "$(php -r 'echo PHP_MAJOR_VERSION;')" = "5" ];then +if [ "$(${PHP_BINARY} -r 'echo PHP_MAJOR_VERSION;')" = "5" ];then X_DEBUG_EXT="$(find ${PHP_EXT_DIR} -type f -name 'xdebug.so' || '')" echo "Xdebug found at: ${X_DEBUG_EXT}" # pcov does not exist for PHP 5 COVERAGE_EXTENSION="-d zend_extension=${X_DEBUG_EXT} -d xdebug.mode=coverage" # 5.5, 5.4, 5.3 - if [ "$(php -r 'echo (PHP_MINOR_VERSION < 6) ? "true" : "false";')" = "true" ];then - # seems like there is no bcmath extension to be found - BCMATH_EXT="" + if [ "$(${PHP_BINARY} -r 'echo (PHP_MINOR_VERSION < 6) ? "true" : "false";')" = "true" ];then IMAGICK_OR_GD="-dextension=imagick.so" - # Seems not to exist in 5.5, 5.4, 5.3 - JSON_EXT="" - XML_EXT="" fi fi # PHP >= 8.x.x -if [ "$(php -r 'echo (PHP_MAJOR_VERSION >= 8) ? "true" : "false";')" = "true" ];then +if [ "$(${PHP_BINARY} -r 'echo (PHP_MAJOR_VERSION >= 8) ? "true" : "false";')" = "true" ];then # The json ext is bundled into PHP 8.0 JSON_EXT="" fi echo "Root folder: ${ROOT_DIR}" echo "Temporary folder: ${TEMP_FOLDER}" +echo "PHP version: $(${PHP_BINARY} -v)" FAILED_FLAG=0 @@ -69,13 +67,15 @@ cd "${ROOT_DIR}/examples" for file in $EXAMPLE_FILES; do echo "File: $file" - php -l "${ROOT_DIR}/$file" > /dev/null + ${PHP_BINARY} -l "${ROOT_DIR}/$file" > /dev/null if [ $? -eq 0 ]; then echo "File-lint-passed: $file" fi set +e # Some examples load a bit more into memory (this is why the limit is set to 1G) - php -n \ + # Avoid side effects on classes installed on the system, set include_path to a folder wihout php classes (include_path) + ${PHP_BINARY} -n \ + -d include_path="${TEMP_FOLDER}" \ -d date.timezone=UTC \ ${IMAGICK_OR_GD} ${COVERAGE_EXTENSION} \ ${BCMATH_EXT} \ @@ -136,12 +136,14 @@ done for file in $EXAMPLE_BARCODE_FILES; do echo "File: $file" - php -l "${ROOT_DIR}/$file" > /dev/null + ${PHP_BINARY} -l "${ROOT_DIR}/$file" > /dev/null if [ $? -eq 0 ]; then echo "File-lint-passed: $file" fi set +e - php -n \ + # Avoid side effects on classes installed on the system, set include_path to a folder wihout php classes (include_path) + ${PHP_BINARY} -n \ + -d include_path="${TEMP_FOLDER}" \ -d date.timezone=UTC \ ${BCMATH_EXT} ${COVERAGE_EXTENSION} \ -d display_errors=on \