From 6f3fff579894c5a28cfa1dd0116a57593624b04c Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 15 Jul 2011 17:40:37 -0700 Subject: [PATCH 1/2] fix some bugs --- pdf.js | 55 +++++++++++++++++++++++++++++++++++++++++++------- test/driver.js | 5 ++++- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/pdf.js b/pdf.js index a3179406c..4de525be0 100644 --- a/pdf.js +++ b/pdf.js @@ -19,6 +19,7 @@ function warn(msg) { } function error(msg) { + console.log(backtrace()); throw new Error(msg); } @@ -43,6 +44,16 @@ function assertWellFormed(cond, msg) { malformed(msg); } +function backtrace() { + var stackStr; + try { + throw new Error(); + } catch(e) { + stackStr = e.stack; + }; + return stackStr.split('\n').slice(1).join('\n'); +} + function shadow(obj, prop, value) { Object.defineProperty(obj, prop, { value: value, enumerable: true, configurable: true, writable: false }); return value; @@ -2838,6 +2849,13 @@ var XRef = (function() { return this.fetch(obj); }, fetch: function(ref) { + + + if ("undefined" == typeof ref) { + console.log(backtrace()); + } + + var num = ref.num; var e = this.cache[num]; if (e) @@ -2960,7 +2978,7 @@ var Page = (function() { return shadow(this, 'mediaBox', ((IsArray(obj) && obj.length == 4) ? obj : null)); }, - startRendering: function(canvasCtx, continuation) { + startRendering: function(canvasCtx, continuation, onerror) { var self = this; var stats = self.stats; stats.compile = stats.fonts = stats.render = 0; @@ -2978,9 +2996,14 @@ var Page = (function() { // Always defer call to display() to work around bug in // Firefox error reporting from XHR callbacks. setTimeout(function () { - self.display(gfx); - stats.render = Date.now(); - continuation(); + var exc = null; + try { + self.display(gfx); + stats.render = Date.now(); + } catch (e) { + exc = e.toString(); + } + continuation(exc); }); }); }, @@ -3639,7 +3662,12 @@ var PartialEvaluator = (function() { if (!df) return null; compositeFont = true; - descendant = xref.fetch(df[0]); + + if (IsRef(df)) { + df = xref.fetch(df); + } + + descendant = xref.fetch(IsRef(df) ? df : df[0]); subType = descendant.get('Subtype'); fd = descendant.get('FontDescriptor'); } else { @@ -4765,6 +4793,15 @@ var ColorSpace = (function() { }; constructor.parse = function colorspace_parse(cs, xref, res) { + + + + if ("undefined" == typeof(cs)) + console.log(backtrace()); + + + + if (IsName(cs)) { var colorSpaces = res.get('ColorSpace'); if (colorSpaces) { @@ -4854,10 +4891,10 @@ var ColorSpace = (function() { case 'Lab': case 'DeviceN': default: - error("unrecognized color space object '" + mode + "'"); + error("unimplemented color space object '" + mode + "'"); } } else { - error('unrecognized color space object'); + error('unrecognized color space object: "'+ cs +"'"); } }; @@ -5131,6 +5168,10 @@ var PDFImage = (function() { this.bpc = bitsPerComponent; var colorSpace = dict.get('ColorSpace', 'CS'); + if (!colorSpace) { + TODO('JPX images (which don"t require color spaces'); + colorSpace = new Name('DeviceRGB'); + } this.colorSpace = ColorSpace.parse(colorSpace, xref, res); this.numComps = this.colorSpace.numComps; diff --git a/test/driver.js b/test/driver.js index e397f108b..a6b0b1dc2 100644 --- a/test/driver.js +++ b/test/driver.js @@ -111,7 +111,10 @@ function nextPage(task, loadError) { page.startRendering( ctx, - function() { snapshotCurrentPage(page, task, failure); }); + function(e) { + snapshotCurrentPage(page, task, + (!failure && e) ? ('render: '+ e) : failure); + }); } catch(e) { failure = 'page setup: '+ e.toString(); } From daf23a0341eddeb38a4762af3cb7a95b4dc33747 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 15 Jul 2011 18:41:52 -0700 Subject: [PATCH 2/2] remove debugging code --- pdf.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/pdf.js b/pdf.js index 4de525be0..05330db84 100644 --- a/pdf.js +++ b/pdf.js @@ -19,7 +19,7 @@ function warn(msg) { } function error(msg) { - console.log(backtrace()); + log(backtrace()); throw new Error(msg); } @@ -2849,13 +2849,6 @@ var XRef = (function() { return this.fetch(obj); }, fetch: function(ref) { - - - if ("undefined" == typeof ref) { - console.log(backtrace()); - } - - var num = ref.num; var e = this.cache[num]; if (e) @@ -4793,15 +4786,6 @@ var ColorSpace = (function() { }; constructor.parse = function colorspace_parse(cs, xref, res) { - - - - if ("undefined" == typeof(cs)) - console.log(backtrace()); - - - - if (IsName(cs)) { var colorSpaces = res.get('ColorSpace'); if (colorSpaces) {