From 11f427d235012f24f65cbd43e9991bd6a257b0eb Mon Sep 17 00:00:00 2001 From: sbarman Date: Mon, 6 Jun 2011 14:26:28 -0700 Subject: [PATCH] Fixed FlateStreams to read in multiple blocks --- pdf.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pdf.js b/pdf.js index 0d377d139..42f000842 100644 --- a/pdf.js +++ b/pdf.js @@ -220,7 +220,6 @@ var FlateStream = (function() { function constructor(stream) { this.stream = stream; this.dict = stream.dict; - this.eof = true; var cmf = stream.getByte(); var flg = stream.getByte(); if (cmf == -1 || flg == -1) @@ -235,6 +234,8 @@ var FlateStream = (function() { this.codeSize = 0; this.codeBuf = 0; this.pos = 0; + this.bufferPos = 0; + this.bufferLength = 0; } constructor.prototype = { @@ -296,7 +297,6 @@ var FlateStream = (function() { if (this.eof) return; this.readBlock(); - bufferPos = this.bufferPos; } return String.fromCharCode(this.buffer[bufferPos]); }, @@ -376,10 +376,10 @@ var FlateStream = (function() { check |= (b << 8); if (check != (~this.blockLen & 0xffff)) error("Bad uncompressed block length in flate stream"); - var buffer = this.ensureBuffer(blockLen); - this.bufferLength = blockLen; - this.bufferPos = 0; - for (var n = 0; n < blockLen; ++n) { + var bufferLength = this.bufferLength; + var buffer = this.ensureBuffer(bufferLength + blockLen); + this.bufferLength = bufferLength + blockLen; + for (var n = bufferLength; n < blockLen; ++n) { if ((b = stream.getByte()) == -1) { this.eof = true; break; @@ -435,12 +435,13 @@ var FlateStream = (function() { error("Unknown block type in flate stream"); } - var pos = 0; + var pos = this.bufferLength; while (true) { var code1 = this.getCode(litCodeTable); if (code1 == 256) { this.bufferLength = pos; - this.bufferPos = 0; + //logBuffer(this.buffer, 0, pos); + //log(pos); return; } if (code1 < 256) {