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>
12 #include <vcl/bitmapex.hxx>
18 void drawPolyLineOffset(OutputDevice
& rDevice
, tools::Rectangle
const& rRect
, int nOffset
)
20 int nMidOffset
= rRect
.GetWidth() / 2;
21 basegfx::B2DPolygon aPolygon
{
22 basegfx::B2DPoint(rRect
.Left() + nOffset
- (nOffset
+ 1) / 2, rRect
.Top() + nOffset
- 1),
23 basegfx::B2DPoint(rRect
.Right() - nMidOffset
- nOffset
/ 3, rRect
.Top() + nOffset
- 1),
24 basegfx::B2DPoint(rRect
.Right() - nMidOffset
- nOffset
/ 3, rRect
.Bottom() - nOffset
+ 1),
25 basegfx::B2DPoint(rRect
.Left() + nOffset
- (nOffset
+ 1) / 2, rRect
.Bottom() - nOffset
+ 1),
27 aPolygon
.setClosed(true);
29 rDevice
.DrawPolyLine(aPolygon
, 0.0); // draw hairline
32 void addDiamondPoints(tools::Rectangle rRect
, int nOffset
, basegfx::B2DPolygon
& rPolygon
)
34 double midPointX
= rRect
.Left() + (rRect
.Right() - rRect
.Left()) / 2.0;
35 double midPointY
= rRect
.Top() + (rRect
.Bottom() - rRect
.Top()) / 2.0;
37 rPolygon
.append({ midPointX
, midPointY
- nOffset
});
38 rPolygon
.append({ midPointX
+ nOffset
, midPointY
});
39 rPolygon
.append({ midPointX
, midPointY
+ nOffset
});
40 rPolygon
.append({ midPointX
- nOffset
, midPointY
});
43 } // end anonymous namespace
45 Bitmap
OutputDeviceTestPolyLineB2D::setupRectangle(bool bEnableAA
)
47 initialSetup(13, 13, constBackgroundColor
, bEnableAA
);
49 mpVirtualDevice
->SetLineColor(constLineColor
);
50 mpVirtualDevice
->SetFillColor();
52 drawPolyLineOffset(*mpVirtualDevice
, maVDRectangle
, 2);
53 drawPolyLineOffset(*mpVirtualDevice
, maVDRectangle
, 5);
55 return mpVirtualDevice
->GetBitmapEx(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize())
59 Bitmap
OutputDeviceTestPolyLineB2D::setupDiamond()
61 initialSetup(11, 11, constBackgroundColor
);
63 mpVirtualDevice
->SetLineColor(constLineColor
);
64 mpVirtualDevice
->SetFillColor();
66 basegfx::B2DPolygon aPolygon
;
67 addDiamondPoints(maVDRectangle
, 4, aPolygon
);
68 aPolygon
.setClosed(true);
70 mpVirtualDevice
->DrawPolyLine(aPolygon
);
72 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
75 Bitmap
OutputDeviceTestPolyLineB2D::setupBezier()
77 initialSetup(21, 21, constBackgroundColor
, false);
79 mpVirtualDevice
->SetLineColor(constLineColor
);
80 mpVirtualDevice
->SetFillColor();
82 basegfx::B2DPolygon aPolygon
;
83 addDiamondPoints(maVDRectangle
, 8, aPolygon
);
84 aPolygon
.setClosed(true);
86 double minX
= maVDRectangle
.Left() + 4;
87 double maxX
= maVDRectangle
.Right() - 4;
88 double minY
= maVDRectangle
.Top() + 4;
89 double maxY
= maVDRectangle
.Bottom() - 4;
91 aPolygon
.setControlPoints(0, { minX
, minY
}, { maxX
, minY
});
92 aPolygon
.setControlPoints(1, { maxX
, minY
}, { maxX
, maxY
});
93 aPolygon
.setControlPoints(2, { maxX
, maxY
}, { minX
, maxY
});
94 aPolygon
.setControlPoints(3, { minX
, maxY
}, { minX
, minY
});
96 mpVirtualDevice
->DrawPolyLine(aPolygon
);
98 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
101 Bitmap
OutputDeviceTestPolyLineB2D::setupAABezier()
103 initialSetup(21, 21, constBackgroundColor
, true);
105 mpVirtualDevice
->SetLineColor(constLineColor
);
106 mpVirtualDevice
->SetFillColor();
108 basegfx::B2DPolygon aPolygon
;
109 addDiamondPoints(maVDRectangle
, 8, aPolygon
);
110 aPolygon
.setClosed(true);
112 double minX
= maVDRectangle
.Left() + 4;
113 double maxX
= maVDRectangle
.Right() - 4;
114 double minY
= maVDRectangle
.Top() + 4;
115 double maxY
= maVDRectangle
.Bottom() - 4;
117 aPolygon
.setControlPoints(0, { minX
, minY
}, { maxX
, minY
});
118 aPolygon
.setControlPoints(1, { maxX
, minY
}, { maxX
, maxY
});
119 aPolygon
.setControlPoints(2, { maxX
, maxY
}, { minX
, maxY
});
120 aPolygon
.setControlPoints(3, { minX
, maxY
}, { minX
, minY
});
122 mpVirtualDevice
->DrawPolyLine(aPolygon
);
124 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
127 Bitmap
OutputDeviceTestPolyLineB2D::setupHalfEllipse(bool aEnableAA
)
129 initialSetup(19, 21, constBackgroundColor
, aEnableAA
);
131 mpVirtualDevice
->SetLineColor(constLineColor
);
132 mpVirtualDevice
->SetFillColor();
134 mpVirtualDevice
->DrawPolyLine(OutputDeviceTestCommon::createHalfEllipsePolygon());
136 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
139 Bitmap
OutputDeviceTestPolyLineB2D::setupRectangleOnSize1028()
141 initialSetup(1028, 1028, constBackgroundColor
);
143 mpVirtualDevice
->SetLineColor(constLineColor
);
144 mpVirtualDevice
->SetFillColor();
146 drawPolyLineOffset(*mpVirtualDevice
, maVDRectangle
, 2);
147 drawPolyLineOffset(*mpVirtualDevice
, maVDRectangle
, 5);
149 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
152 Bitmap
OutputDeviceTestPolyLineB2D::setupRectangleOnSize4096()
154 initialSetup(4096, 4096, constBackgroundColor
);
156 mpVirtualDevice
->SetLineColor(constLineColor
);
157 mpVirtualDevice
->SetFillColor();
159 drawPolyLineOffset(*mpVirtualDevice
, maVDRectangle
, 2);
160 drawPolyLineOffset(*mpVirtualDevice
, maVDRectangle
, 5);
162 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
165 Bitmap
OutputDeviceTestPolyLineB2D::setupOpenPolygon()
167 initialSetup(21, 21, constBackgroundColor
);
169 mpVirtualDevice
->SetLineColor(constLineColor
);
170 mpVirtualDevice
->SetFillColor();
172 mpVirtualDevice
->DrawPolyLine(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle
));
173 mpVirtualDevice
->DrawPolyLine(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle
, 7));
175 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
178 Bitmap
OutputDeviceTestPolyLineB2D::setupOpenBezier()
180 initialSetup(21, 21, constBackgroundColor
);
182 mpVirtualDevice
->SetLineColor(constLineColor
);
183 mpVirtualDevice
->SetFillColor();
185 mpVirtualDevice
->DrawPolyLine(OutputDeviceTestCommon::createOpenBezier());
187 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
190 } // end namespace vcl::test
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */