1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/plugin/TestPlugIn.h>
14 #include <drawinglayer/geometry/viewinformation2d.hxx>
15 #include <drawinglayer/primitive2d/borderlineprimitive2d.hxx>
16 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
17 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
18 #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
19 #include <rtl/ref.hxx>
20 #include <test/bootstrapfixture.hxx>
21 #include <vcl/metaact.hxx>
22 #include <vcl/vclptr.hxx>
23 #include <vcl/virdev.hxx>
24 #include <editeng/borderline.hxx>
25 #include <svtools/borderhelper.hxx>
27 using namespace com::sun::star
;
31 class DrawinglayerBorderTest
: public test::BootstrapFixture
35 CPPUNIT_TEST_FIXTURE(DrawinglayerBorderTest
, testDoubleDecompositionSolid
)
37 // Create a border line primitive that's similar to the one from the bugdoc:
38 // 1.47 pixels is 0.03cm at 130% zoom and 96 DPI.
39 basegfx::B2DPoint
aStart(0, 20);
40 basegfx::B2DPoint
aEnd(100, 20);
41 double const fLeftWidth
= 1.47;
42 double const fDistance
= 1.47;
43 double const fRightWidth
= 1.47;
44 double const fExtendLeftStart
= 0;
45 double const fExtendLeftEnd
= 0;
46 double const fExtendRightStart
= 0;
47 double const fExtendRightEnd
= 0;
48 basegfx::BColor aColorRight
;
49 basegfx::BColor aColorLeft
;
50 const std::vector
<double> aDashing(svtools::GetLineDashing(SvxBorderLineStyle::DOUBLE
, 10.0));
51 const drawinglayer::attribute::StrokeAttribute
aStrokeAttribute(aDashing
);
52 std::vector
<drawinglayer::primitive2d::BorderLine
> aBorderlines
;
54 aBorderlines
.push_back(drawinglayer::primitive2d::BorderLine(
55 drawinglayer::attribute::LineAttribute(aColorLeft
, fLeftWidth
), fExtendLeftStart
,
56 fExtendLeftStart
, fExtendLeftEnd
, fExtendLeftEnd
));
58 aBorderlines
.push_back(drawinglayer::primitive2d::BorderLine(fDistance
));
60 aBorderlines
.push_back(drawinglayer::primitive2d::BorderLine(
61 drawinglayer::attribute::LineAttribute(aColorRight
, fRightWidth
), fExtendRightStart
,
62 fExtendRightStart
, fExtendRightEnd
, fExtendRightEnd
));
64 rtl::Reference
<drawinglayer::primitive2d::BorderLinePrimitive2D
> aBorder(
65 new drawinglayer::primitive2d::BorderLinePrimitive2D(aStart
, aEnd
, aBorderlines
,
68 // Decompose it into polygons.
69 drawinglayer::geometry::ViewInformation2D aView
;
70 drawinglayer::primitive2d::Primitive2DContainer aContainer
;
71 aBorder
->get2DDecomposition(aContainer
, aView
);
73 // Make sure it results in two borders as it's a double one.
74 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(2), aContainer
.size());
76 // Get the inside line, now a PolygonStrokePrimitive2D
77 auto pInside
= dynamic_cast<const drawinglayer::primitive2d::PolygonStrokePrimitive2D
*>(
79 CPPUNIT_ASSERT(pInside
);
81 // Make sure the inside line's height is fLeftWidth.
82 const double fLineWidthFromDecompose
= pInside
->getLineAttribute().getWidth();
84 // 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.
85 CPPUNIT_ASSERT_DOUBLES_EQUAL(fLeftWidth
, fLineWidthFromDecompose
,
86 basegfx::fTools::getSmallValue());
89 CPPUNIT_TEST_FIXTURE(DrawinglayerBorderTest
, testDoublePixelProcessing
)
91 // Create a pixel processor.
92 ScopedVclPtrInstance
<VirtualDevice
> pDev
;
93 drawinglayer::geometry::ViewInformation2D aView
;
94 std::unique_ptr
<drawinglayer::processor2d::BaseProcessor2D
> pProcessor(
95 drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(*pDev
, aView
));
96 CPPUNIT_ASSERT(pProcessor
);
97 GDIMetaFile aMetaFile
;
98 // Start recording after the processor is created, so we can test the pixel processor.
99 aMetaFile
.Record(pDev
);
101 // Create a border line primitive that's similar to the one from the bugdoc:
102 // 1.47 pixels is 0.03cm at 130% zoom and 96 DPI.
103 basegfx::B2DPoint
aStart(0, 20);
104 basegfx::B2DPoint
aEnd(100, 20);
105 double const fLeftWidth
= 1.47;
106 double const fDistance
= 1.47;
107 double const fRightWidth
= 1.47;
108 double const fExtendLeftStart
= 0;
109 double const fExtendLeftEnd
= 0;
110 double const fExtendRightStart
= 0;
111 double const fExtendRightEnd
= 0;
112 basegfx::BColor aColorRight
;
113 basegfx::BColor aColorLeft
;
114 const std::vector
<double> aDashing(svtools::GetLineDashing(SvxBorderLineStyle::DOUBLE
, 10.0));
115 const drawinglayer::attribute::StrokeAttribute
aStrokeAttribute(aDashing
);
116 std::vector
<drawinglayer::primitive2d::BorderLine
> aBorderlines
;
118 aBorderlines
.push_back(drawinglayer::primitive2d::BorderLine(
119 drawinglayer::attribute::LineAttribute(aColorLeft
, fLeftWidth
), fExtendLeftStart
,
120 fExtendLeftStart
, fExtendLeftEnd
, fExtendLeftEnd
));
122 aBorderlines
.push_back(drawinglayer::primitive2d::BorderLine(fDistance
));
124 aBorderlines
.push_back(drawinglayer::primitive2d::BorderLine(
125 drawinglayer::attribute::LineAttribute(aColorRight
, fRightWidth
), fExtendRightStart
,
126 fExtendRightStart
, fExtendRightEnd
, fExtendRightEnd
));
128 rtl::Reference
<drawinglayer::primitive2d::BorderLinePrimitive2D
> aBorder(
129 new drawinglayer::primitive2d::BorderLinePrimitive2D(aStart
, aEnd
, aBorderlines
,
132 drawinglayer::primitive2d::Primitive2DContainer aPrimitives
;
133 aPrimitives
.push_back(drawinglayer::primitive2d::Primitive2DReference(aBorder
.get()));
135 // Process the primitives.
136 pProcessor
->process(aPrimitives
);
138 // Double line now gets decomposed in Metafile to painting four lines
139 // with width == 0 in a cross pattern due to real line width being between
140 // 1.0 and 2.0. Count created lines
142 aMetaFile
.WindStart();
143 sal_uInt32 nPolyLineActionCount
= 0;
145 for (std::size_t nAction
= 0; nAction
< aMetaFile
.GetActionSize(); ++nAction
)
147 MetaAction
* pAction
= aMetaFile
.GetAction(nAction
);
149 if (MetaActionType::POLYLINE
== pAction
->GetType())
151 auto pMPLAction
= static_cast<MetaPolyLineAction
*>(pAction
);
153 if (0 != pMPLAction
->GetLineInfo().GetWidth()
154 && LineStyle::Solid
== pMPLAction
->GetLineInfo().GetStyle())
156 nPolyLineActionCount
++;
161 // Check if all eight (2x four) simple lines with width == 0 and
162 // solid were created
164 // This has changed: Now, just the needed 'real' lines get created
165 // which have a width of 1. This are two lines. The former multiple
166 // lines were a combination of view-dependent force to a single-pixel
167 // line width (0 == lineWidth -> hairline) and vcl rendering this
168 // using a (insane) combination of single non-AAed lines. All the
169 // system-dependent part of the BorderLine stuff is now done in
170 // SdrFrameBorderPrimitive2D and svx.
171 // Adapted this test - still useful, breaking it may be a hint :-)
172 const sal_uInt32 nExpectedNumPolyLineActions
= 2;
174 CPPUNIT_ASSERT_EQUAL(nExpectedNumPolyLineActions
, nPolyLineActionCount
);
178 CPPUNIT_PLUGIN_IMPLEMENT();
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */