summaryrefslogtreecommitdiff
path: root/vcl/source/outdev
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-03-13 13:41:31 +0000
committerCaolán McNamara <caolanm@redhat.com>2022-03-13 20:53:19 +0100
commit0898179afc9334bc2370cdccbf3392337585b860 (patch)
tree4b4cd7a76ba4c2b009dffd29802fe30a7cfc8af3 /vcl/source/outdev
parent924791c51b27226e34fd1e0a32cc7d3d66683d0b (diff)
ofz: Divide-by-zero
Change-Id: I8d88558be5bcf4556d94ab86015f5e039e72da08 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131503 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/source/outdev')
-rw-r--r--vcl/source/outdev/font.cxx40
1 files changed, 24 insertions, 16 deletions
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<vcl::Font&>(maFont), aSize.Height());
+
+ return bRet;
+}
+
+bool OutputDevice::AttemptOLEFontScaleFix(vcl::Font& rFont, tools::Long nHeight) const
+{
+ const float fDenominator = static_cast<float>(maMapRes.mnMapScNumY) * maMapRes.mnMapScDenomX;
+ if (fDenominator == 0.0)
+ return false;
+ const float fNumerator = static_cast<float>(maMapRes.mnMapScNumX) * maMapRes.mnMapScDenomY;
+ float fStretch = fNumerator / fDenominator;
+ int nOrigWidth = mpFontInstance->mxFontMetric->GetWidth();
+ int nNewWidth = static_cast<int>(nOrigWidth * fStretch + 0.5);
+ bool bRet = true;
+ if (nNewWidth != nOrigWidth && nNewWidth != 0)
{
- int nOrigWidth = pFontInstance->mxFontMetric->GetWidth();
- float fStretch = static_cast<float>(maMapRes.mnMapScNumX) * maMapRes.mnMapScDenomY;
- fStretch /= static_cast<float>(maMapRes.mnMapScNumY) * maMapRes.mnMapScDenomX;
- int nNewWidth = static_cast<int>(nOrigWidth * fStretch + 0.5);
- if( (nNewWidth != nOrigWidth) && (nNewWidth != 0) )
- {
- Size aOrigSize = maFont.GetFontSize();
- const_cast<vcl::Font&>(maFont).SetFontSize( Size( nNewWidth, aSize.Height() ) );
- mbMap = false;
- mbNewFont = true;
- bRet = ImplNewFont(); // recurse once using stretched width
- mbMap = true;
- const_cast<vcl::Font&>(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;
}