diff --git a/client/homebrew/brewRenderer/toolBar/toolBar.jsx b/client/homebrew/brewRenderer/toolBar/toolBar.jsx index c0e5ca469..71a76252b 100644 --- a/client/homebrew/brewRenderer/toolBar/toolBar.jsx +++ b/client/homebrew/brewRenderer/toolBar/toolBar.jsx @@ -59,7 +59,31 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ const desiredZoom = (iframeWidth / widestPage) * 100; const deltaZoom = (desiredZoom - zoomLevel) - margin; return deltaZoom; - } + }; + + const toFit = ()=>{ + const iframe = document.getElementById('BrewRenderer'); + const iframeWidth = iframe.getBoundingClientRect().width; + const iframeHeight = iframe.getBoundingClientRect().height; + const pages = iframe.contentWindow.document.getElementsByClassName('page'); + + let maxDimRatio = 0; + + [...pages].forEach((page)=>{ + const widthRatio = iframeWidth / page.offsetWidth; + const heightRatio = iframeHeight / page.offsetHeight; + const dimensionRatio = Math.min(widthRatio, heightRatio); + if(dimensionRatio < maxDimRatio || maxDimRatio == 0){ + maxDimRatio = dimensionRatio; + } + }); + + const margin = 5; + const desiredZoom = maxDimRatio * 100; + const deltaZoom = desiredZoom - zoomLevel - margin; + + return deltaZoom; + }; return (
@@ -71,6 +95,13 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ > toFill +