From 824f8c45edb20e27221e92805b0090f1768a2756 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:34:17 +0200 Subject: changed mpdf with tcpdf --- .../libraries/mpdf/mpdfi/filters/FilterASCII85.php | 98 --- .../libraries/mpdf/mpdfi/filters/FilterLZW.php | 154 ----- .../libraries/mpdf/mpdfi/fpdi_pdf_parser.php | 363 ----------- inc/3rdparty/libraries/mpdf/mpdfi/pdf_context.php | 78 --- inc/3rdparty/libraries/mpdf/mpdfi/pdf_parser.php | 690 --------------------- 5 files changed, 1383 deletions(-) delete mode 100644 inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterASCII85.php delete mode 100644 inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterLZW.php delete mode 100644 inc/3rdparty/libraries/mpdf/mpdfi/fpdi_pdf_parser.php delete mode 100644 inc/3rdparty/libraries/mpdf/mpdfi/pdf_context.php delete mode 100644 inc/3rdparty/libraries/mpdf/mpdfi/pdf_parser.php (limited to 'inc/3rdparty/libraries/mpdf/mpdfi') diff --git a/inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterASCII85.php b/inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterASCII85.php deleted file mode 100644 index fc42d574..00000000 --- a/inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterASCII85.php +++ /dev/null @@ -1,98 +0,0 @@ - ORD_u) { - $this->error('Illegal character in ASCII85Decode.'); - } - - $chn[$state++] = $ch - ORD_exclmark; - - if ($state == 5) { - $state = 0; - $r = 0; - for ($j = 0; $j < 5; ++$j) - $r = $r * 85 + $chn[$j]; - $out .= chr($r >> 24); - $out .= chr($r >> 16); - $out .= chr($r >> 8); - $out .= chr($r); - } - } - $r = 0; - - if ($state == 1) - $this->error('Illegal length in ASCII85Decode.'); - if ($state == 2) { - $r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85; - $out .= chr($r >> 24); - } - else if ($state == 3) { - $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2]+1) * 85 * 85; - $out .= chr($r >> 24); - $out .= chr($r >> 16); - } - else if ($state == 4) { - $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3]+1) * 85 ; - $out .= chr($r >> 24); - $out .= chr($r >> 16); - $out .= chr($r >> 8); - } - - return $out; - } - - function encode($in) { - $this->error("ASCII85 encoding not implemented."); - } -} \ No newline at end of file diff --git a/inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterLZW.php b/inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterLZW.php deleted file mode 100644 index 5867603f..00000000 --- a/inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterLZW.php +++ /dev/null @@ -1,154 +0,0 @@ -error('LZW flavour not supported.'); - } - - $this->initsTable(); - - $this->data = $data; - $this->dataLength = strlen($data); - - // Initialize pointers - $this->bytePointer = 0; - $this->bitPointer = 0; - - $this->nextData = 0; - $this->nextBits = 0; - - $oldCode = 0; - - $string = ''; - $uncompData = ''; - - while (($code = $this->getNextCode()) != 257) { - if ($code == 256) { - $this->initsTable(); - $code = $this->getNextCode(); - - if ($code == 257) { - break; - } - - $uncompData .= $this->sTable[$code]; - $oldCode = $code; - - } else { - - if ($code < $this->tIdx) { - $string = $this->sTable[$code]; - $uncompData .= $string; - - $this->addStringToTable($this->sTable[$oldCode], $string[0]); - $oldCode = $code; - } else { - $string = $this->sTable[$oldCode]; - $string = $string.$string[0]; - $uncompData .= $string; - - $this->addStringToTable($string); - $oldCode = $code; - } - } - } - - return $uncompData; - } - - - /** - * Initialize the string table. - */ - function initsTable() { - $this->sTable = array(); - - for ($i = 0; $i < 256; $i++) - $this->sTable[$i] = chr($i); - - $this->tIdx = 258; - $this->bitsToGet = 9; - } - - /** - * Add a new string to the string table. - */ - function addStringToTable ($oldString, $newString='') { - $string = $oldString.$newString; - - // Add this new String to the table - $this->sTable[$this->tIdx++] = $string; - - if ($this->tIdx == 511) { - $this->bitsToGet = 10; - } else if ($this->tIdx == 1023) { - $this->bitsToGet = 11; - } else if ($this->tIdx == 2047) { - $this->bitsToGet = 12; - } - } - - // Returns the next 9, 10, 11 or 12 bits - function getNextCode() { - if ($this->bytePointer == $this->dataLength) { - return 257; - } - - $this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff); - $this->nextBits += 8; - - if ($this->nextBits < $this->bitsToGet) { - $this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff); - $this->nextBits += 8; - } - - $code = ($this->nextData >> ($this->nextBits - $this->bitsToGet)) & $this->andTable[$this->bitsToGet-9]; - $this->nextBits -= $this->bitsToGet; - - return $code; - } - - function encode($in) { - $this->error("LZW encoding not implemented."); - } -} \ No newline at end of file diff --git a/inc/3rdparty/libraries/mpdf/mpdfi/fpdi_pdf_parser.php b/inc/3rdparty/libraries/mpdf/mpdfi/fpdi_pdf_parser.php deleted file mode 100644 index e0f02391..00000000 --- a/inc/3rdparty/libraries/mpdf/mpdfi/fpdi_pdf_parser.php +++ /dev/null @@ -1,363 +0,0 @@ -fpdi =& $fpdi; - $this->filename = $filename; - - parent::pdf_parser($filename); - if ($this->success == false) { return false; } - - // resolve Pages-Dictonary - $pages = $this->pdf_resolve_object($this->c, $this->root[1][1]['/Pages']); - if ($this->success == false) { return false; } - - // Read pages - $this->read_pages($this->c, $pages, $this->pages); - if ($this->success == false) { return false; } - - // count pages; - $this->page_count = count($this->pages); - } - - - /** - * Get pagecount from sourcefile - * - * @return int - */ - function getPageCount() { - return $this->page_count; - } - - - /** - * Set pageno - * - * @param int $pageno Pagenumber to use - */ - function setPageno($pageno) { - $pageno = ((int) $pageno) - 1; - - if ($pageno < 0 || $pageno >= $this->getPageCount()) { - $this->fpdi->error("Pagenumber is wrong!"); - } - - $this->pageno = $pageno; - } - - /** - * Get page-resources from current page - * - * @return array - */ - function getPageResources() { - return $this->_getPageResources($this->pages[$this->pageno]); - } - - /** - * Get page-resources from /Page - * - * @param array $obj Array of pdf-data - */ - function _getPageResources ($obj) { // $obj = /Page - $obj = $this->pdf_resolve_object($this->c, $obj); - - // If the current object has a resources - // dictionary associated with it, we use - // it. Otherwise, we move back to its - // parent object. - if (isset ($obj[1][1]['/Resources'])) { - $res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Resources']); - if ($res[0] == PDF_TYPE_OBJECT) - return $res[1]; - return $res; - } else { - if (!isset ($obj[1][1]['/Parent'])) { - return false; - } else { - $res = $this->_getPageResources($obj[1][1]['/Parent']); - if ($res[0] == PDF_TYPE_OBJECT) - return $res[1]; - return $res; - } - } - } - - - /** - * Get content of current page - * - * If more /Contents is an array, the streams are concated - * - * @return string - */ - function getContent() { - $buffer = ""; - - if (isset($this->pages[$this->pageno][1][1]['/Contents'])) { - $contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']); - foreach($contents AS $tmp_content) { - $buffer .= $this->_rebuildContentStream($tmp_content).' '; - } - } - - return $buffer; - } - - - /** - * Resolve all content-objects - * - * @param array $content_ref - * @return array - */ - function _getPageContent($content_ref) { - $contents = array(); - - if ($content_ref[0] == PDF_TYPE_OBJREF) { - $content = $this->pdf_resolve_object($this->c, $content_ref); - if ($content[1][0] == PDF_TYPE_ARRAY) { - $contents = $this->_getPageContent($content[1]); - } else { - $contents[] = $content; - } - } else if ($content_ref[0] == PDF_TYPE_ARRAY) { - foreach ($content_ref[1] AS $tmp_content_ref) { - $contents = array_merge($contents,$this->_getPageContent($tmp_content_ref)); - } - } - - return $contents; - } - - - /** - * Rebuild content-streams - * - * @param array $obj - * @return string - */ - function _rebuildContentStream($obj) { - $filters = array(); - - if (isset($obj[1][1]['/Filter'])) { - $_filter = $obj[1][1]['/Filter']; - - if ($_filter[0] == PDF_TYPE_TOKEN) { - $filters[] = $_filter; - } else if ($_filter[0] == PDF_TYPE_ARRAY) { - $filters = $_filter[1]; - } - } - - $stream = $obj[2][1]; - - foreach ($filters AS $_filter) { - switch ($_filter[1]) { - case "/FlateDecode": - if (function_exists('gzuncompress')) { - $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : ''; - } else { - $this->fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.",$_filter[1])); - } - if ($stream === false) { - $this->fpdi->error("Error while decompressing stream."); - } - break; - // mPDF 4.2.003 - case '/LZWDecode': - include_once(_MPDF_PATH.'mpdfi/filters/FilterLZW.php'); - // mPDF 5.0 Removed pass by reference =& - $decoder = new FilterLZW(); - $stream = $decoder->decode($stream); - break; - case '/ASCII85Decode': - include_once(_MPDF_PATH.'mpdfi/filters/FilterASCII85.php'); - // mPDF 5.0 Removed pass by reference =& - $decoder = new FilterASCII85(); - $stream = $decoder->decode($stream); - break; - case null: - $stream = $stream; - break; - default: - $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1])); - } - } - - return $stream; - } - - - /** - * Get a Box from a page - * Arrayformat is same as used by fpdf_tpl - * - * @param array $page a /Page - * @param string $box_index Type of Box @see $availableBoxes - * @return array - */ - function getPageBox($page, $box_index) { - $page = $this->pdf_resolve_object($this->c,$page); - $box = null; - if (isset($page[1][1][$box_index])) - $box =& $page[1][1][$box_index]; - - if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) { - $tmp_box = $this->pdf_resolve_object($this->c,$box); - $box = $tmp_box[1]; - } - - if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) { - $b =& $box[1]; - return array("x" => $b[0][1]/_MPDFK, - "y" => $b[1][1]/_MPDFK, - "w" => abs($b[0][1]-$b[2][1])/_MPDFK, - "h" => abs($b[1][1]-$b[3][1])/_MPDFK); // mPDF 5.3.90 - } else if (!isset ($page[1][1]['/Parent'])) { - return false; - } else { - return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index); - } - } - - function getPageBoxes($pageno) { - return $this->_getPageBoxes($this->pages[$pageno-1]); - } - - /** - * Get all Boxes from /Page - * - * @param array a /Page - * @return array - */ - function _getPageBoxes($page) { - $boxes = array(); - - foreach($this->availableBoxes AS $box) { - if ($_box = $this->getPageBox($page,$box)) { - $boxes[$box] = $_box; - } - } - - return $boxes; - } - - function getPageRotation($pageno) { - return $this->_getPageRotation($this->pages[$pageno-1]); - } - - function _getPageRotation ($obj) { // $obj = /Page - $obj = $this->pdf_resolve_object($this->c, $obj); - if (isset ($obj[1][1]['/Rotate'])) { - $res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']); - if ($res[0] == PDF_TYPE_OBJECT) - return $res[1]; - return $res; - } else { - if (!isset ($obj[1][1]['/Parent'])) { - return false; - } else { - $res = $this->_getPageRotation($obj[1][1]['/Parent']); - if ($res[0] == PDF_TYPE_OBJECT) - return $res[1]; - return $res; - } - } - } - - /** - * Read all /Page(es) - * - * @param object pdf_context - * @param array /Pages - * @param array the result-array - */ - function read_pages (&$c, &$pages, &$result) { - // Get the kids dictionary - $kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); - - if (!is_array($kids)) { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("Cannot find /Kids in current /Page-Dictionary"); - return false; - } - foreach ($kids[1] as $v) { - $pg = $this->pdf_resolve_object ($c, $v); - if ($pg[1][1]['/Type'][1] === '/Pages') { - // If one of the kids is an embedded - // /Pages array, resolve it as well. - $this->read_pages ($c, $pg, $result); - } else { - $result[] = $pg; - } - } - } - - - - -} - -?> \ No newline at end of file diff --git a/inc/3rdparty/libraries/mpdf/mpdfi/pdf_context.php b/inc/3rdparty/libraries/mpdf/mpdfi/pdf_context.php deleted file mode 100644 index 6cf4bdcc..00000000 --- a/inc/3rdparty/libraries/mpdf/mpdfi/pdf_context.php +++ /dev/null @@ -1,78 +0,0 @@ -file = $f; - $this->reset(); - } - - // Optionally move the file - // pointer to a new location - // and reset the buffered data - - function reset($pos = null, $l = 100) { - if (!is_null ($pos)) { - fseek ($this->file, $pos); - } - - $this->buffer = $l > 0 ? fread($this->file, $l) : ''; - $this->offset = 0; - $this->length = strlen($this->buffer); - $this->stack = array(); - } - - // Make sure that there is at least one - // character beyond the current offset in - // the buffer to prevent the tokenizer - // from attempting to access data that does - // not exist - - function ensure_content() { - if ($this->offset >= $this->length - 1) { - return $this->increase_length(); - } else { - return true; - } - } - - // Forcefully read more data into the buffer - - function increase_length($l=100) { - if (feof($this->file)) { - return false; - } else { - $this->buffer .= fread($this->file, $l); - $this->length = strlen($this->buffer); - return true; - } - } - -} -?> \ No newline at end of file diff --git a/inc/3rdparty/libraries/mpdf/mpdfi/pdf_parser.php b/inc/3rdparty/libraries/mpdf/mpdfi/pdf_parser.php deleted file mode 100644 index c7d69e2c..00000000 --- a/inc/3rdparty/libraries/mpdf/mpdfi/pdf_parser.php +++ /dev/null @@ -1,690 +0,0 @@ -filename = $filename; - // mPDF 4.0 - $this->success = true; - - $this->f = @fopen($this->filename, "rb"); - - if (!$this->f) { - $this->success = false; - $this->errormsg = sprintf("Cannot open %s !", $filename); - return false; - } - // mPDF 5.0 Removed pass by reference =& - $this->c = new pdf_context($this->f); - // Read xref-Data - $offset = $this->pdf_find_xref(); - if ($offset===false) { - $this->success = false; - $this->errormsg = sprintf("Cannot open %s !", $filename); - return false; - } - $this->pdf_read_xref($this->xref, $offset); - if ($this->success == false) { return false; } - - // Check for Encryption - $this->getEncryption(); - if ($this->success == false) { return false; } - - // Read root - $this->pdf_read_root(); - if ($this->success == false) { return false; } - } - - /** - * Close the opened file - */ - function closeFile() { - if (isset($this->f)) { - fclose($this->f); - unset($this->f); - } - } - - /** - * Print Error and die - * - * @param string $msg Error-Message - */ - function error($msg) { - die("PDF-Parser Error: ".$msg); - } - - /** - * Check Trailer for Encryption - */ - function getEncryption() { - if (isset($this->xref['trailer'][1]['/Encrypt'])) { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("File is encrypted!"); - return false; - } - } - - /** - * Find/Return /Root - * - * @return array - */ - function pdf_find_root() { - if ($this->xref['trailer'][1]['/Root'][0] != PDF_TYPE_OBJREF) { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("Wrong Type of Root-Element! Must be an indirect reference"); - return false; - } - return $this->xref['trailer'][1]['/Root']; - } - - /** - * Read the /Root - */ - function pdf_read_root() { - // read root - $root = $this->pdf_find_root(); - if ($root ===false) { - $this->success = false; - return false; - } - $this->root = $this->pdf_resolve_object($this->c, $root); - } - - /** - * Find the xref-Table - */ - function pdf_find_xref() { - fseek ($this->f, -min(filesize($this->filename),1500), SEEK_END); - $data = fread($this->f, 1500); - - $pos = strlen($data) - strpos(strrev($data), strrev('startxref')); - $data = substr($data, $pos); - - if (!preg_match('/\s*(\d+).*$/s', $data, $matches)) { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("Unable to find pointer to xref table"); - return false; - } - - return (int) $matches[1]; - } - - /** - * Read xref-table - * - * @param array $result Array of xref-table - * @param integer $offset of xref-table - * @param integer $start start-position in xref-table - * @param integer $end end-position in xref-table - */ - function pdf_read_xref(&$result, $offset, $start = null, $end = null) { - if (is_null ($start) || is_null ($end)) { - fseek($this->f, $o_pos = $offset); - $data = trim(fgets($this->f,1024)); - - if (strlen($data) == 0) - $data = trim(fgets($this->f,1024)); - - if ($data !== 'xref') { - fseek($this->f, $o_pos); - $data = trim(_fgets($this->f, true)); - if ($data !== 'xref') { - if (preg_match('/(.*xref)(.*)/m', $data, $m)) { // xref 0 128 - in one line - fseek($this->f, $o_pos+strlen($m[1])); - } elseif (preg_match('/(x|r|e|f)+/', $data, $m)) { // correct invalid xref-pointer - $tmpOffset = $offset-4+strlen($m[0]); - $this->pdf_read_xref($result, $tmpOffset, $start, $end); - return; - } else { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("Unable to find xref table - Maybe a Problem with 'auto_detect_line_endings'"); - return; - } - } - } - - $o_pos = ftell($this->f); - $data = explode(' ', trim(fgets($this->f,1024))); - if (count($data) != 2) { - fseek($this->f, $o_pos); - $data = explode(' ', trim(_fgets($this->f, true))); - - if (count($data) != 2) { - if (count($data) > 2) { // no lineending - $n_pos = $o_pos+strlen($data[0])+strlen($data[1])+2; - fseek($this->f, $n_pos); - } else { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("Unexpected header in xref table"); - return; - } - } - } - $start = $data[0]; - $end = $start + $data[1]; - } - - if (!isset($result['xref_location'])) { - $result['xref_location'] = $offset; - } - - if (!isset($result['max_object']) || $end > $result['max_object']) { - $result['max_object'] = $end; - } - - for (; $start < $end; $start++) { - $data = ltrim(fread($this->f, 20)); // Spezifications says: 20 bytes including newlines - $offset = substr($data, 0, 10); - $generation = substr($data, 11, 5); - - if (!isset ($result['xref'][$start][(int) $generation])) { - $result['xref'][$start][(int) $generation] = (int) $offset; - } - } - - $o_pos = ftell($this->f); - $data = fgets($this->f,1024); - if (strlen(trim($data)) == 0) - $data = fgets($this->f, 1024); - - if (preg_match("/trailer/",$data)) { - if (preg_match("/(.*trailer[ \n\r]*)/",$data,$m)) { - fseek($this->f, $o_pos+strlen($m[1])); - } - - // mPDF 5.0 Removed pass by reference =& - $c = new pdf_context($this->f); - $trailer = $this->pdf_read_value($c); - - if (isset($trailer[1]['/Prev'])) { - $this->pdf_read_xref($result, $trailer[1]['/Prev'][1]); - $result['trailer'][1] = array_merge($result['trailer'][1], $trailer[1]); - } else { - $result['trailer'] = $trailer; - } - } else { - $data = explode(' ', trim($data)); - - if (count($data) != 2) { - fseek($this->f, $o_pos); - $data = explode(' ', trim (_fgets ($this->f, true))); - - if (count($data) != 2) { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("Unexpected data in xref table"); - return; - } - } - - $this->pdf_read_xref($result, null, (int) $data[0], (int) $data[0] + (int) $data[1]); - } - } - - - /** - * Reads an Value - * - * @param object $c pdf_context - * @param string $token a Token - * @return mixed - */ - function pdf_read_value(&$c, $token = null) { - if (is_null($token)) { - $token = $this->pdf_read_token($c); - } - - if ($token === false) { - return false; - } - - switch ($token) { - case '<': - // This is a hex string. - // Read the value, then the terminator - - $pos = $c->offset; - - while(1) { - - $match = strpos ($c->buffer, '>', $pos); - - // If you can't find it, try - // reading more data from the stream - - if ($match === false) { - if (!$c->increase_length()) { - return false; - } else { - continue; - } - } - - $result = substr ($c->buffer, $c->offset, $match - $c->offset); - $c->offset = $match+1; - - return array (PDF_TYPE_HEX, $result); - } - - break; - case '<<': - // This is a dictionary. - - $result = array(); - - // Recurse into this function until we reach - // the end of the dictionary. - while (($key = $this->pdf_read_token($c)) !== '>>') { - if ($key === false) { - return false; - } - - if (($value = $this->pdf_read_value($c)) === false) { - return false; - } - $result[$key] = $value; - } - - return array (PDF_TYPE_DICTIONARY, $result); - - case '[': - // This is an array. - - $result = array(); - - // Recurse into this function until we reach - // the end of the array. - while (($token = $this->pdf_read_token($c)) !== ']') { - if ($token === false) { - return false; - } - - if (($value = $this->pdf_read_value($c, $token)) === false) { - return false; - } - - $result[] = $value; - } - - return array (PDF_TYPE_ARRAY, $result); - - case '(' : - // This is a string - - $pos = $c->offset; - - while(1) { - - // Start by finding the next closed - // parenthesis - - $match = strpos ($c->buffer, ')', $pos); - - // If you can't find it, try - // reading more data from the stream - - if ($match === false) { - if (!$c->increase_length()) { - return false; - } else { - continue; - } - } - - // Make sure that there is no backslash - // before the parenthesis. If there is, - // move on. Otherwise, return the string. - $esc = preg_match('/([\\\\]+)$/', $tmpresult = substr($c->buffer, $c->offset, $match - $c->offset), $m); - - if ($esc === 0 || strlen($m[1]) % 2 == 0) { - $result = $tmpresult; - $c->offset = $match + 1; - return array (PDF_TYPE_STRING, $result); - } else { - $pos = $match + 1; - - if ($pos > $c->offset + $c->length) { - $c->increase_length(); - } - } - } - - case "stream": - $o_pos = ftell($c->file)-strlen($c->buffer); - $o_offset = $c->offset; - - $c->reset($startpos = $o_pos + $o_offset); - - $e = 0; // ensure line breaks in front of the stream - if ($c->buffer[0] == chr(10) || $c->buffer[0] == chr(13)) - $e++; - if ($c->buffer[1] == chr(10) && $c->buffer[0] != chr(10)) - $e++; - - if ($this->actual_obj[1][1]['/Length'][0] == PDF_TYPE_OBJREF) { - // mPDF 5.0 Removed pass by reference =& - $tmp_c = new pdf_context($this->f); - $tmp_length = $this->pdf_resolve_object($tmp_c,$this->actual_obj[1][1]['/Length']); - $length = $tmp_length[1][1]; - } else { - $length = $this->actual_obj[1][1]['/Length'][1]; - } - - if ($length > 0) { - $c->reset($startpos+$e,$length); - $v = $c->buffer; - } else { - $v = ''; - } - $c->reset($startpos+$e+$length+9); // 9 = strlen("endstream") - - return array(PDF_TYPE_STREAM, $v); - - default : - if (is_numeric ($token)) { - // A numeric token. Make sure that - // it is not part of something else. - if (($tok2 = $this->pdf_read_token ($c)) !== false) { - if (is_numeric ($tok2)) { - - // Two numeric tokens in a row. - // In this case, we're probably in - // front of either an object reference - // or an object specification. - // Determine the case and return the data - if (($tok3 = $this->pdf_read_token ($c)) !== false) { - switch ($tok3) { - case 'obj' : - return array (PDF_TYPE_OBJDEC, (int) $token, (int) $tok2); - case 'R' : - return array (PDF_TYPE_OBJREF, (int) $token, (int) $tok2); - } - // If we get to this point, that numeric value up - // there was just a numeric value. Push the extra - // tokens back into the stack and return the value. - array_push ($c->stack, $tok3); - } - } - - array_push ($c->stack, $tok2); - } - - return array (PDF_TYPE_NUMERIC, $token); - } else { - - // Just a token. Return it. - return array (PDF_TYPE_TOKEN, $token); - } - - } - } - - /** - * Resolve an object - * - * @param object $c pdf_context - * @param array $obj_spec The object-data - * @param boolean $encapsulate Must set to true, cause the parsing and fpdi use this method only without this para - */ - function pdf_resolve_object(&$c, $obj_spec, $encapsulate = true) { - // Exit if we get invalid data - if (!is_array($obj_spec)) { - return false; - } - - if ($obj_spec[0] == PDF_TYPE_OBJREF) { - - // This is a reference, resolve it - if (isset($this->xref['xref'][$obj_spec[1]][$obj_spec[2]])) { - - // Save current file position - // This is needed if you want to resolve - // references while you're reading another object - // (e.g.: if you need to determine the length - // of a stream) - - $old_pos = ftell($c->file); - - // Reposition the file pointer and - // load the object header. - - $c->reset($this->xref['xref'][$obj_spec[1]][$obj_spec[2]]); - - $header = $this->pdf_read_value($c,null,true); - - if ($header[0] != PDF_TYPE_OBJDEC || $header[1] != $obj_spec[1] || $header[2] != $obj_spec[2]) { - // mPDF 4.0 - $this->success = false; - $this->errormsg = sprintf("Unable to find object ({$obj_spec[1]}, {$obj_spec[2]}) at expected location"); - return false; - } - - // If we're being asked to store all the information - // about the object, we add the object ID and generation - // number for later use - $this->actual_obj =& $result; - if ($encapsulate) { - $result = array ( - PDF_TYPE_OBJECT, - 'obj' => $obj_spec[1], - 'gen' => $obj_spec[2] - ); - } else { - $result = array(); - } - - // Now simply read the object data until - // we encounter an end-of-object marker - while(1) { - $value = $this->pdf_read_value($c); - if ($value === false || count($result) > 4) { - // in this case the parser coudn't find an endobj so we break here - break; - } - - if ($value[0] == PDF_TYPE_TOKEN && $value[1] === 'endobj') { - break; - } - - $result[] = $value; - } - - $c->reset($old_pos); - - if (isset($result[2][0]) && $result[2][0] == PDF_TYPE_STREAM) { - $result[0] = PDF_TYPE_STREAM; - } - - return $result; - } - } else { - return $obj_spec; - } - } - - - - /** - * Reads a token from the file - * - * @param object $c pdf_context - * @return mixed - */ - function pdf_read_token(&$c) - { - // If there is a token available - // on the stack, pop it out and - // return it. - - if (count($c->stack)) { - return array_pop($c->stack); - } - - // Strip away any whitespace - - do { - if (!$c->ensure_content()) { - return false; - } - $c->offset += _strspn($c->buffer, " \n\r\t", $c->offset); - } while ($c->offset >= $c->length - 1); - - // Get the first character in the stream - - $char = $c->buffer[$c->offset++]; - - switch ($char) { - - case '[' : - case ']' : - case '(' : - case ')' : - - // This is either an array or literal string - // delimiter, Return it - - return $char; - - case '<' : - case '>' : - - // This could either be a hex string or - // dictionary delimiter. Determine the - // appropriate case and return the token - - if ($c->buffer[$c->offset] == $char) { - if (!$c->ensure_content()) { - return false; - } - $c->offset++; - return $char . $char; - } else { - return $char; - } - - default : - - // This is "another" type of token (probably - // a dictionary entry or a numeric value) - // Find the end and return it. - - if (!$c->ensure_content()) { - return false; - } - - while(1) { - - // Determine the length of the token - - $pos = _strcspn($c->buffer, " []<>()\r\n\t/", $c->offset); - if ($c->offset + $pos <= $c->length - 1) { - break; - } else { - // If the script reaches this point, - // the token may span beyond the end - // of the current buffer. Therefore, - // we increase the size of the buffer - // and try again--just to be safe. - - $c->increase_length(); - } - } - - $result = substr($c->buffer, $c->offset - 1, $pos + 1); - - $c->offset += $pos; - return $result; - } - } - - -} - -?> \ No newline at end of file -- cgit v1.2.3