sd/qa/unit/export-tests-ooxml3.cxx |    2 +-
 svx/source/svdraw/svdotext.cxx     |   15 +++++++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

New commits:
commit 7f73a779e33dd91fad0111629c6b3420c2c9aea0
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Nov 2 20:15:31 2022 +0100
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Nov 3 09:53:54 2022 +0100

    optimize text fitting algorithm to correctly calculate the fit
    
    As we converted the chart stretching variable from int to double
    this can cause the text fitting algorithm to calculate the fit
    wrong. This commit changes the text fitting algorithm a bit so
    that it produces similar result as before the change.
    
    Change test testAutofittedTextboxIndent from 691200 to 712800 as
    the fitting algorithm changed a bit. Visually the document still
    looks correct.
    
    Change-Id: Ib75733360039d80a5aed836f757c3f8e8ec56d61
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142186
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sd/qa/unit/export-tests-ooxml3.cxx 
b/sd/qa/unit/export-tests-ooxml3.cxx
index 62fe34150896..2f2576ed1ce6 100644
--- a/sd/qa/unit/export-tests-ooxml3.cxx
+++ b/sd/qa/unit/export-tests-ooxml3.cxx
@@ -2068,7 +2068,7 @@ void SdOOXMLExportTest3::testAutofittedTextboxIndent()
 
     xmlDocUniquePtr pXmlDocContent1 = parseExport(tempFile, 
"ppt/slides/slide1.xml");
     assertXPath(pXmlDocContent1, 
"/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p[1]/a:pPr", "marL",
-                "691200");
+                "712800");
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest3);
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 5e2a8721cd89..6e47273fe175 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -1252,9 +1252,8 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, 
const Size& rTextSize,
     // loop early-exits if we detect an already attained value
     double nMinStretchX = 0.0;
     double nMinStretchY = 0.0;
-    sal_uInt16 aOldStretchXVals[]={0,0,0,0,0,0,0,0,0,0};
-    const size_t aStretchArySize=SAL_N_ELEMENTS(aOldStretchXVals);
-    for(unsigned int i=0; i<aStretchArySize; ++i)
+    std::array<sal_Int32, 10> aOldStretchXVals = {0,0,0,0,0,0,0,0,0,0};
+    for (size_t i = 0; i < aOldStretchXVals.size(); ++i)
     {
         const Size aCurrTextSize = rOutliner.CalcTextSizeNTP();
         double fFactor = 1.0;
@@ -1279,7 +1278,7 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, 
const Size& rTextSize,
         double nCurrStretchX, nCurrStretchY;
         rOutliner.GetGlobalCharStretching(nCurrStretchX, nCurrStretchY);
 
-        if (fFactor >= 1.0 )
+        if (fFactor >= 0.98)
         {
             // resulting text area fits into available shape rect -
             // err on the larger stretching, to optimally fill area
@@ -1287,14 +1286,14 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, 
const Size& rTextSize,
             nMinStretchY = std::max(nMinStretchY, nCurrStretchY);
         }
 
-        aOldStretchXVals[i] = nCurrStretchX;
-        if( std::find(aOldStretchXVals, aOldStretchXVals+i, nCurrStretchX) != 
aOldStretchXVals+i )
+        aOldStretchXVals[i] = basegfx::fround(nCurrStretchX * 10.0);
+        if (std::find(aOldStretchXVals.begin(), aOldStretchXVals.begin() + i, 
basegfx::fround(nCurrStretchX * 10.0)) != aOldStretchXVals.begin() + i)
             break; // same value already attained once; algo is looping, exit
 
         if (fFactor < 1.0 || nCurrStretchX != 100)
         {
-            nCurrStretchX = nCurrStretchX * fFactor;
-            nCurrStretchY = nCurrStretchY * fFactor;
+            nCurrStretchX = double(basegfx::fround(nCurrStretchX * fFactor * 
100.0)) / 100.00;
+            nCurrStretchY = double(basegfx::fround(nCurrStretchY * fFactor * 
100.0)) / 100.00;
 
             rOutliner.SetGlobalCharStretching(std::min(100.0, nCurrStretchX), 
std::min(100.0, nCurrStretchY));
             SAL_INFO("svx", "zoom is " << nCurrStretchX);

Reply via email to