svx/source/svdraw/svdotext.cxx |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

New commits:
commit d0add4a3a16b40b45029a88845c0beccc58d6330
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Nov 2 20:15:31 2022 +0100
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Apr 7 12:34:59 2023 +0200

    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.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142186
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Change-Id: Idac1da3624799b6950ed356e9c76fc4f037f900e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149932
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 6117acac124c..99249b788c75 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -1268,9 +1268,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;
@@ -1295,7 +1294,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
@@ -1303,14 +1302,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