Skip to content

Commit

Permalink
changed to support php8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Murali Nair committed Nov 22, 2021
1 parent a6ad588 commit 7d4194d
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions fpdi.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FPDI extends FPDF_TPL
* @var fpdi_pdf_parser[]
*/
public $parsers = array();

/**
* Current parser
*
Expand All @@ -58,7 +58,7 @@ class FPDI extends FPDF_TPL
* @var array
*/
protected $_objStack;

/**
* Done object stack
*
Expand All @@ -72,14 +72,14 @@ class FPDI extends FPDF_TPL
* @var integer
*/
protected $_currentObjId;

/**
* Cache for imported pages/template ids
*
* @var array
*/
protected $_importedPages = array();

/**
* Set a source-file.
*
Expand Down Expand Up @@ -117,10 +117,10 @@ public function setSourceFile($filename)
$this->currentParser = $currentParser;
throw $e;
}

return $this->parsers[$filename]->getPageCount();
}

/**
* Returns a PDF parser object
*
Expand All @@ -134,7 +134,7 @@ protected function _getPdfParser($filename)
}
return new fpdi_pdf_parser($filename);
}

/**
* Get the current PDF version.
*
Expand All @@ -144,7 +144,7 @@ public function getPdfVersion()
{
return $this->PDFVersion;
}

/**
* Set the PDF version.
*
Expand All @@ -154,7 +154,7 @@ public function setPdfVersion($version = '1.3')
{
$this->PDFVersion = sprintf('%.1F', $version);
}

/**
* Import a page.
*
Expand Down Expand Up @@ -185,7 +185,7 @@ public function importPage($pageNo, $boxName = 'CropBox', $groupXObject = true)
if ($this->_inTpl) {
throw new LogicException('Please import the desired pages before creating a new template.');
}

$fn = $this->currentFilename;
$boxName = '/' . ltrim($boxName, '/');

Expand All @@ -194,16 +194,16 @@ public function importPage($pageNo, $boxName = 'CropBox', $groupXObject = true)
if (isset($this->_importedPages[$pageKey])) {
return $this->_importedPages[$pageKey];
}

$parser = $this->parsers[$fn];
$parser->setPageNo($pageNo);

if (!in_array($boxName, $parser->availableBoxes)) {
throw new InvalidArgumentException(sprintf('Unknown box: %s', $boxName));
}

$pageBoxes = $parser->getPageBoxes($pageNo, $this->k);

/**
* MediaBox
* CropBox: Default -> MediaBox
Expand All @@ -215,14 +215,14 @@ public function importPage($pageNo, $boxName = 'CropBox', $groupXObject = true)
$boxName = '/CropBox';
if (!isset($pageBoxes[$boxName]) && $boxName == '/CropBox')
$boxName = '/MediaBox';

if (!isset($pageBoxes[$boxName]))
return false;

$this->lastUsedPageBox = $boxName;

$box = $pageBoxes[$boxName];

$this->tpl++;
$this->_tpls[$this->tpl] = array();
$tpl =& $this->_tpls[$this->tpl];
Expand All @@ -237,33 +237,33 @@ public function importPage($pageNo, $boxName = 'CropBox', $groupXObject = true)

// To build an array that can be used by PDF_TPL::useTemplate()
$this->_tpls[$this->tpl] = array_merge($this->_tpls[$this->tpl], $box);

// An imported page will start at 0,0 all the time. Translation will be set in _putformxobjects()
$tpl['x'] = 0;
$tpl['y'] = 0;

// handle rotated pages
$rotation = $parser->getPageRotation($pageNo);
$tpl['_rotationAngle'] = 0;
if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) {
$steps = $angle / 90;

$_w = $tpl['w'];
$_h = $tpl['h'];
$tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
$tpl['h'] = $steps % 2 == 0 ? $_h : $_w;

if ($angle < 0)
$angle += 360;

$tpl['_rotationAngle'] = $angle * -1;
}

$this->_importedPages[$pageKey] = $this->tpl;

return $this->tpl;
}

/**
* Returns the last used page boundary box.
*
Expand Down Expand Up @@ -302,12 +302,12 @@ public function useTemplate($tplIdx, $x = null, $y = null, $w = 0, $h = 0, $adju
$size = $this->getTemplateSize($tplIdx, $w, $h);
$orientation = $size['w'] > $size['h'] ? 'L' : 'P';
$size = array($size['w'], $size['h']);

if (is_subclass_of($this, 'TCPDF')) {
$this->setPageFormat($size, $orientation);
} else {
$size = $this->_getpagesize($size);

if($orientation != $this->CurOrientation ||
$size[0] != $this->CurPageSize[0] ||
$size[1] != $this->CurPageSize[1]
Expand All @@ -331,16 +331,16 @@ public function useTemplate($tplIdx, $x = null, $y = null, $w = 0, $h = 0, $adju
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
}
}
}
}
}

$this->_out('q 0 J 1 w 0 j 0 G 0 g'); // reset standard values
$size = parent::useTemplate($tplIdx, $x, $y, $w, $h);
$this->_out('Q');

return $size;
}

/**
* Copy all imported objects to the resulting document.
*/
Expand Down Expand Up @@ -384,33 +384,33 @@ protected function _putformxobjects()
foreach($this->_tpls AS $tplIdx => $tpl) {
$this->_newobj();
$currentN = $this->n; // TCPDF/Protection: rem current "n"

$this->_tpls[$tplIdx]['n'] = $this->n;
$this->_out('<<' . $filter . '/Type /XObject');
$this->_out('/Subtype /Form');
$this->_out('/FormType 1');
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',

$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
(isset($tpl['box']['llx']) ? $tpl['box']['llx'] : $tpl['x']) * $this->k,
(isset($tpl['box']['lly']) ? $tpl['box']['lly'] : -$tpl['y']) * $this->k,
(isset($tpl['box']['urx']) ? $tpl['box']['urx'] : $tpl['w'] + $tpl['x']) * $this->k,
(isset($tpl['box']['ury']) ? $tpl['box']['ury'] : $tpl['h'] - $tpl['y']) * $this->k
));

$c = 1;
$s = 0;
$tx = 0;
$ty = 0;

if (isset($tpl['box'])) {
$tx = -$tpl['box']['llx'];
$ty = -$tpl['box']['lly'];
$ty = -$tpl['box']['lly'];

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

switch($tpl['_rotationAngle']) {
case -90:
$tx = -$tpl['box']['lly'];
Expand All @@ -430,16 +430,16 @@ protected function _putformxobjects()
$tx = -$tpl['x'] * 2;
$ty = $tpl['y'] * 2;
}

$tx *= $this->k;
$ty *= $this->k;

if ($c != 1 || $s != 0 || $tx != 0 || $ty != 0) {
$this->_out(sprintf('/Matrix [%.5F %.5F %.5F %.5F %.5F %.5F]',
$c, $s, -$s, $c, $tx, $ty
));
}

$this->_out('/Resources ');

if (isset($tpl['resources'])) {
Expand Down Expand Up @@ -495,7 +495,7 @@ protected function _putformxobjects()
$this->_out('endobj');
$this->n = $newN; // TCPDF: reset to new "n"
}

$this->_putimportedobjects();
}

Expand All @@ -520,7 +520,7 @@ public function _newobj($objId = false, $onlyNewObj = false)
$this->_out($objId . ' 0 obj');
$this->_currentObjId = $objId; // for later use with encryption
}

return $objId;
}

Expand All @@ -536,7 +536,7 @@ protected function _writeValue(&$value)
if (is_subclass_of($this, 'TCPDF')) {
parent::_prepareValue($value);
}

switch ($value[0]) {

case pdf_parser::TYPE_TOKEN:
Expand All @@ -550,7 +550,7 @@ protected function _writeValue(&$value)
$this->_straightOut($value[1] . ' ');
}
break;

case pdf_parser::TYPE_ARRAY:

// An array. Output the proper
Expand All @@ -571,7 +571,7 @@ protected function _writeValue(&$value)

reset ($value[1]);

while (list($k, $v) = each($value[1])) {
foreach ($value[1] as $k => $v) {
$this->_straightOut($k . ' ');
$this->_writeValue($v);
}
Expand Down Expand Up @@ -611,23 +611,23 @@ protected function _writeValue(&$value)
$this->_out($value[2][1]);
$this->_straightOut("endstream");
break;

case pdf_parser::TYPE_HEX:
$this->_straightOut('<' . $value[1] . '>');
break;

case pdf_parser::TYPE_BOOLEAN:
$this->_straightOut($value[1] ? 'true ' : 'false ');
break;

case pdf_parser::TYPE_NULL:
// The null object.
$this->_straightOut('null ');
break;
}
}


/**
* Modified _out() method so not each call will add a newline to the output.
*/
Expand Down Expand Up @@ -674,7 +674,7 @@ public function _enddoc()
parent::_enddoc();
$this->_closeParsers();
}

/**
* Close all files opened by parsers.
*
Expand All @@ -689,7 +689,7 @@ protected function _closeParsers()

return false;
}

/**
* Removes cycled references and closes the file handles of the parser objects.
*/
Expand Down

1 comment on commit 7d4194d

@Kunleodusan
Copy link

@Kunleodusan Kunleodusan commented on 7d4194d Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of Totara 19+, we've switch back to the setasign/fpdi library reference

Please sign in to comment.