From dbbd2c63726630d5c370c9c6a2870a01dad5a8d4 Mon Sep 17 00:00:00 2001 From: euxane Date: Thu, 21 Mar 2024 19:00:36 +0100 Subject: screen: handle vertical split --- beamer/viewer/screen/screen.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'beamer/viewer') diff --git a/beamer/viewer/screen/screen.js b/beamer/viewer/screen/screen.js index 3d95acd..4bebab4 100644 --- a/beamer/viewer/screen/screen.js +++ b/beamer/viewer/screen/screen.js @@ -47,9 +47,32 @@ class Screen { }; } + _getScreenOffsets(secondary, width, height) { + if (!secondary) return { xOffset: 0, yOffset: 0 }; + + const viewport = this.page.getViewport(1); + if (viewport.width > viewport.height) + return { xOffset: -width, yOffset: 0 }; + else + return { xOffset: 0, yOffset: -height }; + } + _getSlideSizeRatio() { const viewport = this.page.getViewport(1); - return (viewport.width / 2) / viewport.height; + + if (viewport.width > viewport.height) + return (viewport.width / 2) / viewport.height; + else + return viewport.width / (viewport.height / 2); + } + + _getScaleFactor(width, height) { + const viewport = this.page.getViewport(1); + + if (viewport.width > viewport.height) + return height / viewport.height; + else + return width / viewport.width; } _newCanvas(width, height, xOffset, yOffset) { @@ -86,9 +109,11 @@ class Screen { const screenRatio = this._getSlideSizeRatio(); const { width, height } = this._getScreenSize(screenRatio); - const scaleFactor = height / this.page.getViewport(1).height; - const xOffset = this.secondary ? -width : 0; - const { canvas, context } = this._newCanvas(width, height, xOffset, 0); + const scaleFactor = this._getScaleFactor(width, height); + const { xOffset, yOffset } = + this._getScreenOffsets(this.secondary, width, height); + const { canvas, context } = + this._newCanvas(width, height, xOffset, yOffset); this._render(canvas, context, scaleFactor); } } -- cgit v1.2.3