LibreOffice Module vcl (master) 1
drawmode.cxx
Go to the documentation of this file.
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.
4 *
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 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
23#include <vcl/settings.hxx>
24#include <vcl/virdev.hxx>
25
26#include <drawmode.hxx>
27
29{
30Color GetLineColor(Color const& rColor, DrawModeFlags nDrawMode,
31 StyleSettings const& rStyleSettings)
32{
33 Color aColor(rColor);
34
35 if (nDrawMode
38 {
39 if (!aColor.IsTransparent())
40 {
41 if (nDrawMode & DrawModeFlags::BlackLine)
42 {
43 aColor = COL_BLACK;
44 }
45 else if (nDrawMode & DrawModeFlags::WhiteLine)
46 {
47 aColor = COL_WHITE;
48 }
49 else if (nDrawMode & DrawModeFlags::GrayLine)
50 {
51 const sal_uInt8 cLum = aColor.GetLuminance();
52 aColor = Color(cLum, cLum, cLum);
53 }
54 else if (nDrawMode & DrawModeFlags::SettingsLine)
55 {
57 aColor = rStyleSettings.GetHighlightColor();
58 else
59 aColor = rStyleSettings.GetWindowTextColor();
60 }
61 }
62 }
63
64 return aColor;
65}
66
67Color GetFillColor(Color const& rColor, DrawModeFlags nDrawMode,
68 StyleSettings const& rStyleSettings)
69{
70 Color aColor(rColor);
71
72 if (nDrawMode
75 {
76 if (!aColor.IsTransparent())
77 {
78 if (nDrawMode & DrawModeFlags::BlackFill)
79 {
80 aColor = COL_BLACK;
81 }
82 else if (nDrawMode & DrawModeFlags::WhiteFill)
83 {
84 aColor = COL_WHITE;
85 }
86 else if (nDrawMode & DrawModeFlags::GrayFill)
87 {
88 const sal_uInt8 cLum = aColor.GetLuminance();
89 aColor = Color(cLum, cLum, cLum);
90 }
91 else if (nDrawMode & DrawModeFlags::NoFill)
92 {
93 aColor = COL_TRANSPARENT;
94 }
95 else if (nDrawMode & DrawModeFlags::SettingsFill)
96 {
98 aColor = rStyleSettings.GetHighlightColor();
99 else
100 aColor = rStyleSettings.GetWindowColor();
101 }
102 }
103 }
104
105 return aColor;
106}
107
108Color GetHatchColor(Color const& rColor, DrawModeFlags nDrawMode,
109 StyleSettings const& rStyleSettings)
110{
111 Color aColor(rColor);
112
113 if (nDrawMode & DrawModeFlags::BlackLine)
114 {
115 aColor = COL_BLACK;
116 }
117 else if (nDrawMode & DrawModeFlags::WhiteLine)
118 {
119 aColor = COL_WHITE;
120 }
121 else if (nDrawMode & DrawModeFlags::GrayLine)
122 {
123 const sal_uInt8 cLum = aColor.GetLuminance();
124 aColor = Color(cLum, cLum, cLum);
125 }
126 else if (nDrawMode & DrawModeFlags::SettingsLine)
127 {
129 aColor = rStyleSettings.GetHighlightColor();
130 else
131 aColor = rStyleSettings.GetWindowTextColor();
132 }
133
134 return aColor;
135}
136
137Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode,
138 StyleSettings const& rStyleSettings)
139{
140 Color aColor(rColor);
141
142 if (nDrawMode
145 {
146 if (nDrawMode & DrawModeFlags::BlackText)
147 {
148 aColor = COL_BLACK;
149 }
150 else if (nDrawMode & DrawModeFlags::WhiteText)
151 {
152 aColor = COL_WHITE;
153 }
154 else if (nDrawMode & DrawModeFlags::GrayText)
155 {
156 const sal_uInt8 cLum = aColor.GetLuminance();
157 aColor = Color(cLum, cLum, cLum);
158 }
159 else if (nDrawMode & DrawModeFlags::SettingsText)
160 {
162 aColor = rStyleSettings.GetHighlightTextColor();
163 else
164 aColor = rStyleSettings.GetWindowTextColor();
165 }
166 }
167
168 return aColor;
169}
170
171vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
172 StyleSettings const& rStyleSettings)
173{
174 vcl::Font aFont(rFont);
175
176 if (nDrawMode
180 {
181 Color aTextColor(aFont.GetColor());
182
183 if (nDrawMode & DrawModeFlags::BlackText)
184 {
185 aTextColor = COL_BLACK;
186 }
187 else if (nDrawMode & DrawModeFlags::WhiteText)
188 {
189 aTextColor = COL_WHITE;
190 }
191 else if (nDrawMode & DrawModeFlags::GrayText)
192 {
193 const sal_uInt8 cLum = aTextColor.GetLuminance();
194 aTextColor = Color(cLum, cLum, cLum);
195 }
196 else if (nDrawMode & DrawModeFlags::SettingsText)
197 {
199 aTextColor = rStyleSettings.GetHighlightTextColor();
200 else
201 aTextColor = rStyleSettings.GetWindowTextColor();
202 }
203
204 aFont.SetColor(aTextColor);
205
206 if (!aFont.IsTransparent())
207 {
208 Color aTextFillColor(aFont.GetFillColor());
209
210 if (nDrawMode & DrawModeFlags::BlackFill)
211 {
212 aTextFillColor = COL_BLACK;
213 }
214 else if (nDrawMode & DrawModeFlags::WhiteFill)
215 {
216 aTextFillColor = COL_WHITE;
217 }
218 else if (nDrawMode & DrawModeFlags::GrayFill)
219 {
220 const sal_uInt8 cLum = aTextFillColor.GetLuminance();
221 aTextFillColor = Color(cLum, cLum, cLum);
222 }
223 else if (nDrawMode & DrawModeFlags::SettingsFill)
224 {
226 aTextFillColor = rStyleSettings.GetHighlightColor();
227 else
228 aTextFillColor = rStyleSettings.GetWindowColor();
229 }
230 else if (nDrawMode & DrawModeFlags::NoFill)
231 {
232 aTextFillColor = COL_TRANSPARENT;
233 }
234
235 aFont.SetFillColor(aTextFillColor);
236 }
237 }
238
239 return aFont;
240}
241
242BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode)
243{
244 BitmapEx aBmpEx(rBitmapEx);
245
247 {
248 Bitmap aColorBmp(aBmpEx.GetSizePixel(), vcl::PixelFormat::N8_BPP,
250 sal_uInt8 cCmpVal;
251
252 if (nDrawMode & DrawModeFlags::BlackBitmap)
253 cCmpVal = 0;
254 else
255 cCmpVal = 255;
256
257 aColorBmp.Erase(Color(cCmpVal, cCmpVal, cCmpVal));
258
259 if (aBmpEx.IsAlpha())
260 {
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 aMaskEx.Invert(); // convert to transparency
267 aMaskEx.Invert(); // convert to alpha
268 aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
269 }
270 else
271 {
272 aBmpEx = BitmapEx(aColorBmp, aBmpEx.GetAlphaMask());
273 }
274 }
275
276 if (nDrawMode & DrawModeFlags::GrayBitmap && !aBmpEx.IsEmpty())
278
279 return aBmpEx;
280}
281}
282
283/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
DrawModeFlags
Bitmap const & GetBitmap() const
Definition: alpha.cxx:77
bool Invert()
Perform the Invert operation on every pixel.
Definition: BitmapEx.cxx:258
const AlphaMask & GetAlphaMask() const
Definition: bitmapex.hxx:71
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Definition: BitmapEx.cxx:383
bool IsAlpha() const
Definition: BitmapEx.cxx:207
bool IsEmpty() const
Definition: BitmapEx.cxx:186
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
static const BitmapPalette & GetGreyPalette(int nEntries)
bool Erase(const Color &rFillColor)
Fill the entire bitmap with the given color.
Definition: bitmappaint.cxx:34
sal_uInt8 GetLuminance() const
bool IsTransparent() const
const Color & GetWindowColor() const
const Color & GetWindowTextColor() const
const Color & GetHighlightColor() const
const Color & GetHighlightTextColor() const
void SetFillColor(const Color &)
Definition: font/font.cxx:115
void SetColor(const Color &)
Definition: font/font.cxx:107
bool IsTransparent() const
Definition: font/font.cxx:900
const Color & GetColor() const
Definition: font/font.cxx:898
const Color & GetFillColor() const
Definition: font/font.cxx:899
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
Color GetTextColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:137
BitmapEx GetBitmapEx(BitmapEx const &rBitmapEx, DrawModeFlags nDrawMode)
Definition: drawmode.cxx:242
Color GetHatchColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:108
Color GetFillColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:67
Color GetLineColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:30
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:171
unsigned char sal_uInt8