summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tools/poly.hxx30
-rw-r--r--tools/CppunitTest_tools_test.mk1
-rw-r--r--tools/qa/cppunit/test_poly.cxx54
-rw-r--r--tools/source/generic/poly.cxx4
-rw-r--r--tools/source/generic/poly2.cxx22
5 files changed, 111 insertions, 0 deletions
diff --git a/include/tools/poly.hxx b/include/tools/poly.hxx
index de03619eaf31..9caec8bbe210 100644
--- a/include/tools/poly.hxx
+++ b/include/tools/poly.hxx
@@ -262,6 +262,36 @@ public:
explicit PolyPolygon(const ::basegfx::B2DPolyPolygon& rPolyPolygon);
};
+template< typename charT, typename traits >
+inline std::basic_ostream<charT, traits> & operator <<(
+ std::basic_ostream<charT, traits> & stream, const Polygon& poly )
+{
+ stream << "<" << poly.GetSize() << ":";
+ for (sal_uInt16 i = 0; i < poly.GetSize(); i++)
+ {
+ if (i > 0)
+ stream << "--";
+ stream << poly.GetPoint(i);
+ }
+ stream << ">";
+ return stream;
+}
+
+template< typename charT, typename traits >
+inline std::basic_ostream<charT, traits> & operator <<(
+ std::basic_ostream<charT, traits> & stream, const PolyPolygon& poly )
+{
+ stream << "[" << poly.Count() << ":";
+ for (sal_uInt16 i = 0; i < poly.Count(); i++)
+ {
+ if (i > 0)
+ stream << ",";
+ stream << poly.GetObject(i);
+ }
+ stream << "]";
+ return stream;
+}
+
} /* namespace tools */
typedef std::vector< tools::PolyPolygon > PolyPolyVector;
diff --git a/tools/CppunitTest_tools_test.mk b/tools/CppunitTest_tools_test.mk
index ae22813a61fd..96fb96b08117 100644
--- a/tools/CppunitTest_tools_test.mk
+++ b/tools/CppunitTest_tools_test.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \
tools/qa/cppunit/test_inetmime \
tools/qa/cppunit/test_json_writer \
tools/qa/cppunit/test_pathutils \
+ tools/qa/cppunit/test_poly \
tools/qa/cppunit/test_reversemap \
tools/qa/cppunit/test_stream \
tools/qa/cppunit/test_urlobj \
diff --git a/tools/qa/cppunit/test_poly.cxx b/tools/qa/cppunit/test_poly.cxx
new file mode 100644
index 000000000000..f966f5317a48
--- /dev/null
+++ b/tools/qa/cppunit/test_poly.cxx
@@ -0,0 +1,54 @@
+/* -*- 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 <tools/poly.hxx>
+
+namespace
+{
+class Test : public CppUnit::TestFixture
+{
+public:
+ void testTdf137068();
+
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testTdf137068);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void Test::testTdf137068()
+{
+ // Make sure PolyPolygon::Clip() does not break bezier curves.
+ const Point points[] = { { 1337, 411 }, { 1337, 471 }, { 1313, 530 }, { 1268, 582 } };
+ const PolyFlags flags[]
+ = { PolyFlags::Normal, PolyFlags::Control, PolyFlags::Control, PolyFlags::Normal };
+ tools::Polygon polygon(4, points, flags);
+ tools::PolyPolygon polyPolygon(polygon);
+ polyPolygon.Clip(tools::Rectangle(Point(0, 0), Size(1920, 1080)));
+ // operator== is stupid and just compares pointers, compare data manually
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), polyPolygon.Count());
+ tools::Polygon result = polyPolygon.GetObject(0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4), result.GetSize());
+ CPPUNIT_ASSERT_EQUAL(points[0], result.GetPoint(0));
+ CPPUNIT_ASSERT_EQUAL(points[1], result.GetPoint(1));
+ CPPUNIT_ASSERT_EQUAL(points[2], result.GetPoint(2));
+ CPPUNIT_ASSERT_EQUAL(points[3], result.GetPoint(3));
+ CPPUNIT_ASSERT_EQUAL(flags[0], result.GetFlags(0));
+ CPPUNIT_ASSERT_EQUAL(flags[1], result.GetFlags(1));
+ CPPUNIT_ASSERT_EQUAL(flags[2], result.GetFlags(2));
+ CPPUNIT_ASSERT_EQUAL(flags[3], result.GetFlags(3));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx
index 73531236f522..f4631dfb1d86 100644
--- a/tools/source/generic/poly.cxx
+++ b/tools/source/generic/poly.cxx
@@ -1425,6 +1425,10 @@ void Polygon::Rotate( const Point& rCenter, double fSin, double fCos )
void Polygon::Clip( const tools::Rectangle& rRect )
{
+ // This algorithm is broken for bezier curves, they would get converted to lines.
+ // Use PolyPolygon::Clip().
+ assert( !HasFlags());
+
// #105251# Justify rect before edge filtering
tools::Rectangle aJustifiedRect( rRect );
aJustifiedRect.Justify();
diff --git a/tools/source/generic/poly2.cxx b/tools/source/generic/poly2.cxx
index 2534fb63b029..8825ad049841 100644
--- a/tools/source/generic/poly2.cxx
+++ b/tools/source/generic/poly2.cxx
@@ -27,6 +27,7 @@
#include <tools/gen.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolypolygoncutter.hxx>
+#include <basegfx/polygon/b2dpolygonclipper.hxx>
namespace tools {
@@ -280,6 +281,27 @@ void PolyPolygon::Clip( const tools::Rectangle& rRect )
if ( !nPolyCount )
return;
+ // If there are bezier curves involved, Polygon::Clip() is broken.
+ // Use a temporary B2DPolyPolygon for the clipping.
+ for ( i = 0; i < nPolyCount; i++ )
+ {
+ if(mpImplPolyPolygon->mvPolyAry[i].HasFlags())
+ {
+ const basegfx::B2DPolyPolygon aPoly(
+ basegfx::utils::clipPolyPolygonOnRange(
+ getB2DPolyPolygon(),
+ basegfx::B2DRange(
+ rRect.Left(),
+ rRect.Top(),
+ rRect.Right() + 1,
+ rRect.Bottom() + 1),
+ true,
+ false));
+ *this = PolyPolygon( aPoly );
+ return;
+ }
+ }
+
// Clip every polygon, deleting the empty ones
for ( i = 0; i < nPolyCount; i++ )
mpImplPolyPolygon->mvPolyAry[i].Clip( rRect );