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:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user