[Libreoffice-commits] core.git: include/svx oox/source sd/qa svx/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sun Jun 6 19:58:46 UTC 2021


 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 a1ae30166e92a0a40dff06740f0bb8e9ee63f70a
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Jun 6 21:50:53 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Jun 6 21:58:09 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.kaganski at collabora.com>

diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 61a63f660950..a3ff2e1fda50 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -392,7 +392,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 6805c1bd3a49..684623a41813 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -3302,10 +3302,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 af1fb0e7d99a..abf469788695 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -1899,10 +1899,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 ef9cedaeedb5..090ffc901dfe 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;
 
@@ -1186,67 +1187,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 1c6d3c9c451c..984356691261 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -186,14 +186,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();
 }
 }
 


More information about the Libreoffice-commits mailing list