/src/libreoffice/vcl/source/rendercontext/drawmode.cxx
Line | Count | Source |
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 | | |
20 | | #include <vcl/alpha.hxx> |
21 | | #include <vcl/bitmap/BitmapMonochromeFilter.hxx> |
22 | | #include <vcl/bitmap/BitmapTypes.hxx> |
23 | | #include <vcl/rendercontext/DrawModeFlags.hxx> |
24 | | #include <vcl/settings.hxx> |
25 | | #include <vcl/virdev.hxx> |
26 | | |
27 | | #include <drawmode.hxx> |
28 | | |
29 | | namespace vcl::drawmode |
30 | | { |
31 | | Color GetLineColor(Color const& rColor, DrawModeFlags nDrawMode, |
32 | | StyleSettings const& rStyleSettings) |
33 | 8.34M | { |
34 | 8.34M | Color aColor(rColor); |
35 | | |
36 | 8.34M | if (nDrawMode |
37 | 8.34M | & (DrawModeFlags::BlackLine | DrawModeFlags::WhiteLine | DrawModeFlags::GrayLine |
38 | 8.34M | | DrawModeFlags::SettingsLine)) |
39 | 0 | { |
40 | 0 | if (!aColor.IsTransparent()) |
41 | 0 | { |
42 | 0 | if (nDrawMode & DrawModeFlags::BlackLine) |
43 | 0 | { |
44 | 0 | aColor = COL_BLACK; |
45 | 0 | } |
46 | 0 | else if (nDrawMode & DrawModeFlags::WhiteLine) |
47 | 0 | { |
48 | 0 | aColor = COL_WHITE; |
49 | 0 | } |
50 | 0 | else if (nDrawMode & DrawModeFlags::GrayLine) |
51 | 0 | { |
52 | 0 | const sal_uInt8 cLum = aColor.GetLuminance(); |
53 | 0 | aColor = Color(cLum, cLum, cLum); |
54 | 0 | } |
55 | 0 | else if (nDrawMode & DrawModeFlags::SettingsLine) |
56 | 0 | { |
57 | 0 | if (nDrawMode & DrawModeFlags::SettingsForSelection) |
58 | 0 | aColor = rStyleSettings.GetHighlightColor(); |
59 | 0 | else |
60 | 0 | aColor = rStyleSettings.GetWindowTextColor(); |
61 | 0 | } |
62 | 0 | } |
63 | 0 | } |
64 | | |
65 | 8.34M | return aColor; |
66 | 8.34M | } |
67 | | |
68 | | Color GetFillColor(Color const& rColor, DrawModeFlags nDrawMode, |
69 | | StyleSettings const& rStyleSettings) |
70 | 4.02M | { |
71 | 4.02M | Color aColor(rColor); |
72 | | |
73 | 4.02M | if (nDrawMode |
74 | 4.02M | & (DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill | DrawModeFlags::GrayFill |
75 | 4.02M | | DrawModeFlags::NoFill | DrawModeFlags::SettingsFill)) |
76 | 0 | { |
77 | 0 | if (!aColor.IsTransparent()) |
78 | 0 | { |
79 | 0 | if (nDrawMode & DrawModeFlags::BlackFill) |
80 | 0 | { |
81 | 0 | aColor = COL_BLACK; |
82 | 0 | } |
83 | 0 | else if (nDrawMode & DrawModeFlags::WhiteFill) |
84 | 0 | { |
85 | 0 | aColor = COL_WHITE; |
86 | 0 | } |
87 | 0 | else if (nDrawMode & DrawModeFlags::GrayFill) |
88 | 0 | { |
89 | 0 | const sal_uInt8 cLum = aColor.GetLuminance(); |
90 | 0 | aColor = Color(cLum, cLum, cLum); |
91 | 0 | } |
92 | 0 | else if (nDrawMode & DrawModeFlags::NoFill) |
93 | 0 | { |
94 | 0 | aColor = COL_TRANSPARENT; |
95 | 0 | } |
96 | 0 | else if (nDrawMode & DrawModeFlags::SettingsFill) |
97 | 0 | { |
98 | 0 | if (nDrawMode & DrawModeFlags::SettingsForSelection) |
99 | 0 | aColor = rStyleSettings.GetHighlightColor(); |
100 | 0 | else |
101 | 0 | aColor = rStyleSettings.GetWindowColor(); |
102 | 0 | } |
103 | 0 | } |
104 | 0 | } |
105 | | |
106 | 4.02M | return aColor; |
107 | 4.02M | } |
108 | | |
109 | | Color GetHatchColor(Color const& rColor, DrawModeFlags nDrawMode, |
110 | | StyleSettings const& rStyleSettings) |
111 | 10.5k | { |
112 | 10.5k | Color aColor(rColor); |
113 | | |
114 | 10.5k | if (nDrawMode & DrawModeFlags::BlackLine) |
115 | 0 | { |
116 | 0 | aColor = COL_BLACK; |
117 | 0 | } |
118 | 10.5k | else if (nDrawMode & DrawModeFlags::WhiteLine) |
119 | 0 | { |
120 | 0 | aColor = COL_WHITE; |
121 | 0 | } |
122 | 10.5k | else if (nDrawMode & DrawModeFlags::GrayLine) |
123 | 0 | { |
124 | 0 | const sal_uInt8 cLum = aColor.GetLuminance(); |
125 | 0 | aColor = Color(cLum, cLum, cLum); |
126 | 0 | } |
127 | 10.5k | else if (nDrawMode & DrawModeFlags::SettingsLine) |
128 | 0 | { |
129 | 0 | if (nDrawMode & DrawModeFlags::SettingsForSelection) |
130 | 0 | aColor = rStyleSettings.GetHighlightColor(); |
131 | 0 | else |
132 | 0 | aColor = rStyleSettings.GetWindowTextColor(); |
133 | 0 | } |
134 | | |
135 | 10.5k | return aColor; |
136 | 10.5k | } |
137 | | |
138 | | Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode, |
139 | | StyleSettings const& rStyleSettings) |
140 | 7.46M | { |
141 | 7.46M | Color aColor(rColor); |
142 | | |
143 | 7.46M | if (nDrawMode |
144 | 7.46M | & (DrawModeFlags::BlackText | DrawModeFlags::GrayText | DrawModeFlags::SettingsText)) |
145 | 0 | { |
146 | 0 | if (nDrawMode & DrawModeFlags::BlackText) |
147 | 0 | { |
148 | 0 | aColor = COL_BLACK; |
149 | 0 | } |
150 | 0 | else if (nDrawMode & DrawModeFlags::GrayText) |
151 | 0 | { |
152 | 0 | const sal_uInt8 cLum = aColor.GetLuminance(); |
153 | 0 | aColor = Color(cLum, cLum, cLum); |
154 | 0 | } |
155 | 0 | else if (nDrawMode & DrawModeFlags::SettingsText) |
156 | 0 | { |
157 | 0 | if (nDrawMode & DrawModeFlags::SettingsForSelection) |
158 | 0 | aColor = rStyleSettings.GetHighlightTextColor(); |
159 | 0 | else |
160 | 0 | aColor = rStyleSettings.GetWindowTextColor(); |
161 | 0 | } |
162 | 0 | } |
163 | | |
164 | 7.46M | return aColor; |
165 | 7.46M | } |
166 | | |
167 | | vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode, |
168 | | StyleSettings const& rStyleSettings) |
169 | 23.8M | { |
170 | 23.8M | vcl::Font aFont(rFont); |
171 | | |
172 | 23.8M | if (nDrawMode |
173 | 23.8M | & (DrawModeFlags::BlackText | DrawModeFlags::GrayText | DrawModeFlags::SettingsText |
174 | 23.8M | | DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill | DrawModeFlags::GrayFill |
175 | 23.8M | | DrawModeFlags::NoFill | DrawModeFlags::SettingsFill)) |
176 | 128 | { |
177 | 128 | Color aTextColor(aFont.GetColor()); |
178 | | |
179 | 128 | if (nDrawMode & DrawModeFlags::BlackText) |
180 | 0 | { |
181 | 0 | aTextColor = COL_BLACK; |
182 | 0 | } |
183 | 128 | else if (nDrawMode & DrawModeFlags::GrayText) |
184 | 0 | { |
185 | 0 | const sal_uInt8 cLum = aTextColor.GetLuminance(); |
186 | 0 | aTextColor = Color(cLum, cLum, cLum); |
187 | 0 | } |
188 | 128 | else if (nDrawMode & DrawModeFlags::SettingsText) |
189 | 0 | { |
190 | 0 | if (nDrawMode & DrawModeFlags::SettingsForSelection) |
191 | 0 | aTextColor = rStyleSettings.GetHighlightTextColor(); |
192 | 0 | else |
193 | 0 | aTextColor = rStyleSettings.GetWindowTextColor(); |
194 | 0 | } |
195 | | |
196 | 128 | aFont.SetColor(aTextColor); |
197 | | |
198 | 128 | if (!aFont.IsTransparent()) |
199 | 0 | { |
200 | 0 | Color aTextFillColor(aFont.GetFillColor()); |
201 | |
|
202 | 0 | if (nDrawMode & DrawModeFlags::BlackFill) |
203 | 0 | { |
204 | 0 | aTextFillColor = COL_BLACK; |
205 | 0 | } |
206 | 0 | else if (nDrawMode & DrawModeFlags::WhiteFill) |
207 | 0 | { |
208 | 0 | aTextFillColor = COL_WHITE; |
209 | 0 | } |
210 | 0 | else if (nDrawMode & DrawModeFlags::GrayFill) |
211 | 0 | { |
212 | 0 | const sal_uInt8 cLum = aTextFillColor.GetLuminance(); |
213 | 0 | aTextFillColor = Color(cLum, cLum, cLum); |
214 | 0 | } |
215 | 0 | else if (nDrawMode & DrawModeFlags::SettingsFill) |
216 | 0 | { |
217 | 0 | if (nDrawMode & DrawModeFlags::SettingsForSelection) |
218 | 0 | aTextFillColor = rStyleSettings.GetHighlightColor(); |
219 | 0 | else |
220 | 0 | aTextFillColor = rStyleSettings.GetWindowColor(); |
221 | 0 | } |
222 | 0 | else if (nDrawMode & DrawModeFlags::NoFill) |
223 | 0 | { |
224 | 0 | aTextFillColor = COL_TRANSPARENT; |
225 | 0 | } |
226 | |
|
227 | 0 | aFont.SetFillColor(aTextFillColor); |
228 | 0 | } |
229 | 128 | } |
230 | | |
231 | 23.8M | return aFont; |
232 | 23.8M | } |
233 | | |
234 | | Bitmap GetBitmap(Bitmap const& rBitmap, DrawModeFlags nDrawMode) |
235 | 1.00k | { |
236 | 1.00k | Bitmap aBmp(rBitmap); |
237 | | |
238 | 1.00k | if (nDrawMode & (DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap)) |
239 | 0 | { |
240 | 0 | Bitmap aColorBmp(aBmp.GetSizePixel(), vcl::PixelFormat::N8_BPP, |
241 | 0 | &Bitmap::GetGreyPalette(256)); |
242 | 0 | sal_uInt8 cCmpVal; |
243 | |
|
244 | 0 | if (nDrawMode & DrawModeFlags::BlackBitmap) |
245 | 0 | cCmpVal = 0; |
246 | 0 | else |
247 | 0 | cCmpVal = 255; |
248 | |
|
249 | 0 | aColorBmp.Erase(Color(cCmpVal, cCmpVal, cCmpVal)); |
250 | |
|
251 | 0 | if (aBmp.HasAlpha()) |
252 | 0 | { |
253 | | // Create one-bit mask out of alpha channel, by thresholding it at alpha=0.5. As |
254 | | // DRAWMODE_BLACK/WHITEBITMAP requires monochrome output, having alpha-induced |
255 | | // grey levels is not acceptable |
256 | 0 | Bitmap aMask(aBmp.CreateAlphaMask().GetBitmap()); |
257 | 0 | aMask.Invert(); // convert to transparency |
258 | 0 | BitmapFilter::Filter(aMask, BitmapMonochromeFilter(129)); |
259 | 0 | aMask.Invert(); // convert to alpha |
260 | 0 | aBmp = Bitmap(aColorBmp, aMask); |
261 | 0 | } |
262 | 0 | else |
263 | 0 | { |
264 | 0 | aBmp = std::move(aColorBmp); |
265 | 0 | } |
266 | 0 | } |
267 | | |
268 | 1.00k | if (nDrawMode & DrawModeFlags::GrayBitmap && !aBmp.IsEmpty()) |
269 | 0 | aBmp.Convert(BmpConversion::N8BitGreys); |
270 | | |
271 | 1.00k | return aBmp; |
272 | 1.00k | } |
273 | | } |
274 | | |
275 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |