Fixed FlateStreams to read in multiple blocks

This commit is contained in:
sbarman 2011-06-06 14:26:28 -07:00
parent 386d70f33c
commit 11f427d235

17
pdf.js
View File

@ -220,7 +220,6 @@ var FlateStream = (function() {
function constructor(stream) { function constructor(stream) {
this.stream = stream; this.stream = stream;
this.dict = stream.dict; this.dict = stream.dict;
this.eof = true;
var cmf = stream.getByte(); var cmf = stream.getByte();
var flg = stream.getByte(); var flg = stream.getByte();
if (cmf == -1 || flg == -1) if (cmf == -1 || flg == -1)
@ -235,6 +234,8 @@ var FlateStream = (function() {
this.codeSize = 0; this.codeSize = 0;
this.codeBuf = 0; this.codeBuf = 0;
this.pos = 0; this.pos = 0;
this.bufferPos = 0;
this.bufferLength = 0;
} }
constructor.prototype = { constructor.prototype = {
@ -296,7 +297,6 @@ var FlateStream = (function() {
if (this.eof) if (this.eof)
return; return;
this.readBlock(); this.readBlock();
bufferPos = this.bufferPos;
} }
return String.fromCharCode(this.buffer[bufferPos]); return String.fromCharCode(this.buffer[bufferPos]);
}, },
@ -376,10 +376,10 @@ var FlateStream = (function() {
check |= (b << 8); check |= (b << 8);
if (check != (~this.blockLen & 0xffff)) if (check != (~this.blockLen & 0xffff))
error("Bad uncompressed block length in flate stream"); error("Bad uncompressed block length in flate stream");
var buffer = this.ensureBuffer(blockLen); var bufferLength = this.bufferLength;
this.bufferLength = blockLen; var buffer = this.ensureBuffer(bufferLength + blockLen);
this.bufferPos = 0; this.bufferLength = bufferLength + blockLen;
for (var n = 0; n < blockLen; ++n) { for (var n = bufferLength; n < blockLen; ++n) {
if ((b = stream.getByte()) == -1) { if ((b = stream.getByte()) == -1) {
this.eof = true; this.eof = true;
break; break;
@ -435,12 +435,13 @@ var FlateStream = (function() {
error("Unknown block type in flate stream"); error("Unknown block type in flate stream");
} }
var pos = 0; var pos = this.bufferLength;
while (true) { while (true) {
var code1 = this.getCode(litCodeTable); var code1 = this.getCode(litCodeTable);
if (code1 == 256) { if (code1 == 256) {
this.bufferLength = pos; this.bufferLength = pos;
this.bufferPos = 0; //logBuffer(this.buffer, 0, pos);
//log(pos);
return; return;
} }
if (code1 < 256) { if (code1 < 256) {