From c164f03e5ad700f01b9369377577554662ad411b Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 2 Mar 2013 09:29:13 +0000 Subject: [PATCH] /XYZ destinations: default to top left of the page. The previous default in the absence of provided coordinates was the bottom left, so that if you followed a PDF link annotation with a destination of [page /XYZ null null null] then you would see a gutter followed by the page _after_ the intended one, because pdf.js had carefully aligned the lower left corner of the target page with the top of the window. As part of this change we allow missing x,y parameters in URLs with a &zoom= parameter to propagate nulls into pageViewScrollIntoView instead of being replaced with zero in pdfViewSetHash, so as to do this substitution in one place. --- web/viewer.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 749117472..12353c854 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1523,8 +1523,10 @@ var PDFView = { if (zoomArgNumber) zoomArg = zoomArgNumber / 100; - var dest = [null, {name: 'XYZ'}, (zoomArgs[1] | 0), - (zoomArgs[2] | 0), zoomArg]; + var dest = [null, {name: 'XYZ'}, + zoomArgs.length > 1 ? (zoomArgs[1] | 0) : null, + zoomArgs.length > 2 ? (zoomArgs[2] | 0) : null, + zoomArg]; var currentPage = this.pages[pageNumber - 1]; currentPage.scrollIntoView(dest); } else { @@ -2036,6 +2038,12 @@ var PageView = function pageView(container, pdfPage, id, scale, x = dest[2]; y = dest[3]; scale = dest[4]; + // If x and/or y coordinates are not supplied, default to + // _top_ left of the page (not the obvious bottom left, + // since aligning the bottom of the intended page with the + // top of the window is rarely helpful). + x = x !== null ? x : 0; + y = y !== null ? y : this.height / this.scale; break; case 'Fit': case 'FitB':