basegfx/test/LengthUnitTest.cxx        |   16 +++++++++++++++
 include/basegfx/units/Range2DLWrap.hxx |   27 +++++++++++++++++++++++--
 include/svx/svdobj.hxx                 |    4 ++-
 include/svx/svdomeas.hxx               |    2 -
 include/svx/svdpage.hxx                |   13 ++++++++----
 svx/source/svdraw/svdobj.cxx           |   35 +++++++++++++++++++++------------
 svx/source/svdraw/svdpage.cxx          |   21 +++++++++++--------
 sw/source/core/draw/dcontact.cxx       |    9 ++++----
 sw/source/core/draw/dflyobj.cxx        |    6 ++---
 9 files changed, 97 insertions(+), 36 deletions(-)

New commits:
commit 806ade8c19031370727b67c8dd3b36ca878cc91c
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Feb 8 10:42:19 2023 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Wed Feb 8 10:42:19 2023 +0900

    use Range2DLWrap for "OutRectangle" in SdrObject
    
    Change-Id: I243b44a84bc09991744009ae24ac7657d493c5cf

diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index 6b779775bc3d..8d72bed2af9d 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -34,6 +34,7 @@
 #include <tools/gen.hxx>
 #include <unotools/resmgr.hxx>
 #include <unotools/weakref.hxx>
+#include <basegfx/units/Range2DLWrap.hxx>
 #include <osl/diagnose.h>
 #include <typeinfo>
 
@@ -899,7 +900,8 @@ protected:
     void resetOutRectangle();
     void moveOutRectangle(sal_Int32 nXDelta, sal_Int32 nYDelta);
 
-    mutable tools::Rectangle m_aOutRect;     // surrounding rectangle for 
Paint (incl. LineWidth, ...)
+    mutable gfx::Range2DLWrap m_aOutterRange; // surrounding rectangle for 
Paint (incl. LineWidth, ...)
+
     Point                       m_aAnchor;      // anchor position (Writer)
     SdrObjUserCall*             m_pUserCall;
     std::unique_ptr<SdrObjPlusData>
diff --git a/include/svx/svdomeas.hxx b/include/svx/svdomeas.hxx
index cf0f06e3fb5b..7ddf4d7e3b62 100644
--- a/include/svx/svdomeas.hxx
+++ b/include/svx/svdomeas.hxx
@@ -65,7 +65,7 @@ private:
     {
         bTextDirty=true;
         SetTextSizeDirty();
-        if (!m_aOutRect.IsEmpty())
+        if (!getOutRectangle().IsEmpty())
         {
             SetBoundRectDirty();
             SetBoundAndSnapRectsDirty(/*bNotMyself*/true);
diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx
index c7a6115646b3..de6827173c47 100644
--- a/include/svx/svdpage.hxx
+++ b/include/svx/svdpage.hxx
@@ -398,6 +398,14 @@ public:
     tools::Long upperUnit() const { return maUpper.as(meUnit); }
     tools::Long lowerUnit() const { return maLower.as(meUnit); }
 
+    bool operator==(Border const& other) const
+    {
+        return maLeft == other.maLeft
+        &&  maRight == other.maRight
+        &&  maUpper == other.maUpper
+        &&  maLower == other.maLower;
+    }
+
     tools::Rectangle toToolsRect() const
     {
         return tools::Rectangle(leftUnit(), upperUnit(), rightUnit(), 
lowerUnit());
@@ -588,10 +596,7 @@ public:
         return maBorder;
     }
 
-    virtual void setBorder(svx::Border const& rBorder)
-    {
-        maBorder = rBorder;
-    }
+    virtual void setBorder(svx::Border const& rBorder);
 
     virtual void  SetBorder(sal_Int32 nLeft, sal_Int32 nUpper, sal_Int32 
nRight, sal_Int32 Lower);
     virtual void  SetLeftBorder(sal_Int32 nBorder);
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index f9e061d59e17..c04a5bdcf49b 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -34,6 +34,7 @@
 #include <basegfx/polygon/b2dpolygontools.hxx>
 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/units/Range2DLWrap.hxx>
 #include <basegfx/range/b2drange.hxx>
 #include <drawinglayer/processor2d/contourextractor2d.hxx>
 #include <drawinglayer/processor2d/linegeometryextractor2d.hxx>
@@ -969,13 +970,13 @@ void SdrObject::RecalcBoundRect()
 
     if (!aRange.isEmpty())
     {
-        tools::Rectangle aNewRectangle(
-            tools::Long(floor(aRange.getMinX())),
-            tools::Long(floor(aRange.getMinY())),
-            tools::Long(ceil(aRange.getMaxX())),
-            tools::Long(ceil(aRange.getMaxY())));
-        setOutRectangle(aNewRectangle);
-        return;
+        const basegfx::B2DRange aRoundedRange(
+            std::floor(aRange.getMinX()),
+            std::floor(aRange.getMinY()),
+            std::ceil(aRange.getMaxX()),
+            std::ceil(aRange.getMaxY()));
+        m_aOutterRange = gfx::Range2DLWrap::create(aRoundedRange, 
getSdrModelFromSdrObject().getUnit());
+        setOutRectangle(m_aOutterRange.toToolsRect());
     }
 }
 
@@ -3181,27 +3182,37 @@ void 
SdrObject::ForceMetricToItemPoolMetric(basegfx::B2DPolyPolygon& rPolyPolygo
 
 const tools::Rectangle& SdrObject::getOutRectangle() const
 {
-    return m_aOutRect;
+    return m_aOutterRange.toToolsRect();
 }
 
 void SdrObject::setOutRectangleConst(tools::Rectangle const& rRectangle) const
 {
-    m_aOutRect = rRectangle;
+    auto eUnit = getSdrModelFromSdrObject().getUnit();
+    m_aOutterRange = gfx::Range2DLWrap::create(rRectangle, eUnit);
 }
 
 void SdrObject::setOutRectangle(tools::Rectangle const& rRectangle)
 {
-    m_aOutRect = rRectangle;
+    auto eUnit = getSdrModelFromSdrObject().getUnit();
+    m_aOutterRange = gfx::Range2DLWrap::create(rRectangle, eUnit);
 }
 
 void SdrObject::resetOutRectangle()
 {
-    m_aOutRect = tools::Rectangle();
+    auto eUnit = getSdrModelFromSdrObject().getUnit();
+    m_aOutterRange = gfx::Range2DLWrap(eUnit);
 }
 
 void SdrObject::moveOutRectangle(sal_Int32 nXDelta, sal_Int32 nYDelta)
 {
-    m_aOutRect.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);
+
+    m_aOutterRange.shift(xDelta, yDelta);
 }
 
 E3dScene* DynCastE3dScene(SdrObject* pObj)
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 5fe6ffcb4150..fdcd3ce4e94f 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -1429,16 +1429,11 @@ rtl::Reference<SdrPage> SdrPage::CloneSdrPage(SdrModel& 
rTargetModel) const
 
 void SdrPage::setSize(gfx::Size2DLWrap const& rSize)
 {
-    bool bChanged = false;
-
-    if (maSize != rSize)
-    {
-        maSize = rSize;
-        bChanged = true;
-    }
+    if (maSize == rSize)
+        return;
 
-    if (bChanged)
-        SetChanged();
+    maSize = rSize;
+    SetChanged();
 }
 
 void SdrPage::SetOrientation(Orientation eOri)
@@ -1462,6 +1457,14 @@ Orientation SdrPage::GetOrientation() const
     return Orientation::Portrait;
 }
 
+void SdrPage::setBorder(svx::Border const& rBorder)
+{
+    if (maBorder == rBorder)
+        return;
+
+    maBorder = rBorder;
+    SetChanged();
+}
 
 void  SdrPage::SetBorder(sal_Int32 nLeft, sal_Int32 nUpper, sal_Int32 nRight, 
sal_Int32 nLower)
 {
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index 156f73adc58a..d283f8a96bc0 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -2428,24 +2428,25 @@ void SwDrawVirtObj::NbcSetAnchorPos(const Point& rPnt)
 
 const tools::Rectangle& SwDrawVirtObj::GetCurrentBoundRect() const
 {
-    if (m_aOutRect.IsEmpty())
+    auto const& rRectangle = getOutRectangle();
+    if (rRectangle.IsEmpty())
     {
         const_cast<SwDrawVirtObj*>(this)->RecalcBoundRect();
     }
 
-    return m_aOutRect;
+    return rRectangle;
 }
 
 const tools::Rectangle& SwDrawVirtObj::GetLastBoundRect() const
 {
-    return m_aOutRect;
+    return getOutRectangle();
 }
 
 Point SwDrawVirtObj::GetOffset() const
 {
     // do NOT use IsEmpty() here, there is already a useful offset
     // in the position
-    if (m_aOutRect == tools::Rectangle())
+    if (getOutRectangle() == tools::Rectangle())
     {
         return Point();
     }
diff --git a/sw/source/core/draw/dflyobj.cxx b/sw/source/core/draw/dflyobj.cxx
index 9e2b96ce3118..3095d5a2a6f4 100644
--- a/sw/source/core/draw/dflyobj.cxx
+++ b/sw/source/core/draw/dflyobj.cxx
@@ -559,7 +559,7 @@ void SwVirtFlyDrawObj::SetRect() const
 const tools::Rectangle& SwVirtFlyDrawObj::GetCurrentBoundRect() const
 {
     SetRect();
-    return m_aOutRect;
+    return getOutRectangle();
 }
 
 const tools::Rectangle& SwVirtFlyDrawObj::GetLastBoundRect() const
@@ -580,7 +580,7 @@ void SwVirtFlyDrawObj::RecalcSnapRect()
 const tools::Rectangle& SwVirtFlyDrawObj::GetSnapRect()  const
 {
     SetRect();
-    return m_aOutRect;
+    return getOutRectangle();
 }
 
 void SwVirtFlyDrawObj::SetSnapRect(const tools::Rectangle& )
@@ -601,7 +601,7 @@ void SwVirtFlyDrawObj::NbcSetSnapRect(const 
tools::Rectangle& )
 const tools::Rectangle& SwVirtFlyDrawObj::GetLogicRect() const
 {
     SetRect();
-    return m_aOutRect;
+    return getOutRectangle();
 }
 
 void SwVirtFlyDrawObj::SetLogicRect(const tools::Rectangle& )
commit 6a4dd78ec19ab81459691baf42e32d333f13a7ad
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Feb 8 10:41:22 2023 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Wed Feb 8 10:41:22 2023 +0900

    gfx::Length updates
    
    Change-Id: I4c5936bb28456ababcfd4df4128e00b3d07d3b93

diff --git a/basegfx/test/LengthUnitTest.cxx b/basegfx/test/LengthUnitTest.cxx
index c3445b41b3ee..2f597f0274d2 100644
--- a/basegfx/test/LengthUnitTest.cxx
+++ b/basegfx/test/LengthUnitTest.cxx
@@ -288,6 +288,22 @@ public:
             CPPUNIT_ASSERT_EQUAL(100_hmm, aRange.getMaxY());
             CPPUNIT_ASSERT_EQUAL(0_hmm, aRange.getWidth());
             CPPUNIT_ASSERT_EQUAL(0_hmm, aRange.getHeight());
+
+            auto aRectFromRange = aRange.toToolsRect();
+            CPPUNIT_ASSERT_EQUAL(tools::Long(100), aRectFromRange.Left());
+            CPPUNIT_ASSERT_EQUAL(tools::Long(100), aRectFromRange.Top());
+            CPPUNIT_ASSERT_EQUAL(tools::Long(100), aRectFromRange.Right());
+            CPPUNIT_ASSERT_EQUAL(tools::Long(100), aRectFromRange.Bottom());
+            CPPUNIT_ASSERT_EQUAL(tools::Long(0), aRectFromRange.GetWidth());
+            CPPUNIT_ASSERT_EQUAL(tools::Long(0), aRectFromRange.GetHeight());
+        }
+        {
+            basegfx::B2DRange aB2DRange(0.5, 0.5, 1.5, 1.5);
+            gfx::Range2DL aRange = gfx::Range2DLWrap::create(aB2DRange, 
gfx::LengthUnit::hmm);
+            CPPUNIT_ASSERT_EQUAL(180_emu, aRange.getMinX());
+            CPPUNIT_ASSERT_EQUAL(180_emu, aRange.getMinY());
+            CPPUNIT_ASSERT_EQUAL(540_emu, aRange.getMaxX());
+            CPPUNIT_ASSERT_EQUAL(540_emu, aRange.getMaxY());
         }
     }
 
diff --git a/include/basegfx/units/Range2DLWrap.hxx 
b/include/basegfx/units/Range2DLWrap.hxx
index cb15a20d5d4d..196e751ada9a 100644
--- a/include/basegfx/units/Range2DLWrap.hxx
+++ b/include/basegfx/units/Range2DLWrap.hxx
@@ -36,6 +36,20 @@ public:
         return Range2DLWrap(left, top, right, bottom, eUnit);
     }
 
+    static Range2DLWrap create(basegfx::B2DRange const& rRange2D,
+                               LengthUnit eUnit = LengthUnit::hmm)
+    {
+        if (rRange2D.isEmpty())
+            return Range2DLWrap(eUnit);
+
+        auto left = Length::from(eUnit, rRange2D.getMinX());
+        auto top = Length::from(eUnit, rRange2D.getMinY());
+        auto right = Length::from(eUnit, rRange2D.getMaxX());
+        auto bottom = Length::from(eUnit, rRange2D.getMaxY());
+
+        return Range2DLWrap(left, top, right, bottom, eUnit);
+    }
+
     Range2DLWrap(LengthUnit eUnit = LengthUnit::hmm)
         : Range2DL()
         , meUnit(eUnit)
@@ -61,8 +75,17 @@ public:
             auto top = getMinY().as(meUnit);
             auto right = getMaxX().as(meUnit);
             auto bottom = getMaxY().as(meUnit);
-            maRectangle = tools::Rectangle(basegfx::fround(left), 
basegfx::fround(top),
-                                           basegfx::fround(right), 
basegfx::fround(bottom));
+
+            if (left == right && top == bottom)
+            {
+                maRectangle = tools::Rectangle();
+                maRectangle.Move(basegfx::fround(left), basegfx::fround(top));
+            }
+            else
+            {
+                maRectangle = tools::Rectangle(basegfx::fround(left), 
basegfx::fround(top),
+                                               basegfx::fround(right), 
basegfx::fround(bottom));
+            }
         }
         return maRectangle;
     }

Reply via email to