0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-28 15:42:38 +00:00

fixing toFit to actually fit in any mode

This commit is contained in:
Víctor Losada Hernández
2025-04-21 22:17:52 +02:00
parent 25629173c9
commit b747968e74

View File

@@ -61,17 +61,19 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
const widestPage = _.maxBy([...pages], 'offsetWidth').offsetWidth; const widestPage = _.maxBy([...pages], 'offsetWidth').offsetWidth;
if(displayOptions.spread === 'facing') if(displayOptions.spread === 'facing')
desiredZoom = (iframeWidth / widestPage) * 50; desiredZoom = (iframeWidth / ((widestPage * 2) + parseInt(displayOptions.columnGap))) * 100;
else else
desiredZoom = (iframeWidth / widestPage) * 100; desiredZoom = (iframeWidth / widestPage) * 100;
} else if(mode == 'fit'){ } else if(mode == 'fit'){
let minDimRatio;
// find the page with the largest single dim (height or width) so that zoom can be adapted to fit it. // find the page with the largest single dim (height or width) so that zoom can be adapted to fit it.
if(displayOptions.spread === 'facing') const minDimRatio = [...pages].reduce(
minDimRatio = [...pages].reduce((minRatio, page)=>Math.min(minRatio, iframeWidth / page.offsetWidth / 2), Infinity); // if 'facing' spread, fit two pages in view (minRatio, page)=>Math.min(minRatio,
else iframeWidth / ((page.offsetWidth * 2) + parseInt(displayOptions.columnGap)),
minDimRatio = [...pages].reduce((minRatio, page)=>Math.min(minRatio, iframeWidth / page.offsetWidth, iframeHeight / page.offsetHeight), Infinity); iframeHeight / page.offsetHeight
),
Infinity
);
desiredZoom = minDimRatio * 100; desiredZoom = minDimRatio * 100;
} }