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/.
10 #include <test/bootstrapfixture.hxx>
11 #include <test/outputdevice.hxx>
13 #include <sal/log.hxx>
14 #include <basegfx/matrix/b2dhommatrix.hxx>
15 #include <basegfx/numeric/ftools.hxx>
16 #include <basegfx/polygon/b2dpolygon.hxx>
17 #include <basegfx/polygon/b2dpolypolygon.hxx>
18 #include <basegfx/vector/b2enums.hxx>
20 #include <vcl/gradient.hxx>
21 #include <vcl/lineinfo.hxx>
22 #include <vcl/print.hxx>
23 #include <vcl/rendercontext/RasterOp.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/gdimtf.hxx>
27 #include <vcl/metaact.hxx>
29 #include <bitmap/BitmapWriteAccess.hxx>
30 #include <bufferdevice.hxx>
33 class VclGradientTest
: public test::BootstrapFixture
37 : BootstrapFixture(true, false)
41 void testAddGradientActions_rect_linear();
42 void testAddGradientActions_rect_axial();
43 void testAddGradientActions_rect_complex();
45 CPPUNIT_TEST_SUITE(VclGradientTest
);
46 CPPUNIT_TEST(testAddGradientActions_rect_linear
);
47 CPPUNIT_TEST(testAddGradientActions_rect_axial
);
48 CPPUNIT_TEST(testAddGradientActions_rect_complex
);
49 CPPUNIT_TEST_SUITE_END();
52 static size_t TestLinearStripes(GDIMetaFile
& rMtf
, size_t nTimes
, size_t nIndex
)
55 MetaAction
* pAction
= rMtf
.GetAction(nIndex
);
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action (start)", MetaActionType::FILLCOLOR
,
60 pAction
= rMtf
.GetAction(nIndex
);
61 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action (start)", MetaActionType::POLYGON
,
64 for (size_t i
= 0; i
< nTimes
- 1; i
++)
67 pAction
= rMtf
.GetAction(nIndex
);
68 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR
,
72 pAction
= rMtf
.GetAction(nIndex
);
73 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON
,
78 pAction
= rMtf
.GetAction(nIndex
);
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action (end)", MetaActionType::FILLCOLOR
,
83 pAction
= rMtf
.GetAction(nIndex
);
84 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action (end)", MetaActionType::POLYGON
,
90 void VclGradientTest::testAddGradientActions_rect_linear()
93 tools::Rectangle
aRect(Point(10, 10), Size(40, 40));
94 Gradient
aGradient(css::awt::GradientStyle_LINEAR
, COL_RED
, COL_WHITE
);
95 aGradient
.SetBorder(100);
97 aGradient
.AddGradientActions(aRect
, aMtf
);
101 MetaAction
* pAction
= aMtf
.GetAction(nIndex
);
102 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH
, pAction
->GetType());
105 pAction
= aMtf
.GetAction(nIndex
);
106 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rectangular intersect clip action",
107 MetaActionType::ISECTRECTCLIPREGION
, pAction
->GetType());
110 pAction
= aMtf
.GetAction(nIndex
);
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a line color action", MetaActionType::LINECOLOR
,
114 TestLinearStripes(aMtf
, 3, nIndex
);
117 static size_t TestAxialStripes(GDIMetaFile
& rMtf
, size_t nTimes
, size_t nIndex
)
120 MetaAction
* pAction
= rMtf
.GetAction(nIndex
);
121 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR
,
125 pAction
= rMtf
.GetAction(nIndex
);
126 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON
,
130 pAction
= rMtf
.GetAction(nIndex
);
131 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON
,
134 for (size_t i
= 0; i
< nTimes
- 1; i
++)
137 pAction
= rMtf
.GetAction(nIndex
);
138 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR
,
142 pAction
= rMtf
.GetAction(nIndex
);
143 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON
,
147 pAction
= rMtf
.GetAction(nIndex
);
148 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON
,
153 pAction
= rMtf
.GetAction(nIndex
);
154 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR
,
158 pAction
= rMtf
.GetAction(nIndex
);
159 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON
,
165 void VclGradientTest::testAddGradientActions_rect_axial()
168 tools::Rectangle
aRect(Point(10, 10), Size(40, 40));
169 Gradient
aGradient(css::awt::GradientStyle_AXIAL
, COL_RED
, COL_WHITE
);
170 aGradient
.SetBorder(100);
172 aGradient
.AddGradientActions(aRect
, aMtf
);
176 MetaAction
* pAction
= aMtf
.GetAction(nIndex
);
177 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH
, pAction
->GetType());
180 pAction
= aMtf
.GetAction(nIndex
);
181 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rectangular intersect clip action",
182 MetaActionType::ISECTRECTCLIPREGION
, pAction
->GetType());
185 pAction
= aMtf
.GetAction(nIndex
);
186 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a line color action", MetaActionType::LINECOLOR
,
189 TestAxialStripes(aMtf
, 3, nIndex
);
192 static size_t TestComplexStripes(GDIMetaFile
& rMtf
, size_t nTimes
, size_t nIndex
)
195 MetaAction
* pAction
= rMtf
.GetAction(nIndex
);
196 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR
,
199 for (size_t i
= 1; i
< nTimes
; i
++)
202 pAction
= rMtf
.GetAction(nIndex
);
203 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", MetaActionType::POLYPOLYGON
,
207 pAction
= rMtf
.GetAction(nIndex
);
208 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR
,
213 pAction
= rMtf
.GetAction(nIndex
);
214 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR
,
218 pAction
= rMtf
.GetAction(nIndex
);
219 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", MetaActionType::POLYGON
,
225 void VclGradientTest::testAddGradientActions_rect_complex()
228 tools::Rectangle
aRect(Point(10, 10), Size(40, 40));
229 Gradient
aGradient(css::awt::GradientStyle_SQUARE
, COL_RED
, COL_WHITE
);
230 aGradient
.SetBorder(10);
232 aGradient
.AddGradientActions(aRect
, aMtf
);
236 MetaAction
* pAction
= aMtf
.GetAction(nIndex
);
237 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH
, pAction
->GetType());
240 pAction
= aMtf
.GetAction(nIndex
);
241 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rectangular intersect clip action",
242 MetaActionType::ISECTRECTCLIPREGION
, pAction
->GetType());
245 pAction
= aMtf
.GetAction(nIndex
);
246 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a line color action", MetaActionType::LINECOLOR
,
249 TestComplexStripes(aMtf
, 40, nIndex
);
252 CPPUNIT_TEST_SUITE_REGISTRATION(VclGradientTest
);
254 CPPUNIT_PLUGIN_IMPLEMENT();
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */