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>
13 #include <basegfx/matrix/b2dhommatrix.hxx>
14 #include <bitmapwriteaccess.hxx>
19 Bitmap
OutputDeviceTestBitmap::setupDrawTransformedBitmap()
21 Size
aBitmapSize(9, 9);
22 Bitmap
aBitmap(aBitmapSize
, 24);
24 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
25 aWriteAccess
->Erase(constFillColor
);
26 aWriteAccess
->SetLineColor(COL_YELLOW
);
27 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
28 aWriteAccess
->DrawRect(tools::Rectangle(2, 2, 6, 6));
31 initialSetup(13, 13, constBackgroundColor
);
33 basegfx::B2DHomMatrix aTransform
;
34 aTransform
.scale(aBitmapSize
.Width(), aBitmapSize
.Height());
35 aTransform
.translate((maVDRectangle
.GetWidth() / 2.0) - (aBitmapSize
.Width() / 2.0),
36 (maVDRectangle
.GetHeight() / 2.0) - (aBitmapSize
.Height() / 2.0));
38 mpVirtualDevice
->DrawTransformedBitmapEx(aTransform
, BitmapEx(aBitmap
));
40 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
44 Bitmap
OutputDeviceTestBitmap::setupDrawBitmap()
46 Size
aBitmapSize(9, 9);
47 Bitmap
aBitmap(aBitmapSize
, 24);
49 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
50 aWriteAccess
->Erase(constFillColor
);
51 aWriteAccess
->SetLineColor(COL_YELLOW
);
52 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
53 aWriteAccess
->DrawRect(tools::Rectangle(2, 2, 6, 6));
56 initialSetup(13, 13, constBackgroundColor
);
58 Point
aPoint((maVDRectangle
.GetWidth() / 2.0) - (aBitmapSize
.Width() / 2.0),
59 (maVDRectangle
.GetHeight() / 2.0) - (aBitmapSize
.Height() / 2.0));
61 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
));
63 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
66 Bitmap
OutputDeviceTestBitmap::setupDrawBitmapExWithAlpha()
68 Size
aBitmapSize(9, 9);
69 Bitmap
aBitmap(aBitmapSize
, 24);
71 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
72 aWriteAccess
->Erase(COL_WHITE
);
73 aWriteAccess
->SetLineColor(Color(0xFF, 0xFF, 0x00));
74 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
75 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
78 AlphaMask
aAlpha(aBitmapSize
);
80 AlphaScopedWriteAccess
aWriteAccess(aAlpha
);
81 aWriteAccess
->Erase(COL_WHITE
);
82 aWriteAccess
->SetLineColor(Color(0x44, 0x44, 0x44));
83 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
84 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
87 initialSetup(13, 13, constBackgroundColor
);
89 Point
aPoint(alignToCenter(maVDRectangle
, tools::Rectangle(Point(), aBitmapSize
)).TopLeft());
91 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
, aAlpha
));
93 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
96 Bitmap
OutputDeviceTestBitmap::setupDrawMask()
98 Size
aBitmapSize(9, 9);
99 Bitmap
aBitmap(aBitmapSize
, 24);
101 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
102 aWriteAccess
->Erase(COL_WHITE
);
103 aWriteAccess
->SetLineColor(COL_BLACK
);
104 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
105 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
108 initialSetup(13, 13, constBackgroundColor
);
110 mpVirtualDevice
->DrawMask(Point(2, 2), aBitmap
, constFillColor
);
112 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
115 TestResult
OutputDeviceTestBitmap::checkTransformedBitmap(Bitmap
& rBitmap
)
117 std::vector
<Color
> aExpected
119 constBackgroundColor
, constBackgroundColor
,
120 COL_YELLOW
, constFillColor
, COL_YELLOW
, constFillColor
, constFillColor
122 return checkRectangles(rBitmap
, aExpected
);
125 TestResult
OutputDeviceTestBitmap::checkBitmapExWithAlpha(Bitmap
& rBitmap
)
127 const Color
aBlendedColor(0xEE, 0xEE, 0x33);
129 std::vector
<Color
> aExpected
131 constBackgroundColor
, constBackgroundColor
,
132 aBlendedColor
, constBackgroundColor
, constBackgroundColor
,
133 aBlendedColor
, constBackgroundColor
135 return checkRectangles(rBitmap
, aExpected
);
138 TestResult
OutputDeviceTestBitmap::checkMask(Bitmap
& rBitmap
)
140 return checkRectangle(rBitmap
);
143 }} // end namespace vcl::test
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */