Added HTML2PDF and FPDI to the project.
[openemr.git] / library / html2pdf / fpdi / pdf_context.php
blob435df1e83dac84177d74d5a57054515dcf136e8b
1 <?php
2 //
3 // FPDI - Version 1.4.2
4 //
5 // Copyright 2004-2011 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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 if (!class_exists('pdf_context', false)) {
22 class pdf_context {
24 /**
25 * Modi
27 * @var integer 0 = file | 1 = string
29 var $_mode = 0;
31 var $file;
32 var $buffer;
33 var $offset;
34 var $length;
36 var $stack;
38 // Constructor
40 function pdf_context(&$f) {
41 $this->file =& $f;
42 if (is_string($this->file))
43 $this->_mode = 1;
44 $this->reset();
47 // Optionally move the file
48 // pointer to a new location
49 // and reset the buffered data
51 function reset($pos = null, $l = 100) {
52 if ($this->_mode == 0) {
53 if (!is_null ($pos)) {
54 fseek ($this->file, $pos);
57 $this->buffer = $l > 0 ? fread($this->file, $l) : '';
58 $this->length = strlen($this->buffer);
59 if ($this->length < $l)
60 $this->increase_length($l - $this->length);
61 } else {
62 $this->buffer = $this->file;
63 $this->length = strlen($this->buffer);
65 $this->offset = 0;
66 $this->stack = array();
69 // Make sure that there is at least one
70 // character beyond the current offset in
71 // the buffer to prevent the tokenizer
72 // from attempting to access data that does
73 // not exist
75 function ensure_content() {
76 if ($this->offset >= $this->length - 1) {
77 return $this->increase_length();
78 } else {
79 return true;
83 // Forcefully read more data into the buffer
85 function increase_length($l = 100) {
86 if ($this->_mode == 0 && feof($this->file)) {
87 return false;
88 } else if ($this->_mode == 0) {
89 $totalLength = $this->length + $l;
90 do {
91 $toRead = $totalLength - $this->length;
92 if ($toRead < 1)
93 break;
95 $this->buffer .= fread($this->file, $toRead);
96 } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
98 return true;
99 } else {
100 return false;