diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-04-02 11:16:30 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-04-03 16:41:59 +0200 |
commit | a3daf52dd21ae03a8b04e1f9132a6713c9cc414f (patch) | |
tree | 3da8eac339f92e9a22feb1449db9115e6bf02413 /editeng | |
parent | 387a9c445793e8377f85e508d935dc070fd8ab74 (diff) |
Base scale on 1.0, not on 100.0
Simplifies things by avoiding many repeated multiplications / divisions
by 100 during calculations.
Change-Id: Ib063d343549139c8d83e5b06570dc61f39ea0df6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165666
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/impedit.hxx | 16 | ||||
-rw-r--r-- | editeng/source/editeng/impedit3.cxx | 50 | ||||
-rw-r--r-- | editeng/source/outliner/outliner.cxx | 8 |
3 files changed, 36 insertions, 38 deletions
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index e09712f74bad..07f6af002358 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -780,34 +780,34 @@ private: double scaleXSpacingValue(tools::Long nXValue) const { - if (!maStatus.DoStretch() || maScalingParameters.fSpacingX == 100.0) + if (!maStatus.DoStretch() || maScalingParameters.fSpacingX == 1.0) return nXValue; - return double(nXValue) * (maScalingParameters.fSpacingX / 100.0); + return double(nXValue) * maScalingParameters.fSpacingX; } double scaleYSpacingValue(sal_uInt16 nYValue) const { - if (!maStatus.DoStretch() || maScalingParameters.fSpacingY == 100.0) + if (!maStatus.DoStretch() || maScalingParameters.fSpacingY == 1.0) return nYValue; - return double(nYValue) * (maScalingParameters.fSpacingY / 100.0); + return double(nYValue) * maScalingParameters.fSpacingY; } double scaleXFontValue(tools::Long nXValue) const { - if (!maStatus.DoStretch() || (maScalingParameters.fFontX == 100.0)) + if (!maStatus.DoStretch() || (maScalingParameters.fFontX == 1.0)) return nXValue; - return double(nXValue) * (maScalingParameters.fFontX / 100.0); + return double(nXValue) * maScalingParameters.fFontX; } double scaleYFontValue(sal_uInt16 nYValue) const { - if (!maStatus.DoStretch() || (maScalingParameters.fFontY == 100.0)) + if (!maStatus.DoStretch() || (maScalingParameters.fFontY == 1.0)) return nYValue; - return double(nYValue) * (maScalingParameters.fFontY / 100.0); + return double(nYValue) * maScalingParameters.fFontY; } void setRoundToNearestPt(bool bRound) { mbRoundToNearestPt = bRound; } diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index a2dee889aa63..75fe99e684ee 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -447,19 +447,19 @@ namespace { constexpr std::array<ScalingParameters, 13> constScaleLevels = { - ScalingParameters{100.0, 100.0, 100.0, 90.0 }, - ScalingParameters{ 92.5, 92.5, 100.0, 90.0 }, - ScalingParameters{ 92.5, 92.5, 100.0, 80.0 }, - ScalingParameters{ 85.0, 85.0, 100.0, 90.0 }, - ScalingParameters{ 85.0, 85.0, 100.0, 80.0 }, - ScalingParameters{ 77.5, 77.5, 100.0, 80.0 }, - ScalingParameters{ 70.0, 70.0, 100.0, 80.0 }, - ScalingParameters{ 62.5, 62.5, 100.0, 80.0 }, - ScalingParameters{ 55.0, 55.0, 100.0, 80.0 }, - ScalingParameters{ 47.5, 47.5, 100.0, 80.0 }, - ScalingParameters{ 40.0, 40.0, 100.0, 80.0 }, - ScalingParameters{ 32.5, 32.5, 100.0, 80.0 }, - ScalingParameters{ 25.0, 25.0, 100.0, 80.0 }, + ScalingParameters{ 1.000, 1.000, 1.0, 0.9 }, + ScalingParameters{ 0.925, 0.925, 1.0, 0.9 }, + ScalingParameters{ 0.925, 0.925, 1.0, 0.8 }, + ScalingParameters{ 0.850, 0.850, 1.0, 0.9 }, + ScalingParameters{ 0.850, 0.850, 1.0, 0.8 }, + ScalingParameters{ 0.775, 0.775, 1.0, 0.8 }, + ScalingParameters{ 0.700, 0.700, 1.0, 0.8 }, + ScalingParameters{ 0.625, 0.625, 1.0, 0.8 }, + ScalingParameters{ 0.550, 0.550, 1.0, 0.8 }, + ScalingParameters{ 0.475, 0.475, 1.0, 0.8 }, + ScalingParameters{ 0.400, 0.400, 1.0, 0.8 }, + ScalingParameters{ 0.325, 0.325, 1.0, 0.8 }, + ScalingParameters{ 0.250, 0.250, 1.0, 0.8 }, }; } // end anonymous ns @@ -1069,8 +1069,8 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) tools::Long nCurPos = nTmpWidth + nStartX; // consider scaling double fFontScalingX = maScalingParameters.fFontX; - if (maStatus.DoStretch() && (fFontScalingX != 100.0)) - nCurPos = basegfx::fround(double(nCurPos) * 100.0 / std::max(fFontScalingX, 1.0)); + if (maStatus.DoStretch() && (fFontScalingX != 1.0)) + nCurPos = basegfx::fround(double(nCurPos) / std::max(fFontScalingX, 0.01)); short nAllSpaceBeforeText = short(rLRItem.GetTextLeft()); aCurrentTab.aTabStop = pNode->GetContentAttribs().FindTabStop( nCurPos - nAllSpaceBeforeText , maEditDoc.GetDefTab() ); @@ -1593,7 +1593,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) sal_uInt16 nPropLineSpace = rLSItem.GetPropLineSpace(); double fProportionalScale = double(nPropLineSpace) / 100.0; constexpr const double f80Percent = 8.0 / 10.0; - double fSpacingFactor = maScalingParameters.fSpacingY / 100.0; + double fSpacingFactor = maScalingParameters.fSpacingY; if (nPropLineSpace && nPropLineSpace < 100) { // Adapted code from sw/source/core/text/itrform2.cxx @@ -1617,9 +1617,9 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) } else if (rLSItem.GetInterLineSpaceRule() == SvxInterLineSpaceRule::Off) { - if (maScalingParameters.fSpacingY < 100.0) + if (maScalingParameters.fSpacingY < 1.0) { - double fSpacingFactor = maScalingParameters.fSpacingY / 100.0; + double fSpacingFactor = maScalingParameters.fSpacingY; sal_uInt16 nPropLineSpace = basegfx::fround(100.0 * fSpacingFactor); if (nPropLineSpace && nPropLineSpace < 100) { @@ -3085,14 +3085,14 @@ void ImpEditEngine::SeekCursor( ContentNode* pNode, sal_Int32 nPos, SvxFont& rFo if (maStatus.DoStretch()) { - if (maScalingParameters.fFontY != 100.0) + if (maScalingParameters.fFontY != 1.0) { double fHeightRounded = roundToNearestPt(aRealSz.Height()); - double fNewHeight = fHeightRounded * (maScalingParameters.fFontY / 100.0); + double fNewHeight = fHeightRounded * maScalingParameters.fFontY; fNewHeight = roundToNearestPt(fNewHeight); aRealSz.setHeight(basegfx::fround(fNewHeight)); } - if (maScalingParameters.fFontX != 100.0) + if (maScalingParameters.fFontX != 1.0) { auto fFontX = maScalingParameters.fFontX; auto fFontY = maScalingParameters.fFontY; @@ -3103,7 +3103,7 @@ void ImpEditEngine::SeekCursor( ContentNode* pNode, sal_Int32 nPos, SvxFont& rFo else { double fWidthRounded = roundToNearestPt(aRealSz.Width()); - double fNewWidth = fWidthRounded * (fFontX / 100.0); + double fNewWidth = fWidthRounded * fFontX; fNewWidth = roundToNearestPt(fNewWidth); aRealSz.setWidth(basegfx::fround(fNewWidth)); @@ -3120,15 +3120,15 @@ void ImpEditEngine::SeekCursor( ContentNode* pNode, sal_Int32 nPos, SvxFont& rFo >0 >100 > (Proportional) <0 >100 < (The amount, thus disproportional) */ - if (nKerning < 0 && fFontX > 100.0) + if (nKerning < 0 && fFontX > 1.0) { // disproportional - nKerning = basegfx::fround((double(nKerning) * 100.0) / fFontX); + nKerning = basegfx::fround(nKerning / fFontX); } else if ( nKerning ) { // Proportional - nKerning = basegfx::fround((double(nKerning) * fFontX) / 100.0); + nKerning = basegfx::fround(nKerning * fFontX); } rFont.SetFixKerning( static_cast<short>(nKerning) ); } diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index b6f715da52d0..2e8541e72051 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -846,10 +846,8 @@ vcl::Font Outliner::ImpCalcBulletFont( sal_Int32 nPara ) const // Use original scale... - double fFontScaleY = pFmt->GetBulletRelSize() * (getScalingParameters().fFontY / 100.0); - double fScaledLineHeight = aStdFont.GetFontSize().Height(); - fScaledLineHeight *= fFontScaleY * 10; - fScaledLineHeight /= 1000.0; + double fFontScaleY = pFmt->GetBulletRelSize() / 100.0 * getScalingParameters().fFontY; + double fScaledLineHeight = aStdFont.GetFontSize().Height() * fFontScaleY; aBulletFont.SetAlignment( ALIGN_BOTTOM ); aBulletFont.SetFontSize(Size(0, basegfx::fround(fScaledLineHeight))); @@ -891,7 +889,7 @@ void Outliner::PaintBullet(sal_Int32 nPara, const Point& rStartPos, const Point& tools::Rectangle aBulletArea( ImpCalcBulletArea( nPara, true, false ) ); - double fSpacingFactorX = getScalingParameters().fSpacingX / 100.0; + double fSpacingFactorX = getScalingParameters().fSpacingX; tools::Long nStretchBulletX = basegfx::fround(double(aBulletArea.Left()) * fSpacingFactorX); tools::Long nStretchBulletWidth = basegfx::fround(double(aBulletArea.GetWidth()) * fSpacingFactorX); |