[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * This file is part of FPDI 4 * 5 * @package FPDI 6 * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) 7 * @license http://opensource.org/licenses/mit-license The MIT License 8 * @version 1.6.1 9 */ 10 11 /** 12 * Class pdf_context 13 */ 14 class pdf_context 15 { 16 /** 17 * Mode 18 * 19 * @var integer 0 = file | 1 = string 20 */ 21 protected $_mode = 0; 22 23 /** 24 * @var resource|string 25 */ 26 public $file; 27 28 /** 29 * @var string 30 */ 31 public $buffer; 32 33 /** 34 * @var integer 35 */ 36 public $offset; 37 38 /** 39 * @var integer 40 */ 41 public $length; 42 43 /** 44 * @var array 45 */ 46 public $stack; 47 48 /** 49 * The constructor 50 * 51 * @param resource $f 52 */ 53 public function __construct(&$f) 54 { 55 $this->file =& $f; 56 if (is_string($this->file)) 57 $this->_mode = 1; 58 59 $this->reset(); 60 } 61 62 /** 63 * Get the position in the file stream 64 * 65 * @return int 66 */ 67 public function getPos() 68 { 69 if ($this->_mode == 0) { 70 return ftell($this->file); 71 } else { 72 return 0; 73 } 74 } 75 76 /** 77 * Reset the position in the file stream. 78 * 79 * Optionally move the file pointer to a new location and reset the buffered data. 80 * 81 * @param null $pos 82 * @param int $l 83 */ 84 public function reset($pos = null, $l = 100) 85 { 86 if ($this->_mode == 0) { 87 if (!is_null($pos)) { 88 fseek ($this->file, $pos); 89 } 90 91 $this->buffer = $l > 0 ? fread($this->file, $l) : ''; 92 $this->length = strlen($this->buffer); 93 if ($this->length < $l) 94 $this->increaseLength($l - $this->length); 95 } else { 96 $this->buffer = $this->file; 97 $this->length = strlen($this->buffer); 98 } 99 $this->offset = 0; 100 $this->stack = array(); 101 } 102 103 /** 104 * Make sure that there is at least one character beyond the current offset in the buffer. 105 * 106 * To prevent the tokenizer from attempting to access data that does not exist. 107 * 108 * @return bool 109 */ 110 public function ensureContent() 111 { 112 if ($this->offset >= $this->length - 1) { 113 return $this->increaseLength(); 114 } else { 115 return true; 116 } 117 } 118 119 /** 120 * Forcefully read more data into the buffer 121 * 122 * @param int $l 123 * @return bool 124 */ 125 public function increaseLength($l = 100) 126 { 127 if ($this->_mode == 0 && feof($this->file)) { 128 return false; 129 } else if ($this->_mode == 0) { 130 $totalLength = $this->length + $l; 131 do { 132 $toRead = $totalLength - $this->length; 133 if ($toRead < 1) 134 break; 135 136 $this->buffer .= fread($this->file, $toRead); 137 } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); 138 139 return true; 140 } else { 141 return false; 142 } 143 } 144 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |