bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / rendercontext / drawmode.cxx
blob995017c1f5b11073926da82beffccf292b0aac69
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/BitmapMonochromeFilter.hxx>
21 #include <vcl/bitmap/BitmapTypes.hxx>
22 #include <vcl/rendercontext/DrawModeFlags.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/virdev.hxx>
26 #include <drawmode.hxx>
28 namespace vcl::drawmode
30 Color GetLineColor(Color const& rColor, DrawModeFlags nDrawMode,
31 StyleSettings const& rStyleSettings)
33 Color aColor(rColor);
35 if (nDrawMode
36 & (DrawModeFlags::BlackLine | DrawModeFlags::WhiteLine | DrawModeFlags::GrayLine
37 | DrawModeFlags::SettingsLine))
39 if (!aColor.IsTransparent())
41 if (nDrawMode & DrawModeFlags::BlackLine)
43 aColor = COL_BLACK;
45 else if (nDrawMode & DrawModeFlags::WhiteLine)
47 aColor = COL_WHITE;
49 else if (nDrawMode & DrawModeFlags::GrayLine)
51 const sal_uInt8 cLum = aColor.GetLuminance();
52 aColor = Color(cLum, cLum, cLum);
54 else if (nDrawMode & DrawModeFlags::SettingsLine)
56 if (nDrawMode & DrawModeFlags::SettingsForSelection)
57 aColor = rStyleSettings.GetHighlightColor();
58 else
59 aColor = rStyleSettings.GetWindowTextColor();
64 return aColor;
67 Color GetFillColor(Color const& rColor, DrawModeFlags nDrawMode,
68 StyleSettings const& rStyleSettings)
70 Color aColor(rColor);
72 if (nDrawMode
73 & (DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill | DrawModeFlags::GrayFill
74 | DrawModeFlags::NoFill | DrawModeFlags::SettingsFill))
76 if (!aColor.IsTransparent())
78 if (nDrawMode & DrawModeFlags::BlackFill)
80 aColor = COL_BLACK;
82 else if (nDrawMode & DrawModeFlags::WhiteFill)
84 aColor = COL_WHITE;
86 else if (nDrawMode & DrawModeFlags::GrayFill)
88 const sal_uInt8 cLum = aColor.GetLuminance();
89 aColor = Color(cLum, cLum, cLum);
91 else if (nDrawMode & DrawModeFlags::NoFill)
93 aColor = COL_TRANSPARENT;
95 else if (nDrawMode & DrawModeFlags::SettingsFill)
97 if (nDrawMode & DrawModeFlags::SettingsForSelection)
98 aColor = rStyleSettings.GetHighlightColor();
99 else
100 aColor = rStyleSettings.GetWindowColor();
105 return aColor;
108 Color GetHatchColor(Color const& rColor, DrawModeFlags nDrawMode,
109 StyleSettings const& rStyleSettings)
111 Color aColor(rColor);
113 if (nDrawMode & DrawModeFlags::BlackLine)
115 aColor = COL_BLACK;
117 else if (nDrawMode & DrawModeFlags::WhiteLine)
119 aColor = COL_WHITE;
121 else if (nDrawMode & DrawModeFlags::GrayLine)
123 const sal_uInt8 cLum = aColor.GetLuminance();
124 aColor = Color(cLum, cLum, cLum);
126 else if (nDrawMode & DrawModeFlags::SettingsLine)
128 if (nDrawMode & DrawModeFlags::SettingsForSelection)
129 aColor = rStyleSettings.GetHighlightColor();
130 else
131 aColor = rStyleSettings.GetWindowTextColor();
134 return aColor;
137 Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode,
138 StyleSettings const& rStyleSettings)
140 Color aColor(rColor);
142 if (nDrawMode
143 & (DrawModeFlags::BlackText | DrawModeFlags::WhiteText | DrawModeFlags::GrayText
144 | DrawModeFlags::SettingsText))
146 if (nDrawMode & DrawModeFlags::BlackText)
148 aColor = COL_BLACK;
150 else if (nDrawMode & DrawModeFlags::WhiteText)
152 aColor = COL_WHITE;
154 else if (nDrawMode & DrawModeFlags::GrayText)
156 const sal_uInt8 cLum = aColor.GetLuminance();
157 aColor = Color(cLum, cLum, cLum);
159 else if (nDrawMode & DrawModeFlags::SettingsText)
161 if (nDrawMode & DrawModeFlags::SettingsForSelection)
162 aColor = rStyleSettings.GetHighlightTextColor();
163 else
164 aColor = rStyleSettings.GetWindowTextColor();
168 return aColor;
171 vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
172 StyleSettings const& rStyleSettings)
174 vcl::Font aFont(rFont);
176 if (nDrawMode
177 & (DrawModeFlags::BlackText | DrawModeFlags::WhiteText | DrawModeFlags::GrayText
178 | DrawModeFlags::SettingsText | DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill
179 | DrawModeFlags::GrayFill | DrawModeFlags::NoFill | DrawModeFlags::SettingsFill))
181 Color aTextColor(aFont.GetColor());
183 if (nDrawMode & DrawModeFlags::BlackText)
185 aTextColor = COL_BLACK;
187 else if (nDrawMode & DrawModeFlags::WhiteText)
189 aTextColor = COL_WHITE;
191 else if (nDrawMode & DrawModeFlags::GrayText)
193 const sal_uInt8 cLum = aTextColor.GetLuminance();
194 aTextColor = Color(cLum, cLum, cLum);
196 else if (nDrawMode & DrawModeFlags::SettingsText)
198 if (nDrawMode & DrawModeFlags::SettingsForSelection)
199 aTextColor = rStyleSettings.GetHighlightTextColor();
200 else
201 aTextColor = rStyleSettings.GetWindowTextColor();
204 aFont.SetColor(aTextColor);
206 if (!aFont.IsTransparent())
208 Color aTextFillColor(aFont.GetFillColor());
210 if (nDrawMode & DrawModeFlags::BlackFill)
212 aTextFillColor = COL_BLACK;
214 else if (nDrawMode & DrawModeFlags::WhiteFill)
216 aTextFillColor = COL_WHITE;
218 else if (nDrawMode & DrawModeFlags::GrayFill)
220 const sal_uInt8 cLum = aTextFillColor.GetLuminance();
221 aTextFillColor = Color(cLum, cLum, cLum);
223 else if (nDrawMode & DrawModeFlags::SettingsFill)
225 if (nDrawMode & DrawModeFlags::SettingsForSelection)
226 aTextFillColor = rStyleSettings.GetHighlightColor();
227 else
228 aTextFillColor = rStyleSettings.GetWindowColor();
230 else if (nDrawMode & DrawModeFlags::NoFill)
232 aTextFillColor = COL_TRANSPARENT;
235 aFont.SetFillColor(aTextFillColor);
239 return aFont;
242 BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode)
244 BitmapEx aBmpEx(rBitmapEx);
246 if (nDrawMode & (DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap))
248 Bitmap aColorBmp(aBmpEx.GetSizePixel(), vcl::PixelFormat::N8_BPP,
249 &Bitmap::GetGreyPalette(256));
250 sal_uInt8 cCmpVal;
252 if (nDrawMode & DrawModeFlags::BlackBitmap)
253 cCmpVal = 0;
254 else
255 cCmpVal = 255;
257 aColorBmp.Erase(Color(cCmpVal, cCmpVal, cCmpVal));
259 if (aBmpEx.IsAlpha())
261 // Create one-bit mask out of alpha channel, by thresholding it at alpha=0.5. As
262 // DRAWMODE_BLACK/WHITEBITMAP requires monochrome output, having alpha-induced
263 // grey levels is not acceptable
264 BitmapEx aMaskEx(aBmpEx.GetAlphaMask().GetBitmap());
265 BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(129));
266 aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
268 else
270 aBmpEx = BitmapEx(aColorBmp, aBmpEx.GetAlphaMask());
274 if (nDrawMode & DrawModeFlags::GrayBitmap && !aBmpEx.IsEmpty())
275 aBmpEx.Convert(BmpConversion::N8BitGreys);
277 return aBmpEx;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */