sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / vcl / backendtest / outputdevice / polypolygon_b2d.cxx
blob59391abe1922ae83d22c651c601adbef70b1c0c6
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 basegfx::B2DPolygon createPolygonOffset(tools::Rectangle const& rRect, int nOffset, int nFix = 0)
19 // Note: According to https://lists.freedesktop.org/archives/libreoffice/2019-November/083709.html
20 // filling polygons always skips the right-most and bottom-most pixels, in order to avoid
21 // overlaps when drawing adjacent polygons. Specifying nFix = 1 allows to visually compensate
22 // for this by making the polygon explicitly larger.
23 int nMidOffset = rRect.GetWidth() / 2;
24 basegfx::B2DPolygon aPolygon{
25 basegfx::B2DPoint(rRect.Left() + nOffset - (nOffset + 1) / 2, rRect.Top() + nOffset - 1),
26 basegfx::B2DPoint(rRect.Right() - nMidOffset - nOffset / 3 + nFix,
27 rRect.Top() + nOffset - 1),
28 basegfx::B2DPoint(rRect.Right() - nMidOffset - nOffset / 3 + nFix,
29 rRect.Bottom() - nOffset + 1 + nFix),
30 basegfx::B2DPoint(rRect.Left() + nOffset - (nOffset + 1) / 2,
31 rRect.Bottom() - nOffset + 1 + nFix),
33 aPolygon.setClosed(true);
34 return aPolygon;
37 } // end anonymous namespace
39 Bitmap OutputDeviceTestPolyPolygonB2D::setupRectangle(bool bEnableAA)
41 initialSetup(13, 13, constBackgroundColor, bEnableAA);
43 mpVirtualDevice->SetLineColor(constLineColor);
44 mpVirtualDevice->SetFillColor();
46 basegfx::B2DPolyPolygon aPolyPolygon;
47 aPolyPolygon.append(createPolygonOffset(maVDRectangle, 2));
48 aPolyPolygon.append(createPolygonOffset(maVDRectangle, 5));
50 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
52 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
55 Bitmap OutputDeviceTestPolyPolygonB2D::setupFilledRectangle(bool useLineColor)
57 initialSetup(13, 13, constBackgroundColor);
59 if (useLineColor)
60 mpVirtualDevice->SetLineColor(constLineColor);
61 else
62 mpVirtualDevice->SetLineColor();
63 mpVirtualDevice->SetFillColor(constFillColor);
65 basegfx::B2DPolyPolygon aPolyPolygon(
66 createPolygonOffset(maVDRectangle, 2, useLineColor ? 0 : 1));
68 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
70 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
73 Bitmap OutputDeviceTestPolyPolygonB2D::setupIntersectingRectangles()
75 initialSetup(24, 24, constBackgroundColor);
77 mpVirtualDevice->SetLineColor(constLineColor);
78 mpVirtualDevice->SetFillColor(constFillColor);
80 basegfx::B2DPolyPolygon aPolyPolygon;
82 int nOffset = 2, nFix = 1;
83 basegfx::B2DPolygon aPolygon1, aPolygon2, aPolygon3, aPolygon4;
86 The intersection between different rectangles has been
87 achieved by stacking them on top of each other and decreasing and
88 increasing the top and bottom offset accordingly to the rectangle
89 keeping the left and the right offset intact which in turn coalesced
90 them to each other helping in achieving multiple intersecting rectangles.
91 The desired color fill pattern is then achieved by setting the fill
92 color which in turn would fill the shape with the provided color
93 in accordance to the even-odd filling rule.
96 //Rect - 1
97 aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
98 maVDRectangle.Top() + (nOffset - 1) + nFix));
99 aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
100 maVDRectangle.Top() + (nOffset - 1) + nFix));
101 aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
102 maVDRectangle.Bottom() - (nOffset + 8) + nFix));
103 aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
104 maVDRectangle.Bottom() - (nOffset + 8) + nFix));
105 aPolygon1.setClosed(true);
106 aPolyPolygon.append(aPolygon1);
108 //Rect - 2
109 aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
110 maVDRectangle.Top() + (nOffset + 2) + nFix));
111 aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
112 maVDRectangle.Top() + (nOffset + 2) + nFix));
113 aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
114 maVDRectangle.Bottom() - (nOffset + 5) + nFix));
115 aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
116 maVDRectangle.Bottom() - (nOffset + 5) + nFix));
117 aPolygon2.setClosed(true);
118 aPolyPolygon.append(aPolygon2);
120 //Rect - 3
121 aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
122 maVDRectangle.Top() + (nOffset + 5) + nFix));
123 aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
124 maVDRectangle.Top() + (nOffset + 5) + nFix));
125 aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
126 maVDRectangle.Bottom() - (nOffset + 2) + nFix));
127 aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
128 maVDRectangle.Bottom() - (nOffset + 2) + nFix));
129 aPolygon3.setClosed(true);
130 aPolyPolygon.append(aPolygon3);
132 //Rect - 4
133 aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
134 maVDRectangle.Top() + (nOffset + 8) + nFix));
135 aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
136 maVDRectangle.Top() + (nOffset + 8) + nFix));
137 aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
138 maVDRectangle.Bottom() - nOffset + nFix));
139 aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
140 maVDRectangle.Bottom() - nOffset + nFix));
141 aPolygon4.setClosed(true);
142 aPolyPolygon.append(aPolygon4);
144 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
146 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
149 Bitmap OutputDeviceTestPolyPolygonB2D::setupRectangleOnSize1028()
151 initialSetup(1028, 1028, constBackgroundColor);
153 mpVirtualDevice->SetLineColor(constLineColor);
154 mpVirtualDevice->SetFillColor();
156 basegfx::B2DPolyPolygon aPolyPolygon;
157 aPolyPolygon.append(createPolygonOffset(maVDRectangle, 2));
158 aPolyPolygon.append(createPolygonOffset(maVDRectangle, 5));
160 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
162 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
165 Bitmap OutputDeviceTestPolyPolygonB2D::setupRectangleOnSize4096()
167 initialSetup(4096, 4096, constBackgroundColor);
169 mpVirtualDevice->SetLineColor(constLineColor);
170 mpVirtualDevice->SetFillColor();
172 basegfx::B2DPolyPolygon aPolyPolygon;
173 aPolyPolygon.append(createPolygonOffset(maVDRectangle, 2));
174 aPolyPolygon.append(createPolygonOffset(maVDRectangle, 5));
176 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
178 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
181 Bitmap OutputDeviceTestPolyPolygonB2D::setupOpenPolygon()
183 initialSetup(21, 21, constBackgroundColor);
185 mpVirtualDevice->SetLineColor(constLineColor);
186 mpVirtualDevice->SetFillColor();
188 basegfx::B2DPolyPolygon aPolyPolygon;
189 aPolyPolygon.append(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle));
190 aPolyPolygon.append(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7));
192 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
194 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
197 } // end namespace vcl::test
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */