summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-11-02 20:15:31 +0100
committerTomaž Vajngerl <quikee@gmail.com>2023-04-07 12:34:59 +0200
commitd0add4a3a16b40b45029a88845c0beccc58d6330 (patch)
tree3721fb7ccc44a6399a2fa823e5c069f5d33e5f4a /svx
parent9fc6702071d243652d48e7311db39b84be70903d (diff)
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 <quikee@gmail.com> Change-Id: Idac1da3624799b6950ed356e9c76fc4f037f900e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149932 Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdotext.cxx15
1 files changed, 7 insertions, 8 deletions
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);