| 1 |
<?php |
| 2 |
// |
| 3 |
// FPDI - Version 1.2 |
| 4 |
// |
| 5 |
// Copyright 2004-2007 Setasign - Jan Slabon |
| 6 |
// |
| 7 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
// you may not use this file except in compliance with the License. |
| 9 |
// You may obtain a copy of the License at |
| 10 |
// |
| 11 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
// |
| 13 |
// Unless required by applicable law or agreed to in writing, software |
| 14 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
// See the License for the specific language governing permissions and |
| 17 |
// limitations under the License. |
| 18 |
// |
| 19 |
|
| 20 |
class pdf_context { |
| 21 |
|
| 22 |
var $file; |
| 23 |
var $buffer; |
| 24 |
var $offset; |
| 25 |
var $length; |
| 26 |
|
| 27 |
var $stack; |
| 28 |
|
| 29 |
// Constructor |
| 30 |
|
| 31 |
function pdf_context($f) { |
| 32 |
$this->file = $f; |
| 33 |
$this->reset(); |
| 34 |
} |
| 35 |
|
| 36 |
// Optionally move the file |
| 37 |
// pointer to a new location |
| 38 |
// and reset the buffered data |
| 39 |
|
| 40 |
function reset($pos = null, $l = 100) { |
| 41 |
if (!is_null ($pos)) { |
| 42 |
fseek ($this->file, $pos); |
| 43 |
} |
| 44 |
|
| 45 |
$this->buffer = $l > 0 ? fread($this->file, $l) : ''; |
| 46 |
$this->offset = 0; |
| 47 |
$this->length = strlen($this->buffer); |
| 48 |
$this->stack = array(); |
| 49 |
} |
| 50 |
|
| 51 |
// Make sure that there is at least one |
| 52 |
// character beyond the current offset in |
| 53 |
// the buffer to prevent the tokenizer |
| 54 |
// from attempting to access data that does |
| 55 |
// not exist |
| 56 |
|
| 57 |
function ensure_content() { |
| 58 |
if ($this->offset >= $this->length - 1) { |
| 59 |
return $this->increase_length(); |
| 60 |
} else { |
| 61 |
return true; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
// Forcefully read more data into the buffer |
| 66 |
|
| 67 |
function increase_length($l=100) { |
| 68 |
if (feof($this->file)) { |
| 69 |
return false; |
| 70 |
} else { |
| 71 |
$this->buffer .= fread($this->file, $l); |
| 72 |
$this->length = strlen($this->buffer); |
| 73 |
return true; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
?> |