sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / vcl / backendtest / outputdevice / polygon.cxx
blob051c0d893cb1799016ffe1e197b7e6e6caab70b8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <test/outputdevice.hxx>
13 namespace vcl::test
15 namespace
17 void drawPolygonOffset(OutputDevice& rDevice, tools::Rectangle const& rRect, int nOffset,
18 int nFix = 0)
20 // Note: According to https://lists.freedesktop.org/archives/libreoffice/2019-November/083709.html
21 // filling polygons always skips the right-most and bottom-most pixels, in order to avoid
22 // overlaps when drawing adjacent polygons. Specifying nFix = 1 allows to visually compensate
23 // for this by making the polygon explicitly larger.
24 tools::Polygon aPolygon(4);
25 int nMidOffset = rRect.GetWidth() / 2;
26 aPolygon.SetPoint(Point(rRect.Left() + nOffset - (nOffset+1)/2, rRect.Top() + nOffset - 1), 0);
27 aPolygon.SetPoint(Point(rRect.Right() - nMidOffset + nFix - nOffset/3, rRect.Top() + nOffset - 1), 1);
28 aPolygon.SetPoint(Point(rRect.Right() - nMidOffset + nFix - nOffset/3, rRect.Bottom() - nOffset + nFix + 1), 2);
29 aPolygon.SetPoint(Point(rRect.Left() + nOffset - (nOffset+1)/2, rRect.Bottom() - nOffset + nFix + 1), 3);
30 aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
32 rDevice.DrawPolygon(aPolygon);
35 } // end anonymous namespace
37 Bitmap OutputDeviceTestPolygon::setupRectangle(bool bEnableAA)
39 initialSetup(13, 13, constBackgroundColor, bEnableAA);
41 mpVirtualDevice->SetLineColor(constLineColor);
42 mpVirtualDevice->SetFillColor();
44 drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2);
45 drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 5);
47 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
50 Bitmap OutputDeviceTestPolygon::setupFilledRectangle(bool useLineColor)
52 initialSetup(13, 13, constBackgroundColor);
54 if (useLineColor)
55 mpVirtualDevice->SetLineColor(constLineColor);
56 else
57 mpVirtualDevice->SetLineColor();
58 mpVirtualDevice->SetFillColor(constFillColor);
59 drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2, useLineColor ? 0 : 1);
61 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
64 Bitmap OutputDeviceTestPolygon::setupDiamond()
66 initialSetup(11, 11, constBackgroundColor);
68 mpVirtualDevice->SetLineColor(constLineColor);
69 mpVirtualDevice->SetFillColor();
71 Point aPoint1, aPoint2, aPoint3, aPoint4;
72 OutputDeviceTestCommon::createDiamondPoints(maVDRectangle, 4, aPoint1, aPoint2, aPoint3,
73 aPoint4);
75 tools::Polygon aPolygon(4);
77 aPolygon.SetPoint(aPoint1, 0);
78 aPolygon.SetPoint(aPoint2, 1);
79 aPolygon.SetPoint(aPoint3, 2);
80 aPolygon.SetPoint(aPoint4, 3);
81 aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
83 mpVirtualDevice->DrawPolygon(aPolygon);
85 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
88 Bitmap OutputDeviceTestPolygon::setupLines()
90 initialSetup(13, 13, constBackgroundColor);
92 mpVirtualDevice->SetLineColor(constLineColor);
93 mpVirtualDevice->SetFillColor();
95 Point aHorizontalLinePoint1, aHorizontalLinePoint2;
96 Point aVerticalLinePoint1, aVerticalLinePoint2;
97 Point aDiagonalLinePoint1, aDiagonalLinePoint2;
99 OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
100 maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2, aVerticalLinePoint1,
101 aVerticalLinePoint2, aDiagonalLinePoint1, aDiagonalLinePoint2);
103 tools::Polygon aHorizontalPolygon(2);
104 aHorizontalPolygon.SetPoint(aHorizontalLinePoint1, 0);
105 aHorizontalPolygon.SetPoint(aHorizontalLinePoint2, 1);
106 mpVirtualDevice->DrawPolygon(aHorizontalPolygon);
108 tools::Polygon aVerticalPolygon(2);
109 aVerticalPolygon.SetPoint(aVerticalLinePoint1, 0);
110 aVerticalPolygon.SetPoint(aVerticalLinePoint2, 1);
111 mpVirtualDevice->DrawPolygon(aVerticalPolygon);
113 tools::Polygon aDiagonalPolygon(2);
114 aDiagonalPolygon.SetPoint(aDiagonalLinePoint1, 0);
115 aDiagonalPolygon.SetPoint(aDiagonalLinePoint2, 1);
116 mpVirtualDevice->DrawPolygon(aDiagonalPolygon);
118 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
121 Bitmap OutputDeviceTestPolygon::setupAALines()
123 initialSetup(13, 13, constBackgroundColor);
125 mpVirtualDevice->SetAntialiasing(AntialiasingFlags::Enable);
126 mpVirtualDevice->SetLineColor(constLineColor);
127 mpVirtualDevice->SetFillColor();
129 Point aHorizontalLinePoint1, aHorizontalLinePoint2;
130 Point aVerticalLinePoint1, aVerticalLinePoint2;
131 Point aDiagonalLinePoint1, aDiagonalLinePoint2;
133 OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
134 maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2, aVerticalLinePoint1,
135 aVerticalLinePoint2, aDiagonalLinePoint1, aDiagonalLinePoint2);
137 tools::Polygon aHorizontalPolygon(2);
138 aHorizontalPolygon.SetPoint(aHorizontalLinePoint1, 0);
139 aHorizontalPolygon.SetPoint(aHorizontalLinePoint2, 1);
140 mpVirtualDevice->DrawPolygon(aHorizontalPolygon);
142 tools::Polygon aVerticalPolygon(2);
143 aVerticalPolygon.SetPoint(aVerticalLinePoint1, 0);
144 aVerticalPolygon.SetPoint(aVerticalLinePoint2, 1);
145 mpVirtualDevice->DrawPolygon(aVerticalPolygon);
147 tools::Polygon aDiagonalPolygon(2);
148 aDiagonalPolygon.SetPoint(aDiagonalLinePoint1, 0);
149 aDiagonalPolygon.SetPoint(aDiagonalLinePoint2, 1);
150 mpVirtualDevice->DrawPolygon(aDiagonalPolygon);
152 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
155 Bitmap OutputDeviceTestPolygon::setupDropShape()
157 initialSetup(21, 21, constBackgroundColor);
159 mpVirtualDevice->SetLineColor(constLineColor);
160 mpVirtualDevice->SetFillColor();
162 mpVirtualDevice->DrawPolygon(OutputDeviceTestCommon::createDropShapePolygon());
164 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
167 Bitmap OutputDeviceTestPolygon::setupAADropShape()
169 initialSetup(21, 21, constBackgroundColor, true);
171 mpVirtualDevice->SetLineColor(constLineColor);
172 mpVirtualDevice->SetFillColor();
174 mpVirtualDevice->DrawPolygon(OutputDeviceTestCommon::createDropShapePolygon());
176 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
179 Bitmap OutputDeviceTestPolygon::setupHalfEllipse(bool aEnableAA)
181 initialSetup(19, 21, constBackgroundColor, aEnableAA);
183 mpVirtualDevice->SetLineColor(constLineColor);
184 mpVirtualDevice->SetFillColor();
186 mpVirtualDevice->DrawPolyLine(
187 tools::Polygon(OutputDeviceTestCommon::createHalfEllipsePolygon()));
189 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
192 Bitmap OutputDeviceTestPolygon::setupClosedBezier()
194 initialSetup(21, 16, constBackgroundColor);
196 mpVirtualDevice->SetLineColor(constLineColor);
197 mpVirtualDevice->SetFillColor();
199 mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createClosedBezierLoop(maVDRectangle));
201 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
204 Bitmap OutputDeviceTestPolygon::setupFilledAsymmetricalDropShape()
206 initialSetup(21, 21, constBackgroundColor);
208 mpVirtualDevice->SetLineColor();
209 mpVirtualDevice->SetFillColor(constFillColor);
211 mpVirtualDevice->DrawPolygon(OutputDeviceTestCommon::createDropShapePolygon());
213 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
216 Bitmap OutputDeviceTestPolygon::setupRectangleOnSize1028()
218 initialSetup(1028, 1028, constBackgroundColor);
220 mpVirtualDevice->SetLineColor(constLineColor);
221 mpVirtualDevice->SetFillColor();
223 drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2);
224 drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 5);
226 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
229 Bitmap OutputDeviceTestPolygon::setupRectangleOnSize4096()
231 initialSetup(4096, 4096, constBackgroundColor);
233 mpVirtualDevice->SetLineColor(constLineColor);
234 mpVirtualDevice->SetFillColor();
236 drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2);
237 drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 5);
239 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
242 Bitmap OutputDeviceTestPolygon::setupOpenPolygon()
244 initialSetup(21, 21, constBackgroundColor);
246 mpVirtualDevice->SetLineColor(constLineColor);
247 mpVirtualDevice->SetFillColor();
249 mpVirtualDevice->DrawPolygon(tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle)));
250 mpVirtualDevice->DrawPolygon(tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7)));
252 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
255 } // end namespace vcl::test
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */