[Libreoffice-commits] core.git: 2 commits - sw/inc sw/qa sw/source
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Tue Oct 5 06:02:02 UTC 2021
sw/inc/swrect.hxx | 17 +++++++++++++++++
sw/qa/core/test_rect.cxx | 22 ++++++++++++++++++++++
sw/source/core/bastyp/swrect.cxx | 6 ------
sw/source/core/view/viewimp.cxx | 26 ++++++++++++++++++++++++++
4 files changed, 65 insertions(+), 6 deletions(-)
New commits:
commit 71429b93ec0687bbbedcbb776b38c981f4017177
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 08:01:42 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/+/123077
Tested-by: Jenkins
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 e2243bb1ad88..abb2ef6b174a 100644
--- a/sw/source/core/view/viewimp.cxx
+++ b/sw/source/core/view/viewimp.cxx
@@ -126,6 +126,32 @@ bool SwViewShellImp::AddPaintRect( const SwRect &rRect )
m_pPaintRegion.reset(new SwRegionRects);
m_pPaintRegion->ChangeOrigin(rArea);
}
+ if(!m_pPaintRegion->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_pPaintRegion->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_pPaintRegion->size() > 1)
+ {
+ SwRect& last2 = (*m_pPaintRegion)[m_pPaintRegion->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_pPaintRegion->pop_back();
+ return true;
+ }
+ }
+ return true;
+ }
+ }
(*m_pPaintRegion) += rRect;
return true;
}
commit 8e49016473f0142cb07a1b30f4073f3e73aa4747
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 08:01:31 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/+/123076
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/sw/inc/swrect.hxx b/sw/inc/swrect.hxx
index f6d8430b9d11..b4db7384f456 100644
--- a/sw/inc/swrect.hxx
+++ b/sw/inc/swrect.hxx
@@ -251,6 +251,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
index 755dbb91bb6e..cfb9fa63a04f 100644
--- a/sw/qa/core/test_rect.cxx
+++ b/sw/qa/core/test_rect.cxx
@@ -17,15 +17,37 @@
class RectUnittest : public CppUnit::TestFixture
{
public:
+ void testBasic();
void testUnion();
void testIntersection();
CPPUNIT_TEST_SUITE(RectUnittest);
+ CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testUnion);
CPPUNIT_TEST(testIntersection);
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());
+}
+
void RectUnittest::testUnion()
{
SwRect rect1(Point(10, 10), Size(10, 10));
diff --git a/sw/source/core/bastyp/swrect.cxx b/sw/source/core/bastyp/swrect.cxx
index 8f7131aae47c..4a25b8b22742 100644
--- a/sw/source/core/bastyp/swrect.cxx
+++ b/sw/source/core/bastyp/swrect.cxx
@@ -134,12 +134,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