Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / vcl / backendtest / outputdevice / line.cxx
blob5cb6db10a9af440609c59f60e49248032516b67b
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 #include <basegfx/matrix/b2dhommatrix.hxx>
14 #include <vcl/BitmapReadAccess.hxx>
16 #include <list>
18 namespace vcl::test {
20 namespace
23 void drawLineOffset(OutputDevice& rDevice, tools::Rectangle const & rRect, int nOffset)
26 int nMidOffset = rRect.GetWidth()/2;
27 Point aLeftTop (rRect.Left() + nOffset - (nOffset+1)/2, rRect.Top() + nOffset - 1);
28 Point aRightTop (rRect.Right() - nMidOffset - nOffset/3, rRect.Top() + nOffset - 1);
29 Point aLeftBottom (rRect.Left() + nOffset - (nOffset+1)/2, rRect.Bottom() - nOffset + 1);
30 Point aRightBottom (rRect.Right() - nMidOffset - nOffset/3, rRect.Bottom() - nOffset + 1);
32 rDevice.DrawLine(aLeftTop, aRightTop);
33 rDevice.DrawLine(aRightTop, aRightBottom);
34 rDevice.DrawLine(aRightBottom, aLeftBottom);
35 rDevice.DrawLine(aLeftBottom, aLeftTop);
38 } // end anonymous namespace
40 Bitmap OutputDeviceTestLine::setupRectangle(bool bEnableAA)
42 initialSetup(13, 13, constBackgroundColor, bEnableAA);
44 mpVirtualDevice->SetLineColor(constLineColor);
45 mpVirtualDevice->SetFillColor();
47 drawLineOffset(*mpVirtualDevice, maVDRectangle, 2);
48 drawLineOffset(*mpVirtualDevice, maVDRectangle, 5);
50 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
53 Bitmap OutputDeviceTestLine::setupRectangleOnSize1028()
55 initialSetup(1028, 1028, constBackgroundColor);
57 mpVirtualDevice->SetLineColor(constLineColor);
58 mpVirtualDevice->SetFillColor();
60 drawLineOffset(*mpVirtualDevice, maVDRectangle, 2);
61 drawLineOffset(*mpVirtualDevice, maVDRectangle, 5);
63 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
66 Bitmap OutputDeviceTestLine::setupRectangleOnSize4096()
68 initialSetup(4096, 4096, constBackgroundColor);
70 mpVirtualDevice->SetLineColor(constLineColor);
71 mpVirtualDevice->SetFillColor();
73 drawLineOffset(*mpVirtualDevice, maVDRectangle, 2);
74 drawLineOffset(*mpVirtualDevice, maVDRectangle, 5);
76 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
79 Bitmap OutputDeviceTestLine::setupDiamond()
81 initialSetup(11, 11, constBackgroundColor);
83 mpVirtualDevice->SetLineColor(constLineColor);
84 mpVirtualDevice->SetFillColor();
86 Point aPoint1, aPoint2, aPoint3, aPoint4;
87 OutputDeviceTestCommon::createDiamondPoints(maVDRectangle, 4, aPoint1, aPoint2, aPoint3, aPoint4);
89 mpVirtualDevice->DrawLine(aPoint1, aPoint2);
90 mpVirtualDevice->DrawLine(aPoint2, aPoint3);
91 mpVirtualDevice->DrawLine(aPoint3, aPoint4);
92 mpVirtualDevice->DrawLine(aPoint4, aPoint1);
94 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
97 Bitmap OutputDeviceTestLine::setupLines()
99 initialSetup(13, 13, constBackgroundColor);
101 mpVirtualDevice->SetLineColor(constLineColor);
102 mpVirtualDevice->SetFillColor();
104 Point aHorizontalLinePoint1, aHorizontalLinePoint2;
105 Point aVerticalLinePoint1, aVerticalLinePoint2;
106 Point aDiagonalLinePoint1, aDiagonalLinePoint2;
108 OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
109 maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2,
110 aVerticalLinePoint1, aVerticalLinePoint2,
111 aDiagonalLinePoint1, aDiagonalLinePoint2);
113 mpVirtualDevice->DrawLine(aHorizontalLinePoint1, aHorizontalLinePoint2);
114 mpVirtualDevice->DrawLine(aVerticalLinePoint1, aVerticalLinePoint2);
115 mpVirtualDevice->DrawLine(aDiagonalLinePoint1, aDiagonalLinePoint2);
117 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
120 Bitmap OutputDeviceTestLine::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 mpVirtualDevice->DrawLine(aHorizontalLinePoint1, aHorizontalLinePoint2);
138 mpVirtualDevice->DrawLine(aVerticalLinePoint1, aVerticalLinePoint2);
139 mpVirtualDevice->DrawLine(aDiagonalLinePoint1, aDiagonalLinePoint2);
141 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
144 Bitmap OutputDeviceTestLine::setupDashedLine()
146 initialSetup(13, 13, constBackgroundColor);
148 mpVirtualDevice->SetLineColor(constLineColor);
149 mpVirtualDevice->SetFillColor();
151 tools::Rectangle rectangle = maVDRectangle;
152 rectangle.shrink(2);
154 std::vector<double> stroke({ 2.0, 1.0 });
155 mpVirtualDevice->DrawPolyLineDirect( basegfx::B2DHomMatrix(),
156 basegfx::B2DPolygon{
157 basegfx::B2DPoint(rectangle.Left(), rectangle.Top()),
158 basegfx::B2DPoint(rectangle.Left(), rectangle.Bottom()),
159 basegfx::B2DPoint(rectangle.Right(), rectangle.Bottom()),
160 basegfx::B2DPoint(rectangle.Right(), rectangle.Top()),
161 basegfx::B2DPoint(rectangle.Left(), rectangle.Top())},
162 1, 0, &stroke, basegfx::B2DLineJoin::NONE );
164 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
167 TestResult OutputDeviceTestLine::checkDashedLine(Bitmap& rBitmap)
169 TestResult returnValue = TestResult::Passed;
170 for (int i = 0; i < 7; i++)
172 TestResult eResult = TestResult::Passed;
173 if( i == 2 )
175 // Build a sequence of pixels for the drawn rectangle border,
176 // check that they alternate appropriately (there should be
177 // normally 2 line, 1 background).
178 std::list< bool > dash; // true - line color, false - background
179 const int width = rBitmap.GetSizePixel().Width();
180 const int height = rBitmap.GetSizePixel().Height();
181 BitmapReadAccess access(rBitmap);
182 for( int x = 2; x < width - 2; ++x )
183 dash.push_back( access.GetPixel( 2, x ) == constLineColor );
184 for( int y = 3; y < height - 3; ++y )
185 dash.push_back( access.GetPixel( y, width - 3 ) == constLineColor );
186 for( int x = width - 3; x >= 2; --x )
187 dash.push_back( access.GetPixel( height - 3, x ) == constLineColor );
188 for( int y = height - 4; y >= 3; --y )
189 dash.push_back( access.GetPixel( y, 2 ) == constLineColor );
190 for( int x = 2; x < width - 2; ++x ) // repeat, to check also the corner
191 dash.push_back( access.GetPixel( 2, x ) == constLineColor );
192 bool last = false;
193 int lastCount = 0;
194 while( !dash.empty())
196 if( dash.front() == last )
198 ++lastCount;
199 if( lastCount > ( last ? 4 : 3 ))
200 eResult = TestResult::Failed;
201 else if( lastCount > ( last ? 3 : 2 ) && eResult != TestResult::Failed)
202 eResult = TestResult::PassedWithQuirks;
204 else
206 last = dash.front();
207 lastCount = 1;
209 dash.pop_front();
212 else
214 eResult = OutputDeviceTestCommon::checkRectangle(rBitmap, i, constBackgroundColor);
217 if (eResult == TestResult::Failed)
218 returnValue = TestResult::Failed;
219 if (eResult == TestResult::PassedWithQuirks && returnValue != TestResult::Failed)
220 returnValue = TestResult::PassedWithQuirks;
222 return returnValue;
225 constexpr int CAPSHRINK = 25;
226 constexpr int CAPWIDTH = 20;
227 Bitmap OutputDeviceTestLine::setupLineCap( css::drawing::LineCap lineCap )
229 initialSetup(101, 101, constBackgroundColor);
231 mpVirtualDevice->SetLineColor(constLineColor);
232 mpVirtualDevice->SetFillColor();
234 tools::Rectangle rectangle = maVDRectangle;
235 rectangle.shrink(CAPSHRINK);
237 const basegfx::B2DPolygon poly{
238 basegfx::B2DPoint(rectangle.LeftCenter().getX(), rectangle.LeftCenter().getY()),
239 basegfx::B2DPoint(rectangle.RightCenter().getX(), rectangle.RightCenter().getY())};
241 mpVirtualDevice->DrawPolyLineDirect( basegfx::B2DHomMatrix(),poly,
242 CAPWIDTH, 0, nullptr, basegfx::B2DLineJoin::NONE, lineCap );
244 mpVirtualDevice->SetLineColor(constFillColor);
245 mpVirtualDevice->DrawPolyLineDirect( basegfx::B2DHomMatrix(), poly,
246 0, 0, nullptr, basegfx::B2DLineJoin::NONE );
248 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
251 Bitmap OutputDeviceTestLine::setupLineJoin( basegfx::B2DLineJoin lineJoin )
253 initialSetup(101, 101, constBackgroundColor);
255 mpVirtualDevice->SetLineColor(constLineColor);
256 mpVirtualDevice->SetFillColor();
258 tools::Rectangle rectangle = maVDRectangle;
259 rectangle.shrink(CAPSHRINK);
261 const basegfx::B2DPolygon poly{
262 basegfx::B2DPoint(rectangle.TopLeft().getX(), rectangle.TopLeft().getY()),
263 basegfx::B2DPoint(rectangle.TopRight().getX(), rectangle.TopRight().getY()),
264 basegfx::B2DPoint(rectangle.BottomRight().getX(), rectangle.BottomRight().getY())};
266 mpVirtualDevice->DrawPolyLineDirect( basegfx::B2DHomMatrix(), poly,
267 CAPWIDTH, 0, nullptr, lineJoin );
269 mpVirtualDevice->SetLineColor(constFillColor);
270 mpVirtualDevice->DrawPolyLineDirect( basegfx::B2DHomMatrix(), poly,
271 0, 0, nullptr, lineJoin );
273 return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
276 } // end namespace vcl::test
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */