mirror of
https://github.com/Karaka-Management/Resources.git
synced 2026-01-11 05:18:40 +00:00
add more global namespacing
This commit is contained in:
parent
03a9cf0aef
commit
368e8d687f
|
|
@ -63,13 +63,13 @@ class TCPDF_PARSER {
|
||||||
* XREF data.
|
* XREF data.
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
protected $xref = array();
|
protected $xref = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of PDF objects.
|
* Array of PDF objects.
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
protected $objects = array();
|
protected $objects = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class object for decoding filters.
|
* Class object for decoding filters.
|
||||||
|
|
@ -99,24 +99,24 @@ class TCPDF_PARSER {
|
||||||
* @public
|
* @public
|
||||||
* @since 1.0.000 (2011-05-24)
|
* @since 1.0.000 (2011-05-24)
|
||||||
*/
|
*/
|
||||||
public function __construct($data, $cfg=array()) {
|
public function __construct($data, $cfg=[]) {
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->Error('Empty PDF data.');
|
$this->Error('Empty PDF data.');
|
||||||
}
|
}
|
||||||
// find the pdf header starting position
|
// find the pdf header starting position
|
||||||
if (($trimpos = strpos($data, '%PDF-')) === FALSE) {
|
if (($trimpos = \strpos($data, '%PDF-')) === FALSE) {
|
||||||
$this->Error('Invalid PDF data: missing %PDF header.');
|
$this->Error('Invalid PDF data: missing %PDF header.');
|
||||||
}
|
}
|
||||||
// get PDF content string
|
// get PDF content string
|
||||||
$this->pdfdata = substr($data, $trimpos);
|
$this->pdfdata = \substr($data, $trimpos);
|
||||||
// get length
|
// get length
|
||||||
$pdflen = strlen($this->pdfdata);
|
$pdflen = \strlen($this->pdfdata);
|
||||||
// set configuration parameters
|
// set configuration parameters
|
||||||
$this->setConfig($cfg);
|
$this->setConfig($cfg);
|
||||||
// get xref and trailer data
|
// get xref and trailer data
|
||||||
$this->xref = $this->getXrefData();
|
$this->xref = $this->getXrefData();
|
||||||
// parse all document objects
|
// parse all document objects
|
||||||
$this->objects = array();
|
$this->objects = [];
|
||||||
foreach ($this->xref['xref'] as $obj => $offset) {
|
foreach ($this->xref['xref'] as $obj => $offset) {
|
||||||
if (!isset($this->objects[$obj]) AND ($offset > 0)) {
|
if (!isset($this->objects[$obj]) AND ($offset > 0)) {
|
||||||
// decode objects with positive offset
|
// decode objects with positive offset
|
||||||
|
|
@ -166,7 +166,7 @@ class TCPDF_PARSER {
|
||||||
* @protected
|
* @protected
|
||||||
* @since 1.0.000 (2011-05-24)
|
* @since 1.0.000 (2011-05-24)
|
||||||
*/
|
*/
|
||||||
protected function getXrefData($offset=0, $xref=array()) {
|
protected function getXrefData($offset=0, $xref=[]) {
|
||||||
if ($offset == 0) {
|
if ($offset == 0) {
|
||||||
// find last startxref
|
// find last startxref
|
||||||
if (preg_match_all('/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_SET_ORDER, $offset) == 0) {
|
if (preg_match_all('/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_SET_ORDER, $offset) == 0) {
|
||||||
|
|
@ -174,20 +174,20 @@ class TCPDF_PARSER {
|
||||||
}
|
}
|
||||||
$matches = array_pop($matches);
|
$matches = array_pop($matches);
|
||||||
$startxref = $matches[1];
|
$startxref = $matches[1];
|
||||||
} elseif (strpos($this->pdfdata, 'xref', $offset) == $offset) {
|
} elseif (\strpos($this->pdfdata, 'xref', $offset) == $offset) {
|
||||||
// Already pointing at the xref table
|
// Already pointing at the xref table
|
||||||
$startxref = $offset;
|
$startxref = $offset;
|
||||||
} elseif (preg_match('/([0-9]+[\s][0-9]+[\s]obj)/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset)) {
|
} elseif (\preg_match('/([0-9]+[\s][0-9]+[\s]obj)/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset)) {
|
||||||
// Cross-Reference Stream object
|
// Cross-Reference Stream object
|
||||||
$startxref = $offset;
|
$startxref = $offset;
|
||||||
} elseif (preg_match('/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset)) {
|
} elseif (\preg_match('/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset)) {
|
||||||
// startxref found
|
// startxref found
|
||||||
$startxref = $matches[1][0];
|
$startxref = $matches[1][0];
|
||||||
} else {
|
} else {
|
||||||
$this->Error('Unable to find startxref');
|
$this->Error('Unable to find startxref');
|
||||||
}
|
}
|
||||||
// check xref position
|
// check xref position
|
||||||
if (strpos($this->pdfdata, 'xref', $startxref) == $startxref) {
|
if (\strpos($this->pdfdata, 'xref', $startxref) == $startxref) {
|
||||||
// Cross-Reference
|
// Cross-Reference
|
||||||
$xref = $this->decodeXref($startxref, $xref);
|
$xref = $this->decodeXref($startxref, $xref);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -208,63 +208,63 @@ class TCPDF_PARSER {
|
||||||
* @protected
|
* @protected
|
||||||
* @since 1.0.000 (2011-06-20)
|
* @since 1.0.000 (2011-06-20)
|
||||||
*/
|
*/
|
||||||
protected function decodeXref($startxref, $xref=array()) {
|
protected function decodeXref($startxref, $xref=[]) {
|
||||||
$startxref += 4; // 4 is the length of the word 'xref'
|
$startxref += 4; // 4 is the length of the word 'xref'
|
||||||
// skip initial white space chars: \x00 null (NUL), \x09 horizontal tab (HT), \x0A line feed (LF), \x0C form feed (FF), \x0D carriage return (CR), \x20 space (SP)
|
// skip initial white space chars: \x00 null (NUL), \x09 horizontal tab (HT), \x0A line feed (LF), \x0C form feed (FF), \x0D carriage return (CR), \x20 space (SP)
|
||||||
$offset = $startxref + strspn($this->pdfdata, "\x00\x09\x0a\x0c\x0d\x20", $startxref);
|
$offset = $startxref + strspn($this->pdfdata, "\x00\x09\x0a\x0c\x0d\x20", $startxref);
|
||||||
// initialize object number
|
// initialize object number
|
||||||
$obj_num = 0;
|
$obj_num = 0;
|
||||||
// search for cross-reference entries or subsection
|
// search for cross-reference entries or subsection
|
||||||
while (preg_match('/([0-9]+)[\x20]([0-9]+)[\x20]?([nf]?)(\r\n|[\x20]?[\r\n])/', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
|
while (\preg_match('/([0-9]+)[\x20]([0-9]+)[\x20]?([nf]?)(\r\n|[\x20]?[\r\n])/', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
|
||||||
if ($matches[0][1] != $offset) {
|
if ($matches[0][1] != $offset) {
|
||||||
// we are on another section
|
// we are on another section
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$offset += strlen($matches[0][0]);
|
$offset += \strlen($matches[0][0]);
|
||||||
if ($matches[3][0] == 'n') {
|
if ($matches[3][0] == 'n') {
|
||||||
// create unique object index: [object number]_[generation number]
|
// create unique object index: [object number]_[generation number]
|
||||||
$index = $obj_num.'_'.intval($matches[2][0]);
|
$index = $obj_num.'_'.\intval($matches[2][0]);
|
||||||
// check if object already exist
|
// check if object already exist
|
||||||
if (!isset($xref['xref'][$index])) {
|
if (!isset($xref['xref'][$index])) {
|
||||||
// store object offset position
|
// store object offset position
|
||||||
$xref['xref'][$index] = intval($matches[1][0]);
|
$xref['xref'][$index] = \intval($matches[1][0]);
|
||||||
}
|
}
|
||||||
++$obj_num;
|
++$obj_num;
|
||||||
} elseif ($matches[3][0] == 'f') {
|
} elseif ($matches[3][0] == 'f') {
|
||||||
++$obj_num;
|
++$obj_num;
|
||||||
} else {
|
} else {
|
||||||
// object number (index)
|
// object number (index)
|
||||||
$obj_num = intval($matches[1][0]);
|
$obj_num = \intval($matches[1][0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// get trailer data
|
// get trailer data
|
||||||
if (preg_match('/trailer[\s]*<<(.*)>>/isU', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
|
if (\preg_match('/trailer[\s]*<<(.*)>>/isU', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
|
||||||
$trailer_data = $matches[1][0];
|
$trailer_data = $matches[1][0];
|
||||||
if (!isset($xref['trailer']) OR empty($xref['trailer'])) {
|
if (!isset($xref['trailer']) OR empty($xref['trailer'])) {
|
||||||
// get only the last updated version
|
// get only the last updated version
|
||||||
$xref['trailer'] = array();
|
$xref['trailer'] = [];
|
||||||
// parse trailer_data
|
// parse trailer_data
|
||||||
if (preg_match('/Size[\s]+([0-9]+)/i', $trailer_data, $matches) > 0) {
|
if (\preg_match('/Size[\s]+([0-9]+)/i', $trailer_data, $matches) > 0) {
|
||||||
$xref['trailer']['size'] = intval($matches[1]);
|
$xref['trailer']['size'] = \intval($matches[1]);
|
||||||
}
|
}
|
||||||
if (preg_match('/Root[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
|
if (\preg_match('/Root[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
|
||||||
$xref['trailer']['root'] = intval($matches[1]).'_'.intval($matches[2]);
|
$xref['trailer']['root'] = \intval($matches[1]).'_'.\intval($matches[2]);
|
||||||
}
|
}
|
||||||
if (preg_match('/Encrypt[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
|
if (\preg_match('/Encrypt[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
|
||||||
$xref['trailer']['encrypt'] = intval($matches[1]).'_'.intval($matches[2]);
|
$xref['trailer']['encrypt'] = \intval($matches[1]).'_'.\intval($matches[2]);
|
||||||
}
|
}
|
||||||
if (preg_match('/Info[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
|
if (\preg_match('/Info[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
|
||||||
$xref['trailer']['info'] = intval($matches[1]).'_'.intval($matches[2]);
|
$xref['trailer']['info'] = \intval($matches[1]).'_'.\intval($matches[2]);
|
||||||
}
|
}
|
||||||
if (preg_match('/ID[\s]*[\[][\s]*[<]([^>]*)[>][\s]*[<]([^>]*)[>]/i', $trailer_data, $matches) > 0) {
|
if (\preg_match('/ID[\s]*[\[][\s]*[<]([^>]*)[>][\s]*[<]([^>]*)[>]/i', $trailer_data, $matches) > 0) {
|
||||||
$xref['trailer']['id'] = array();
|
$xref['trailer']['id'] = [];
|
||||||
$xref['trailer']['id'][0] = $matches[1];
|
$xref['trailer']['id'][0] = $matches[1];
|
||||||
$xref['trailer']['id'][1] = $matches[2];
|
$xref['trailer']['id'][1] = $matches[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (preg_match('/Prev[\s]+([0-9]+)/i', $trailer_data, $matches) > 0) {
|
if (\preg_match('/Prev[\s]+([0-9]+)/i', $trailer_data, $matches) > 0) {
|
||||||
// get previous xref
|
// get previous xref
|
||||||
$xref = $this->getXrefData(intval($matches[1]), $xref);
|
$xref = $this->getXrefData(\intval($matches[1]), $xref);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->Error('Unable to find trailer');
|
$this->Error('Unable to find trailer');
|
||||||
|
|
@ -280,50 +280,50 @@ class TCPDF_PARSER {
|
||||||
* @protected
|
* @protected
|
||||||
* @since 1.0.003 (2013-03-16)
|
* @since 1.0.003 (2013-03-16)
|
||||||
*/
|
*/
|
||||||
protected function decodeXrefStream($startxref, $xref=array()) {
|
protected function decodeXrefStream($startxref, $xref=[]) {
|
||||||
// try to read Cross-Reference Stream
|
// try to read Cross-Reference Stream
|
||||||
$xrefobj = $this->getRawObject($startxref);
|
$xrefobj = $this->getRawObject($startxref);
|
||||||
$xrefcrs = $this->getIndirectObject($xrefobj[1], $startxref, true);
|
$xrefcrs = $this->getIndirectObject($xrefobj[1], $startxref, true);
|
||||||
if (!isset($xref['trailer']) OR empty($xref['trailer'])) {
|
if (!isset($xref['trailer']) OR empty($xref['trailer'])) {
|
||||||
// get only the last updated version
|
// get only the last updated version
|
||||||
$xref['trailer'] = array();
|
$xref['trailer'] = [];
|
||||||
$filltrailer = true;
|
$filltrailer = true;
|
||||||
} else {
|
} else {
|
||||||
$filltrailer = false;
|
$filltrailer = false;
|
||||||
}
|
}
|
||||||
if (!isset($xref['xref'])) {
|
if (!isset($xref['xref'])) {
|
||||||
$xref['xref'] = array();
|
$xref['xref'] = [];
|
||||||
}
|
}
|
||||||
$valid_crs = false;
|
$valid_crs = false;
|
||||||
$columns = 0;
|
$columns = 0;
|
||||||
$sarr = $xrefcrs[0][1];
|
$sarr = $xrefcrs[0][1];
|
||||||
if (!is_array($sarr)) {
|
if (!is_array($sarr)) {
|
||||||
$sarr = array();
|
$sarr = [];
|
||||||
}
|
}
|
||||||
foreach ($sarr as $k => $v) {
|
foreach ($sarr as $k => $v) {
|
||||||
if (($v[0] == '/') AND ($v[1] == 'Type') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == '/') AND ($sarr[($k +1)][1] == 'XRef'))) {
|
if (($v[0] == '/') AND ($v[1] == 'Type') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == '/') AND ($sarr[($k +1)][1] == 'XRef'))) {
|
||||||
$valid_crs = true;
|
$valid_crs = true;
|
||||||
} elseif (($v[0] == '/') AND ($v[1] == 'Index') AND (isset($sarr[($k +1)]))) {
|
} elseif (($v[0] == '/') AND ($v[1] == 'Index') AND (isset($sarr[($k +1)]))) {
|
||||||
// first object number in the subsection
|
// first object number in the subsection
|
||||||
$index_first = intval($sarr[($k +1)][1][0][1]);
|
$index_first = \intval($sarr[($k +1)][1][0][1]);
|
||||||
// number of entries in the subsection
|
// number of entries in the subsection
|
||||||
$index_entries = intval($sarr[($k +1)][1][1][1]);
|
$index_entries = \intval($sarr[($k +1)][1][1][1]);
|
||||||
} elseif (($v[0] == '/') AND ($v[1] == 'Prev') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'numeric'))) {
|
} elseif (($v[0] == '/') AND ($v[1] == 'Prev') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'numeric'))) {
|
||||||
// get previous xref offset
|
// get previous xref offset
|
||||||
$prevxref = intval($sarr[($k +1)][1]);
|
$prevxref = \intval($sarr[($k +1)][1]);
|
||||||
} elseif (($v[0] == '/') AND ($v[1] == 'W') AND (isset($sarr[($k +1)]))) {
|
} elseif (($v[0] == '/') AND ($v[1] == 'W') AND (isset($sarr[($k +1)]))) {
|
||||||
// number of bytes (in the decoded stream) of the corresponding field
|
// number of bytes (in the decoded stream) of the corresponding field
|
||||||
$wb = array();
|
$wb = [];
|
||||||
$wb[0] = intval($sarr[($k +1)][1][0][1]);
|
$wb[0] = \intval($sarr[($k +1)][1][0][1]);
|
||||||
$wb[1] = intval($sarr[($k +1)][1][1][1]);
|
$wb[1] = \intval($sarr[($k +1)][1][1][1]);
|
||||||
$wb[2] = intval($sarr[($k +1)][1][2][1]);
|
$wb[2] = \intval($sarr[($k +1)][1][2][1]);
|
||||||
} elseif (($v[0] == '/') AND ($v[1] == 'DecodeParms') AND (isset($sarr[($k +1)][1]))) {
|
} elseif (($v[0] == '/') AND ($v[1] == 'DecodeParms') AND (isset($sarr[($k +1)][1]))) {
|
||||||
$decpar = $sarr[($k +1)][1];
|
$decpar = $sarr[($k +1)][1];
|
||||||
foreach ($decpar as $kdc => $vdc) {
|
foreach ($decpar as $kdc => $vdc) {
|
||||||
if (($vdc[0] == '/') AND ($vdc[1] == 'Columns') AND (isset($decpar[($kdc +1)]) AND ($decpar[($kdc +1)][0] == 'numeric'))) {
|
if (($vdc[0] == '/') AND ($vdc[1] == 'Columns') AND (isset($decpar[($kdc +1)]) AND ($decpar[($kdc +1)][0] == 'numeric'))) {
|
||||||
$columns = intval($decpar[($kdc +1)][1]);
|
$columns = \intval($decpar[($kdc +1)][1]);
|
||||||
} elseif (($vdc[0] == '/') AND ($vdc[1] == 'Predictor') AND (isset($decpar[($kdc +1)]) AND ($decpar[($kdc +1)][0] == 'numeric'))) {
|
} elseif (($vdc[0] == '/') AND ($vdc[1] == 'Predictor') AND (isset($decpar[($kdc +1)]) AND ($decpar[($kdc +1)][0] == 'numeric'))) {
|
||||||
$predictor = intval($decpar[($kdc +1)][1]);
|
$predictor = \intval($decpar[($kdc +1)][1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($filltrailer) {
|
} elseif ($filltrailer) {
|
||||||
|
|
@ -336,7 +336,7 @@ class TCPDF_PARSER {
|
||||||
} elseif (($v[0] == '/') AND ($v[1] == 'Encrypt') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'objref'))) {
|
} elseif (($v[0] == '/') AND ($v[1] == 'Encrypt') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'objref'))) {
|
||||||
$xref['trailer']['encrypt'] = $sarr[($k +1)][1];
|
$xref['trailer']['encrypt'] = $sarr[($k +1)][1];
|
||||||
} elseif (($v[0] == '/') AND ($v[1] == 'ID') AND (isset($sarr[($k +1)]))) {
|
} elseif (($v[0] == '/') AND ($v[1] == 'ID') AND (isset($sarr[($k +1)]))) {
|
||||||
$xref['trailer']['id'] = array();
|
$xref['trailer']['id'] = [];
|
||||||
$xref['trailer']['id'][0] = $sarr[($k +1)][1][0][1];
|
$xref['trailer']['id'][0] = $sarr[($k +1)][1][0][1];
|
||||||
$xref['trailer']['id'][1] = $sarr[($k +1)][1][1][1];
|
$xref['trailer']['id'][1] = $sarr[($k +1)][1][1][1];
|
||||||
}
|
}
|
||||||
|
|
@ -351,13 +351,13 @@ class TCPDF_PARSER {
|
||||||
// split the rows
|
// split the rows
|
||||||
$sdata = array_chunk($sdata, $rowlen);
|
$sdata = array_chunk($sdata, $rowlen);
|
||||||
// initialize decoded array
|
// initialize decoded array
|
||||||
$ddata = array();
|
$ddata = [];
|
||||||
// initialize first row with zeros
|
// initialize first row with zeros
|
||||||
$prev_row = array_fill (0, $rowlen, 0);
|
$prev_row = array_fill (0, $rowlen, 0);
|
||||||
// for each row apply PNG unpredictor
|
// for each row apply PNG unpredictor
|
||||||
foreach ($sdata as $k => $row) {
|
foreach ($sdata as $k => $row) {
|
||||||
// initialize new row
|
// initialize new row
|
||||||
$ddata[$k] = array();
|
$ddata[$k] = [];
|
||||||
// get PNG predictor value
|
// get PNG predictor value
|
||||||
$predictor = (10 + $row[0]);
|
$predictor = (10 + $row[0]);
|
||||||
// for each byte on the row
|
// for each byte on the row
|
||||||
|
|
@ -393,10 +393,10 @@ class TCPDF_PARSER {
|
||||||
// initial estimate
|
// initial estimate
|
||||||
$p = ($row_left + $row_up - $row_upleft);
|
$p = ($row_left + $row_up - $row_upleft);
|
||||||
// distances
|
// distances
|
||||||
$pa = abs($p - $row_left);
|
$pa = \abs($p - $row_left);
|
||||||
$pb = abs($p - $row_up);
|
$pb = \abs($p - $row_up);
|
||||||
$pc = abs($p - $row_upleft);
|
$pc = \abs($p - $row_upleft);
|
||||||
$pmin = min($pa, $pb, $pc);
|
$pmin = \min($pa, $pb, $pc);
|
||||||
// return minimum distance
|
// return minimum distance
|
||||||
switch ($pmin) {
|
switch ($pmin) {
|
||||||
case $pa: {
|
case $pa: {
|
||||||
|
|
@ -423,7 +423,7 @@ class TCPDF_PARSER {
|
||||||
$prev_row = $ddata[$k];
|
$prev_row = $ddata[$k];
|
||||||
} // end for each row
|
} // end for each row
|
||||||
// complete decoding
|
// complete decoding
|
||||||
$sdata = array();
|
$sdata = [];
|
||||||
// for every row
|
// for every row
|
||||||
foreach ($ddata as $k => $row) {
|
foreach ($ddata as $k => $row) {
|
||||||
// initialize new row
|
// initialize new row
|
||||||
|
|
@ -444,7 +444,7 @@ class TCPDF_PARSER {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$ddata = array();
|
$ddata = [];
|
||||||
// fill xref
|
// fill xref
|
||||||
if (isset($index_first)) {
|
if (isset($index_first)) {
|
||||||
$obj_num = $index_first;
|
$obj_num = $index_first;
|
||||||
|
|
@ -516,9 +516,9 @@ class TCPDF_PARSER {
|
||||||
// name object
|
// name object
|
||||||
$objtype = $char;
|
$objtype = $char;
|
||||||
++$offset;
|
++$offset;
|
||||||
if (preg_match('/^([^\x00\x09\x0a\x0c\x0d\x20\s\x28\x29\x3c\x3e\x5b\x5d\x7b\x7d\x2f\x25]+)/', substr($this->pdfdata, $offset, 256), $matches) == 1) {
|
if (\preg_match('/^([^\x00\x09\x0a\x0c\x0d\x20\s\x28\x29\x3c\x3e\x5b\x5d\x7b\x7d\x2f\x25]+)/', \substr($this->pdfdata, $offset, 256), $matches) == 1) {
|
||||||
$objval = $matches[1]; // unescaped value
|
$objval = $matches[1]; // unescaped value
|
||||||
$offset += strlen($objval);
|
$offset += \strlen($objval);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +552,7 @@ class TCPDF_PARSER {
|
||||||
}
|
}
|
||||||
++$strpos;
|
++$strpos;
|
||||||
}
|
}
|
||||||
$objval = substr($this->pdfdata, $offset, ($strpos - $offset - 1));
|
$objval = \substr($this->pdfdata, $offset, ($strpos - $offset - 1));
|
||||||
$offset = $strpos;
|
$offset = $strpos;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -564,7 +564,7 @@ class TCPDF_PARSER {
|
||||||
++$offset;
|
++$offset;
|
||||||
if ($char == '[') {
|
if ($char == '[') {
|
||||||
// get array content
|
// get array content
|
||||||
$objval = array();
|
$objval = [];
|
||||||
do {
|
do {
|
||||||
// get element
|
// get element
|
||||||
$element = $this->getRawObject($offset);
|
$element = $this->getRawObject($offset);
|
||||||
|
|
@ -584,7 +584,7 @@ class TCPDF_PARSER {
|
||||||
$offset += 2;
|
$offset += 2;
|
||||||
if ($char == '<') {
|
if ($char == '<') {
|
||||||
// get array content
|
// get array content
|
||||||
$objval = array();
|
$objval = [];
|
||||||
do {
|
do {
|
||||||
// get element
|
// get element
|
||||||
$element = $this->getRawObject($offset);
|
$element = $this->getRawObject($offset);
|
||||||
|
|
@ -598,65 +598,65 @@ class TCPDF_PARSER {
|
||||||
// hexadecimal string object
|
// hexadecimal string object
|
||||||
$objtype = $char;
|
$objtype = $char;
|
||||||
++$offset;
|
++$offset;
|
||||||
if (($char == '<') AND (preg_match('/^([0-9A-Fa-f\x09\x0a\x0c\x0d\x20]+)>/iU', substr($this->pdfdata, $offset), $matches) == 1)) {
|
if (($char == '<') AND (\preg_match('/^([0-9A-Fa-f\x09\x0a\x0c\x0d\x20]+)>/iU', \substr($this->pdfdata, $offset), $matches) == 1)) {
|
||||||
// remove white space characters
|
// remove white space characters
|
||||||
$objval = \str_replace(["\x09", "\x0a", "\x0c", "\x0d", "\x20"], '', $matches[1]);
|
$objval = \str_replace(["\x09", "\x0a", "\x0c", "\x0d", "\x20"], '', $matches[1]);
|
||||||
$offset += strlen($matches[0]);
|
$offset += \strlen($matches[0]);
|
||||||
} elseif (($endpos = strpos($this->pdfdata, '>', $offset)) !== FALSE) {
|
} elseif (($endpos = \strpos($this->pdfdata, '>', $offset)) !== FALSE) {
|
||||||
$offset = $endpos + 1;
|
$offset = $endpos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
if (substr($this->pdfdata, $offset, 6) == 'endobj') {
|
if (\substr($this->pdfdata, $offset, 6) == 'endobj') {
|
||||||
// indirect object
|
// indirect object
|
||||||
$objtype = 'endobj';
|
$objtype = 'endobj';
|
||||||
$offset += 6;
|
$offset += 6;
|
||||||
} elseif (substr($this->pdfdata, $offset, 4) == 'null') {
|
} elseif (\substr($this->pdfdata, $offset, 4) == 'null') {
|
||||||
// null object
|
// null object
|
||||||
$objtype = 'null';
|
$objtype = 'null';
|
||||||
$offset += 4;
|
$offset += 4;
|
||||||
$objval = 'null';
|
$objval = 'null';
|
||||||
} elseif (substr($this->pdfdata, $offset, 4) == 'true') {
|
} elseif (\substr($this->pdfdata, $offset, 4) == 'true') {
|
||||||
// boolean true object
|
// boolean true object
|
||||||
$objtype = 'boolean';
|
$objtype = 'boolean';
|
||||||
$offset += 4;
|
$offset += 4;
|
||||||
$objval = 'true';
|
$objval = 'true';
|
||||||
} elseif (substr($this->pdfdata, $offset, 5) == 'false') {
|
} elseif (\substr($this->pdfdata, $offset, 5) == 'false') {
|
||||||
// boolean false object
|
// boolean false object
|
||||||
$objtype = 'boolean';
|
$objtype = 'boolean';
|
||||||
$offset += 5;
|
$offset += 5;
|
||||||
$objval = 'false';
|
$objval = 'false';
|
||||||
} elseif (substr($this->pdfdata, $offset, 6) == 'stream') {
|
} elseif (\substr($this->pdfdata, $offset, 6) == 'stream') {
|
||||||
// start stream object
|
// start stream object
|
||||||
$objtype = 'stream';
|
$objtype = 'stream';
|
||||||
$offset += 6;
|
$offset += 6;
|
||||||
if (preg_match('/^([\r]?[\n])/isU', substr($this->pdfdata, $offset), $matches) == 1) {
|
if (\preg_match('/^([\r]?[\n])/isU', \substr($this->pdfdata, $offset), $matches) == 1) {
|
||||||
$offset += strlen($matches[0]);
|
$offset += \strlen($matches[0]);
|
||||||
if (preg_match('/(endstream)[\x09\x0a\x0c\x0d\x20]/isU', substr($this->pdfdata, $offset), $matches, PREG_OFFSET_CAPTURE) == 1) {
|
if (\preg_match('/(endstream)[\x09\x0a\x0c\x0d\x20]/isU', \substr($this->pdfdata, $offset), $matches, PREG_OFFSET_CAPTURE) == 1) {
|
||||||
$objval = substr($this->pdfdata, $offset, $matches[0][1]);
|
$objval = \substr($this->pdfdata, $offset, $matches[0][1]);
|
||||||
$offset += $matches[1][1];
|
$offset += $matches[1][1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (substr($this->pdfdata, $offset, 9) == 'endstream') {
|
} elseif (\substr($this->pdfdata, $offset, 9) == 'endstream') {
|
||||||
// end stream object
|
// end stream object
|
||||||
$objtype = 'endstream';
|
$objtype = 'endstream';
|
||||||
$offset += 9;
|
$offset += 9;
|
||||||
} elseif (preg_match('/^([0-9]+)[\s]+([0-9]+)[\s]+R/iU', substr($this->pdfdata, $offset, 33), $matches) == 1) {
|
} elseif (\preg_match('/^([0-9]+)[\s]+([0-9]+)[\s]+R/iU', \substr($this->pdfdata, $offset, 33), $matches) == 1) {
|
||||||
// indirect object reference
|
// indirect object reference
|
||||||
$objtype = 'objref';
|
$objtype = 'objref';
|
||||||
$offset += strlen($matches[0]);
|
$offset += \strlen($matches[0]);
|
||||||
$objval = intval($matches[1]).'_'.intval($matches[2]);
|
$objval = \intval($matches[1]).'_'.\intval($matches[2]);
|
||||||
} elseif (preg_match('/^([0-9]+)[\s]+([0-9]+)[\s]+obj/iU', substr($this->pdfdata, $offset, 33), $matches) == 1) {
|
} elseif (\preg_match('/^([0-9]+)[\s]+([0-9]+)[\s]+obj/iU', \substr($this->pdfdata, $offset, 33), $matches) == 1) {
|
||||||
// object start
|
// object start
|
||||||
$objtype = 'obj';
|
$objtype = 'obj';
|
||||||
$objval = intval($matches[1]).'_'.intval($matches[2]);
|
$objval = \intval($matches[1]).'_'.\intval($matches[2]);
|
||||||
$offset += strlen ($matches[0]);
|
$offset += strlen ($matches[0]);
|
||||||
} elseif (($numlen = strspn($this->pdfdata, '+-.0123456789', $offset)) > 0) {
|
} elseif (($numlen = strspn($this->pdfdata, '+-.0123456789', $offset)) > 0) {
|
||||||
// numeric object
|
// numeric object
|
||||||
$objtype = 'numeric';
|
$objtype = 'numeric';
|
||||||
$objval = substr($this->pdfdata, $offset, $numlen);
|
$objval = \substr($this->pdfdata, $offset, $numlen);
|
||||||
$offset += $numlen;
|
$offset += $numlen;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -683,14 +683,14 @@ class TCPDF_PARSER {
|
||||||
$objref = $obj[0].' '.$obj[1].' obj';
|
$objref = $obj[0].' '.$obj[1].' obj';
|
||||||
// ignore leading zeros
|
// ignore leading zeros
|
||||||
$offset += strspn($this->pdfdata, '0', $offset);
|
$offset += strspn($this->pdfdata, '0', $offset);
|
||||||
if (strpos($this->pdfdata, $objref, $offset) != $offset) {
|
if (\strpos($this->pdfdata, $objref, $offset) != $offset) {
|
||||||
// an indirect reference to an undefined object shall be considered a reference to the null object
|
// an indirect reference to an undefined object shall be considered a reference to the null object
|
||||||
return array('null', 'null', $offset);
|
return array('null', 'null', $offset);
|
||||||
}
|
}
|
||||||
// starting position of object content
|
// starting position of object content
|
||||||
$offset += strlen($objref);
|
$offset += \strlen($objref);
|
||||||
// get array of object content
|
// get array of object content
|
||||||
$objdata = array();
|
$objdata = [];
|
||||||
$i = 0; // object main index
|
$i = 0; // object main index
|
||||||
do {
|
do {
|
||||||
$oldoffset = $offset;
|
$oldoffset = $offset;
|
||||||
|
|
@ -742,18 +742,18 @@ class TCPDF_PARSER {
|
||||||
*/
|
*/
|
||||||
protected function decodeStream($sdic, $stream) {
|
protected function decodeStream($sdic, $stream) {
|
||||||
// get stream length and filters
|
// get stream length and filters
|
||||||
$slength = strlen($stream);
|
$slength = \strlen($stream);
|
||||||
if ($slength <= 0) {
|
if ($slength <= 0) {
|
||||||
return array('', array());
|
return array('', []);
|
||||||
}
|
}
|
||||||
$filters = array();
|
$filters = [];
|
||||||
foreach ($sdic as $k => $v) {
|
foreach ($sdic as $k => $v) {
|
||||||
if ($v[0] == '/') {
|
if ($v[0] == '/') {
|
||||||
if (($v[1] == 'Length') AND (isset($sdic[($k + 1)])) AND ($sdic[($k + 1)][0] == 'numeric')) {
|
if (($v[1] == 'Length') AND (isset($sdic[($k + 1)])) AND ($sdic[($k + 1)][0] == 'numeric')) {
|
||||||
// get declared stream length
|
// get declared stream length
|
||||||
$declength = intval($sdic[($k + 1)][1]);
|
$declength = \intval($sdic[($k + 1)][1]);
|
||||||
if ($declength < $slength) {
|
if ($declength < $slength) {
|
||||||
$stream = substr($stream, 0, $declength);
|
$stream = \substr($stream, 0, $declength);
|
||||||
$slength = $declength;
|
$slength = $declength;
|
||||||
}
|
}
|
||||||
} elseif (($v[1] == 'Filter') AND (isset($sdic[($k + 1)]))) {
|
} elseif (($v[1] == 'Filter') AND (isset($sdic[($k + 1)]))) {
|
||||||
|
|
@ -774,7 +774,7 @@ class TCPDF_PARSER {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// decode the stream
|
// decode the stream
|
||||||
$remaining_filters = array();
|
$remaining_filters = [];
|
||||||
foreach ($filters as $filter) {
|
foreach ($filters as $filter) {
|
||||||
if (in_array($filter, TCPDF_FILTERS::getAvailableFilters())) {
|
if (in_array($filter, TCPDF_FILTERS::getAvailableFilters())) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user