summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-10-31 13:28:27 +0100
committerTomaž Vajngerl <quikee@gmail.com>2023-04-07 12:34:37 +0200
commit9fc6702071d243652d48e7311db39b84be70903d (patch)
treecb3d1dee6c227d1dacc00178108e1b6232ec94df /svx/source
parent27dc2814941423d202053cf65bbf755e403c6044 (diff)
fix rendering of text when "fit to frame" is enabled
This changes the nStretchX and nStretchY from sal_uInt16 to double so the text in text boxes is rendered correctly (text should be resized to the same size as the textbox). Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142064 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Change-Id: Ifdf2481ddbaac0e9cf62a6ddf8a83984be134855 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149931 Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/svdraw/svdotext.cxx110
-rw-r--r--svx/source/svdraw/svdotextdecomposition.cxx2
2 files changed, 72 insertions, 40 deletions
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 91a0870630e0..6117acac124c 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -937,56 +937,88 @@ void SdrTextObj::ImpSetCharStretching(SdrOutliner& rOutliner, const Size& rTextS
tools::Long nXTolMi=nWantWdt/25; // tolerance: -4%
tools::Long nXCorr =nWantWdt/20; // correction scale: 5%
- tools::Long nX=(nWantWdt*100) /nIsWdt; // calculate X stretching
- tools::Long nY=(nWantHgt*100) /nIsHgt; // calculate Y stretching
+ double nX = (nWantWdt * 100.0) / double(nIsWdt); // calculate X stretching
+ double nY = (nWantHgt * 100.0) / double(nIsHgt); // calculate Y stretching
bool bChkX = true;
- if (bNoStretching) { // might only be possible proportionally
- if (nX>nY) { nX=nY; bChkX=false; }
- else { nY=nX; }
+ if (bNoStretching)
+ { // might only be possible proportionally
+ if (nX > nY)
+ {
+ nX = nY;
+ bChkX = false;
+ }
+ else
+ {
+ nY = nX;
+ }
}
- while (nLoopCount<5 && !bNoMoreLoop) {
- if (nX<0) nX=-nX;
- if (nX<1) { nX=1; bNoMoreLoop = true; }
- if (nX>65535) { nX=65535; bNoMoreLoop = true; }
+ while (nLoopCount<5 && !bNoMoreLoop)
+ {
+ if (nX < 0.0)
+ nX = -nX;
+ if (nX < 1.0)
+ {
+ nX = 1.0;
+ bNoMoreLoop = true;
+ }
+ if (nX > 65535.0)
+ {
+ nX = 65535.0;
+ bNoMoreLoop = true;
+ }
- if (nY<0) nY=-nY;
- if (nY<1) { nY=1; bNoMoreLoop = true; }
- if (nY>65535) { nY=65535; bNoMoreLoop = true; }
+ if (nY < 0.0)
+ {
+ nY = -nY;
+ }
+ if (nY < 1.0)
+ {
+ nY = 1.0;
+ bNoMoreLoop = true;
+ }
+ if (nY > 65535.0)
+ {
+ nY = 65535.0;
+ bNoMoreLoop = true;
+ }
// exception, there is no text yet (horizontal case)
- if(nIsWdt <= 1)
+ if (nIsWdt <= 1)
{
nX = nY;
bNoMoreLoop = true;
}
// exception, there is no text yet (vertical case)
- if(nIsHgt <= 1)
+ if (nIsHgt <= 1)
{
nY = nX;
bNoMoreLoop = true;
}
-
- rOutliner.SetGlobalCharStretching(static_cast<sal_uInt16>(nX),static_cast<sal_uInt16>(nY));
+ rOutliner.SetGlobalCharStretching(nX, nY);
nLoopCount++;
Size aSiz(rOutliner.CalcTextSize());
- tools::Long nXDiff=aSiz.Width()-nWantWdt;
+ tools::Long nXDiff = aSiz.Width() - nWantWdt;
rFitXCorrection=Fraction(nWantWdt,aSiz.Width());
if (((nXDiff>=nXTolMi || !bChkX) && nXDiff<=nXTolPl) || nXDiff==nXDiff0) {
bNoMoreLoop = true;
} else {
// correct stretching factors
- tools::Long nMul=nWantWdt;
- tools::Long nDiv=aSiz.Width();
- if (std::abs(nXDiff)<=2*nXCorr) {
- if (nMul>nDiv) nDiv+=(nMul-nDiv)/2; // but only add half of what we calculated,
- else nMul+=(nDiv-nMul)/2; // because the EditEngine calculates wrongly later on
+ tools::Long nMul = nWantWdt;
+ tools::Long nDiv = aSiz.Width();
+ if (std::abs(nXDiff) <= 2 * nXCorr)
+ {
+ if (nMul > nDiv)
+ nDiv += (nMul - nDiv) / 2.0; // but only add half of what we calculated,
+ else
+ nMul += (nDiv - nMul) / 2.0;// because the EditEngine calculates wrongly later on
}
- nX=nX*nMul/nDiv;
- if (bNoStretching) nY=nX;
+ nX = nX * double(nMul) / double(nDiv);
+ if (bNoStretching)
+ nY = nX;
}
- nXDiff0=nXDiff;
+ nXDiff0 = nXDiff;
}
}
@@ -1149,7 +1181,7 @@ void SdrTextObj::ImpInitDrawOutliner( SdrOutliner& rOutl ) const
nOutlinerMode = OutlinerMode::TextObject;
rOutl.Init( nOutlinerMode );
- rOutl.SetGlobalCharStretching();
+ rOutl.SetGlobalCharStretching(100.0, 100.0);
EEControlBits nStat=rOutl.GetControlWord();
nStat &= ~EEControlBits(EEControlBits::STRETCHING|EEControlBits::AUTOPAGESIZE);
rOutl.SetControlWord(nStat);
@@ -1213,8 +1245,8 @@ sal_uInt16 SdrTextObj::GetFontScaleY() const
// This eventually calls ImpAutoFitText
UpdateOutlinerFormatting(rOutliner, o3tl::temporary(tools::Rectangle()));
- sal_uInt16 nStretchY;
- rOutliner.GetGlobalCharStretching(o3tl::temporary(sal_uInt16()), nStretchY);
+ double nStretchY;
+ rOutliner.GetGlobalCharStretching(o3tl::temporary(double()), nStretchY);
return nStretchY;
}
@@ -1234,13 +1266,14 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize,
// line-breaking text that we need some more samples
// loop early-exits if we detect an already attained value
- sal_uInt16 nMinStretchX=0, nMinStretchY=0;
+ 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)
{
const Size aCurrTextSize = rOutliner.CalcTextSizeNTP();
- double fFactor(1.0);
+ double fFactor = 1.0;
if( bIsVerticalWriting )
{
if (aCurrTextSize.Width() != 0)
@@ -1259,15 +1292,15 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize,
// - bulleted words will have to go through more iterations
fFactor = std::sqrt(fFactor);
- sal_uInt16 nCurrStretchX, nCurrStretchY;
+ double nCurrStretchX, nCurrStretchY;
rOutliner.GetGlobalCharStretching(nCurrStretchX, nCurrStretchY);
if (fFactor >= 1.0 )
{
// resulting text area fits into available shape rect -
// err on the larger stretching, to optimally fill area
- nMinStretchX = std::max(nMinStretchX,nCurrStretchX);
- nMinStretchY = std::max(nMinStretchY,nCurrStretchY);
+ nMinStretchX = std::max(nMinStretchX, nCurrStretchX);
+ nMinStretchY = std::max(nMinStretchY, nCurrStretchY);
}
aOldStretchXVals[i] = nCurrStretchX;
@@ -1276,10 +1309,10 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize,
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));
+ nCurrStretchX = nCurrStretchX * fFactor;
+ nCurrStretchY = nCurrStretchY * fFactor;
+
+ rOutliner.SetGlobalCharStretching(std::min(100.0, nCurrStretchX), std::min(100.0, nCurrStretchY));
SAL_INFO("svx", "zoom is " << nCurrStretchX);
}
}
@@ -1292,8 +1325,7 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize,
}
SAL_INFO("svx", "final zoom is " << nMinStretchX);
- rOutliner.SetGlobalCharStretching(std::min(sal_uInt16(100),nMinStretchX),
- std::min(sal_uInt16(100),nMinStretchY));
+ rOutliner.SetGlobalCharStretching(std::min(100.0, nMinStretchX), std::min(100.0, nMinStretchY));
}
void SdrTextObj::SetupOutlinerFormatting( SdrOutliner& rOutl, tools::Rectangle& rPaintRect ) const
diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx
index 607a2546d1d5..1fc6b8f08cff 100644
--- a/svx/source/svdraw/svdotextdecomposition.cxx
+++ b/svx/source/svdraw/svdotextdecomposition.cxx
@@ -1203,7 +1203,7 @@ void SdrTextObj::impDecomposeStretchTextPrimitive(
// to layout without mirroring
const double fScaleX(fabs(aScale.getX()) / aOutlinerScale.getX());
const double fScaleY(fabs(aScale.getY()) / aOutlinerScale.getY());
- rOutliner.SetGlobalCharStretching(static_cast<sal_Int16>(FRound(fScaleX * 100.0)), static_cast<sal_Int16>(FRound(fScaleY * 100.0)));
+ rOutliner.SetGlobalCharStretching(fScaleX * 100.0, fScaleY * 100.0);
// When mirroring in X and Y,
// move the null point which was top left to bottom right.