From 0898179afc9334bc2370cdccbf3392337585b860 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Sun, 13 Mar 2022 13:41:31 +0000 Subject: ofz: Divide-by-zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8d88558be5bcf4556d94ab86015f5e039e72da08 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131503 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- vcl/source/outdev/font.cxx | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'vcl/source/outdev') diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx index 71e4091e754e..ba487b0198c3 100644 --- a/vcl/source/outdev/font.cxx +++ b/vcl/source/outdev/font.cxx @@ -990,24 +990,32 @@ bool OutputDevice::ImplNewFont() const bool bRet = true; // #95414# fix for OLE objects which use scale factors very creatively - if( mbMap && !aSize.Width() ) + if (mbMap && !aSize.Width()) + bRet = AttemptOLEFontScaleFix(const_cast(maFont), aSize.Height()); + + return bRet; +} + +bool OutputDevice::AttemptOLEFontScaleFix(vcl::Font& rFont, tools::Long nHeight) const +{ + const float fDenominator = static_cast(maMapRes.mnMapScNumY) * maMapRes.mnMapScDenomX; + if (fDenominator == 0.0) + return false; + const float fNumerator = static_cast(maMapRes.mnMapScNumX) * maMapRes.mnMapScDenomY; + float fStretch = fNumerator / fDenominator; + int nOrigWidth = mpFontInstance->mxFontMetric->GetWidth(); + int nNewWidth = static_cast(nOrigWidth * fStretch + 0.5); + bool bRet = true; + if (nNewWidth != nOrigWidth && nNewWidth != 0) { - int nOrigWidth = pFontInstance->mxFontMetric->GetWidth(); - float fStretch = static_cast(maMapRes.mnMapScNumX) * maMapRes.mnMapScDenomY; - fStretch /= static_cast(maMapRes.mnMapScNumY) * maMapRes.mnMapScDenomX; - int nNewWidth = static_cast(nOrigWidth * fStretch + 0.5); - if( (nNewWidth != nOrigWidth) && (nNewWidth != 0) ) - { - Size aOrigSize = maFont.GetFontSize(); - const_cast(maFont).SetFontSize( Size( nNewWidth, aSize.Height() ) ); - mbMap = false; - mbNewFont = true; - bRet = ImplNewFont(); // recurse once using stretched width - mbMap = true; - const_cast(maFont).SetFontSize( aOrigSize ); - } + Size aOrigSize = rFont.GetFontSize(); + rFont.SetFontSize(Size(nNewWidth, nHeight)); + mbMap = false; + mbNewFont = true; + bRet = ImplNewFont(); // recurse once using stretched width + mbMap = true; + rFont.SetFontSize(aOrigSize); } - return bRet; } -- cgit