From 1971440a409fabd1bd2fa754f8a5311c950d0a48 Mon Sep 17 00:00:00 2001 From: Pdf Bot Date: Wed, 8 Jun 2016 23:32:13 +0100 Subject: [PATCH] PDF.js version 1.5.292 - See mozilla/pdf.js@f97d52182a6ef90fc16f7c5441b6931fbfe98099 --- bower.json | 2 +- build/pdf.combined.js | 41 ++++++++++++--- build/pdf.js | 11 ++-- build/pdf.worker.js | 34 +++++++++--- package.json | 2 +- web/pdf_viewer.js | 118 +++++++++++++++++++++++++++++++----------- 6 files changed, 157 insertions(+), 51 deletions(-) diff --git a/bower.json b/bower.json index b6829f410..a4f84ff56 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "pdfjs-dist", - "version": "1.5.289", + "version": "1.5.292", "main": [ "build/pdf.js", "build/pdf.worker.js" diff --git a/build/pdf.combined.js b/build/pdf.combined.js index 6e5a5f01c..8fdf8788b 100644 --- a/build/pdf.combined.js +++ b/build/pdf.combined.js @@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdfCombined = {})); // Use strict in our context only - users might not want it 'use strict'; -var pdfjsVersion = '1.5.289'; -var pdfjsBuild = '70b3eea'; +var pdfjsVersion = '1.5.292'; +var pdfjsBuild = 'f97d521'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? @@ -17711,6 +17711,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; } @@ -17725,6 +17729,7 @@ exports.isCmd = isCmd; exports.isDict = isDict; exports.isName = isName; exports.isRef = isRef; +exports.isRefsEqual = isRefsEqual; exports.isStream = isStream; })); @@ -40100,7 +40105,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) { @@ -42746,6 +42756,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; @@ -43212,7 +43223,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. @@ -43221,15 +43232,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) { @@ -43239,7 +43256,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; @@ -43275,7 +43292,7 @@ var Catalog = (function CatalogClosure() { }); } - return next(ref); + return next(pageRef); } }; @@ -49085,9 +49102,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`. diff --git a/build/pdf.js b/build/pdf.js index afe16b725..4e55a93ed 100644 --- a/build/pdf.js +++ b/build/pdf.js @@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdf = {})); // Use strict in our context only - users might not want it 'use strict'; -var pdfjsVersion = '1.5.289'; -var pdfjsBuild = '70b3eea'; +var pdfjsVersion = '1.5.292'; +var pdfjsBuild = 'f97d521'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? @@ -10206,7 +10206,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) { diff --git a/build/pdf.worker.js b/build/pdf.worker.js index f17403814..2b56d517e 100644 --- a/build/pdf.worker.js +++ b/build/pdf.worker.js @@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdfWorker = {})); // Use strict in our context only - users might not want it 'use strict'; -var pdfjsVersion = '1.5.289'; -var pdfjsBuild = '70b3eea'; +var pdfjsVersion = '1.5.292'; +var pdfjsBuild = 'f97d521'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? @@ -17711,6 +17711,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; } @@ -17725,6 +17729,7 @@ exports.isCmd = isCmd; exports.isDict = isDict; exports.isName = isName; exports.isRef = isRef; +exports.isRefsEqual = isRefsEqual; exports.isStream = isStream; })); @@ -34405,6 +34410,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; @@ -34871,7 +34877,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. @@ -34880,15 +34886,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) { @@ -34898,7 +34910,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; @@ -34934,7 +34946,7 @@ var Catalog = (function CatalogClosure() { }); } - return next(ref); + return next(pageRef); } }; @@ -40744,9 +40756,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`. diff --git a/package.json b/package.json index cb297798d..3575e4244 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pdfjs-dist", - "version": "1.5.289", + "version": "1.5.292", "main": "build/pdf.js", "description": "Generic build of Mozilla's PDF.js library.", "keywords": [ diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index bf708ca04..1bb81c7bd 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -1839,6 +1839,11 @@ exports.PDFFindController = PDFFindController; var parseQueryString = uiUtils.parseQueryString; +var PageNumberRegExp = /^\d+$/; +function isPageNumber(str) { + return PageNumberRegExp.test(str); +} + /** * @typedef {Object} PDFLinkServiceOptions * @property {EventBus} eventBus - The application event bus. @@ -1850,7 +1855,7 @@ var parseQueryString = uiUtils.parseQueryString; * @class * @implements {IPDFLinkService} */ -var PDFLinkService = (function () { +var PDFLinkService = (function PDFLinkServiceClosure() { /** * @constructs PDFLinkService * @param {PDFLinkServiceOptions} options @@ -1910,7 +1915,7 @@ var PDFLinkService = (function () { var self = this; var goToDestination = function(destRef) { - // dest array looks like that: + // dest array looks like that: var pageNumber = destRef instanceof Object ? self._pagesRefCache[destRef.num + ' ' + destRef.gen + ' R'] : (destRef + 1); @@ -1960,30 +1965,15 @@ var PDFLinkService = (function () { */ getDestinationHash: function PDFLinkService_getDestinationHash(dest) { if (typeof dest === 'string') { - return this.getAnchorUrl('#' + escape(dest)); + // 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. + return this.getAnchorUrl( + '#' + (isPageNumber(dest) ? 'nameddest=' : '') + escape(dest)); } if (dest instanceof Array) { - var destRef = dest[0]; // see navigateTo method for dest format - var pageNumber = destRef instanceof Object ? - this._pagesRefCache[destRef.num + ' ' + destRef.gen + ' R'] : - (destRef + 1); - if (pageNumber) { - var pdfOpenParams = this.getAnchorUrl('#page=' + pageNumber); - var destKind = dest[1]; - if (typeof destKind === 'object' && 'name' in destKind && - destKind.name === 'XYZ') { - var scale = (dest[4] || this.pdfViewer.currentScaleValue); - var scaleNumber = parseFloat(scale); - if (scaleNumber) { - scale = scaleNumber * 100; - } - pdfOpenParams += '&zoom=' + scale; - if (dest[2] || dest[3]) { - pdfOpenParams += ',' + (dest[2] || 0) + ',' + (dest[3] || 0); - } - } - return pdfOpenParams; - } + var str = JSON.stringify(dest); + return this.getAnchorUrl('#' + escape(str)); } return this.getAnchorUrl(''); }, @@ -2002,6 +1992,7 @@ var PDFLinkService = (function () { * @param {string} hash */ setHash: function PDFLinkService_setHash(hash) { + var pageNumber, dest; if (hash.indexOf('=') >= 0) { var params = parseQueryString(hash); if ('search' in params) { @@ -2019,7 +2010,6 @@ var PDFLinkService = (function () { this.navigateTo(params.nameddest); return; } - var pageNumber, dest; if ('page' in params) { pageNumber = (params.page | 0) || 1; } @@ -2069,13 +2059,23 @@ var PDFLinkService = (function () { mode: params.pagemode }); } - } else if (/^\d+$/.test(hash)) { // page number - this.page = hash; - } else { // named destination - if (this.pdfHistory) { - this.pdfHistory.updateNextHashParam(unescape(hash)); + } else if (isPageNumber(hash)) { // Page number. + this.page = hash | 0; + } else { // Named (or explicit) destination. + dest = unescape(hash); + try { + dest = JSON.parse(dest); + } catch (ex) {} + + if (typeof dest === 'string' || isValidExplicitDestination(dest)) { + if (this.pdfHistory) { + this.pdfHistory.updateNextHashParam(dest); + } + this.navigateTo(dest); + return; } - this.navigateTo(unescape(hash)); + console.error('PDFLinkService_setHash: \'' + unescape(hash) + + '\' is not a valid destination.'); } }, @@ -2133,6 +2133,60 @@ var PDFLinkService = (function () { } }; + function isValidExplicitDestination(dest) { + if (!(dest instanceof Array)) { + return false; + } + var destLength = dest.length, allowNull = true; + if (destLength < 2) { + return false; + } + var page = dest[0]; + if (!(typeof page === 'object' && + typeof page.num === 'number' && (page.num | 0) === page.num && + typeof page.gen === 'number' && (page.gen | 0) === page.gen) && + !(typeof page === 'number' && (page | 0) === page && page >= 0)) { + return false; + } + var zoom = dest[1]; + if (!(typeof zoom === 'object' && typeof zoom.name === 'string')) { + return false; + } + switch (zoom.name) { + case 'XYZ': + if (destLength !== 5) { + return false; + } + break; + case 'Fit': + case 'FitB': + return destLength === 2; + case 'FitH': + case 'FitBH': + case 'FitV': + case 'FitBV': + if (destLength !== 3) { + return false; + } + break; + case 'FitR': + if (destLength !== 6) { + return false; + } + allowNull = false; + break; + default: + return false; + } + for (var i = 2; i < destLength; i++) { + var param = dest[i]; + if (!(typeof param === 'number' || (allowNull && param === null))) { + return false; + } + } + return true; + } + return PDFLinkService; })(); @@ -3794,6 +3848,8 @@ var PDFViewer = (function pdfViewer() { scale = Math.min(Math.abs(widthScale), Math.abs(heightScale)); break; default: + console.error('PDFViewer_scrollPageIntoView: \'' + dest[1].name + + '\' is not a valid destination type.'); return; }