include/svx/svdotext.hxx           |    2 -
 oox/source/export/drawingml.cxx    |    5 --
 sd/qa/unit/export-tests-ooxml2.cxx |    5 +-
 svx/source/svdraw/svdotext.cxx     |   65 +++----------------------------------
 svx/source/unodraw/unoshape.cxx    |    9 -----
 5 files changed, 12 insertions(+), 74 deletions(-)

New commits:
commit 4e42d99169a1e609b73d102b2947fd09d8e6ea13
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Jun 6 21:50:53 2021 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Jun 7 13:31:38 2021 +0200

    Fix and unify the two methods that get scaled text size
    
    GetTextFitToSizeScale and SdrTextObj::GetFontScaleY both didn't
    initialize outliners properly, and thus returned wrong results.
    
    Change-Id: I6fe63c51ed838a0d0fafdfa03597cac97ce29831
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116765
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit a1ae30166e92a0a40dff06740f0bb8e9ee63f70a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116704
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 9d74bffec93e..3911759b82fe 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -389,7 +389,7 @@ public:
     // FitToSize and Fontwork are not taken into account in GetTextSize()!
     virtual const Size& GetTextSize() const;
     void FitFrameToTextSize();
-    double GetFontScaleY() const;
+    sal_uInt16 GetFontScaleY() const;
 
     // Simultaneously sets the text into the Outliner (possibly
     // the one of the EditOutliner) and sets the PaperSize.
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 8cfd4a6dabc5..fcd93e0b6df2 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -3229,10 +3229,7 @@ void DrawingML::WriteText(const Reference<XInterface>& 
rXIface, bool bBodyPr, bo
                 {
                     SdrTextObj* pTextObject = 
dynamic_cast<SdrTextObj*>(pTextShape->GetSdrObject());
                     if (pTextObject)
-                    {
-                        double fScaleY = pTextObject->GetFontScaleY();
-                        nFontScale = static_cast<sal_uInt32>(fScaleY * 100) * 
1000;
-                    }
+                        nFontScale = pTextObject->GetFontScaleY() * 1000;
                 }
 
                 mpFS->singleElementNS(XML_a, XML_normAutofit, XML_fontScale,
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx 
b/sd/qa/unit/export-tests-ooxml2.cxx
index ef74eb9a4850..c17820ea318b 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -1861,10 +1861,9 @@ void SdOOXMLExportTest2::testFontScale()
     xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
     xmlDocUniquePtr pXmlDocContent = parseExport(tempFile, 
"ppt/slides/slide1.xml");
 
-    // Rounding errors possible, approximate value
+    // Rounding errors possible, approximate value (+/- 1%)
     OUString sScale = getXPath(pXmlDocContent, 
"/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr/a:normAutofit", "fontScale");
-    if (sScale != "73000" && sScale != "72000" && sScale != "74000")
-        CPPUNIT_ASSERT_EQUAL(OUString("73000"), sScale);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(76000), sScale.toInt32(), 1000);
 
     xDocShRef->DoClose();
 }
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 0daeb7cc9a5d..1894c9c94d78 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -51,6 +51,7 @@
 #include <vcl/virdev.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <sal/log.hxx>
+#include <o3tl/temporary.hxx>
 
 using namespace com::sun::star;
 
@@ -1188,67 +1189,15 @@ void SdrTextObj::ImpSetupDrawOutlinerForPaint( bool     
        bContourFrame,
     }
 }
 
