include/vcl/outdev.hxx     |    1 +
 vcl/source/outdev/font.cxx |   40 ++++++++++++++++++++++++----------------
 2 files changed, 25 insertions(+), 16 deletions(-)

New commits:
commit 0898179afc9334bc2370cdccbf3392337585b860
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sun Mar 13 13:41:31 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sun Mar 13 20:53:19 2022 +0100

    ofz: Divide-by-zero
    
    Change-Id: I8d88558be5bcf4556d94ab86015f5e039e72da08
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131503
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index a777f9d73569..fe1d9583e2ba 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -1113,6 +1113,7 @@ private:
     SAL_DLLPRIVATE void         ImplDrawStrikeoutChar( tools::Long nBaseX, 
tools::Long nBaseY, tools::Long nX, tools::Long nY, tools::Long nWidth, 
FontStrikeout eStrikeout, Color aColor );
     SAL_DLLPRIVATE void         ImplDrawMnemonicLine( tools::Long nX, 
tools::Long nY, tools::Long nWidth );
 
+    SAL_DLLPRIVATE bool         AttemptOLEFontScaleFix(vcl::Font& rFont, 
tools::Long nHeight) const;
 
     ///@}
 
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;
 }
 

Reply via email to