From 299d05eaa51457bab6ebf46a0310071dae0eabfb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 22 Jul 2015 23:40:38 +0200 Subject: [PATCH 1/2] Prevent documents from intermittently opening with the zoom level set to 1% (issue 6253) *This fixes a regression from PR 6192.* Under some circumstances, the `resize` event handler in `viewer.js` is fired before the scale has been set. This can lead to PDF documents being rendered at the wrong zoom level when they are opened. It seems that a way to reliably trigger this is to, using the Firefox addon, open a PDF file that triggers the `fallback` bar, in a new background tab (i.e. middle clicking on a link, or use the context menu). Prior to PR 6192, we checked the selected option in the `scaleSelect` dropdown instead. Since `pageAutoOption` is selected by default in `viewer.html`, this should explain why the issue wasn't visible previously. --- web/viewer.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index fc6e8f3ba..602750c9f 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1639,13 +1639,16 @@ window.addEventListener('updateviewarea', function (evt) { window.addEventListener('resize', function webViewerResize(evt) { if (PDFViewerApplication.initialized) { var currentScaleValue = PDFViewerApplication.pdfViewer.currentScaleValue; - switch (currentScaleValue) { - case 'auto': - case 'page-fit': - case 'page-width': - // Note: the scale is constant for 'page-actual'. - PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue; - break; + if (currentScaleValue === 'auto' || + currentScaleValue === 'page-fit' || + currentScaleValue === 'page-width') { + // Note: the scale is constant for 'page-actual'. + PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue; + } else if (!currentScaleValue) { + // Normally this shouldn't happen, but if the scale wasn't initialized + // we set it to the default value in order to prevent any issues. + // (E.g. the document being rendered with the wrong scale on load.) + PDFViewerApplication.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; } } updateViewarea(); From fa53cd6ca3f0b04d1074eac0cea30800fd7ba903 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 22 Jul 2015 23:58:30 +0200 Subject: [PATCH 2/2] Use `DEFAULT_SCALE_VALUE` as default when fetching the `zoom` parameter from `PDFViewerApplication.store` (i.e. `ViewHistory`) Since the zoom value should be in percent, using `PDFViewer.currentScale` will be wrong by a factor of 100, potentially causing the zoom level of the document to become wrong on load. --- web/viewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/viewer.js b/web/viewer.js index 602750c9f..5ef1218c5 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -790,7 +790,7 @@ var PDFViewerApplication = { store.get('exists', false)) { var pageNum = store.get('page', '1'); var zoom = self.preferenceDefaultZoomValue || - store.get('zoom', self.pdfViewer.currentScale); + store.get('zoom', DEFAULT_SCALE_VALUE); var left = store.get('scrollLeft', '0'); var top = store.get('scrollTop', '0');