From d610397d1e4ec6500da543e7a866a957ccc629f7 Mon Sep 17 00:00:00 2001 From: sbarman Date: Wed, 22 Jun 2011 19:20:03 -0700 Subject: [PATCH 1/3] fake stream for unimplemented filters --- pdf.js | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/pdf.js b/pdf.js index 39e9e26df..cd3cdfba5 100644 --- a/pdf.js +++ b/pdf.js @@ -220,6 +220,43 @@ var DecodeStream = (function() { })(); +var FakeStream = (function() { + function constructor(stream) { + this.dict = stream.dict; + DecodeStream.call(this); + }; + + constructor.prototype = Object.create(DecodeStream.prototype); + constructor.prototype.readBlock = function() { + var bufferLength = this.bufferLength; + bufferLength += 1024; + var buffer = this.ensureBuffer(bufferLength); + this.bufferLength = bufferLength; + }; + constructor.prototype.getBytes = function(length) { + var pos = this.pos; + + if (length) { + this.ensureBuffer(pos + length); + var end = pos + length; + + while (!this.eof && this.bufferLength < end) + this.readBlock(); + + var bufEnd = this.bufferLength; + if (end > bufEnd) + end = bufEnd; + } else { + this.eof = true; + var end = this.bufferLength; + } + + this.pos = end; + return this.buffer.subarray(pos, end) + }; + + return constructor; +})(); var FlateStream = (function() { const codeLenCodeMap = Uint32Array([ @@ -597,9 +634,6 @@ var PredictorStream = (function() { constructor.prototype = Object.create(DecodeStream.prototype); constructor.prototype.readBlockTiff = function() { - var buffer = this.buffer; - var pos = this.pos; - var rowBytes = this.rowBytes; var pixBytes = this.pixBytes; @@ -660,9 +694,6 @@ var PredictorStream = (function() { this.bufferLength += rowBytes; }; constructor.prototype.readBlockPng = function() { - var buffer = this.buffer; - var pos = this.pos; - var rowBytes = this.rowBytes; var pixBytes = this.pixBytes; @@ -1448,6 +1479,9 @@ var Parser = (function() { return new JpegStream(bytes, stream.dict); } else if (name == "ASCII85Decode") { return new Ascii85Stream(stream); + } else if (name == "CCITTFaxDecode") { + TODO("implement fax stream"); + return new FakeStream(stream); } else { error("filter '" + name + "' not supported yet"); } From 1532e86dcb82ff78d2fe0b52c0b7f1bc45eca0ce Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 22 Jun 2011 20:47:37 -0700 Subject: [PATCH 2/3] fix bug in testing multiple browsers --- test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.py b/test.py index 1557714d6..9eab0e80e 100644 --- a/test.py +++ b/test.py @@ -117,8 +117,8 @@ def setUp(manifestFile, masterMode): assert not os.path.isdir(TMPDIR) testBrowsers = [ b for b in - ( 'firefox5', ) -#'chrome12', 'chrome13', 'firefox4', 'firefox6','opera11' ): + ( 'firefox5', 'firefox6', ) +#'chrome12', 'chrome13', 'firefox4', 'opera11' ): if os.access(b, os.R_OK | os.X_OK) ] mf = open(manifestFile) @@ -152,7 +152,7 @@ def setUp(manifestFile, masterMode): taskResults.append([ ]) State.taskResults[b][id] = taskResults - State.remaining = len(manifestList) + State.remaining = len(testBrowsers) * len(manifestList) for b in testBrowsers: print 'Launching', b From 18afc896f610253a20040067a3dc8c53eaed9f8d Mon Sep 17 00:00:00 2001 From: sbarman Date: Thu, 23 Jun 2011 09:41:59 -0700 Subject: [PATCH 3/3] fix for uncompressed flatestream blocks --- pdf.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pdf.js b/pdf.js index d940c4f8b..326c31234 100644 --- a/pdf.js +++ b/pdf.js @@ -479,17 +479,17 @@ var FlateStream = (function() { array[i++] = what; } - var bytes = this.bytes; - var bytesPos = this.bytesPos; - // read block header var hdr = this.getBits(3); if (hdr & 1) this.eof = true; hdr >>= 1; - var b; if (hdr == 0) { // uncompressed block + var bytes = this.bytes; + var bytesPos = this.bytesPos; + var b; + if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad block header in flate stream"); var blockLen = b; @@ -502,18 +502,24 @@ var FlateStream = (function() { if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad block header in flate stream"); check |= (b << 8); - if (check != (~this.blockLen & 0xffff)) + if (check != (~blockLen & 0xffff)) error("Bad uncompressed block length in flate stream"); + + this.codeBuf = 0; + this.codeSize = 0; + var bufferLength = this.bufferLength; var buffer = this.ensureBuffer(bufferLength + blockLen); - this.bufferLength = bufferLength + blockLen; - for (var n = bufferLength; n < blockLen; ++n) { + var end = bufferLength + blockLen; + this.bufferLength = end; + for (var n = bufferLength; n < end; ++n) { if (typeof (b = bytes[bytesPos++]) == "undefined") { this.eof = true; break; } buffer[n] = b; } + this.bytesPos = bytesPos; return; }