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>
18 Bitmap
OutputDeviceTestBitmap::setupDrawTransformedBitmap()
20 Size
aBitmapSize(9, 9);
21 Bitmap
aBitmap(aBitmapSize
, 24);
23 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
24 aWriteAccess
->Erase(constFillColor
);
25 aWriteAccess
->SetLineColor(COL_YELLOW
);
26 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
27 aWriteAccess
->DrawRect(tools::Rectangle(2, 2, 6, 6));
30 initialSetup(13, 13, constBackgroundColor
);
32 basegfx::B2DHomMatrix aTransform
;
33 aTransform
.scale(aBitmapSize
.Width(), aBitmapSize
.Height());
34 aTransform
.translate((maVDRectangle
.GetWidth() / 2.0) - (aBitmapSize
.Width() / 2.0),
35 (maVDRectangle
.GetHeight() / 2.0) - (aBitmapSize
.Height() / 2.0));
37 mpVirtualDevice
->DrawTransformedBitmapEx(aTransform
, BitmapEx(aBitmap
));
39 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
43 Bitmap
OutputDeviceTestBitmap::setupDrawBitmap()
45 Size
aBitmapSize(9, 9);
46 Bitmap
aBitmap(aBitmapSize
, 24);
48 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
49 aWriteAccess
->Erase(constFillColor
);
50 aWriteAccess
->SetLineColor(COL_YELLOW
);
51 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
52 aWriteAccess
->DrawRect(tools::Rectangle(2, 2, 6, 6));
55 initialSetup(13, 13, constBackgroundColor
);
57 Point
aPoint((maVDRectangle
.GetWidth() / 2.0) - (aBitmapSize
.Width() / 2.0),
58 (maVDRectangle
.GetHeight() / 2.0) - (aBitmapSize
.Height() / 2.0));
60 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
));
62 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
65 Bitmap
OutputDeviceTestBitmap::setupDrawBitmapExWithAlpha()
67 Size
aBitmapSize(9, 9);
68 Bitmap
aBitmap(aBitmapSize
, 24);
70 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
71 aWriteAccess
->Erase(COL_WHITE
);
72 aWriteAccess
->SetLineColor(Color(0xFF, 0xFF, 0x00));
73 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
74 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
77 AlphaMask
aAlpha(aBitmapSize
);
79 AlphaScopedWriteAccess
aWriteAccess(aAlpha
);
80 aWriteAccess
->Erase(COL_WHITE
);
81 aWriteAccess
->SetLineColor(Color(0x44, 0x44, 0x44));
82 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
83 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
86 initialSetup(13, 13, constBackgroundColor
);
88 Point
aPoint(alignToCenter(maVDRectangle
, tools::Rectangle(Point(), aBitmapSize
)).TopLeft());
90 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
, aAlpha
));
92 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
95 Bitmap
OutputDeviceTestBitmap::setupDrawMask()
97 Size
aBitmapSize(9, 9);
98 Bitmap
aBitmap(aBitmapSize
, 24);
100 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
101 aWriteAccess
->Erase(COL_WHITE
);
102 aWriteAccess
->SetLineColor(COL_BLACK
);
103 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
104 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
107 initialSetup(13, 13, constBackgroundColor
);
109 mpVirtualDevice
->DrawMask(Point(2, 2), aBitmap
, constLineColor
);
111 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
114 BitmapEx
OutputDeviceTestBitmap::setupDrawBlend()
116 Size
aBitmapSize(9, 9);
117 Bitmap
aBitmap(aBitmapSize
, 24);
119 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
120 aWriteAccess
->Erase(COL_WHITE
);
121 aWriteAccess
->SetLineColor(Color(0xFF, 0xFF, 0x00));
122 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
123 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
126 AlphaMask
aAlpha(aBitmapSize
);
128 AlphaScopedWriteAccess
aWriteAccess(aAlpha
);
129 aWriteAccess
->Erase(COL_WHITE
);
130 aWriteAccess
->SetLineColor(Color(0x44, 0x44, 0x44));
131 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
132 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
135 initialSetup(13, 13, COL_TRANSPARENT
, false, true);
136 mpVirtualDevice
->SetFillColor(constBackgroundColor
);
137 mpVirtualDevice
->SetLineColor(constBackgroundColor
);
138 // Leave the outer part of the device transparent, the inner part set to the background color.
139 // This will test blending of VirtualDevice's "alpha" device (outer yellow rectangle
140 // will be blended with transparent background, inner with the grey one).
141 mpVirtualDevice
->DrawRect( tools::Rectangle( Point( 3, 3 ), Size( 7, 7 )));
143 Point
aPoint(alignToCenter(maVDRectangle
, tools::Rectangle(Point(), aBitmapSize
)).TopLeft());
145 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
, aAlpha
));
147 return mpVirtualDevice
->GetBitmapEx(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
150 TestResult
OutputDeviceTestBitmap::checkTransformedBitmap(Bitmap
& rBitmap
)
152 std::vector
<Color
> aExpected
154 constBackgroundColor
, constBackgroundColor
,
155 COL_YELLOW
, constFillColor
, COL_YELLOW
, constFillColor
, constFillColor
157 return checkRectangles(rBitmap
, aExpected
);
160 TestResult
OutputDeviceTestBitmap::checkBitmapExWithAlpha(Bitmap
& rBitmap
)
162 const Color
aBlendedColor(0xEE, 0xEE, 0x33);
164 std::vector
<Color
> aExpected
166 constBackgroundColor
, constBackgroundColor
,
167 aBlendedColor
, constBackgroundColor
, constBackgroundColor
,
168 aBlendedColor
, constBackgroundColor
170 return checkRectangles(rBitmap
, aExpected
);
173 TestResult
OutputDeviceTestBitmap::checkMask(Bitmap
& rBitmap
)
175 return checkRectangle(rBitmap
);
178 TestResult
OutputDeviceTestBitmap::checkBlend(const BitmapEx
& rBitmapEx
)
180 const Color
aBlendedColor(0xEE, 0xEE, 0x33);
182 std::vector
<Color
> aExpected
184 COL_WHITE
, COL_WHITE
, COL_YELLOW
, constBackgroundColor
,
185 constBackgroundColor
, aBlendedColor
, constBackgroundColor
187 Bitmap
aBitmap(rBitmapEx
.GetBitmap());
188 return checkRectangles(aBitmap
, aExpected
);
191 } // end namespace vcl::test
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */