mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #7341 from Snuffleupagus/getDestinationHash-Array
[api-minor] Improve handling of links that are using explicit destination arrays
This commit is contained in:
commit
f97d52182a
10 changed files with 201 additions and 44 deletions
|
@ -757,9 +757,17 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
|
|||
if (isName(remoteDest)) {
|
||||
remoteDest = remoteDest.name;
|
||||
}
|
||||
if (isString(remoteDest) && isString(url)) {
|
||||
if (isString(url)) {
|
||||
var baseUrl = url.split('#')[0];
|
||||
url = baseUrl + '#' + remoteDest;
|
||||
if (isString(remoteDest)) {
|
||||
// In practice, a named destination may contain only a number.
|
||||
// If that happens, use the '#nameddest=' form to avoid the link
|
||||
// redirecting to a page, instead of the correct destination.
|
||||
url = baseUrl + '#' +
|
||||
(/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
|
||||
} else if (isArray(remoteDest)) {
|
||||
url = baseUrl + '#' + JSON.stringify(remoteDest);
|
||||
}
|
||||
}
|
||||
}
|
||||
// The 'NewWindow' property, equal to `LinkTarget.BLANK`.
|
||||
|
|
|
@ -56,6 +56,7 @@ var isName = corePrimitives.isName;
|
|||
var isCmd = corePrimitives.isCmd;
|
||||
var isDict = corePrimitives.isDict;
|
||||
var isRef = corePrimitives.isRef;
|
||||
var isRefsEqual = corePrimitives.isRefsEqual;
|
||||
var isStream = corePrimitives.isStream;
|
||||
var CipherTransformFactory = coreCrypto.CipherTransformFactory;
|
||||
var Lexer = coreParser.Lexer;
|
||||
|
@ -522,7 +523,7 @@ var Catalog = (function CatalogClosure() {
|
|||
return capability.promise;
|
||||
},
|
||||
|
||||
getPageIndex: function Catalog_getPageIndex(ref) {
|
||||
getPageIndex: function Catalog_getPageIndex(pageRef) {
|
||||
// The page tree nodes have the count of all the leaves below them. To get
|
||||
// how many pages are before we just have to walk up the tree and keep
|
||||
// adding the count of siblings to the left of the node.
|
||||
|
@ -531,15 +532,21 @@ var Catalog = (function CatalogClosure() {
|
|||
var total = 0;
|
||||
var parentRef;
|
||||
return xref.fetchAsync(kidRef).then(function (node) {
|
||||
if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
|
||||
!(isDict(node) && !node.has('Type') && node.has('Contents'))) {
|
||||
throw new Error('The reference does not point to a /Page Dict.');
|
||||
}
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
assert(isDict(node), 'node must be a Dict.');
|
||||
parentRef = node.getRaw('Parent');
|
||||
return node.getAsync('Parent');
|
||||
}).then(function (parent) {
|
||||
if (!parent) {
|
||||
return null;
|
||||
}
|
||||
assert(isDict(parent), 'parent must be a Dict.');
|
||||
return parent.getAsync('Kids');
|
||||
}).then(function (kids) {
|
||||
if (!kids) {
|
||||
|
@ -549,7 +556,7 @@ var Catalog = (function CatalogClosure() {
|
|||
var found = false;
|
||||
for (var i = 0; i < kids.length; i++) {
|
||||
var kid = kids[i];
|
||||
assert(isRef(kid), 'kids must be a ref');
|
||||
assert(isRef(kid), 'kid must be a Ref.');
|
||||
if (kid.num === kidRef.num) {
|
||||
found = true;
|
||||
break;
|
||||
|
@ -585,7 +592,7 @@ var Catalog = (function CatalogClosure() {
|
|||
});
|
||||
}
|
||||
|
||||
return next(ref);
|
||||
return next(pageRef);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -290,6 +290,10 @@ function isRef(v) {
|
|||
return v instanceof Ref;
|
||||
}
|
||||
|
||||
function isRefsEqual(v1, v2) {
|
||||
return v1.num === v2.num && v1.gen === v2.gen;
|
||||
}
|
||||
|
||||
function isStream(v) {
|
||||
return typeof v === 'object' && v !== null && v.getBytes !== undefined;
|
||||
}
|
||||
|
@ -304,5 +308,6 @@ exports.isCmd = isCmd;
|
|||
exports.isDict = isDict;
|
||||
exports.isName = isName;
|
||||
exports.isRef = isRef;
|
||||
exports.isRefsEqual = isRefsEqual;
|
||||
exports.isStream = isStream;
|
||||
}));
|
||||
|
|
|
@ -1683,7 +1683,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
},
|
||||
|
||||
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
|
||||
return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
|
||||
return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).
|
||||
then(function (pageIndex) {
|
||||
return pageIndex;
|
||||
}, function (reason) {
|
||||
return Promise.reject(new Error(reason));
|
||||
});
|
||||
},
|
||||
|
||||
getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue