Merge pull request #1042 from notmasteryet/tree-55

fetch/getEntry returns null if the entry is free
This commit is contained in:
Artur Adib 2012-01-09 12:22:16 -08:00
commit 4322e7e339

View File

@ -120,11 +120,11 @@ var Catalog = (function CatalogClosure() {
return shadow(this, 'toplevelPagesDict', xrefObj); return shadow(this, 'toplevelPagesDict', xrefObj);
}, },
get documentOutline() { get documentOutline() {
var obj = this.catDict.get('Outlines');
var xref = this.xref; var xref = this.xref;
var obj = xref.fetchIfRef(this.catDict.get('Outlines'));
var root = { items: [] }; var root = { items: [] };
if (isRef(obj)) { if (isDict(obj)) {
obj = xref.fetch(obj).get('First'); obj = obj.get('First');
var processed = new RefSet(); var processed = new RefSet();
if (isRef(obj)) { if (isRef(obj)) {
var queue = [{obj: obj, parent: root}]; var queue = [{obj: obj, parent: root}];
@ -552,9 +552,7 @@ var XRef = (function XRefClosure() {
}, },
getEntry: function xRefGetEntry(i) { getEntry: function xRefGetEntry(i) {
var e = this.entries[i]; var e = this.entries[i];
if (e.free) return e.free ? null : e; // returns null is the entry is free
error('reading an XRef stream not implemented yet');
return e;
}, },
fetchIfRef: function xRefFetchIfRef(obj) { fetchIfRef: function xRefFetchIfRef(obj) {
if (!isRef(obj)) if (!isRef(obj))
@ -563,11 +561,15 @@ var XRef = (function XRefClosure() {
}, },
fetch: function xRefFetch(ref, suppressEncryption) { fetch: function xRefFetch(ref, suppressEncryption) {
var num = ref.num; var num = ref.num;
var e = this.cache[num]; if (num in this.cache)
if (e) return this.cache[num];
return e;
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 gen = ref.gen;
var stream, parser; var stream, parser;
if (e.uncompressed) { if (e.uncompressed) {