- Timestamp:
- 2010/12/11 12:15:20 (12 years ago)
- Location:
- branches/version-2_5-dev/data/module/fpdf
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/module/fpdf/pdf_context.php
r18701 r19716 1 1 <?php 2 2 // 3 // FPDI - Version 1. 23 // FPDI - Version 1.4 4 4 // 5 // Copyright 2004-20 07Setasign - Jan Slabon5 // Copyright 2004-2010 Setasign - Jan Slabon 6 6 // 7 7 // Licensed under the Apache License, Version 2.0 (the "License"); … … 18 18 // 19 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 20 if (!class_exists('pdf_context', false)) { 21 22 class pdf_context { 23 24 /** 25 * Modi 26 * 27 * @var integer 0 = file | 1 = string 28 */ 29 var $_mode = 0; 30 31 var $file; 32 var $buffer; 33 var $offset; 34 var $length; 35 36 var $stack; 37 38 // Constructor 39 40 function pdf_context(&$f) { 41 $this->file =& $f; 42 if (is_string($this->file)) 43 $this->_mode = 1; 44 $this->reset(); 45 } 46 47 // Optionally move the file 48 // pointer to a new location 49 // and reset the buffered data 50 51 function reset($pos = null, $l = 100) { 52 if ($this->_mode == 0) { 53 if (!is_null ($pos)) { 54 fseek ($this->file, $pos); 55 } 56 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); 64 } 65 $this->offset = 0; 66 $this->stack = array(); 67 } 68 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 74 75 function ensure_content() { 76 if ($this->offset >= $this->length - 1) { 77 return $this->increase_length(); 78 } else { 79 return true; 80 } 81 } 82 83 // Forcefully read more data into the buffer 84 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 $this->buffer .= fread($this->file, $totalLength-$this->length); 92 } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); 93 94 return true; 95 } else { 96 return false; 97 } 98 } 99 } 77 100 } 78 ?>
Note: See TracChangeset
for help on using the changeset viewer.