sc/source/ui/view/gridwin4.cxx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
New commits: commit 6d9091197b311321543ea0f0dac30825bf8cc2b8 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Feb 17 12:44:03 2023 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Feb 17 13:05:58 2023 +0000 sc: fix divide by zero in ScGridWindow::DrawPagePreview Seen in https://crashreport.libreoffice.org/stats/signature/ScGridWindow::DrawPagePreview(short,long,short,long,OutputDevice%20&) Change-Id: Iff64d0fe84c7d53b18db38598709ac47475a6715 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147206 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index 6c9c2a7b1819..c30052237646 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -2039,13 +2039,16 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, // find right font size for DrawText aFont.SetFontSize( Size( 0,100 ) ); rRenderContext.SetFont( aFont ); - Size aSize100(rRenderContext.GetTextWidth( aThisPageStr ), rRenderContext.GetTextHeight() ); - // 40% of width or 60% of height - tools::Long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width(); - tools::Long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height(); - aFont.SetFontSize( Size( 0,std::min(nSizeX,nSizeY) ) ); - rRenderContext.SetFont( aFont ); + Size aSize100(rRenderContext.GetTextWidth( aThisPageStr ), rRenderContext.GetTextHeight() ); + if (aSize100.Width() && aSize100.Height()) + { + // 40% of width or 60% of height + tools::Long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width(); + tools::Long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height(); + aFont.SetFontSize( Size( 0,std::min(nSizeX,nSizeY) ) ); + rRenderContext.SetFont( aFont ); + } // centered output with DrawText Size aTextSize(rRenderContext.GetTextWidth( aThisPageStr ), rRenderContext.GetTextHeight() );