calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qa / cppunit / drawmode.cxx
blob9a1408bb2ec999c967f69bf96c75b15bf3a67d1f
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/.
8 */
10 #include <test/bootstrapfixture.hxx>
11 #include <cppunit/TestAssert.h>
13 #include <tools/color.hxx>
15 #include <vcl/font.hxx>
16 #include <vcl/metric.hxx>
17 #include <vcl/settings.hxx>
19 #include <bitmap/BitmapWriteAccess.hxx>
20 #include <drawmode.hxx>
22 class VclDrawModeTest : public test::BootstrapFixture
24 public:
25 VclDrawModeTest()
26 : BootstrapFixture(true, false)
30 void testDrawModeLineColor();
31 void testDrawModeFillColor();
32 void testDrawModeHatchColor();
33 void testDrawModeTextColor();
34 void testDrawModeFontColor();
35 void testDrawModeBitmapEx();
37 CPPUNIT_TEST_SUITE(VclDrawModeTest);
39 CPPUNIT_TEST(testDrawModeLineColor);
40 CPPUNIT_TEST(testDrawModeFillColor);
41 CPPUNIT_TEST(testDrawModeHatchColor);
42 CPPUNIT_TEST(testDrawModeTextColor);
43 CPPUNIT_TEST(testDrawModeFontColor);
44 CPPUNIT_TEST(testDrawModeBitmapEx);
46 CPPUNIT_TEST_SUITE_END();
49 void VclDrawModeTest::testDrawModeLineColor()
51 const Color aColor = COL_RED;
52 const sal_uInt8 cLum = aColor.GetLuminance();
53 const StyleSettings aStyleSettings;
55 CPPUNIT_ASSERT_EQUAL(
56 COL_BLACK, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
57 CPPUNIT_ASSERT_EQUAL(
58 COL_WHITE, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
59 CPPUNIT_ASSERT_EQUAL(
60 Color(cLum, cLum, cLum),
61 vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
62 CPPUNIT_ASSERT_EQUAL(
63 aStyleSettings.GetWindowTextColor(),
64 vcl::drawmode::GetLineColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
66 Color aTransparentRed = COL_RED;
67 aTransparentRed.SetAlpha(100);
69 CPPUNIT_ASSERT_EQUAL(
70 aTransparentRed,
71 vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::BlackLine, aStyleSettings));
72 CPPUNIT_ASSERT_EQUAL(
73 aTransparentRed,
74 vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::WhiteLine, aStyleSettings));
75 CPPUNIT_ASSERT_EQUAL(
76 aTransparentRed,
77 vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::GrayLine, aStyleSettings));
78 CPPUNIT_ASSERT_EQUAL(
79 aTransparentRed,
80 vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::SettingsLine, aStyleSettings));
82 // noops
83 CPPUNIT_ASSERT_EQUAL(
84 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::NoFill, aStyleSettings));
85 CPPUNIT_ASSERT_EQUAL(
86 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
87 CPPUNIT_ASSERT_EQUAL(
88 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
89 CPPUNIT_ASSERT_EQUAL(
90 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
91 CPPUNIT_ASSERT_EQUAL(
92 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
93 CPPUNIT_ASSERT_EQUAL(
94 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
95 CPPUNIT_ASSERT_EQUAL(
96 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
97 CPPUNIT_ASSERT_EQUAL(
98 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
99 CPPUNIT_ASSERT_EQUAL(
100 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
101 CPPUNIT_ASSERT_EQUAL(
102 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
103 CPPUNIT_ASSERT_EQUAL(
104 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
105 CPPUNIT_ASSERT_EQUAL(
106 aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
109 void VclDrawModeTest::testDrawModeFillColor()
111 const Color aColor = COL_RED;
112 const sal_uInt8 cLum = aColor.GetLuminance();
113 const StyleSettings aStyleSettings;
115 CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::NoFill,
116 aStyleSettings));
117 CPPUNIT_ASSERT_EQUAL(
118 COL_BLACK, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
119 CPPUNIT_ASSERT_EQUAL(
120 COL_WHITE, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
121 CPPUNIT_ASSERT_EQUAL(
122 Color(cLum, cLum, cLum),
123 vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
124 CPPUNIT_ASSERT_EQUAL(
125 aStyleSettings.GetWindowColor(),
126 vcl::drawmode::GetFillColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
128 Color aTransparentRed = COL_RED;
129 aTransparentRed.SetAlpha(100);
131 CPPUNIT_ASSERT_EQUAL(
132 aTransparentRed,
133 vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::BlackLine, aStyleSettings));
134 CPPUNIT_ASSERT_EQUAL(
135 aTransparentRed,
136 vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::WhiteLine, aStyleSettings));
137 CPPUNIT_ASSERT_EQUAL(
138 aTransparentRed,
139 vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::GrayLine, aStyleSettings));
140 CPPUNIT_ASSERT_EQUAL(
141 aTransparentRed,
142 vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::SettingsLine, aStyleSettings));
144 // noops
145 CPPUNIT_ASSERT_EQUAL(
146 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
147 CPPUNIT_ASSERT_EQUAL(
148 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
149 CPPUNIT_ASSERT_EQUAL(
150 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
151 CPPUNIT_ASSERT_EQUAL(
152 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
153 CPPUNIT_ASSERT_EQUAL(
154 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
155 CPPUNIT_ASSERT_EQUAL(
156 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
157 CPPUNIT_ASSERT_EQUAL(
158 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
159 CPPUNIT_ASSERT_EQUAL(
160 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
161 CPPUNIT_ASSERT_EQUAL(
162 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
163 CPPUNIT_ASSERT_EQUAL(
164 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
165 CPPUNIT_ASSERT_EQUAL(
166 aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
169 void VclDrawModeTest::testDrawModeHatchColor()
171 const Color aColor = COL_RED;
172 const sal_uInt8 cLum = aColor.GetLuminance();
173 const StyleSettings aStyleSettings;
175 CPPUNIT_ASSERT_EQUAL(
176 COL_BLACK, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
177 CPPUNIT_ASSERT_EQUAL(
178 COL_WHITE, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
179 CPPUNIT_ASSERT_EQUAL(
180 Color(cLum, cLum, cLum),
181 vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
182 CPPUNIT_ASSERT_EQUAL(
183 aStyleSettings.GetWindowTextColor(),
184 vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
186 // noops
187 CPPUNIT_ASSERT_EQUAL(
188 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::NoFill, aStyleSettings));
189 CPPUNIT_ASSERT_EQUAL(
190 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
191 CPPUNIT_ASSERT_EQUAL(
192 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
193 CPPUNIT_ASSERT_EQUAL(
194 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
195 CPPUNIT_ASSERT_EQUAL(
196 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
197 CPPUNIT_ASSERT_EQUAL(
198 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
199 CPPUNIT_ASSERT_EQUAL(
200 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
201 CPPUNIT_ASSERT_EQUAL(
202 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
203 CPPUNIT_ASSERT_EQUAL(
204 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
205 CPPUNIT_ASSERT_EQUAL(
206 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
207 CPPUNIT_ASSERT_EQUAL(
208 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
209 CPPUNIT_ASSERT_EQUAL(
210 aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
213 void VclDrawModeTest::testDrawModeTextColor()
215 const Color aColor = COL_RED;
216 const sal_uInt8 cLum = aColor.GetLuminance();
217 const StyleSettings aStyleSettings;
219 CPPUNIT_ASSERT_EQUAL(
220 COL_BLACK, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
221 CPPUNIT_ASSERT_EQUAL(
222 COL_WHITE, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
223 CPPUNIT_ASSERT_EQUAL(
224 Color(cLum, cLum, cLum),
225 vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
226 CPPUNIT_ASSERT_EQUAL(
227 aStyleSettings.GetWindowTextColor(),
228 vcl::drawmode::GetTextColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
230 // noops
231 CPPUNIT_ASSERT_EQUAL(
232 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
233 CPPUNIT_ASSERT_EQUAL(
234 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
235 CPPUNIT_ASSERT_EQUAL(
236 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
237 CPPUNIT_ASSERT_EQUAL(
238 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
239 CPPUNIT_ASSERT_EQUAL(
240 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::NoFill, aStyleSettings));
241 CPPUNIT_ASSERT_EQUAL(
242 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
243 CPPUNIT_ASSERT_EQUAL(
244 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
245 CPPUNIT_ASSERT_EQUAL(
246 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
247 CPPUNIT_ASSERT_EQUAL(
248 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
249 CPPUNIT_ASSERT_EQUAL(
250 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
251 CPPUNIT_ASSERT_EQUAL(
252 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
253 CPPUNIT_ASSERT_EQUAL(
254 aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
257 void VclDrawModeTest::testDrawModeFontColor()
259 const StyleSettings aStyleSettings;
261 vcl::Font aFont;
262 aFont.SetFillColor(COL_RED);
264 // black text and fill
265 aFont.SetTransparent(false);
266 vcl::Font aTestFont = vcl::drawmode::GetFont(
267 aFont, DrawModeFlags::BlackText | DrawModeFlags::BlackFill, aStyleSettings);
268 CPPUNIT_ASSERT_EQUAL(COL_BLACK, aTestFont.GetColor());
269 CPPUNIT_ASSERT_EQUAL(COL_BLACK, aTestFont.GetFillColor());
271 aFont.SetTransparent(true);
272 aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::BlackText | DrawModeFlags::BlackFill,
273 aStyleSettings);
274 CPPUNIT_ASSERT_EQUAL(COL_BLACK, aTestFont.GetColor());
275 CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
277 // white text and fill
278 aFont.SetTransparent(false);
279 aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::WhiteText | DrawModeFlags::WhiteFill,
280 aStyleSettings);
281 CPPUNIT_ASSERT_EQUAL(COL_WHITE, aTestFont.GetColor());
282 CPPUNIT_ASSERT_EQUAL(COL_WHITE, aTestFont.GetFillColor());
284 aFont.SetTransparent(true);
285 aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::WhiteText | DrawModeFlags::WhiteFill,
286 aStyleSettings);
287 CPPUNIT_ASSERT_EQUAL(COL_WHITE, aTestFont.GetColor());
288 CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
290 // gray text and fill
291 const sal_uInt8 cTextLum = aFont.GetColor().GetLuminance();
292 const Color aTextGray(cTextLum, cTextLum, cTextLum);
293 const sal_uInt8 cFillLum = aFont.GetFillColor().GetLuminance();
294 const Color aFillGray(cFillLum, cFillLum, cFillLum);
296 aFont.SetTransparent(false);
297 aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::GrayText | DrawModeFlags::GrayFill,
298 aStyleSettings);
299 CPPUNIT_ASSERT_EQUAL(aTextGray, aTestFont.GetColor());
300 CPPUNIT_ASSERT_EQUAL(aFillGray, aTestFont.GetFillColor());
302 aFont.SetTransparent(true);
303 aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::GrayText | DrawModeFlags::GrayFill,
304 aStyleSettings);
305 CPPUNIT_ASSERT_EQUAL(aTextGray, aTestFont.GetColor());
306 CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
308 // no text fill
309 aFont.SetTransparent(false);
310 aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::NoFill, aStyleSettings);
311 CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, aTestFont.GetFillColor());
313 aFont.SetTransparent(true);
314 aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::NoFill, aStyleSettings);
315 CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
317 // white text and fill
318 aFont.SetTransparent(false);
319 aTestFont = vcl::drawmode::GetFont(
320 aFont, DrawModeFlags::SettingsText | DrawModeFlags::SettingsFill, aStyleSettings);
321 CPPUNIT_ASSERT_EQUAL(aStyleSettings.GetWindowTextColor(), aTestFont.GetColor());
322 CPPUNIT_ASSERT_EQUAL(aStyleSettings.GetWindowColor(), aTestFont.GetFillColor());
324 aFont.SetTransparent(true);
325 aTestFont = vcl::drawmode::GetFont(
326 aFont, DrawModeFlags::SettingsText | DrawModeFlags::SettingsFill, aStyleSettings);
327 CPPUNIT_ASSERT_EQUAL(aStyleSettings.GetWindowTextColor(), aTestFont.GetColor());
328 CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
331 void VclDrawModeTest::testDrawModeBitmapEx()
333 const StyleSettings aStyleSettings;
335 Bitmap aBmp(Size(1, 1), vcl::PixelFormat::N24_BPP);
336 BitmapWriteAccess(aBmp).SetPixel(0, 0, BitmapColor(COL_RED));
338 BitmapEx aBmpEx(aBmp);
341 BitmapEx aResultBitmapEx(vcl::drawmode::GetBitmapEx(aBmpEx, DrawModeFlags::GrayBitmap));
342 Bitmap aResultBitmap(aResultBitmapEx.GetBitmap());
343 Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
345 const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
346 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x26, 0x26, 0x26), rColor);
349 // any other operation other than DrawModeFlags::GrayBitmap is a noop
351 BitmapEx aResultBitmapEx(vcl::drawmode::GetBitmapEx(aBmpEx, DrawModeFlags::NoFill));
352 Bitmap aResultBitmap(aResultBitmapEx.GetBitmap());
353 Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
355 const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
356 CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), rColor);
360 CPPUNIT_TEST_SUITE_REGISTRATION(VclDrawModeTest);
362 CPPUNIT_PLUGIN_IMPLEMENT();
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */