From d3b38429460f931488af4b0a13b03eca78e1ee0a Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 8 Jan 2012 14:03:00 -0600 Subject: [PATCH] fetch/getEntry returns null if the entry is free --- src/obj.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/obj.js b/src/obj.js index a0c1fdc8a..ef7932546 100644 --- a/src/obj.js +++ b/src/obj.js @@ -120,11 +120,11 @@ var Catalog = (function CatalogClosure() { return shadow(this, 'toplevelPagesDict', xrefObj); }, get documentOutline() { - var obj = this.catDict.get('Outlines'); var xref = this.xref; + var obj = xref.fetchIfRef(this.catDict.get('Outlines')); var root = { items: [] }; - if (isRef(obj)) { - obj = xref.fetch(obj).get('First'); + if (isDict(obj)) { + obj = obj.get('First'); var processed = new RefSet(); if (isRef(obj)) { var queue = [{obj: obj, parent: root}]; @@ -552,9 +552,7 @@ var XRef = (function XRefClosure() { }, getEntry: function xRefGetEntry(i) { var e = this.entries[i]; - if (e.free) - error('reading an XRef stream not implemented yet'); - return e; + return e.free ? null : e; // returns null is the entry is free }, fetchIfRef: function xRefFetchIfRef(obj) { if (!isRef(obj)) @@ -563,11 +561,15 @@ var XRef = (function XRefClosure() { }, fetch: function xRefFetch(ref, suppressEncryption) { var num = ref.num; - var e = this.cache[num]; - if (e) - return e; + if (num in this.cache) + return this.cache[num]; + + var e = this.getEntry(num); + + // the referenced entry can be free + if (e === null) + return (this.cache[num] = e); - e = this.getEntry(num); var gen = ref.gen; var stream, parser; if (e.uncompressed) {