1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <vcl/BitmapMonochromeFilter.hxx>
#include <vcl/bitmap/BitmapTypes.hxx>
#include <vcl/rendercontext/DrawModeFlags.hxx>
#include <vcl/settings.hxx>
#include <vcl/virdev.hxx>
#include <drawmode.hxx>
namespace vcl::drawmode
{
Color GetLineColor(Color const& rColor, DrawModeFlags nDrawMode,
StyleSettings const& rStyleSettings)
{
Color aColor(rColor);
if (nDrawMode
& (DrawModeFlags::BlackLine | DrawModeFlags::WhiteLine | DrawModeFlags::GrayLine
| DrawModeFlags::SettingsLine))
{
if (!aColor.IsTransparent())
{
if (nDrawMode & DrawModeFlags::BlackLine)
{
aColor = COL_BLACK;
}
else if (nDrawMode & DrawModeFlags::WhiteLine)
{
aColor = COL_WHITE;
}
else if (nDrawMode & DrawModeFlags::GrayLine)
{
const sal_uInt8 cLum = aColor.GetLuminance();
aColor = Color(cLum, cLum, cLum);
}
else if (nDrawMode & DrawModeFlags::SettingsLine)
{
aColor = rStyleSettings.GetFontColor();
}
}
}
return aColor;
}
Color GetFillColor(Color const& rColor, DrawModeFlags nDrawMode,
StyleSettings const& rStyleSettings)
{
Color aColor(rColor);
if (nDrawMode
& (DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill | DrawModeFlags::GrayFill
| DrawModeFlags::NoFill | DrawModeFlags::SettingsFill))
{
if (!aColor.IsTransparent())
{
if (nDrawMode & DrawModeFlags::BlackFill)
{
aColor = COL_BLACK;
}
else if (nDrawMode & DrawModeFlags::WhiteFill)
{
aColor = COL_WHITE;
}
else if (nDrawMode & DrawModeFlags::GrayFill)
{
const sal_uInt8 cLum = aColor.GetLuminance();
aColor = Color(cLum, cLum, cLum);
}
else if (nDrawMode & DrawModeFlags::NoFill)
{
aColor = COL_TRANSPARENT;
}
else if (nDrawMode & DrawModeFlags::SettingsFill)
{
aColor = rStyleSettings.GetWindowColor();
}
}
}
return aColor;
}
Color GetHatchColor(Color const& rColor, DrawModeFlags nDrawMode,
StyleSettings const& rStyleSettings)
{
Color aColor(rColor);
if (nDrawMode & DrawModeFlags::BlackLine)
{
aColor = COL_BLACK;
}
else if (nDrawMode & DrawModeFlags::WhiteLine)
{
aColor = COL_WHITE;
}
else if (nDrawMode & DrawModeFlags::GrayLine)
{
const sal_uInt8 cLum = aColor.GetLuminance();
aColor = Color(cLum, cLum, cLum);
}
else if (nDrawMode & DrawModeFlags::SettingsLine)
{
aColor = rStyleSettings.GetFontColor();
}
return aColor;
}
Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode,
StyleSettings const& rStyleSettings)
{
Color aColor(rColor);
if (nDrawMode
& (DrawModeFlags::BlackText | DrawModeFlags::WhiteText | DrawModeFlags::GrayText
| DrawModeFlags::SettingsText))
{
if (nDrawMode & DrawModeFlags::BlackText)
{
aColor = COL_BLACK;
}
else if (nDrawMode & DrawModeFlags::WhiteText)
{
aColor = COL_WHITE;
}
else if (nDrawMode & DrawModeFlags::GrayText)
{
const sal_uInt8 cLum = aColor.GetLuminance();
aColor = Color(cLum, cLum, cLum);
}
else if (nDrawMode & DrawModeFlags::SettingsText)
{
aColor = rStyleSettings.GetFontColor();
}
}
return aColor;
}
vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
StyleSettings const& rStyleSettings)
{
vcl::Font aFont(rFont);
if (nDrawMode
& (DrawModeFlags::BlackText | DrawModeFlags::WhiteText | DrawModeFlags::GrayText
| DrawModeFlags::SettingsText | DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill
| DrawModeFlags::GrayFill | DrawModeFlags::NoFill | DrawModeFlags::SettingsFill))
{
Color aTextColor(aFont.GetColor());
if (nDrawMode & DrawModeFlags::BlackText)
{
aTextColor = COL_BLACK;
}
else if (nDrawMode & DrawModeFlags::WhiteText)
{
aTextColor = COL_WHITE;
}
else if (nDrawMode & DrawModeFlags::GrayText)
{
const sal_uInt8 cLum = aTextColor.GetLuminance();
aTextColor = Color(cLum, cLum, cLum);
}
else if (nDrawMode & DrawModeFlags::SettingsText)
{
aTextColor = rStyleSettings.GetFontColor();
}
aFont.SetColor(aTextColor);
if (!aFont.IsTransparent())
{
Color aTextFillColor(aFont.GetFillColor());
if (nDrawMode & DrawModeFlags::BlackFill)
{
aTextFillColor = COL_BLACK;
}
else if (nDrawMode & DrawModeFlags::WhiteFill)
{
aTextFillColor = COL_WHITE;
}
else if (nDrawMode & DrawModeFlags::GrayFill)
{
const sal_uInt8 cLum = aTextFillColor.GetLuminance();
aTextFillColor = Color(cLum, cLum, cLum);
}
else if (nDrawMode & DrawModeFlags::SettingsFill)
{
aTextFillColor = rStyleSettings.GetWindowColor();
}
else if (nDrawMode & DrawModeFlags::NoFill)
{
aTextFillColor = COL_TRANSPARENT;
}
aFont.SetFillColor(aTextFillColor);
}
}
return aFont;
}
BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode)
{
BitmapEx aBmpEx(rBitmapEx);
if (nDrawMode & (DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap))
{
Bitmap aColorBmp(aBmpEx.GetSizePixel(), vcl::PixelFormat::N1_BPP);
sal_uInt8 cCmpVal;
if (nDrawMode & DrawModeFlags::BlackBitmap)
cCmpVal = 0;
else
cCmpVal = 255;
aColorBmp.Erase(Color(cCmpVal, cCmpVal, cCmpVal));
if (aBmpEx.IsAlpha())
{
// Create one-bit mask out of alpha channel, by thresholding it at alpha=0.5. As
// DRAWMODE_BLACK/WHITEBITMAP requires monochrome output, having alpha-induced
// grey levels is not acceptable
BitmapEx aMaskEx(aBmpEx.GetAlpha().GetBitmap());
BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(129));
aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
}
else
{
aBmpEx = BitmapEx(aColorBmp, aBmpEx.GetAlpha());
}
}
if (nDrawMode & DrawModeFlags::GrayBitmap && !aBmpEx.IsEmpty())
aBmpEx.Convert(BmpConversion::N8BitGreys);
return aBmpEx;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|