Skip to content

Commit

Permalink
Add PHP 8.3 support (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Pichler <[email protected]>
  • Loading branch information
fetzi and Johannes Pichler authored Feb 5, 2024
1 parent 5742169 commit 35497ed
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ "8.0", "8.1", "8.2" ]
php: [ "8.0", "8.1", "8.2", "8.3" ]

runs-on: ubuntu-latest
name: PHP@${{ matrix.php }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.0] - 2024-02-05
### Added
- Support for PHP 8.2

## [3.0.0] - 2023-03-01
### Added
- Support for PHP 8.2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "8.0.* | 8.1.* | 8.2.*",
"php": "8.0.* | 8.1.* | 8.2.* | 8.3.*",
"tecnickcom/tcpdf": "^6.3"
},
"require-dev": {
Expand Down
28 changes: 14 additions & 14 deletions tcpi/fpdf_tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function beginTemplate($x = null, $y = null, $w = null, $h = null)

// Save settings
$this->tpl++;
$tpl =& $this->tpls[$this->tpl];
$tpl = & $this->tpls[$this->tpl];
$tpl = array(
'o_x' => $this->x,
'o_y' => $this->y,
Expand Down Expand Up @@ -135,7 +135,7 @@ public function beginTemplate($x = null, $y = null, $w = null, $h = null)

if ($this->CurrentFont) {
$fontkey = $this->FontFamily . $this->FontStyle;
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] = & $this->fonts[$fontkey];

$this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
}
Expand All @@ -159,7 +159,7 @@ public function endTemplate()

if ($this->_intpl) {
$this->_intpl = false;
$tpl =& $this->tpls[$this->tpl];
$tpl = & $this->tpls[$this->tpl];
$this->SetXY($tpl['o_x'], $tpl['o_y']);
$this->tMargin = $tpl['o_tMargin'];
$this->lMargin = $tpl['o_lMargin'];
Expand All @@ -175,7 +175,7 @@ public function endTemplate()

$fontkey = $this->FontFamily . $this->FontStyle;
if ($fontkey) {
$this->CurrentFont =& $this->fonts[$fontkey];
$this->CurrentFont = & $this->fonts[$fontkey];
}

return $this->tpl;
Expand Down Expand Up @@ -212,10 +212,10 @@ public function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0)
}

if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] = & $this->tpls[$tplidx];
}

$tpl =& $this->tpls[$tplidx];
$tpl = & $this->tpls[$tplidx];
$w = $tpl['w'];
$h = $tpl['h'];

Expand Down Expand Up @@ -269,7 +269,7 @@ public function getTemplateSize($tplidx, $_w = 0, $_h = 0)
return false;
}

$tpl =& $this->tpls[$tplidx];
$tpl = & $this->tpls[$tplidx];
$w = $tpl['w'];
$h = $tpl['h'];

Expand All @@ -291,7 +291,7 @@ public function getTemplateSize($tplidx, $_w = 0, $_h = 0)
/**
* See FPDF/TCPDF-Documentation ;-)
*/
public function SetFont($family, $style = '', $size = 0, $fontfile='', $subset='default', $out=true)
public function SetFont($family, $style = '', $size = 0, $fontfile = '', $subset = 'default', $out = true)
{
if (is_subclass_of($this, 'TCPDF')) {
$args = func_get_args();
Expand All @@ -303,9 +303,9 @@ public function SetFont($family, $style = '', $size = 0, $fontfile='', $subset='
$fontkey = $this->FontFamily . $this->FontStyle;

if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] = & $this->fonts[$fontkey];
} else {
$this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
$this->_res['page'][$this->page]['fonts'][$fontkey] = & $this->fonts[$fontkey];
}
}

Expand Down Expand Up @@ -340,9 +340,9 @@ public function Image(

$ret = parent::Image($file, $x, $y, $w, $h, $type, $link);
if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
$this->_res['tpl'][$this->tpl]['images'][$file] = & $this->images[$file];
} else {
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
$this->_res['page'][$this->page]['images'][$file] = & $this->images[$file];
}

