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/.
11 #include <test/outputdevice.hxx>
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),
28 Point(rRect
.Right() - nMidOffset
+ nFix
- nOffset
/ 3, rRect
.Top() + nOffset
- 1), 1);
30 Point(rRect
.Right() - nMidOffset
+ nFix
- nOffset
/ 3, rRect
.Bottom() - nOffset
+ nFix
+ 1),
33 Point(rRect
.Left() + nOffset
- (nOffset
+ 1) / 2, rRect
.Bottom() - nOffset
+ nFix
+ 1), 3);
34 aPolygon
.Optimize(PolyOptimizeFlags::CLOSE
);
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
);
61 mpVirtualDevice
->SetLineColor(constLineColor
);
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.
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
),
108 Point(maVDRectangle
.Left() + nOffset
+ nFix
, maVDRectangle
.Bottom() - (nOffset
+ 8) + nFix
),
110 aPolyPolygon
.Insert(aPolygon1
);
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
),
123 Point(maVDRectangle
.Left() + nOffset
+ nFix
, maVDRectangle
.Bottom() - (nOffset
+ 5) + nFix
),
125 aPolyPolygon
.Insert(aPolygon2
);
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
),
138 Point(maVDRectangle
.Left() + nOffset
+ nFix
, maVDRectangle
.Bottom() - (nOffset
+ 2) + nFix
),
140 aPolyPolygon
.Insert(aPolygon3
);
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
),
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
)));
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: */