[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - 2 commits - sw/CppunitTest_sw_uwriter.mk sw/inc sw/qa sw/source

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Tue Oct 5 11:08:10 UTC 2021


 sw/CppunitTest_sw_uwriter.mk     |    1 
 sw/inc/swrect.hxx                |   17 +++++++++++++
 sw/qa/core/test_rect.cxx         |   49 +++++++++++++++++++++++++++++++++++++++
 sw/source/core/bastyp/swrect.cxx |    6 ----
 sw/source/core/view/viewimp.cxx  |   26 ++++++++++++++++++++
 5 files changed, 93 insertions(+), 6 deletions(-)

New commits:
commit 90aa650da26b2359bbf055b8d952fbc60838890f
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Oct 4 22:58:24 2021 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Oct 5 13:07:50 2021 +0200

    try to merge rectangles already in AddPaintRect()
    
    It turns out that e.g. adding a new line in Writer results
    in a number of paint rectangles that actually often line up and
    form a large rectangle. So try to detect these and merge them
    directly, resulting in less work for SwRegionsRects::Compress().
    
    Change-Id: If89ae9463d9c80a1492431afd37bcedfd24bea2d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123079
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/sw/source/core/view/viewimp.cxx b/sw/source/core/view/viewimp.cxx
index 92bde3c9bab5..4f4309d38f88 100644
--- a/sw/source/core/view/viewimp.cxx
+++ b/sw/source/core/view/viewimp.cxx
@@ -131,6 +131,32 @@ bool SwViewShellImp::AddPaintRect( const SwRect &rRect )
             m_pRegion.reset(new SwRegionRects);
             m_pRegion->ChangeOrigin(rArea);
         }
+        if(!m_pRegion->empty())
+        {
+            // This function often gets called with rectangles that line up vertically.
+            // Try to extend the last one downwards to include the new one.
+            SwRect& last = m_pRegion->back();
+            if(last.Left() == rRect.Left() && last.Width() == rRect.Width()
+                && last.Bottom() + 1 >= rRect.Top() && last.Bottom() <= rRect.Bottom())
+            {
+                last = SwRect( last.TopLeft(), rRect.BottomRight());
+                // And these rectangles lined up vertically often come up in groups
+                // that line up horizontally. Try to extend the previous rectangle
+                // to the right to include the last one.
+                if(m_pRegion->size() > 1)
+                {
+                    SwRect& last2 = m_pRegion->at(m_pRegion->size() - 2);
+                    if(last2.Top() == last.Top() && last2.Height() == last.Height()
+                        && last2.Right() + 1 >= last.Left() && last2.Right() <= last2.Right())
+                    {
+                        last2 = SwRect( last.TopLeft(), rRect.BottomRight());
+                        m_pRegion->pop_back();
+                        return true;
+                    }
+                }
+                return true;
+            }
+        }
         (*m_pRegion) += rRect;
         return true;
     }
commit c3f00a512b82c8260fa3ba32dca37235904a2936
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Oct 4 21:19:13 2021 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Oct 5 13:07:36 2021 +0200

    fix broken SwRect corner getters
    
    BottomRight() wasn't equal to Point( Right(), Bottom()). Smart *sigh*.
    
    Change-Id: I0af1c018cdf10a4ff23d95752004e565b4102b13
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123078
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/sw/CppunitTest_sw_uwriter.mk b/sw/CppunitTest_sw_uwriter.mk
index 6507224393dc..3a67143f0552 100644
--- a/sw/CppunitTest_sw_uwriter.mk
+++ b/sw/CppunitTest_sw_uwriter.mk
@@ -20,6 +20,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_uwriter, \
     sw/qa/core/test_ToxLinkProcessor \
     sw/qa/core/test_ToxTextGenerator \
     sw/qa/core/test_ToxMiscTest \
+    sw/qa/core/test_rect \
     sw/qa/core/test_region \
 ))
 
diff --git a/sw/inc/swrect.hxx b/sw/inc/swrect.hxx
index b41374e47bdc..4e0b21dd08b8 100644
--- a/sw/inc/swrect.hxx
+++ b/sw/inc/swrect.hxx
@@ -278,6 +278,23 @@ inline tools::Long SwRect::Bottom() const
     return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
 }
 
+inline Point SwRect::TopLeft() const
+{
+    return Point( Left(), Top());
+}
+inline Point SwRect::TopRight() const
+{
+    return Point( Right(), Top());
+}
+inline Point SwRect::BottomLeft() const
+{
+    return Point( Left(), Bottom());
+}
+inline Point SwRect::BottomRight() const
+{
+    return Point( Right(), Bottom());
+}
+
 inline bool SwRect::operator == ( const SwRect& rRect ) const
 {
     return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
diff --git a/sw/qa/core/test_rect.cxx b/sw/qa/core/test_rect.cxx
new file mode 100644
index 000000000000..1ad34c67e440
--- /dev/null
+++ b/sw/qa/core/test_rect.cxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <swrect.hxx>
+
+class RectUnittest : public CppUnit::TestFixture
+{
+public:
+    void testBasic();
+
+    CPPUNIT_TEST_SUITE(RectUnittest);
+    CPPUNIT_TEST(testBasic);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void RectUnittest::testBasic()
+{
+    SwRect rect(Point(10, 15), Size(20, 25));
+
+    CPPUNIT_ASSERT_EQUAL(rect, SwRect(10, 15, 20, 25));
+    CPPUNIT_ASSERT_EQUAL(rect, SwRect(Point(10, 15), Point(10 + 20 - 1, 15 + 25 - 1)));
+
+    CPPUNIT_ASSERT_EQUAL(tools::Long(20), rect.Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(25), rect.Height());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(10), rect.Left());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(15), rect.Top());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(10 + 20 - 1), rect.Right());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(15 + 25 - 1), rect.Bottom());
+
+    CPPUNIT_ASSERT_EQUAL(Point(rect.Left(), rect.Top()), rect.TopLeft());
+    CPPUNIT_ASSERT_EQUAL(Point(rect.Right(), rect.Top()), rect.TopRight());
+    CPPUNIT_ASSERT_EQUAL(Point(rect.Left(), rect.Bottom()), rect.BottomLeft());
+    CPPUNIT_ASSERT_EQUAL(Point(rect.Right(), rect.Bottom()), rect.BottomRight());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(RectUnittest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/bastyp/swrect.cxx b/sw/source/core/bastyp/swrect.cxx
index 1da034d60ab1..a72318229211 100644
--- a/sw/source/core/bastyp/swrect.cxx
+++ b/sw/source/core/bastyp/swrect.cxx
@@ -136,12 +136,6 @@ void SwRect::SetPosY( const tools::Long nNew ){ m_Point.setY(nNew); }
 Size  SwRect::Size_() const { return SSize(); }
 Size  SwRect::SwappedSize() const { return Size( m_Size.getHeight(), m_Size.getWidth() ); }
 
-Point SwRect::TopLeft() const { return Pos(); }
-Point SwRect::TopRight() const { return Point( m_Point.getX() + m_Size.getWidth(), m_Point.getY() ); }
-Point SwRect::BottomLeft() const { return Point( m_Point.getX(), m_Point.getY() + m_Size.getHeight() ); }
-Point SwRect::BottomRight() const
-    { return Point( m_Point.getX() + m_Size.getWidth(), m_Point.getY() + m_Size.getHeight() ); }
-
 tools::Long SwRect::GetLeftDistance( tools::Long nLimit ) const { return m_Point.getX() - nLimit; }
 tools::Long SwRect::GetBottomDistance( tools::Long nLim ) const { return nLim - m_Point.getY() - m_Size.getHeight();}
 tools::Long SwRect::GetTopDistance( tools::Long nLimit ) const { return m_Point.getY() - nLimit; }


More information about the Libreoffice-commits mailing list