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>
18 void drawPolygonOffset(OutputDevice
& rDevice
, tools::Rectangle
const & rRect
, int nOffset
, 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 aPolygon
.SetPoint(Point(rRect
.Left() + nOffset
, rRect
.Top() + nOffset
), 0);
26 aPolygon
.SetPoint(Point(rRect
.Right() - nOffset
+ nFix
, rRect
.Top() + nOffset
), 1);
27 aPolygon
.SetPoint(Point(rRect
.Right() - nOffset
+ nFix
, rRect
.Bottom() - nOffset
+ nFix
), 2);
28 aPolygon
.SetPoint(Point(rRect
.Left() + nOffset
, rRect
.Bottom() - nOffset
+ nFix
), 3);
29 aPolygon
.Optimize(PolyOptimizeFlags::CLOSE
);
31 rDevice
.DrawPolygon(aPolygon
);
34 } // end anonymous namespace
36 Bitmap
OutputDeviceTestPolygon::setupRectangle(bool bEnableAA
)
38 initialSetup(13, 13, constBackgroundColor
, bEnableAA
);
40 mpVirtualDevice
->SetLineColor(constLineColor
);
41 mpVirtualDevice
->SetFillColor();
43 drawPolygonOffset(*mpVirtualDevice
, maVDRectangle
, 2);
44 drawPolygonOffset(*mpVirtualDevice
, maVDRectangle
, 5);
46 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
49 Bitmap
OutputDeviceTestPolygon::setupFilledRectangle(bool useLineColor
)
51 initialSetup(13, 13, constBackgroundColor
);
54 mpVirtualDevice
->SetLineColor(constLineColor
);
56 mpVirtualDevice
->SetLineColor();
57 mpVirtualDevice
->SetFillColor(constFillColor
);
58 drawPolygonOffset(*mpVirtualDevice
, maVDRectangle
, 2, useLineColor
? 0 : 1);
60 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
63 Bitmap
OutputDeviceTestPolygon::setupDiamond()
65 initialSetup(11, 11, constBackgroundColor
);
67 mpVirtualDevice
->SetLineColor(constLineColor
);
68 mpVirtualDevice
->SetFillColor();
70 Point aPoint1
, aPoint2
, aPoint3
, aPoint4
;
71 OutputDeviceTestCommon::createDiamondPoints(maVDRectangle
, 4, aPoint1
, aPoint2
, aPoint3
, aPoint4
);
73 tools::Polygon
aPolygon(4);
75 aPolygon
.SetPoint(aPoint1
, 0);
76 aPolygon
.SetPoint(aPoint2
, 1);
77 aPolygon
.SetPoint(aPoint3
, 2);
78 aPolygon
.SetPoint(aPoint4
, 3);
79 aPolygon
.Optimize(PolyOptimizeFlags::CLOSE
);
81 mpVirtualDevice
->DrawPolygon(aPolygon
);
83 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
86 Bitmap
OutputDeviceTestPolygon::setupLines()
88 initialSetup(13, 13, constBackgroundColor
);
90 mpVirtualDevice
->SetLineColor(constLineColor
);
91 mpVirtualDevice
->SetFillColor();
93 Point aHorizontalLinePoint1
, aHorizontalLinePoint2
;
94 Point aVerticalLinePoint1
, aVerticalLinePoint2
;
95 Point aDiagonalLinePoint1
, aDiagonalLinePoint2
;
97 OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
98 maVDRectangle
, aHorizontalLinePoint1
, aHorizontalLinePoint2
,
99 aVerticalLinePoint1
, aVerticalLinePoint2
,
100 aDiagonalLinePoint1
, aDiagonalLinePoint2
);
102 tools::Polygon
aHorizontalPolygon(2);
103 aHorizontalPolygon
.SetPoint(aHorizontalLinePoint1
, 0);
104 aHorizontalPolygon
.SetPoint(aHorizontalLinePoint2
, 1);
105 mpVirtualDevice
->DrawPolygon(aHorizontalPolygon
);
107 tools::Polygon
aVerticalPolygon(2);
108 aVerticalPolygon
.SetPoint(aVerticalLinePoint1
, 0);
109 aVerticalPolygon
.SetPoint(aVerticalLinePoint2
, 1);
110 mpVirtualDevice
->DrawPolygon(aVerticalPolygon
);
112 tools::Polygon
aDiagonalPolygon(2);
113 aDiagonalPolygon
.SetPoint(aDiagonalLinePoint1
, 0);
114 aDiagonalPolygon
.SetPoint(aDiagonalLinePoint2
, 1);
115 mpVirtualDevice
->DrawPolygon(aDiagonalPolygon
);
117 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
120 Bitmap
OutputDeviceTestPolygon::setupAALines()
122 initialSetup(13, 13, constBackgroundColor
);
124 mpVirtualDevice
->SetAntialiasing(AntialiasingFlags::Enable
);
125 mpVirtualDevice
->SetLineColor(constLineColor
);
126 mpVirtualDevice
->SetFillColor();
128 Point aHorizontalLinePoint1
, aHorizontalLinePoint2
;
129 Point aVerticalLinePoint1
, aVerticalLinePoint2
;
130 Point aDiagonalLinePoint1
, aDiagonalLinePoint2
;
132 OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
133 maVDRectangle
, aHorizontalLinePoint1
, aHorizontalLinePoint2
,
134 aVerticalLinePoint1
, aVerticalLinePoint2
,
135 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 } // end namespace vcl::test
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */