diff options
Diffstat (limited to 'beamer/viewer/screen/screen.js')
-rw-r--r-- | beamer/viewer/screen/screen.js | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/beamer/viewer/screen/screen.js b/beamer/viewer/screen/screen.js index c65ebc3..4bebab4 100644 --- a/beamer/viewer/screen/screen.js +++ b/beamer/viewer/screen/screen.js | |||
@@ -1,19 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Beamer Viewer, a web-based PDF presentation viewer | 2 | * Beamer Viewer, a web-based PDF presentation viewer |
3 | * Copyright (C) 2018 Pacien TRAN-GIRARD | 3 | * Copyright 2018-2024 Pacien TRAN-GIRARD |
4 | * | 4 | * SPDX-License-Identifier: EUPL-1.2 |
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | */ | 5 | */ |
18 | 6 | ||
19 | "use strict"; | 7 | "use strict"; |
@@ -42,10 +30,7 @@ class Screen { | |||
42 | } | 30 | } |
43 | 31 | ||
44 | _registerListeners() { | 32 | _registerListeners() { |
45 | const self = this; | 33 | this.window.addEventListener("resize", () => this._repaint()); |
46 | this.window.addEventListener("resize", function() { | ||
47 | self._repaint(); | ||
48 | }); | ||
49 | } | 34 | } |
50 | 35 | ||
51 | _hideWelcomeScreen() { | 36 | _hideWelcomeScreen() { |
@@ -62,9 +47,32 @@ class Screen { | |||
62 | }; | 47 | }; |
63 | } | 48 | } |
64 | 49 | ||
50 | _getScreenOffsets(secondary, width, height) { | ||
51 | if (!secondary) return { xOffset: 0, yOffset: 0 }; | ||
52 | |||
53 | const viewport = this.page.getViewport(1); | ||
54 | if (viewport.width > viewport.height) | ||
55 | return { xOffset: -width, yOffset: 0 }; | ||
56 | else | ||
57 | return { xOffset: 0, yOffset: -height }; | ||
58 | } | ||
59 | |||
65 | _getSlideSizeRatio() { | 60 | _getSlideSizeRatio() { |
66 | const viewport = this.page.getViewport(1); | 61 | const viewport = this.page.getViewport(1); |
67 | return (viewport.width / 2) / viewport.height; | 62 | |
63 | if (viewport.width > viewport.height) | ||
64 | return (viewport.width / 2) / viewport.height; | ||
65 | else | ||
66 | return viewport.width / (viewport.height / 2); | ||
67 | } | ||
68 | |||
69 | _getScaleFactor(width, height) { | ||
70 | const viewport = this.page.getViewport(1); | ||
71 | |||
72 | if (viewport.width > viewport.height) | ||
73 | return height / viewport.height; | ||
74 | else | ||
75 | return width / viewport.width; | ||
68 | } | 76 | } |
69 | 77 | ||
70 | _newCanvas(width, height, xOffset, yOffset) { | 78 | _newCanvas(width, height, xOffset, yOffset) { |
@@ -91,10 +99,9 @@ class Screen { | |||
91 | viewport: this.page.getViewport(scaleFactor) | 99 | viewport: this.page.getViewport(scaleFactor) |
92 | }; | 100 | }; |
93 | 101 | ||
94 | const self = this; | 102 | this.page |
95 | this.page.render(renderContext).then(function() { | 103 | .render(renderContext) |
96 | self._showCanvas(canvas); | 104 | .then(() => this._showCanvas(canvas)); |
97 | }); | ||
98 | } | 105 | } |
99 | 106 | ||
100 | _repaint() { | 107 | _repaint() { |
@@ -102,9 +109,11 @@ class Screen { | |||
102 | 109 | ||
103 | const screenRatio = this._getSlideSizeRatio(); | 110 | const screenRatio = this._getSlideSizeRatio(); |
104 | const { width, height } = this._getScreenSize(screenRatio); | 111 | const { width, height } = this._getScreenSize(screenRatio); |
105 | const scaleFactor = height / this.page.getViewport(1).height; | 112 | const scaleFactor = this._getScaleFactor(width, height); |
106 | const xOffset = this.secondary ? -width : 0; | 113 | const { xOffset, yOffset } = |
107 | const { canvas, context } = this._newCanvas(width, height, xOffset, 0); | 114 | this._getScreenOffsets(this.secondary, width, height); |
115 | const { canvas, context } = | ||
116 | this._newCanvas(width, height, xOffset, yOffset); | ||
108 | this._render(canvas, context, scaleFactor); | 117 | this._render(canvas, context, scaleFactor); |
109 | } | 118 | } |
110 | } | 119 | } |