return $ret;
Expand Down Expand Up @@ -415,10 +415,10 @@ public function SetLink($link, $y = 0, $page = -1)
*/
public function _putformxobjects()
{
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
reset($this->tpls);
foreach ($this->tpls as $tplidx => $tpl) {
$p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
$p = ($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
$this->_newobj();
$this->tpls[$tplidx]['n'] = $this->n;
$this->_out('<<' . $filter . '/Type /XObject');
Expand Down
48 changes: 24 additions & 24 deletions tcpi/tcpdi.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function setSourceFile($filename)
if (!isset($this->parsers[$filename])) {
$this->parsers[$filename] = $this->_getPdfParser($filename);
}
$this->current_parser =& $this->parsers[$filename];
$this->current_parser = & $this->parsers[$filename];
$this->setPDFVersion(max($this->getPDFVersion(), $this->current_parser->getPDFVersion()));

return $this->parsers[$filename]->getPageCount();
Expand All @@ -130,7 +130,7 @@ public function setSourceData($pdfdata)
if (!isset($this->parsers[$filename])) {
$this->parsers[$filename] = new tcpdi_parser($pdfdata, $filename);
}
$this->current_parser =& $this->parsers[$filename];
$this->current_parser = & $this->parsers[$filename];
$this->setPDFVersion(max($this->getPDFVersion(), $this->current_parser->getPDFVersion()));

return $this->parsers[$filename]->getPageCount();
Expand Down Expand Up @@ -188,7 +188,7 @@ public function importPage($pageno, $boxName = '/CropBox')
return $this->_importedPages[$pageKey];
}

$parser =& $this->parsers[$fn];
$parser = & $this->parsers[$fn];
$parser->setPageno($pageno);

if (!in_array($boxName, $parser->availableBoxes)) {
Expand Down Expand Up @@ -221,8 +221,8 @@ public function importPage($pageno, $boxName = '/CropBox')

$this->tpl++;
$this->tpls[$this->tpl] = array();
$tpl =& $this->tpls[$this->tpl];
$tpl['parser'] =& $parser;
$tpl = & $this->tpls[$this->tpl];
$tpl['parser'] = & $parser;
$tpl['resources'] = $parser->getPageResources();
$tpl['buffer'] = $parser->getContent();
$tpl['box'] = $box;
Expand Down Expand Up @@ -259,7 +259,7 @@ public function importPage($pageno, $boxName = '/CropBox')
public function setPageFormatFromTemplatePage($pageno, $orientation)
{
$fn = $this->current_filename;
$parser =& $this->parsers[$fn];
$parser = & $this->parsers[$fn];
$parser->setPageno($pageno);
$boxes = $parser->getPageBoxes($pageno, $this->k);
foreach ($boxes as $name => $box) {
Expand All @@ -272,7 +272,7 @@ public function setPageFormatFromTemplatePage($pageno, $orientation)
}

/* Wrapper for AddPage() which tracks TOC pages to offset annotations later */
public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false)
public function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
{
if ($this->inxobj) {
// we are inside an XObject template
Expand All @@ -285,7 +285,7 @@ public function AddPage($orientation='', $format='', $keepmargins=false, $tocpag
}

/* Wrapper for AddTOC() which tracks TOC position to offset annotations later */
public function AddTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0))
public function AddTOC($page = '', $numbersfont = '', $filler = '.', $toc_name = 'TOC', $style = '', $color = array(0,0,0))
{
if (!TCPDF_STATIC::empty_string($page)) {
$this->_TOCpagenum = $page;
Expand All @@ -299,7 +299,7 @@ public function AddTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC',
public function importAnnotations($pageno)
{
$fn = $this->current_filename;
$parser =& $this->parsers[$fn];
$parser = & $this->parsers[$fn];
$parser->setPageno($pageno);
$annots = $parser->getPageAnnotations();

Expand Down Expand Up @@ -423,7 +423,7 @@ public function _putimportedobjects()
{
if (is_array($this->parsers) && count($this->parsers) > 0) {
foreach ($this->parsers as $filename => $p) {
$this->current_parser =& $this->parsers[$filename];
$this->current_parser = & $this->parsers[$filename];
if (isset($this->_obj_stack[$filename]) && is_array($this->_obj_stack[$filename])) {
while (($n = key($this->_obj_stack[$filename])) !== null) {
$nObj = $this->current_parser->getObjectVal($this->_obj_stack[$filename][$n][1]);
Expand Down Expand Up @@ -456,10 +456,10 @@ public function _putimportedobjects()
*/
public function _putformxobjects()
{
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
reset($this->tpls);
foreach ($this->tpls as $tplidx => $tpl) {
$p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
$p = ($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
$this->_newobj();
$cN = $this->n; // TCPDF/Protection: rem current "n"

Expand All @@ -486,9 +486,9 @@ public function _putformxobjects()
$ty = -$tpl['box']['lly'];

if ($tpl['_rotationAngle'] <> 0) {
$angle = $tpl['_rotationAngle'] * M_PI/180;
$c=cos($angle);
$s=sin($angle);
$angle = $tpl['_rotationAngle'] * M_PI / 180;
$c = cos($angle);
$s = sin($angle);

switch($tpl['_rotationAngle']) {
case -90:
Expand Down Expand Up @@ -528,7 +528,7 @@ public function _putformxobjects()
$this->_out('/Resources ');

if (isset($tpl['resources'])) {
$this->current_parser =& $tpl['parser'];
$this->current_parser = & $tpl['parser'];
$this->pdf_write_value($tpl['resources']); // "n" will be changed
} else {
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
Expand Down Expand Up @@ -675,7 +675,7 @@ public function pdf_write_value(&$value)

// An indirect object reference
// Fill the object stack if needed
$cpfn =& $this->current_parser->uniqueid;
$cpfn = & $this->current_parser->uniqueid;

if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
$this->_newobj(false, true);
Expand Down Expand Up @@ -783,7 +783,7 @@ public function cleanUp()
}

// Functions from here on are taken from FPDI's fpdi2tcpdf_bridge.php to remove dependence on it
public function _putstream($s, $n=0)
public function _putstream($s, $n = 0)
{
$this->_out($this->_getstream($s, $n));
}
Expand All @@ -810,7 +810,7 @@ public function _unescape($s)
{
$out = '';
for ($count = 0, $n = strlen($s); $count < $n; $count++) {
if ($s[$count] != '\\' || $count == $n-1) {
if ($s[$count] != '\\' || $count == $n - 1) {
$out .= $s[$count];
} else {
switch ($s[++$count]) {
Expand All @@ -835,7 +835,7 @@ public function _unescape($s)
$out .= chr(0x0A);
break;
case "\r":
if ($count != $n-1 && $s[$count+1] == "\n") {
if ($count != $n - 1 && $s[$count + 1] == "\n") {
$count++;
}
break;
Expand All @@ -847,12 +847,12 @@ public function _unescape($s)
ord($s[$count]) <= ord('9')) {
$oct = '' . $s[$count];

if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
if (ord($s[$count + 1]) >= ord('0') &&
ord($s[$count + 1]) <= ord('9')) {
$oct .= $s[++$count];

if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
if (ord($s[$count + 1]) >= ord('0') &&
ord($s[$count + 1]) <= ord('9')) {
$oct .= $s[++$count];
}
}
Expand Down
Loading

0 comments on commit 35497ed

Please sign in to comment.