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 
28 namespace vcl::drawmode
29 {
30 Color 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  {
56  aColor = rStyleSettings.GetFontColor();
57  }
58  }
59  }
60 
61  return aColor;
62 }
63 
64 Color GetFillColor(Color const& rColor, DrawModeFlags nDrawMode,
65  StyleSettings const& rStyleSettings)
66 {
67  Color aColor(rColor);
68 
69  if (nDrawMode
72  {
73  if (!aColor.IsTransparent())
74  {
75  if (nDrawMode & DrawModeFlags::BlackFill)
76  {
77  aColor = COL_BLACK;
78  }
79  else if (nDrawMode & DrawModeFlags::WhiteFill)
80  {
81  aColor = COL_WHITE;
82  }
83  else if (nDrawMode & DrawModeFlags::GrayFill)
84  {
85  const sal_uInt8 cLum = aColor.GetLuminance();
86  aColor = Color(cLum, cLum, cLum);
87  }
88  else if (nDrawMode & DrawModeFlags::NoFill)
89  {
90  aColor = COL_TRANSPARENT;
91  }
92  else if (nDrawMode & DrawModeFlags::SettingsFill)
93  {
94  aColor = rStyleSettings.GetWindowColor();
95  }
96  }
97  }
98 
99  return aColor;
100 }
101 
102 Color GetHatchColor(Color const& rColor, DrawModeFlags nDrawMode,
103  StyleSettings const& rStyleSettings)
104 {
105  Color aColor(rColor);
106 
107  if (nDrawMode & DrawModeFlags::BlackLine)
108  {
109  aColor = COL_BLACK;
110  }
111  else if (nDrawMode & DrawModeFlags::WhiteLine)
112  {
113  aColor = COL_WHITE;
114  }
115  else if (nDrawMode & DrawModeFlags::GrayLine)
116  {
117  const sal_uInt8 cLum = aColor.GetLuminance();
118  aColor = Color(cLum, cLum, cLum);
119  }
120  else if (nDrawMode & DrawModeFlags::SettingsLine)
121  {
122  aColor = rStyleSettings.GetFontColor();
123  }
124 
125  return aColor;
126 }
127 
128 Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode,
129  StyleSettings const& rStyleSettings)
130 {
131  Color aColor(rColor);
132 
133  if (nDrawMode
136  {
137  if (nDrawMode & DrawModeFlags::BlackText)
138  {
139  aColor = COL_BLACK;
140  }
141  else if (nDrawMode & DrawModeFlags::WhiteText)
142  {
143  aColor = COL_WHITE;
144  }
145  else if (nDrawMode & DrawModeFlags::GrayText)
146  {
147  const sal_uInt8 cLum = aColor.GetLuminance();
148  aColor = Color(cLum, cLum, cLum);
149  }
150  else if (nDrawMode & DrawModeFlags::SettingsText)
151  {
152  aColor = rStyleSettings.GetFontColor();
153  }
154  }
155 
156  return aColor;
157 }
158 
159 vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
160  StyleSettings const& rStyleSettings)
161 {
162  vcl::Font aFont(rFont);
163 
164  if (nDrawMode
168  {
169  Color aTextColor(aFont.GetColor());
170 
171  if (nDrawMode & DrawModeFlags::BlackText)
172  {
173  aTextColor = COL_BLACK;
174  }
175  else if (nDrawMode & DrawModeFlags::WhiteText)
176  {
177  aTextColor = COL_WHITE;
178  }
179  else if (nDrawMode & DrawModeFlags::GrayText)
180  {
181  const sal_uInt8 cLum = aTextColor.GetLuminance();
182  aTextColor = Color(cLum, cLum, cLum);
183  }
184  else if (nDrawMode & DrawModeFlags::SettingsText)
185  {
186  aTextColor = rStyleSettings.GetFontColor();
187  }
188 
189  aFont.SetColor(aTextColor);
190 
191  if (!aFont.IsTransparent())
192  {
193  Color aTextFillColor(aFont.GetFillColor());
194 
195  if (nDrawMode & DrawModeFlags::BlackFill)
196  {
197  aTextFillColor = COL_BLACK;
198  }
199  else if (nDrawMode & DrawModeFlags::WhiteFill)
200  {
201  aTextFillColor = COL_WHITE;
202  }
203  else if (nDrawMode & DrawModeFlags::GrayFill)
204  {
205  const sal_uInt8 cLum = aTextFillColor.GetLuminance();
206  aTextFillColor = Color(cLum, cLum, cLum);
207  }
208  else if (nDrawMode & DrawModeFlags::SettingsFill)
209  {
210  aTextFillColor = rStyleSettings.GetWindowColor();
211  }
212  else if (nDrawMode & DrawModeFlags::NoFill)
213  {
214  aTextFillColor = COL_TRANSPARENT;
215  }
216 
217  aFont.SetFillColor(aTextFillColor);
218  }
219  }
220 
221  return aFont;
222 }
223 
224 BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode)
225 {
226  BitmapEx aBmpEx(rBitmapEx);
227 
229  {
230  Bitmap aColorBmp(aBmpEx.GetSizePixel(), vcl::PixelFormat::N1_BPP);
231  sal_uInt8 cCmpVal;
232 
233  if (nDrawMode & DrawModeFlags::BlackBitmap)
234  cCmpVal = 0;
235  else
236  cCmpVal = 255;
237 
238  aColorBmp.Erase(Color(cCmpVal, cCmpVal, cCmpVal));
239 
240  if (aBmpEx.IsAlpha())
241  {
242  // Create one-bit mask out of alpha channel, by thresholding it at alpha=0.5. As
243  // DRAWMODE_BLACK/WHITEBITMAP requires monochrome output, having alpha-induced
244  // grey levels is not acceptable
245  BitmapEx aMaskEx(aBmpEx.GetAlpha().GetBitmap());
247  aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
248  }
249  else
250  {
251  aBmpEx = BitmapEx(aColorBmp, aBmpEx.GetAlpha());
252  }
253  }
254 
255  if (nDrawMode & DrawModeFlags::GrayBitmap && !aBmpEx.IsEmpty())
257 
258  return aBmpEx;
259 }
260 }
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
BitmapEx GetBitmapEx(BitmapEx const &rBitmapEx, DrawModeFlags nDrawMode)
Definition: drawmode.cxx:224
void SetFillColor(const Color &)
Definition: font/font.cxx:98
bool IsTransparent() const
Bitmap const & GetBitmap() const
Definition: alpha.cxx:73
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
Color GetTextColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:128
sal_uInt8 GetLuminance() const
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Definition: BitmapEx.cxx:374
bool IsAlpha() const
Definition: BitmapEx.cxx:193
Color GetFillColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:64
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
bool IsEmpty() const
Definition: BitmapEx.cxx:177
const Color & GetFontColor() const
const Color & GetFillColor() const
Definition: font/font.cxx:824
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:159
void SetColor(const Color &)
Definition: font/font.cxx:90
const Color & GetColor() const
Definition: font/font.cxx:823
AlphaMask GetAlpha() const
Definition: BitmapEx.cxx:215
unsigned char sal_uInt8
Color GetLineColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:30
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
bool IsTransparent() const
Definition: font/font.cxx:825
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
const Color & GetWindowColor() const
bool Erase(const Color &rFillColor)
Fill the entire bitmap with the given color.
Definition: bitmappaint.cxx:34
Color GetHatchColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:102
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73
DrawModeFlags