Add getArray method to Dict

This method extend `get`, and will fetch all indirect objects (i.e. `Ref`s) when the result is an `Array`.
This commit is contained in:
Jonas Jenwald 2015-09-28 14:18:11 +02:00
parent 973b15c5de
commit 75557d27d1

View File

@ -135,6 +135,22 @@ var Dict = (function DictClosure() {
return Promise.resolve(value); return Promise.resolve(value);
}, },
// Same as get(), but dereferences all elements if the result is an Array.
getArray: function Dict_getArray(key1, key2, key3) {
var value = this.get(key1, key2, key3);
if (!isArray(value)) {
return value;
}
value = value.slice(); // Ensure that we don't modify the Dict data.
for (var i = 0, ii = value.length; i < ii; i++) {
if (!isRef(value[i])) {
continue;
}
value[i] = this.xref.fetch(value[i]);
}
return value;
},
// no dereferencing // no dereferencing
getRaw: function Dict_getRaw(key) { getRaw: function Dict_getRaw(key) {
return this.map[key]; return this.map[key];