summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-02-17 12:44:03 +0100
committerCaolán McNamara <caolanm@redhat.com>2023-02-20 19:44:58 +0000
commit146b95e138ff38aee755f4954f3305c48e2c3963 (patch)
tree26f32e47dc80c180fd9fa97c5b2ccf37f806f5f2
parentb22446cc1788c1861ea5a8cc5b227f983ea71f8f (diff)
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/+/147236 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sc/source/ui/view/gridwin4.cxx15
1 files changed, 9 insertions, 6 deletions
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 42cc0781d26b..6f305576b3bb 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1992,13 +1992,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() );