From 3ce94a9f6d2fa5ca78ca15e09e3775b6f517e9c9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 19 Mar 2021 12:09:41 +0100 Subject: [PATCH 1/3] Change how landscape pages are rotated, for printing, with `enablePrintAutoRotate = true` set Currently landscape pages are rotated *clockwise*, which for most documents feel wrong since holding the printed pages at their *left* edge causes the landscape pages to be viewed "upside down". In general, since most documents are LTR ones, it feels more appropriate to instead rotate landscape pages *counterclockwise* for printing. --- web/base_viewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index a57bd50c5..34f2e796a 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -1365,7 +1365,7 @@ class BaseViewer { return { width: size.height, height: size.width, - rotation: (size.rotation + 90) % 360, + rotation: (size.rotation - 90) % 360, }; }); } From 1de466896d123486bdffd06bfbbd5735f5792d5b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 19 Mar 2021 12:19:29 +0100 Subject: [PATCH 2/3] Remove one loop from `BaseViewer.getPagesOverview` Currently, with `enablePrintAutoRotate = true` set, we're forced to loop through all the pages *twice* when checking for any landscape pages. This seems completely unnecessary now, and using only *one* loop should be marginally more efficient in general. --- web/base_viewer.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index 34f2e796a..9d77e8bbb 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -1347,25 +1347,21 @@ class BaseViewer { * @returns {Array} Array of objects with width/height/rotation fields. */ getPagesOverview() { - const pagesOverview = this._pages.map(function (pageView) { + return this._pages.map(pageView => { const viewport = pageView.pdfPage.getViewport({ scale: 1 }); - return { - width: viewport.width, - height: viewport.height, - rotation: viewport.rotation, - }; - }); - if (!this.enablePrintAutoRotate) { - return pagesOverview; - } - return pagesOverview.map(function (size) { - if (isPortraitOrientation(size)) { - return size; + + if (!this.enablePrintAutoRotate || isPortraitOrientation(viewport)) { + return { + width: viewport.width, + height: viewport.height, + rotation: viewport.rotation, + }; } + // Landscape orientation. return { - width: size.height, - height: size.width, - rotation: (size.rotation - 90) % 360, + width: viewport.height, + height: viewport.width, + rotation: (viewport.rotation - 90) % 360, }; }); } From 30c06849d81358c0372abcdb5b741e931a60cd00 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 19 Mar 2021 12:27:23 +0100 Subject: [PATCH 3/3] Rotate landscape pages, during printing, by default in the viewer (`enablePrintAutoRotate = true`) While this will perhaps not be perfect for *every* PDF document with mixed page orientation, based on the large number of bugs/issues seen over the years I'm however pretty convinced that it'll be an overall improvement in a majority of cases. In order to improve things further, we'd probably need Firefox to support e.g. `@page` such that the viewer can provide better information to the print engine. --- extensions/chromium/preferences_schema.json | 2 +- web/app_options.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json index de2ae62df..b88a5dc4b 100644 --- a/extensions/chromium/preferences_schema.json +++ b/extensions/chromium/preferences_schema.json @@ -173,7 +173,7 @@ "title": "Automatically rotate printed pages", "description": "When enabled, landscape pages are rotated when printed.", "type": "boolean", - "default": false + "default": true }, "scrollModeOnLoad": { "title": "Scroll mode on load", diff --git a/web/app_options.js b/web/app_options.js index 72ad6d091..9a91ab697 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -62,7 +62,7 @@ const defaultOptions = { }, enablePrintAutoRotate: { /** @type {boolean} */ - value: false, + value: true, kind: OptionKind.VIEWER + OptionKind.PREFERENCE, }, enableScripting: {