summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drawinglayer/CppunitTest_drawinglayer_border.mk35
-rw-r--r--drawinglayer/Module_drawinglayer.mk4
-rw-r--r--drawinglayer/qa/unit/border.cxx82
-rw-r--r--drawinglayer/source/primitive2d/borderlineprimitive2d.cxx2
4 files changed, 122 insertions, 1 deletions
diff --git a/drawinglayer/CppunitTest_drawinglayer_border.mk b/drawinglayer/CppunitTest_drawinglayer_border.mk
new file mode 100644
index 000000000000..d477c4ecb09b
--- /dev/null
+++ b/drawinglayer/CppunitTest_drawinglayer_border.mk
@@ -0,0 +1,35 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,drawinglayer_border))
+
+$(eval $(call gb_CppunitTest_use_api,drawinglayer_border,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,drawinglayer_border, \
+ basegfx \
+ cppu \
+ sal \
+ salhelper \
+ drawinglayer \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,drawinglayer_border,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,drawinglayer_border, \
+ drawinglayer/qa/unit/border \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/drawinglayer/Module_drawinglayer.mk b/drawinglayer/Module_drawinglayer.mk
index 52f2482fc714..6d329e95c60a 100644
--- a/drawinglayer/Module_drawinglayer.mk
+++ b/drawinglayer/Module_drawinglayer.mk
@@ -13,4 +13,8 @@ $(eval $(call gb_Module_add_targets,drawinglayer,\
Library_drawinglayer \
))
+$(eval $(call gb_Module_add_slowcheck_targets,drawinglayer,\
+ CppunitTest_drawinglayer_border \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/drawinglayer/qa/unit/border.cxx b/drawinglayer/qa/unit/border.cxx
new file mode 100644
index 000000000000..40fa12280e3a
--- /dev/null
+++ b/drawinglayer/qa/unit/border.cxx
@@ -0,0 +1,82 @@
+/* -*- 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 <cppunit/plugin/TestPlugIn.h>
+
+#include <com/sun/star/table/BorderLineStyle.hpp>
+
+#include <drawinglayer/geometry/viewinformation2d.hxx>
+#include <drawinglayer/primitive2d/borderlineprimitive2d.hxx>
+#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
+
+using namespace com::sun::star;
+
+namespace
+{
+
+class DrawinglayerBorderTest : public CppUnit::TestFixture
+{
+public:
+ void testDoubleDecompositionSolid();
+
+ CPPUNIT_TEST_SUITE(DrawinglayerBorderTest);
+ CPPUNIT_TEST(testDoubleDecompositionSolid);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void DrawinglayerBorderTest::testDoubleDecompositionSolid()
+{
+ // Create a border line primitive that's similar to the one from the bugdoc:
+ // 1.47 pixels is 0.03cm at 130% zoom and 96 DPI.
+ basegfx::B2DPoint aStart(0, 20);
+ basegfx::B2DPoint aEnd(100, 20);
+ double fLeftWidth = 1.47;
+ double fDistance = 1.47;
+ double fRightWidth = 1.47;
+ double fExtendLeftStart = 0;
+ double fExtendLeftEnd = 0;
+ double fExtendRightStart = 0;
+ double fExtendRightEnd = 0;
+ basegfx::BColor aColorRight;
+ basegfx::BColor aColorLeft;
+ basegfx::BColor aColorGap;
+ bool bHasGapColor = false;
+ sal_Int16 nStyle = table::BorderLineStyle::DOUBLE;
+ drawinglayer::primitive2d::BorderLinePrimitive2D aBorder(aStart, aEnd, fLeftWidth, fDistance, fRightWidth, fExtendLeftStart, fExtendLeftEnd, fExtendRightStart, fExtendRightEnd, aColorRight, aColorLeft, aColorGap, bHasGapColor, nStyle);
+
+ // Decompose it into polygons.
+ drawinglayer::geometry::ViewInformation2D aView;
+ drawinglayer::primitive2d::Primitive2DContainer aContainer = aBorder.get2DDecomposition(aView);
+
+ // Make sure it results in two borders as it's a double one.
+ CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(2), aContainer.size());
+
+ // Get the inside line.
+ auto pInside = dynamic_cast<const drawinglayer::primitive2d::PolyPolygonColorPrimitive2D*>(aContainer[0].get());
+ CPPUNIT_ASSERT(pInside);
+
+ // Make sure the inside line's height is fLeftWidth.
+ const basegfx::B2DPolyPolygon& rPolyPolygon = pInside->getB2DPolyPolygon();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), rPolyPolygon.count());
+ const basegfx::B2DPolygon& rPolygon = rPolyPolygon.getB2DPolygon(0);
+ const basegfx::B2DRange& rRange = rPolygon.getB2DRange();
+ // This was 2.47, i.e. the width of the inner line was 1 unit (in the bugdoc's case: 1 pixel) wider than expected.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fLeftWidth, rRange.getHeight(), basegfx::fTools::getSmallValue());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DrawinglayerBorderTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
index b2df3a35b007..4a6a15018715 100644
--- a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
@@ -63,7 +63,7 @@ primitive2d::Primitive2DReference makeSolidLinePrimitive(
const basegfx::B2DVector& rVector, const basegfx::BColor& rColor, double fLineWidth, double fGap)
{
const basegfx::B2DVector aPerpendicular = basegfx::getPerpendicular(rVector);
- const basegfx::B2DVector aLineWidthOffset = ((fLineWidth + 1.0) * 0.5) * aPerpendicular;
+ const basegfx::B2DVector aLineWidthOffset = (fLineWidth * 0.5) * aPerpendicular;
basegfx::B2DPolygon aPolygon;
aPolygon.append(rStart + aLineWidthOffset);