pdf_context.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. class pdf_context {
  20. var $file;
  21. var $buffer;
  22. var $offset;
  23. var $length;
  24. var $stack;
  25. // Constructor
  26. function pdf_context($f) {
  27. $this->file = $f;
  28. $this->reset();
  29. }
  30. // Optionally move the file
  31. // pointer to a new location
  32. // and reset the buffered data
  33. function reset($pos = null, $l = 100) {
  34. if (!is_null ($pos)) {
  35. fseek ($this->file, $pos);
  36. }
  37. $this->buffer = $l > 0 ? fread($this->file, $l) : '';
  38. $this->offset = 0;
  39. $this->length = strlen($this->buffer);
  40. $this->stack = array();
  41. }
  42. // Make sure that there is at least one
  43. // character beyond the current offset in
  44. // the buffer to prevent the tokenizer
  45. // from attempting to access data that does
  46. // not exist
  47. function ensure_content() {
  48. if ($this->offset >= $this->length - 1) {
  49. return $this->increase_length();
  50. } else {
  51. return true;
  52. }
  53. }
  54. // Forcefully read more data into the buffer
  55. function increase_length($l=100) {
  56. if (feof($this->file)) {
  57. return false;
  58. } else {
  59. $this->buffer .= fread($this->file, $l);
  60. $this->length = strlen($this->buffer);
  61. return true;
  62. }
  63. }
  64. }
  65. ?>