-double SdrTextObj::GetFontScaleY() const
+sal_uInt16 SdrTextObj::GetFontScaleY() const
 {
-    SdrText* pText = getActiveText();
-    if (pText == nullptr || !pText->GetOutlinerParaObject())
-        return 1.0;
-
     SdrOutliner& rOutliner = ImpGetDrawOutliner();
-    const Size aShapeSize = GetSnapRect().GetSize();
-    const Size aSize(aShapeSize.Width() - GetTextLeftDistance() - 
GetTextRightDistance(),
-        aShapeSize.Height() - GetTextUpperDistance() - GetTextLowerDistance());
-
-    rOutliner.SetPaperSize(aSize);
-    rOutliner.SetUpdateMode(true);
-    rOutliner.SetText(*pText->GetOutlinerParaObject());
-    bool bIsVerticalWriting = IsVerticalWriting();
-
-    // Algorithm from SdrTextObj::ImpAutoFitText
-
-    sal_uInt16 nMinStretchX = 0, nMinStretchY = 0;
-    sal_uInt16 nCurrStretchX = 100, nCurrStretchY = 100;
-    sal_uInt16 aOldStretchXVals[] = { 0,0,0 };
-    const size_t aStretchArySize = SAL_N_ELEMENTS(aOldStretchXVals);
-    for (unsigned int i = 0; i<aStretchArySize; ++i)
-    {
-        const Size aCurrTextSize = rOutliner.CalcTextSizeNTP();
-        double fFactor(1.0);
-        if (bIsVerticalWriting)
-        {
-            if (aCurrTextSize.Width() != 0)
-            {
-                fFactor = double(aSize.Width()) / aCurrTextSize.Width();
-            }
-        }
-        else if (aCurrTextSize.Height() != 0)
-        {
-            fFactor = double(aSize.Height()) / aCurrTextSize.Height();
-        }
-        fFactor = std::sqrt(fFactor);
-
-        rOutliner.GetGlobalCharStretching(nCurrStretchX, nCurrStretchY);
-
-        if (fFactor >= 1.0)
-        {
-            nMinStretchX = std::max(nMinStretchX, nCurrStretchX);
-            nMinStretchY = std::max(nMinStretchY, nCurrStretchY);
-        }
-
-        aOldStretchXVals[i] = nCurrStretchX;
-        if (std::find(aOldStretchXVals, aOldStretchXVals + i, nCurrStretchX) 
!= aOldStretchXVals + i)
-            break; // same value already attained once; algo is looping, exit
-
-        if (fFactor < 1.0 || nCurrStretchX != 100)
-        {
-            nCurrStretchX = 
sal::static_int_cast<sal_uInt16>(nCurrStretchX*fFactor);
-            nCurrStretchY = 
sal::static_int_cast<sal_uInt16>(nCurrStretchY*fFactor);
-            rOutliner.SetGlobalCharStretching(std::min(sal_uInt16(100), 
nCurrStretchX),
-                std::min(sal_uInt16(100), nCurrStretchY));
-        }
-    }
+    // This eventually calls ImpAutoFitText
+    UpdateOutlinerFormatting(rOutliner, o3tl::temporary(tools::Rectangle()));
 
-    return std::min(sal_uInt16(100), nCurrStretchY) / 100.0;
+    sal_uInt16 nStretchY;
+    rOutliner.GetGlobalCharStretching(o3tl::temporary(sal_uInt16()), 
nStretchY);
+    return nStretchY;
 }
 
 void SdrTextObj::ImpAutoFitText( SdrOutliner& rOutliner ) const
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index 1885348f9c64..8da9de4358db 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -183,14 +183,7 @@ sal_Int16 GetTextFitToSizeScale(SdrObject* pObject)
         return 0;
     }
 
-    std::unique_ptr<SdrOutliner> pOutliner
-        = 
pTextObj->getSdrModelFromSdrObject().createOutliner(OutlinerMode::TextObject);
-    tools::Rectangle aBoundRect(pTextObj->GetCurrentBoundRect());
-    pTextObj->SetupOutlinerFormatting(*pOutliner, aBoundRect);
-    sal_uInt16 nX = 0;
-    sal_uInt16 nY = 0;
-    pOutliner->GetGlobalCharStretching(nX, nY);
-    return nY;
+    return pTextObj->GetFontScaleY();
 }
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to