calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / backendtest / outputdevice / polypolygon.cxx
blobe1abb2f9014b2f647a3d5485e4281f625747d8a6
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 tools::Polygon 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 tools::Polygon aPolygon(4);
24 int nMidOffset = rRect.GetWidth() / 2;
25 aPolygon.SetPoint(Point(rRect.Left() + nOffset - (nOffset + 1) / 2, rRect.Top() + nOffset - 1),
26 0);
27 aPolygon.SetPoint(
28 Point(rRect.Right() - nMidOffset + nFix - nOffset / 3, rRect.Top() + nOffset - 1), 1);
29 aPolygon.SetPoint(
30 Point(rRect.Right() - nMidOffset + nFix - nOffset / 3, rRect.Bottom() - nOffset + nFix + 1),
31 2);
32 aPolygon.SetPoint(
33 Point(rRect.Left() + nOffset - (nOffset + 1) / 2, rRect.Bottom() - nOffset + nFix + 1), 3);
34 aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
35 return aPolygon;
38 } // end anonymous namespace
40 Bitmap OutputDeviceTestPolyPolygon::setupRectangle(bool bEnableAA)
42 initialSetup(13, 13, constBackgroundColor, bEnableAA);
44 mpVirtualDevice->SetLineColor(constLineColor);
45 mpVirtualDevice->SetFillColor();
47 tools::PolyPolygon aPolyPolygon(2);
48 aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2));
49 aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 5));
51 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
53 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
56 Bitmap OutputDeviceTestPolyPolygon::setupFilledRectangle(bool useLineColor)
58 initialSetup(13, 13, constBackgroundColor);
60 if (useLineColor)
61 mpVirtualDevice->SetLineColor(constLineColor);
62 else
63 mpVirtualDevice->SetLineColor();
64 mpVirtualDevice->SetFillColor(constFillColor);
66 tools::PolyPolygon aPolyPolygon(1);
67 aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2, useLineColor ? 0 : 1));
69 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
71 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
74 Bitmap OutputDeviceTestPolyPolygon::setupIntersectingRectangles()
76 initialSetup(24, 24, constBackgroundColor);
78 mpVirtualDevice->SetLineColor(constLineColor);
79 mpVirtualDevice->SetFillColor(constFillColor);
81 tools::PolyPolygon aPolyPolygon(4);
83 int nOffset = 2, nFix = 1;
84 tools::Polygon aPolygon1(4), aPolygon2(4), aPolygon3(4), aPolygon4(4);
87 The intersection between different rectangles has been
88 achieved by stacking them on top of each other and decreasing and
89 increasing the top and bottom offset accordingly to the rectangle
90 keeping the left and the right offset intact which in turn coalesced
91 them to each other helping in achieving multiple intersecting rectangles.
92 The desired color fill pattern is then achieved by setting the fill
93 color which in turn would fill the shape with the provided color
94 in accordance to the even-odd filling rule.
97 //Rect - 1
98 aPolygon1.SetPoint(
99 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset - 1) + nFix),
101 aPolygon1.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
102 maVDRectangle.Top() + (nOffset - 1) + nFix),
104 aPolygon1.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
105 maVDRectangle.Bottom() - (nOffset + 8) + nFix),
107 aPolygon1.SetPoint(
108 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - (nOffset + 8) + nFix),
110 aPolyPolygon.Insert(aPolygon1);
112 //Rect - 2
113 aPolygon2.SetPoint(
114 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset + 2) + nFix),
116 aPolygon2.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
117 maVDRectangle.Top() + (nOffset + 2) + nFix),
119 aPolygon2.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
120 maVDRectangle.Bottom() - (nOffset + 5) + nFix),
122 aPolygon2.SetPoint(
123 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - (nOffset + 5) + nFix),
125 aPolyPolygon.Insert(aPolygon2);
127 //Rect - 3
128 aPolygon3.SetPoint(
129 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset + 5) + nFix),
131 aPolygon3.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
132 maVDRectangle.Top() + (nOffset + 5) + nFix),
134 aPolygon3.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
135 maVDRectangle.Bottom() - (nOffset + 2) + nFix),
137 aPolygon3.SetPoint(
138 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - (nOffset + 2) + nFix),
140 aPolyPolygon.Insert(aPolygon3);
142 //Rect - 4
143 aPolygon4.SetPoint(
144 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset + 8) + nFix),
146 aPolygon4.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
147 maVDRectangle.Top() + (nOffset + 8) + nFix),
149 aPolygon4.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
150 maVDRectangle.Bottom() - nOffset + nFix),
152 aPolygon4.SetPoint(
153 Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - nOffset + nFix), 3);
154 aPolyPolygon.Insert(aPolygon4);
156 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
158 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
161 Bitmap OutputDeviceTestPolyPolygon::setupRectangleOnSize1028()
163 initialSetup(1028, 1028, constBackgroundColor);
165 mpVirtualDevice->SetLineColor(constLineColor);
166 mpVirtualDevice->SetFillColor();
168 tools::PolyPolygon aPolyPolygon(2);
169 aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2));
170 aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 5));
172 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
174 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
177 Bitmap OutputDeviceTestPolyPolygon::setupRectangleOnSize4096()
179 initialSetup(4096, 4096, constBackgroundColor);
181 mpVirtualDevice->SetLineColor(constLineColor);
182 mpVirtualDevice->SetFillColor();
184 tools::PolyPolygon aPolyPolygon(2);
185 aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2));
186 aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 5));
188 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
190 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
193 Bitmap OutputDeviceTestPolyPolygon::setupOpenPolygon()
195 initialSetup(21, 21, constBackgroundColor);
197 mpVirtualDevice->SetLineColor(constLineColor);
198 mpVirtualDevice->SetFillColor();
200 tools::PolyPolygon aPolyPolygon;
201 aPolyPolygon.Insert(tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle)));
202 aPolyPolygon.Insert(
203 tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7)));
205 mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
207 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
210 } // end namespace vcl::test
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */