From dc86fd38e8952c76fefdbb519275d3b81880fe78 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 10 Feb 2023 18:10:33 +0900 Subject: svx: refactor SdrObject resize to use m_aOutterRange directly Change-Id: I77aad10b32a53545c7f7bbf8fd87b914395a5bad --- include/svx/svdtrans.hxx | 9 ++++++ svx/qa/unit/svdraw.cxx | 68 +++++++++++++++++++++++++++++++++++++++++- svx/source/svdraw/svdobj.cxx | 33 ++++++++++++-------- svx/source/svdraw/svdtrans.cxx | 16 ++++++++++ 4 files changed, 112 insertions(+), 14 deletions(-) diff --git a/include/svx/svdtrans.hxx b/include/svx/svdtrans.hxx index ae225426afd6..79ef179c1a8c 100644 --- a/include/svx/svdtrans.hxx +++ b/include/svx/svdtrans.hxx @@ -29,6 +29,9 @@ #include #include +#include +#include + // That maximum shear angle constexpr Degree100 SDRMAXSHEAR(8900); @@ -39,6 +42,12 @@ inline void MovePoly(tools::Polygon& rPoly, const Size& S) { rPoly.Move(S.W void MoveXPoly(XPolygon& rPoly, const Size& S); SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle& rRect, const Point& rRef, const Fraction& xFact, const Fraction& yFact); + +namespace svx +{ +SVXCORE_DLLPUBLIC void resizeRange(gfx::Range2DLWrap& rRange, gfx::Tuple2DL const& rReference, double fFactorX, double fFactorY); +} + inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract); void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact); void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact); diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 3f91084d6483..b2128ac75c93 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include +#include #include #include @@ -38,6 +38,8 @@ #include +#include + using namespace ::com::sun::star; namespace @@ -711,6 +713,7 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testRotatePoint) } } +<<<<<<< HEAD CPPUNIT_TEST_FIXTURE(SvdrawTest, testClipVerticalTextOverflow) { // File contains a slide with 4 rectangle shapes with text inside @@ -754,6 +757,69 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testClipVerticalTextOverflow) assertXPath(pDocument, "((//sdrblocktext)[7]//textsimpleportion)[1]"_ostr, "x"_ostr, "25417"); assertXPath(pDocument, "((//sdrblocktext)[7]//textsimpleportion)[3]"_ostr, "x"_ostr, "23893"); } + +CPPUNIT_TEST_FIXTURE(SvdrawTest, testResizeRect) +{ + { + tools::Rectangle aRectangle(1, 1, 10, 10); + Point aReference(1, 1); + ResizeRect(aRectangle, aReference, Fraction(1, 2), Fraction(1, 2)); + + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(1, 1, 6, 6), aRectangle); + } + + { + tools::Rectangle aRectangle(1, 1, 10, 10); + Point aReference(10, 10); + ResizeRect(aRectangle, aReference, Fraction(1, 2), Fraction(1, 2)); + + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(5, 5, 10, 10), aRectangle); + } + + { + gfx::Range2DLWrap aRange(1_hmm, 1_hmm, 10_hmm, 10_hmm); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getHeight()); + + gfx::Tuple2DL aReference(1_hmm, 1_hmm); + svx::resizeRange(aRange, aReference, 0.5, 0.5); + + CPPUNIT_ASSERT_EQUAL(false, aRange.isEmpty()); + + CPPUNIT_ASSERT_EQUAL(1_hmm, aRange.getMinX()); + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMaxX()); + CPPUNIT_ASSERT_EQUAL(1_hmm, aRange.getMinY()); + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMaxY()); + + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getHeight()); + + auto aRectangle = aRange.toToolsRect(); + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(1, 1, 6, 6), aRectangle); + } + + { + gfx::Range2DLWrap aRange(1_hmm, 1_hmm, 10_hmm, 10_hmm); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getHeight()); + + gfx::Tuple2DL aReference(10_hmm, 10_hmm); + svx::resizeRange(aRange, aReference, 0.5, 0.5); + + CPPUNIT_ASSERT_EQUAL(false, aRange.isEmpty()); + + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMinX()); + CPPUNIT_ASSERT_EQUAL(10_hmm, aRange.getMaxX()); + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMinY()); + CPPUNIT_ASSERT_EQUAL(10_hmm, aRange.getMaxY()); + + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getHeight()); + + auto aRectangle = aRange.toToolsRect(); + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(6, 6, 10, 10), aRectangle); + } +} } // end anonymous namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index 63a112813bd3..1c06b2a09e9a 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -970,10 +971,8 @@ void SdrObject::RecalcBoundRect() if ((getSdrModelFromSdrObject().isLocked()) || comphelper::IsFuzzing()) return; - auto const& rRectangle = getOutRectangle(); - // central new method which will calculate the BoundRect using primitive geometry - if (!rRectangle.IsEmpty()) + if (!isOutRectangleEmpty()) return; // Use view-independent data - we do not want any connections @@ -1428,24 +1427,32 @@ void SdrObject::NbcMove(const Size& rSize) void SdrObject::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) { - bool bXMirr=(xFact.GetNumerator()<0) != (xFact.GetDenominator()<0); - bool bYMirr=(yFact.GetNumerator()<0) != (yFact.GetDenominator()<0); - if (bXMirr || bYMirr) { + bool bXMirror = (xFact.GetNumerator() < 0) != (xFact.GetDenominator() < 0); + bool bYMirror = (yFact.GetNumerator() < 0) != (yFact.GetDenominator() < 0); + if (bXMirror || bYMirror) + { Point aRef1(GetSnapRect().Center()); - if (bXMirr) { + if (bXMirror) + { Point aRef2(aRef1); aRef2.AdjustY( 1 ); - NbcMirrorGluePoints(aRef1,aRef2); + NbcMirrorGluePoints(aRef1, aRef2); } - if (bYMirr) { + if (bYMirror) + { Point aRef2(aRef1); aRef2.AdjustX( 1 ); - NbcMirrorGluePoints(aRef1,aRef2); + NbcMirrorGluePoints(aRef1, aRef2); } } - auto aRectangle = getOutRectangle(); - ResizeRect(aRectangle, rRef, xFact, yFact); - setOutRectangle(aRectangle); + + auto eUnit = getSdrModelFromSdrObject().getUnit(); + gfx::Tuple2DL aReference{ + gfx::Length::from(eUnit, rRef.X()), + gfx::Length::from(eUnit, rRef.Y())}; + double fFactorX = xFact.IsValid() ? double(xFact) : 1.0; + double fFactorY = yFact.IsValid() ? double(yFact) : 1.0; + svx::resizeRange(m_aOutterRange, aReference, fFactorX, fFactorY); SetBoundAndSnapRectsDirty(); } diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx index 23c7495ad7d7..d4c6ce015b47 100644 --- a/svx/source/svdraw/svdtrans.cxx +++ b/svx/source/svdraw/svdtrans.cxx @@ -61,6 +61,22 @@ void ResizeRect(tools::Rectangle& rRect, const Point& rRef, const Fraction& rxFa rRect.Normalize(); } +namespace svx +{ + +void resizeRange(gfx::Range2DLWrap& rRange, gfx::Tuple2DL const& rReference, double fFactorX, double fFactorY) +{ + auto left = rReference.getX() + ((rRange.getMinX() - rReference.getX()) * fFactorX); + auto right = rReference.getX() + ((rRange.getMaxX() - rReference.getX()) * fFactorX); + + auto top = rReference.getY() + ((rRange.getMinY() - rReference.getY()) * fFactorY); + auto bottom = rReference.getY() + ((rRange.getMaxY() - rReference.getY()) * fFactorY); + + rRange = gfx::Range2DLWrap(left, top, right, bottom, rRange.getUnit()); +} + +} // end svx namespace + void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact) { -- cgit