1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  */
10 
11 #ifndef INCLUDED_VCL_OUTDEVTESTS_HXX
12 #define INCLUDED_VCL_OUTDEVTESTS_HXX
13 
14 #include <vcl/virdev.hxx>
15 
16 namespace vcl::test {
17 
18 /** Rendering test result.
19  *
20  * Test either "Passed", "Failed" or "PassedWithQuirks" which means
21  * the test passed but at least one rendering quirk was detected.
22  */
23 enum class TestResult
24 {
25     Failed,
26     PassedWithQuirks,
27     Passed
28 };
29 
30 /** Common subclass for output device rendering tests.
31  */
32 class VCL_DLLPUBLIC OutputDeviceTestCommon
33 {
34 protected:
35 
36     ScopedVclPtr<VirtualDevice> mpVirtualDevice;
37     tools::Rectangle maVDRectangle;
38 
39     static const Color constBackgroundColor;
40     static const Color constLineColor;
41     static const Color constFillColor;
42 
43 public:
44     OutputDeviceTestCommon();
45 
46     OUString getRenderBackendName() const;
47 
48     void initialSetup(tools::Long nWidth, tools::Long nHeight, Color aColor, bool bEnableAA = false, bool bAlphaVirtualDevice = false);
49 
50     static TestResult checkRectangle(Bitmap& rBitmap);
51     static TestResult checkRectangleAA(Bitmap& rBitmap);
52     static TestResult checkFilledRectangle(Bitmap& rBitmap, bool useLineColor);
53     static TestResult checkLines(Bitmap& rBitmap);
54     static TestResult checkAALines(Bitmap& rBitmap);
55     static TestResult checkDiamond(Bitmap& rBitmap);
56 
57     static TestResult checkInvertRectangle(Bitmap& rBitmap);
58     static TestResult checkInvertN50Rectangle(Bitmap& aBitmap);
59     static TestResult checkInvertTrackFrameRectangle(Bitmap& aBitmap);
60 
61     static TestResult checkRectangles(Bitmap& rBitmap, std::vector<Color>& aExpectedColors);
62     static TestResult checkRectangle(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor);
63 
64     static TestResult checkFilled(Bitmap& rBitmap, tools::Rectangle aRectangle, Color aExpectedColor);
65     static TestResult checkChecker(Bitmap& rBitmap, sal_Int32 nStartX, sal_Int32 nEndX,
66                                    sal_Int32 nStartY, sal_Int32 nEndY, std::vector<Color> const & rExpected);
67 
68     static TestResult checkLinearGradient(Bitmap& bitmap);
69     static TestResult checkLinearGradientAngled(Bitmap& bitmap);
70     static TestResult checkLinearGradientBorder(Bitmap& bitmap);
71     static TestResult checkLinearGradientIntensity(Bitmap& bitmap);
72     static TestResult checkLinearGradientSteps(Bitmap& bitmap);
73     static TestResult checkAxialGradient(Bitmap& bitmap);
74     static TestResult checkRadialGradient(Bitmap& bitmap);
75     static TestResult checkRadialGradientOfs(Bitmap& bitmap);
76 
77     static void createDiamondPoints(tools::Rectangle rRect, int nOffset,
78                                     Point& rPoint1, Point& rPoint2,
79                                     Point& rPoint3, Point& rPoint4);
80 
81     static void createHorizontalVerticalDiagonalLinePoints(tools::Rectangle rRect,
82                                 Point& rHorizontalLinePoint1, Point& rHorizontalLinePoint2,
83                                 Point& rVerticalLinePoint1, Point& rVerticalLinePoint2,
84                                 Point& rDiagonalLinePoint1, Point& rDiagonalLinePoint2);
85     // tools
86     static tools::Rectangle alignToCenter(tools::Rectangle aRect1, tools::Rectangle aRect2);
87 
88     static TestResult checkBezier(Bitmap& rBitmap);
89 
checkLineCapRound(Bitmap & rBitmap)90     static TestResult checkLineCapRound(Bitmap& rBitmap) { return checkLineCap(rBitmap, css::drawing::LineCap_ROUND); }
checkLineCapSquare(Bitmap & rBitmap)91     static TestResult checkLineCapSquare(Bitmap& rBitmap) { return checkLineCap(rBitmap, css::drawing::LineCap_SQUARE); }
checkLineCapButt(Bitmap & rBitmap)92     static TestResult checkLineCapButt(Bitmap& rBitmap) { return checkLineCap(rBitmap, css::drawing::LineCap_BUTT); }
93 
checkLineJoinBevel(Bitmap & rBitmap)94     static TestResult checkLineJoinBevel(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::Bevel); }
checkLineJoinRound(Bitmap & rBitmap)95     static TestResult checkLineJoinRound(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::Round); }
checkLineJoinMiter(Bitmap & rBitmap)96     static TestResult checkLineJoinMiter(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::Miter); }
checkLineJoinNone(Bitmap & rBitmap)97     static TestResult checkLineJoinNone(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::NONE); }
98 private:
99     static TestResult checkLineCap(Bitmap& rBitmap, css::drawing::LineCap lineCap);
100     static TestResult checkLineJoin(Bitmap& rBitmap, basegfx::B2DLineJoin lineJoin);
101 };
102 
103 class VCL_DLLPUBLIC OutputDeviceTestBitmap : public OutputDeviceTestCommon
104 {
105 public:
106     OutputDeviceTestBitmap() = default;
107 
108     Bitmap setupDrawTransformedBitmap();
109     Bitmap setupDrawBitmap();
110     Bitmap setupDrawBitmapExWithAlpha();
111     Bitmap setupDrawMask();
112     BitmapEx setupDrawBlend();
113 
114     static TestResult checkTransformedBitmap(Bitmap& rBitmap);
115     static TestResult checkBitmapExWithAlpha(Bitmap& rBitmap);
116     static TestResult checkMask(Bitmap& rBitmap);
117     static TestResult checkBlend(const BitmapEx& rBitmap);
118 };
119 
120 class VCL_DLLPUBLIC OutputDeviceTestAnotherOutDev : public OutputDeviceTestCommon
121 {
122 public:
123     OutputDeviceTestAnotherOutDev() = default;
124 
125     Bitmap setupDrawOutDev();
126     Bitmap setupXOR();
127 
128     static TestResult checkDrawOutDev(Bitmap& rBitmap);
129     static TestResult checkXOR(Bitmap& rBitmap);
130 };
131 
132 class VCL_DLLPUBLIC OutputDeviceTestPixel : public OutputDeviceTestCommon
133 {
134 public:
135     OutputDeviceTestPixel() = default;
136 
137     Bitmap setupRectangle(bool bEnableAA);
138 };
139 
140 class VCL_DLLPUBLIC OutputDeviceTestLine : public OutputDeviceTestCommon
141 {
142 public:
143     OutputDeviceTestLine() = default;
144 
145     Bitmap setupRectangle(bool bEnableAA);
146     Bitmap setupDiamond();
147     Bitmap setupLines();
148     Bitmap setupAALines();
149 
150     Bitmap setupDashedLine();
151     static TestResult checkDashedLine(Bitmap& rBitmap);
152 
setupLineCapRound()153     Bitmap setupLineCapRound() { return setupLineCap(css::drawing::LineCap_ROUND); }
setupLineCapSquare()154     Bitmap setupLineCapSquare() { return setupLineCap(css::drawing::LineCap_SQUARE); }
setupLineCapButt()155     Bitmap setupLineCapButt() { return setupLineCap(css::drawing::LineCap_BUTT); }
156 
setupLineJoinBevel()157     Bitmap setupLineJoinBevel() { return setupLineJoin(basegfx::B2DLineJoin::Bevel); }
setupLineJoinRound()158     Bitmap setupLineJoinRound() { return setupLineJoin(basegfx::B2DLineJoin::Round); }
setupLineJoinMiter()159     Bitmap setupLineJoinMiter() { return setupLineJoin(basegfx::B2DLineJoin::Miter); }
setupLineJoinNone()160     Bitmap setupLineJoinNone() { return setupLineJoin(basegfx::B2DLineJoin::NONE); }
161 private:
162     Bitmap setupLineCap( css::drawing::LineCap lineCap );
163     Bitmap setupLineJoin( basegfx::B2DLineJoin lineJoin );
164 };
165 
166 class VCL_DLLPUBLIC OutputDeviceTestPolyLine : public OutputDeviceTestCommon
167 {
168 public:
169     OutputDeviceTestPolyLine() = default;
170 
171     Bitmap setupRectangle(bool bEnableAA);
172     Bitmap setupDiamond();
173     Bitmap setupLines();
174     Bitmap setupAALines();
175 };
176 
177 class VCL_DLLPUBLIC OutputDeviceTestPolyLineB2D : public OutputDeviceTestCommon
178 {
179 public:
180     OutputDeviceTestPolyLineB2D() = default;
181 
182     Bitmap setupRectangle(bool bEnableAA);
183     Bitmap setupDiamond();
184     Bitmap setupBezier();
185     Bitmap setupAABezier();
186 };
187 
188 class VCL_DLLPUBLIC OutputDeviceTestRect : public OutputDeviceTestCommon
189 {
190 public:
191     OutputDeviceTestRect() = default;
192 
193     Bitmap setupRectangle(bool bEnableAA);
194     Bitmap setupFilledRectangle(bool useLineColor);
195     Bitmap setupInvert_NONE();
196     Bitmap setupInvert_N50();
197     Bitmap setupInvert_TrackFrame();
198 };
199 
200 class VCL_DLLPUBLIC OutputDeviceTestPolygon : public OutputDeviceTestCommon
201 {
202 public:
203     OutputDeviceTestPolygon() = default;
204 
205     Bitmap setupRectangle(bool bEnableAA);
206     Bitmap setupFilledRectangle(bool useLineColor);
207     Bitmap setupDiamond();
208     Bitmap setupLines();
209     Bitmap setupAALines();
210 };
211 
212 class VCL_DLLPUBLIC OutputDeviceTestPolyPolygon : public OutputDeviceTestCommon
213 {
214 public:
215     OutputDeviceTestPolyPolygon() = default;
216 
217     Bitmap setupRectangle(bool bEnableAA);
218     Bitmap setupFilledRectangle(bool useLineColor);
219 };
220 
221 class VCL_DLLPUBLIC OutputDeviceTestPolyPolygonB2D : public OutputDeviceTestCommon
222 {
223 public:
224     OutputDeviceTestPolyPolygonB2D() = default;
225 
226     Bitmap setupRectangle(bool bEnableAA);
227     Bitmap setupFilledRectangle(bool useLineColor);
228 };
229 
230 class VCL_DLLPUBLIC OutputDeviceTestGradient : public OutputDeviceTestCommon
231 {
232 public:
233     OutputDeviceTestGradient() = default;
234 
235     Bitmap setupLinearGradient();
236     Bitmap setupLinearGradientAngled();
237     Bitmap setupLinearGradientBorder();
238     Bitmap setupLinearGradientIntensity();
239     Bitmap setupLinearGradientSteps();
240     Bitmap setupAxialGradient();
241     Bitmap setupRadialGradient();
242     Bitmap setupRadialGradientOfs();
243 };
244 
245 class VCL_DLLPUBLIC OutputDeviceTestClip : public OutputDeviceTestCommon
246 {
247 public:
248     Bitmap setupClipRectangle();
249     Bitmap setupClipPolygon();
250     Bitmap setupClipPolyPolygon();
251     Bitmap setupClipB2DPolyPolygon();
252 
253     static TestResult checkClip(Bitmap& rBitmap);
254 };
255 
256 
257 } // end namespace vcl::test
258 
259 #endif
260 
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
262