include/svx/svdotext.hxx       |   26 ++++++++++++++++++++------
 svx/source/svdraw/svdocirc.cxx |   10 ++++++----
 svx/source/svdraw/svdotext.cxx |    4 +---
 svx/source/svdraw/svdotxtr.cxx |   40 ++++++++++++++++++++--------------------
 svx/source/table/svdotable.cxx |    2 +-
 5 files changed, 48 insertions(+), 34 deletions(-)

New commits:
commit a077e1df6f4904b1ea26449c9c2f5ce7870a1a11
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Feb 9 10:03:43 2023 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Thu Feb 9 10:03:43 2023 +0900

    use Range2DLWrap for the main rectangle in SdrTextObject
    
    Change-Id: I0d8ac090f9442fe561b4f87aa767185a987874c4

diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index a1cccb0804a4..4861eb3bf5ce 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -28,6 +28,7 @@
 #include <tools/datetime.hxx>
 #include <svl/style.hxx>
 #include <svx/svdtext.hxx>
+#include <svx/svdmodel.hxx>
 #include <svx/svxdllapi.h>
 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
 #include <memory>
@@ -165,31 +166,44 @@ protected:
     // The "aRect" is also the rect of RectObj and CircObj.
     // When mbTextFrame=true the text will be formatted into this rect
     // When mbTextFrame=false the text will be centered around its middle
-    tools::Rectangle maRectangle;
+    gfx::Range2DLWrap maRectangleRange;
 
     tools::Rectangle const& getRectangle() const
     {
-        return maRectangle;
+        return maRectangleRange.toToolsRect();
     }
 
     void setRectangle(tools::Rectangle const& rRectangle)
     {
-        maRectangle = rRectangle;
+        auto eUnit = getSdrModelFromSdrObject().getUnit();
+        maRectangleRange = gfx::Range2DLWrap::create(rRectangle, eUnit);
     }
 
     void setRectangleSize(sal_Int32 nWidth, sal_Int32 nHeight)
     {
-        maRectangle.SetSize(Size(nWidth, nHeight));
+        auto eUnit = getSdrModelFromSdrObject().getUnit();
+        auto width = gfx::Length::from(eUnit, nWidth);
+        auto height = gfx::Length::from(eUnit, nHeight);
+        maRectangleRange.setSize(width, height);
     }
 
     void moveRectangle(sal_Int32 nXDelta, sal_Int32 nYDelta)
     {
-        maRectangle.Move(nXDelta, nYDelta);
+        if (nXDelta == 0 && nYDelta == 0)
+            return;
+
+        auto eUnit = getSdrModelFromSdrObject().getUnit();
+        auto xDelta = gfx::Length::from(eUnit, nXDelta);
+        auto yDelta = gfx::Length::from(eUnit, nYDelta);
+        maRectangleRange.shift(xDelta, yDelta);
     }
 
     void moveRectanglePosition(sal_Int32 nX, sal_Int32 nY)
     {
-        maRectangle.SetPos(Point(nX, nY));
+        auto eUnit = getSdrModelFromSdrObject().getUnit();
+        auto x = gfx::Length::from(eUnit, nX);
+        auto y = gfx::Length::from(eUnit, nY);
+        maRectangleRange.setPosition(x, y);
     }
 
     // The GeoStat contains the rotation and shear angles
diff --git a/svx/source/svdraw/svdocirc.cxx b/svx/source/svdraw/svdocirc.cxx
index ab8bc58ddf85..020551bcdf5e 100644
--- a/svx/source/svdraw/svdocirc.cxx
+++ b/svx/source/svdraw/svdocirc.cxx
@@ -706,8 +706,9 @@ bool SdrCircObj::MovCreate(SdrDragStat& rStat)
     ImpSetCreateParams(rStat);
     ImpCircUser* pU=static_cast<ImpCircUser*>(rStat.GetUser());
     rStat.SetActionRect(pU->aR);
-    setRectangle(pU->aR); // for ObjName
-    ImpJustifyRect(maRectangle);
+    auto aRectangle = pU->aR;
+    ImpJustifyRect(aRectangle);
+    setRectangle(aRectangle); // for ObjName
     nStartAngle=pU->nStart;
     nEndAngle=pU->nEnd;
     SetBoundRectDirty();
@@ -1048,8 +1049,9 @@ void SdrCircObj::NbcSetSnapRect(const tools::Rectangle& 
rRect)
         
NbcResize(maSnapRect.TopLeft(),Fraction(nWdt1,nWdt0),Fraction(nHgt1,nHgt0));
         NbcMove(Size(rRect.Left()-aSR0.Left(),rRect.Top()-aSR0.Top()));
     } else {
-        setRectangle(rRect);
-        ImpJustifyRect(maRectangle);
+        tools::Rectangle aRectangle(rRect);
+        ImpJustifyRect(aRectangle);
+        setRectangle(aRectangle);
     }
     SetBoundAndSnapRectsDirty();
     SetXPolyDirty();
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index d0263a607d2a..2a1bbb1dacb7 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -101,7 +101,7 @@ SdrTextObj::SdrTextObj(SdrModel& rSdrModel, SdrTextObj 
const & rSource)
     // #i25616#
     mbSupportTextIndentingOnLineWidthChange = true;
 
-    maRectangle = rSource.maRectangle;
+    maRectangleRange = rSource.maRectangleRange;
     maGeo = rSource.maGeo;
     maTextSize = rSource.maTextSize;
 
@@ -201,8 +201,6 @@ SdrTextObj::~SdrTextObj()
 
 void SdrTextObj::FitFrameToTextSize()
 {
-    ImpJustifyRect(maRectangle);
-
     SdrText* pText = getActiveText();
     if(pText==nullptr || !pText->GetOutlinerParaObject())
         return;
diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx
index 5c9f28f5115c..8ac600e3a02c 100644
--- a/svx/source/svdraw/svdotxtr.cxx
+++ b/svx/source/svdraw/svdotxtr.cxx
@@ -56,9 +56,9 @@ void SdrTextObj::NbcSetSnapRect(const tools::Rectangle& rRect)
     else
     {
         // No rotation or shear.
-
-        setRectangle(rRect);
-        ImpJustifyRect(maRectangle);
+        tools::Rectangle aRectangle(rRect);
+        ImpJustifyRect(aRectangle);
+        setRectangle(aRectangle);
 
         AdaptTextMinSize();
 
@@ -74,8 +74,9 @@ const tools::Rectangle& SdrTextObj::GetLogicRect() const
 
 void SdrTextObj::NbcSetLogicRect(const tools::Rectangle& rRect)
 {
-    setRectangle(rRect);
-    ImpJustifyRect(maRectangle);
+    tools::Rectangle aRectangle(rRect);
+    ImpJustifyRect(aRectangle);
+    setRectangle(aRectangle);
 
     AdaptTextMinSize();
 
@@ -126,7 +127,7 @@ void SdrTextObj::NbcResize(const Point& rRef, const 
Fraction& xFact, const Fract
         setRectangle(aRectangle);
         if (bYMirr)
         {
-            maRectangle.Normalize();
+            //maRectangle.Normalize();
             moveRectangle(aRectangle.Right() - aRectangle.Left(), 
aRectangle.Bottom() - aRectangle.Top());
             maGeo.nRotationAngle=18000_deg100;
             maGeo.RecalcSinCos();
@@ -134,7 +135,8 @@ void SdrTextObj::NbcResize(const Point& rRef, const 
Fraction& xFact, const Fract
     }
     else
     {
-        tools::Polygon aPol(Rect2Poly(getRectangle(), maGeo));
+        auto aRectangle = getRectangle();
+        tools::Polygon aPol(Rect2Poly(aRectangle, maGeo));
 
         for(sal_uInt16 a(0); a < aPol.GetSize(); a++)
         {
@@ -152,7 +154,6 @@ void SdrTextObj::NbcResize(const Point& rRef, const 
Fraction& xFact, const Fract
             aPol[3] = aPol0[2];
             aPol[4] = aPol0[1];
         }
-        tools::Rectangle aRectangle(getRectangle());
         Poly2Rect(aPol, aRectangle, maGeo);
         setRectangle(aRectangle);
     }
@@ -175,8 +176,6 @@ void SdrTextObj::NbcResize(const Point& rRef, const 
Fraction& xFact, const Fract
         }
     }
 
-    ImpJustifyRect(maRectangle);
-
     AdaptTextMinSize();
 
     if(mbTextFrame && !getSdrModelFromSdrObject().IsPasteResize())
@@ -191,12 +190,13 @@ void SdrTextObj::NbcResize(const Point& rRef, const 
Fraction& xFact, const Fract
 void SdrTextObj::NbcRotate(const Point& rRef, Degree100 nAngle, double sn, 
double cs)
 {
     SetGlueReallyAbsolute(true);
-    tools::Long dx = getRectangle().Right() - getRectangle().Left();
-    tools::Long dy = getRectangle().Bottom() - getRectangle().Top();
-    Point aPoint1(getRectangle().TopLeft());
+    tools::Rectangle aRectangle = getRectangle();
+    tools::Long dx = aRectangle.Right() - aRectangle.Left();
+    tools::Long dy = aRectangle.Bottom() - aRectangle.Top();
+    Point aPoint1(aRectangle.TopLeft());
     RotatePoint(aPoint1, rRef, sn, cs);
     Point aPoint2(aPoint1.X() + dx, aPoint1.Y() + dy);
-    tools::Rectangle aRectangle(aPoint1, aPoint2);
+    aRectangle = tools::Rectangle(aPoint1, aPoint2);
     setRectangle(aRectangle);
 
     if (maGeo.nRotationAngle==0_deg100) {
@@ -216,17 +216,17 @@ void SdrTextObj::NbcShear(const Point& rRef, Degree100 
/*nAngle*/, double tn, bo
 {
     SetGlueReallyAbsolute(true);
 
+    auto aRectangle = getRectangle();
     // when this is a SdrPathObj, aRect may be uninitialized
-    tools::Polygon aPol(Rect2Poly(getRectangle().IsEmpty() ? GetSnapRect() : 
getRectangle(), maGeo));
+    tools::Polygon aPol(Rect2Poly(aRectangle.IsEmpty() ? GetSnapRect() : 
aRectangle, maGeo));
 
     sal_uInt16 nPointCount=aPol.GetSize();
     for (sal_uInt16 i=0; i<nPointCount; i++) {
          ShearPoint(aPol[i],rRef,tn,bVShear);
     }
-    auto aRectangle = getRectangle();
     Poly2Rect(aPol, aRectangle, maGeo);
+    ImpJustifyRect(aRectangle);
     setRectangle(aRectangle);
-    ImpJustifyRect(maRectangle);
 
     if (mbTextFrame) {
         NbcAdjustTextFrameWidthAndHeight();
@@ -247,7 +247,8 @@ void SdrTextObj::NbcMirror(const Point& rRef1, const Point& 
rRef2)
          std::abs(rRef1.X()-rRef2.X())==std::abs(rRef1.Y()-rRef2.Y()))) {
         bRotate90=maGeo.nRotationAngle.get() % 9000 ==0;
     }
-    tools::Polygon aPol(Rect2Poly(getRectangle(),maGeo));
+    tools::Rectangle aRectangle = getRectangle();
+    tools::Polygon aPol(Rect2Poly(aRectangle, maGeo));
     sal_uInt16 i;
     sal_uInt16 nPointCount=aPol.GetSize();
     for (i=0; i<nPointCount; i++) {
@@ -260,7 +261,7 @@ void SdrTextObj::NbcMirror(const Point& rRef1, const Point& 
rRef2)
     aPol[2]=aPol0[3];
     aPol[3]=aPol0[2];
     aPol[4]=aPol0[1];
-    tools::Rectangle aRectangle = getRectangle();
+
     Poly2Rect(aPol, aRectangle, maGeo);
     setRectangle(aRectangle);
 
@@ -282,7 +283,6 @@ void SdrTextObj::NbcMirror(const Point& rRef1, const Point& 
rRef2)
         maGeo.RecalcTan();
     }
 
-    ImpJustifyRect(maRectangle);
     if (mbTextFrame) {
         NbcAdjustTextFrameWidthAndHeight();
     }
diff --git a/svx/source/table/svdotable.cxx b/svx/source/table/svdotable.cxx
index 25ab8715d307..b927bfbd2ebe 100644
--- a/svx/source/table/svdotable.cxx
+++ b/svx/source/table/svdotable.cxx
@@ -842,7 +842,7 @@ SdrTableObj::SdrTableObj(SdrModel& rSdrModel, SdrTableObj 
const & rSource)
     TableModelNotifyGuard aGuard( mpImpl.is() ? mpImpl->mxTable.get() : 
nullptr );
 
     maLogicRect = rSource.maLogicRect;
-    maRectangle = rSource.maRectangle;
+    maRectangleRange = rSource.maRectangleRange;
     maGeo = rSource.maGeo;
     meTextKind = rSource.meTextKind;
     mbTextFrame = rSource.mbTextFrame;

Reply via email to