LibreOffice Module oox (master)  1
color.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <oox/drawingml/color.hxx>
21 #include <algorithm>
22 #include <math.h>
23 #include <osl/diagnose.h>
24 #include <sal/log.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 
31 namespace oox::drawingml {
32 
33 namespace {
34 
36 struct PresetColorsPool
37 {
38  typedef ::std::vector< ::Color > ColorVector;
39 
40  ColorVector maDmlColors;
41  ColorVector maVmlColors;
42  ColorVector maHighlightColors;
43 
44  explicit PresetColorsPool();
45 };
46 
47 PresetColorsPool::PresetColorsPool() :
48  maDmlColors( static_cast< size_t >( XML_TOKEN_COUNT ), API_RGB_TRANSPARENT ),
49  maVmlColors( static_cast< size_t >( XML_TOKEN_COUNT ), API_RGB_TRANSPARENT ),
50  maHighlightColors( static_cast<size_t>(XML_TOKEN_COUNT), API_RGB_TRANSPARENT )
51 {
52  // predefined colors in DrawingML (map XML token identifiers to RGB values)
53  static const std::pair<sal_Int32, ::Color> spnDmlColors[] =
54  {
55  {XML_aliceBlue, ::Color(0xF0F8FF)}, {XML_antiqueWhite, ::Color(0xFAEBD7)},
56  {XML_aqua, ::Color(0x00FFFF)}, {XML_aquamarine, ::Color(0x7FFFD4)},
57  {XML_azure, ::Color(0xF0FFFF)}, {XML_beige, ::Color(0xF5F5DC)},
58  {XML_bisque, ::Color(0xFFE4C4)}, {XML_black, ::Color(0x000000)},
59  {XML_blanchedAlmond, ::Color(0xFFEBCD)}, {XML_blue, ::Color(0x0000FF)},
60  {XML_blueViolet, ::Color(0x8A2BE2)}, {XML_brown, ::Color(0xA52A2A)},
61  {XML_burlyWood, ::Color(0xDEB887)}, {XML_cadetBlue, ::Color(0x5F9EA0)},
62  {XML_chartreuse, ::Color(0x7FFF00)}, {XML_chocolate, ::Color(0xD2691E)},
63  {XML_coral, ::Color(0xFF7F50)}, {XML_cornflowerBlue, ::Color(0x6495ED)},
64  {XML_cornsilk, ::Color(0xFFF8DC)}, {XML_crimson, ::Color(0xDC143C)},
65  {XML_cyan, ::Color(0x00FFFF)}, {XML_deepPink, ::Color(0xFF1493)},
66  {XML_deepSkyBlue, ::Color(0x00BFFF)}, {XML_dimGray, ::Color(0x696969)},
67  {XML_dkBlue, ::Color(0x00008B)}, {XML_dkCyan, ::Color(0x008B8B)},
68  {XML_dkGoldenrod, ::Color(0xB8860B)}, {XML_dkGray, ::Color(0xA9A9A9)},
69  {XML_dkGreen, ::Color(0x006400)}, {XML_dkKhaki, ::Color(0xBDB76B)},
70  {XML_dkMagenta, ::Color(0x8B008B)}, {XML_dkOliveGreen, ::Color(0x556B2F)},
71  {XML_dkOrange, ::Color(0xFF8C00)}, {XML_dkOrchid, ::Color(0x9932CC)},
72  {XML_dkRed, ::Color(0x8B0000)}, {XML_dkSalmon, ::Color(0xE9967A)},
73  {XML_dkSeaGreen, ::Color(0x8FBC8B)}, {XML_dkSlateBlue, ::Color(0x483D8B)},
74  {XML_dkSlateGray, ::Color(0x2F4F4F)}, {XML_dkTurquoise, ::Color(0x00CED1)},
75  {XML_dkViolet, ::Color(0x9400D3)}, {XML_dodgerBlue, ::Color(0x1E90FF)},
76  {XML_firebrick, ::Color(0xB22222)}, {XML_floralWhite, ::Color(0xFFFAF0)},
77  {XML_forestGreen, ::Color(0x228B22)}, {XML_fuchsia, ::Color(0xFF00FF)},
78  {XML_gainsboro, ::Color(0xDCDCDC)}, {XML_ghostWhite, ::Color(0xF8F8FF)},
79  {XML_gold, ::Color(0xFFD700)}, {XML_goldenrod, ::Color(0xDAA520)},
80  {XML_gray, ::Color(0x808080)}, {XML_green, ::Color(0x008000)},
81  {XML_greenYellow, ::Color(0xADFF2F)}, {XML_honeydew, ::Color(0xF0FFF0)},
82  {XML_hotPink, ::Color(0xFF69B4)}, {XML_indianRed, ::Color(0xCD5C5C)},
83  {XML_indigo, ::Color(0x4B0082)}, {XML_ivory, ::Color(0xFFFFF0)},
84  {XML_khaki, ::Color(0xF0E68C)}, {XML_lavender, ::Color(0xE6E6FA)},
85  {XML_lavenderBlush, ::Color(0xFFF0F5)}, {XML_lawnGreen, ::Color(0x7CFC00)},
86  {XML_lemonChiffon, ::Color(0xFFFACD)}, {XML_lime, ::Color(0x00FF00)},
87  {XML_limeGreen, ::Color(0x32CD32)}, {XML_linen, ::Color(0xFAF0E6)},
88  {XML_ltBlue, ::Color(0xADD8E6)}, {XML_ltCoral, ::Color(0xF08080)},
89  {XML_ltCyan, ::Color(0xE0FFFF)}, {XML_ltGoldenrodYellow, ::Color(0xFAFA78)},
90  {XML_ltGray, ::Color(0xD3D3D3)}, {XML_ltGreen, ::Color(0x90EE90)},
91  {XML_ltPink, ::Color(0xFFB6C1)}, {XML_ltSalmon, ::Color(0xFFA07A)},
92  {XML_ltSeaGreen, ::Color(0x20B2AA)}, {XML_ltSkyBlue, ::Color(0x87CEFA)},
93  {XML_ltSlateGray, ::Color(0x778899)}, {XML_ltSteelBlue, ::Color(0xB0C4DE)},
94  {XML_ltYellow, ::Color(0xFFFFE0)}, {XML_magenta, ::Color(0xFF00FF)},
95  {XML_maroon, ::Color(0x800000)}, {XML_medAquamarine, ::Color(0x66CDAA)},
96  {XML_medBlue, ::Color(0x0000CD)}, {XML_medOrchid, ::Color(0xBA55D3)},
97  {XML_medPurple, ::Color(0x9370DB)}, {XML_medSeaGreen, ::Color(0x3CB371)},
98  {XML_medSlateBlue, ::Color(0x7B68EE)}, {XML_medSpringGreen, ::Color(0x00FA9A)},
99  {XML_medTurquoise, ::Color(0x48D1CC)}, {XML_medVioletRed, ::Color(0xC71585)},
100  {XML_midnightBlue, ::Color(0x191970)}, {XML_mintCream, ::Color(0xF5FFFA)},
101  {XML_mistyRose, ::Color(0xFFE4E1)}, {XML_moccasin, ::Color(0xFFE4B5)},
102  {XML_navajoWhite, ::Color(0xFFDEAD)}, {XML_navy, ::Color(0x000080)},
103  {XML_oldLace, ::Color(0xFDF5E6)}, {XML_olive, ::Color(0x808000)},
104  {XML_oliveDrab, ::Color(0x6B8E23)}, {XML_orange, ::Color(0xFFA500)},
105  {XML_orangeRed, ::Color(0xFF4500)}, {XML_orchid, ::Color(0xDA70D6)},
106  {XML_paleGoldenrod, ::Color(0xEEE8AA)}, {XML_paleGreen, ::Color(0x98FB98)},
107  {XML_paleTurquoise, ::Color(0xAFEEEE)}, {XML_paleVioletRed, ::Color(0xDB7093)},
108  {XML_papayaWhip, ::Color(0xFFEFD5)}, {XML_peachPuff, ::Color(0xFFDAB9)},
109  {XML_peru, ::Color(0xCD853F)}, {XML_pink, ::Color(0xFFC0CB)},
110  {XML_plum, ::Color(0xDDA0DD)}, {XML_powderBlue, ::Color(0xB0E0E6)},
111  {XML_purple, ::Color(0x800080)}, {XML_red, ::Color(0xFF0000)},
112  {XML_rosyBrown, ::Color(0xBC8F8F)}, {XML_royalBlue, ::Color(0x4169E1)},
113  {XML_saddleBrown, ::Color(0x8B4513)}, {XML_salmon, ::Color(0xFA8072)},
114  {XML_sandyBrown, ::Color(0xF4A460)}, {XML_seaGreen, ::Color(0x2E8B57)},
115  {XML_seaShell, ::Color(0xFFF5EE)}, {XML_sienna, ::Color(0xA0522D)},
116  {XML_silver, ::Color(0xC0C0C0)}, {XML_skyBlue, ::Color(0x87CEEB)},
117  {XML_slateBlue, ::Color(0x6A5ACD)}, {XML_slateGray, ::Color(0x708090)},
118  {XML_snow, ::Color(0xFFFAFA)}, {XML_springGreen, ::Color(0x00FF7F)},
119  {XML_steelBlue, ::Color(0x4682B4)}, {XML_tan, ::Color(0xD2B48C)},
120  {XML_teal, ::Color(0x008080)}, {XML_thistle, ::Color(0xD8BFD8)},
121  {XML_tomato, ::Color(0xFF6347)}, {XML_turquoise, ::Color(0x40E0D0)},
122  {XML_violet, ::Color(0xEE82EE)}, {XML_wheat, ::Color(0xF5DEB3)},
123  {XML_white, ::Color(0xFFFFFF)}, {XML_whiteSmoke, ::Color(0xF5F5F5)},
124  {XML_yellow, ::Color(0xFFFF00)}, {XML_yellowGreen, ::Color(0x9ACD32)}
125  };
126  for(auto const& nEntry : spnDmlColors)
127  maDmlColors[ static_cast< size_t >(nEntry.first) ] = nEntry.second;
128 
129  // predefined colors in VML (map XML token identifiers to RGB values)
130  static const std::pair<sal_Int32, ::Color> spnVmlColors[] =
131  {
132  {XML_aqua, ::Color(0x00FFFF)}, {XML_black, ::Color(0x000000)},
133  {XML_blue, ::Color(0x0000FF)}, {XML_fuchsia, ::Color(0xFF00FF)},
134  {XML_gray, ::Color(0x808080)}, {XML_green, ::Color(0x008000)},
135  {XML_lime, ::Color(0x00FF00)}, {XML_maroon, ::Color(0x800000)},
136  {XML_navy, ::Color(0x000080)}, {XML_olive, ::Color(0x808000)},
137  {XML_purple, ::Color(0x800080)}, {XML_red, ::Color(0xFF0000)},
138  {XML_silver, ::Color(0xC0C0C0)}, {XML_teal, ::Color(0x008080)},
139  {XML_white, ::Color(0xFFFFFF)}, {XML_yellow, ::Color(0xFFFF00)}
140  };
141  for(auto const& nEntry : spnVmlColors)
142  maVmlColors[ static_cast< size_t >(nEntry.first) ] = nEntry.second;
143 
144  // predefined highlight colors in DML (map XML token identifiers to RGB values)
145  static const std::pair<sal_Int32, ::Color> spnHighlightColors[] =
146  {
147  // tdf#131841 Predefined color for OOXML highlight.
148  {XML_black, ::Color(0x000000)}, {XML_blue, ::Color(0x0000FF)},
149  {XML_cyan, ::Color(0x00FFFF)}, {XML_darkBlue, ::Color(0x00008B)},
150  {XML_darkCyan, ::Color(0x008B8B)}, {XML_darkGray, ::Color(0xA9A9A9)},
151  {XML_darkGreen, ::Color(0x006400)}, {XML_darkMagenta, ::Color(0x800080)},
152  {XML_darkRed, ::Color(0x8B0000)}, {XML_darkYellow, ::Color(0x808000)},
153  {XML_green, ::Color(0x00FF00)}, {XML_lightGray, ::Color(0xD3D3D3)},
154  {XML_magenta, ::Color(0xFF00FF)}, {XML_red, ::Color(0xFF0000)},
155  {XML_white, ::Color(0xFFFFFF)}, {XML_yellow, ::Color(0xFFFF00)}
156  };
157  for (auto const& nEntry : spnHighlightColors)
158  maHighlightColors[static_cast<size_t>(nEntry.first)] = nEntry.second;
159 }
160 
161 struct StaticPresetColorsPool : public ::rtl::Static< PresetColorsPool, StaticPresetColorsPool > {};
162 
163 const double DEC_GAMMA = 2.3;
164 const double INC_GAMMA = 1.0 / DEC_GAMMA;
165 
166 void lclRgbToRgbComponents( sal_Int32& ornR, sal_Int32& ornG, sal_Int32& ornB, ::Color nRgb )
167 {
168  ornR = nRgb.GetRed();
169  ornG = nRgb.GetGreen();
170  ornB = nRgb.GetBlue();
171 }
172 
173 sal_Int32 lclRgbComponentsToRgb( sal_Int32 nR, sal_Int32 nG, sal_Int32 nB )
174 {
175  return static_cast< sal_Int32 >( (nR << 16) | (nG << 8) | nB );
176 }
177 
178 sal_Int32 lclRgbCompToCrgbComp( sal_Int32 nRgbComp )
179 {
180  return static_cast< sal_Int32 >( nRgbComp * MAX_PERCENT / 255 );
181 }
182 
183 sal_Int32 lclCrgbCompToRgbComp( sal_Int32 nCrgbComp )
184 {
185  return static_cast< sal_Int32 >( nCrgbComp * 255 / MAX_PERCENT );
186 }
187 
188 sal_Int32 lclGamma( sal_Int32 nComp, double fGamma )
189 {
190  return static_cast< sal_Int32 >( pow( static_cast< double >( nComp ) / MAX_PERCENT, fGamma ) * MAX_PERCENT + 0.5 );
191 }
192 
193 void lclSetValue( sal_Int32& ornValue, sal_Int32 nNew, sal_Int32 nMax = MAX_PERCENT )
194 {
195  OSL_ENSURE( (0 <= nNew) && (nNew <= nMax), "lclSetValue - invalid value" );
196  if( (0 <= nNew) && (nNew <= nMax) )
197  ornValue = nNew;
198 }
199 
200 void lclModValue( sal_Int32& ornValue, sal_Int32 nMod, sal_Int32 nMax = MAX_PERCENT )
201 {
202  OSL_ENSURE( (0 <= nMod), "lclModValue - invalid modificator" );
203  ornValue = getLimitedValue< sal_Int32, double >( static_cast< double >( ornValue ) * nMod / MAX_PERCENT, 0, nMax );
204 }
205 
206 void lclOffValue( sal_Int32& ornValue, sal_Int32 nOff, sal_Int32 nMax = MAX_PERCENT )
207 {
208  OSL_ENSURE( (-nMax <= nOff) && (nOff <= nMax), "lclOffValue - invalid offset" );
209  ornValue = getLimitedValue< sal_Int32, sal_Int32 >( ornValue + nOff, 0, nMax );
210 }
211 
212 } // namespace
213 
215  meMode( COLOR_UNUSED ),
216  mnC1( 0 ),
217  mnC2( 0 ),
218  mnC3( 0 ),
219  mnAlpha( MAX_PERCENT )
220 {
221 }
222 
223 ::Color Color::getDmlPresetColor( sal_Int32 nToken, ::Color nDefaultRgb )
224 {
225  /* Do not pass nDefaultRgb to ContainerHelper::getVectorElement(), to be
226  able to catch the existing vector entries without corresponding XML
227  token identifier. */
228  ::Color nRgbValue = ContainerHelper::getVectorElement( StaticPresetColorsPool::get().maDmlColors, nToken, API_RGB_TRANSPARENT );
229  return (sal_Int32(nRgbValue) >= 0) ? nRgbValue : nDefaultRgb;
230 }
231 
232 ::Color Color::getVmlPresetColor( sal_Int32 nToken, ::Color nDefaultRgb )
233 {
234  /* Do not pass nDefaultRgb to ContainerHelper::getVectorElement(), to be
235  able to catch the existing vector entries without corresponding XML
236  token identifier. */
237  ::Color nRgbValue = ContainerHelper::getVectorElement( StaticPresetColorsPool::get().maVmlColors, nToken, API_RGB_TRANSPARENT );
238  return (sal_Int32(nRgbValue) >= 0) ? nRgbValue : nDefaultRgb;
239 }
240 
241 ::Color Color::getHighlightColor(sal_Int32 nToken, ::Color nDefaultRgb)
242 {
243  /* Do not pass nDefaultRgb to ContainerHelper::getVectorElement(), to be
244  able to catch the existing vector entries without corresponding XML
245  token identifier. */
246  ::Color nRgbValue = ContainerHelper::getVectorElement( StaticPresetColorsPool::get().maHighlightColors, nToken, API_RGB_TRANSPARENT );
247  return (sal_Int32(nRgbValue) >= 0) ? nRgbValue : nDefaultRgb;
248 }
249 
251 {
253 }
254 
255 void Color::setSrgbClr( ::Color nRgb )
256 {
257  setSrgbClr(sal_Int32(nRgb));
258 }
259 
260 void Color::setSrgbClr( sal_Int32 nRgb )
261 {
262  OSL_ENSURE( (0 <= nRgb) && (nRgb <= 0xFFFFFF), "Color::setSrgbClr - invalid RGB value" );
263  meMode = COLOR_RGB;
264  lclRgbToRgbComponents( mnC1, mnC2, mnC3, ::Color(ColorTransparency, nRgb) );
265 }
266 
267 void Color::setScrgbClr( sal_Int32 nR, sal_Int32 nG, sal_Int32 nB )
268 {
269  OSL_ENSURE( (0 <= nR) && (nR <= MAX_PERCENT), "Color::setScrgbClr - invalid red value" );
270  OSL_ENSURE( (0 <= nG) && (nG <= MAX_PERCENT), "Color::setScrgbClr - invalid green value" );
271  OSL_ENSURE( (0 <= nB) && (nB <= MAX_PERCENT), "Color::setScrgbClr - invalid blue value" );
272  meMode = COLOR_CRGB;
273  mnC1 = getLimitedValue< sal_Int32, sal_Int32 >( nR, 0, MAX_PERCENT );
274  mnC2 = getLimitedValue< sal_Int32, sal_Int32 >( nG, 0, MAX_PERCENT );
275  mnC3 = getLimitedValue< sal_Int32, sal_Int32 >( nB, 0, MAX_PERCENT );
276 }
277 
278 void Color::setHslClr( sal_Int32 nHue, sal_Int32 nSat, sal_Int32 nLum )
279 {
280  OSL_ENSURE( (0 <= nHue) && (nHue <= MAX_DEGREE), "Color::setHslClr - invalid hue value" );
281  OSL_ENSURE( (0 <= nSat) && (nSat <= MAX_PERCENT), "Color::setHslClr - invalid saturation value" );
282  OSL_ENSURE( (0 <= nLum) && (nLum <= MAX_PERCENT), "Color::setHslClr - invalid luminance value" );
283  meMode = COLOR_HSL;
284  mnC1 = getLimitedValue< sal_Int32, sal_Int32 >( nHue, 0, MAX_DEGREE );
285  mnC2 = getLimitedValue< sal_Int32, sal_Int32 >( nSat, 0, MAX_PERCENT );
286  mnC3 = getLimitedValue< sal_Int32, sal_Int32 >( nLum, 0, MAX_PERCENT );
287 }
288 
289 void Color::setPrstClr( sal_Int32 nToken )
290 {
291  ::Color nRgbValue = getDmlPresetColor( nToken, API_RGB_TRANSPARENT );
292  OSL_ENSURE( sal_Int32(nRgbValue) >= 0, "Color::setPrstClr - invalid preset color token" );
293  if( sal_Int32(nRgbValue) >= 0 )
294  setSrgbClr( nRgbValue );
295 }
296 
297 void Color::setHighlight(sal_Int32 nToken)
298 {
299  ::Color nRgbValue = getHighlightColor(nToken, API_RGB_TRANSPARENT);
300  OSL_ENSURE( sal_Int32(nRgbValue) >= 0, "Color::setPrstClr - invalid preset color token" );
301  if ( sal_Int32(nRgbValue) >= 0 )
302  setSrgbClr( nRgbValue );
303 }
304 
305 void Color::setSchemeClr( sal_Int32 nToken )
306 {
307  OSL_ENSURE( nToken != XML_TOKEN_INVALID, "Color::setSchemeClr - invalid color token" );
308  meMode = (nToken == XML_phClr) ? COLOR_PH : COLOR_SCHEME;
309  mnC1 = nToken;
310 }
311 
312 void Color::setPaletteClr( sal_Int32 nPaletteIdx )
313 {
314  OSL_ENSURE( nPaletteIdx >= 0, "Color::setPaletteClr - invalid palette index" );
316  mnC1 = nPaletteIdx;
317 }
318 
319 void Color::setSysClr( sal_Int32 nToken, sal_Int32 nLastRgb )
320 {
321  OSL_ENSURE( (-1 <= nLastRgb) && (nLastRgb <= 0xFFFFFF), "Color::setSysClr - invalid RGB value" );
323  mnC1 = nToken;
324  mnC2 = nLastRgb;
325 }
326 
327 void Color::addTransformation( sal_Int32 nElement, sal_Int32 nValue )
328 {
329  /* Execute alpha transformations directly, store other transformations in
330  a vector, they may depend on a scheme base color which will be resolved
331  in Color::getColor(). */
332  sal_Int32 nToken = getBaseToken( nElement );
333  switch( nToken )
334  {
335  case XML_alpha: lclSetValue( mnAlpha, nValue ); break;
336  case XML_alphaMod: lclModValue( mnAlpha, nValue ); break;
337  case XML_alphaOff: lclOffValue( mnAlpha, nValue ); break;
338  default: maTransforms.emplace_back( nToken, nValue );
339  }
340  sal_Int32 nSize = maInteropTransformations.getLength();
341  maInteropTransformations.realloc(nSize + 1);
342  auto pInteropTransformations = maInteropTransformations.getArray();
343  pInteropTransformations[nSize].Name = getColorTransformationName( nToken );
344  pInteropTransformations[nSize].Value <<= nValue;
345 }
346 
348 {
349  sal_Int32 nValue = getLimitedValue< sal_Int32, double >( fTint * MAX_PERCENT + 0.5, -MAX_PERCENT, MAX_PERCENT );
350  if( nValue < 0 )
351  maTransforms.emplace_back( XML_shade, nValue + MAX_PERCENT );
352  else if( nValue > 0 )
353  maTransforms.emplace_back( XML_tint, MAX_PERCENT - nValue );
354 }
355 
357 {
358  sal_Int32 nValue = getLimitedValue< sal_Int32, double >( fTint * MAX_PERCENT + 0.5, -MAX_PERCENT, MAX_PERCENT );
359  maTransforms.emplace_back( XLS_TOKEN( tint ), nValue );
360 }
361 
363 {
364  maTransforms.clear();
365  maInteropTransformations.realloc(0);
367 }
368 
369 OUString Color::getColorTransformationName( sal_Int32 nElement )
370 {
371  switch( nElement )
372  {
373  case XML_red: return "red";
374  case XML_redMod: return "redMod";
375  case XML_redOff: return "redOff";
376  case XML_green: return "green";
377  case XML_greenMod: return "greenMod";
378  case XML_greenOff: return "greenOff";
379  case XML_blue: return "blue";
380  case XML_blueMod: return "blueMod";
381  case XML_blueOff: return "blueOff";
382  case XML_alpha: return "alpha";
383  case XML_alphaMod: return "alphaMod";
384  case XML_alphaOff: return "alphaOff";
385  case XML_hue: return "hue";
386  case XML_hueMod: return "hueMod";
387  case XML_hueOff: return "hueOff";
388  case XML_sat: return "sat";
389  case XML_satMod: return "satMod";
390  case XML_satOff: return "satOff";
391  case XML_lum: return "lum";
392  case XML_lumMod: return "lumMod";
393  case XML_lumOff: return "lumOff";
394  case XML_shade: return "shade";
395  case XML_tint: return "tint";
396  case XML_gray: return "gray";
397  case XML_comp: return "comp";
398  case XML_inv: return "inv";
399  case XML_gamma: return "gamma";
400  case XML_invGamma: return "invGamma";
401  }
402  SAL_WARN( "oox.drawingml", "Color::getColorTransformationName - unexpected transformation type" );
403  return OUString();
404 }
405 
406 sal_Int32 Color::getColorTransformationToken( std::u16string_view sName )
407 {
408  if( sName == u"red" )
409  return XML_red;
410  else if( sName == u"redMod" )
411  return XML_redMod;
412  else if( sName == u"redOff" )
413  return XML_redOff;
414  else if( sName == u"green" )
415  return XML_green;
416  else if( sName == u"greenMod" )
417  return XML_greenMod;
418  else if( sName == u"greenOff" )
419  return XML_greenOff;
420  else if( sName == u"blue" )
421  return XML_blue;
422  else if( sName == u"blueMod" )
423  return XML_blueMod;
424  else if( sName == u"blueOff" )
425  return XML_blueOff;
426  else if( sName == u"alpha" )
427  return XML_alpha;
428  else if( sName == u"alphaMod" )
429  return XML_alphaMod;
430  else if( sName == u"alphaOff" )
431  return XML_alphaOff;
432  else if( sName == u"hue" )
433  return XML_hue;
434  else if( sName == u"hueMod" )
435  return XML_hueMod;
436  else if( sName == u"hueOff" )
437  return XML_hueOff;
438  else if( sName == u"sat" )
439  return XML_sat;
440  else if( sName == u"satMod" )
441  return XML_satMod;
442  else if( sName == u"satOff" )
443  return XML_satOff;
444  else if( sName == u"lum" )
445  return XML_lum;
446  else if( sName == u"lumMod" )
447  return XML_lumMod;
448  else if( sName == u"lumOff" )
449  return XML_lumOff;
450  else if( sName == u"shade" )
451  return XML_shade;
452  else if( sName == u"tint" )
453  return XML_tint;
454  else if( sName == u"gray" )
455  return XML_gray;
456  else if( sName == u"comp" )
457  return XML_comp;
458  else if( sName == u"inv" )
459  return XML_inv;
460  else if( sName == u"gamma" )
461  return XML_gamma;
462  else if( sName == u"invGamma" )
463  return XML_invGamma;
464 
465  SAL_WARN( "oox.drawingml", "Color::getColorTransformationToken - unexpected transformation type" );
466  return XML_TOKEN_INVALID;
467 }
468 
469 bool Color::equals(const Color& rOther, const GraphicHelper& rGraphicHelper, ::Color nPhClr) const
470 {
471  if (getColor(rGraphicHelper, nPhClr) != rOther.getColor(rGraphicHelper, nPhClr))
472  return false;
473 
474  return getTransparency() == rOther.getTransparency();
475 }
476 
478 {
480 }
481 
483 {
484  for(auto const& aTransform : maTransforms)
485  {
486  switch(aTransform.mnToken)
487  {
488  case XML_tint:
489  // from 1000th percent to 100th percent...
490  return aTransform.mnValue/10;
491  case XML_shade:
492  // from 1000th percent to 100th percent...
493  return -aTransform.mnValue/10;
494  }
495  }
496  return 0;
497 }
498 
499 sal_Int16 Color::getLumMod()
500 {
501  for (const auto& rTransform : maTransforms)
502  {
503  if (rTransform.mnToken != XML_lumMod)
504  {
505  continue;
506  }
507 
508  // From 1000th percent to 100th percent.
509  return rTransform.mnValue / 10;
510  }
511 
512  return 10000;
513 }
514 
515 sal_Int16 Color::getLumOff()
516 {
517  for (const auto& rTransform : maTransforms)
518  {
519  if (rTransform.mnToken != XML_lumOff)
520  {
521  continue;
522  }
523 
524  // From 1000th percent to 100th percent.
525  return rTransform.mnValue / 10;
526  }
527 
528  return 0;
529 }
530 
531 ::Color Color::getColor( const GraphicHelper& rGraphicHelper, ::Color nPhClr ) const
532 {
533  const sal_Int32 nTempC1 = mnC1;
534  const sal_Int32 nTempC2 = mnC2;
535  const sal_Int32 nTempC3 = mnC3;
536  const ColorMode eTempMode = meMode;
537 
538  switch( meMode )
539  {
540  case COLOR_UNUSED: mnC1 = sal_Int32(API_RGB_TRANSPARENT); break;
541 
542  case COLOR_RGB: break; // nothing to do
543  case COLOR_CRGB: break; // nothing to do
544  case COLOR_HSL: break; // nothing to do
545 
546  case COLOR_SCHEME: setResolvedRgb( rGraphicHelper.getSchemeColor( mnC1 ) ); break;
547  case COLOR_PALETTE: setResolvedRgb( rGraphicHelper.getPaletteColor( mnC1 ) ); break;
548  case COLOR_SYSTEM: setResolvedRgb( rGraphicHelper.getSystemColor( mnC1, ::Color(ColorTransparency, mnC2) ) ); break;
549  case COLOR_PH: setResolvedRgb( nPhClr ); break;
550 
551  case COLOR_FINAL: return ::Color(ColorTransparency, mnC1);
552  }
553 
554  // if color is UNUSED or turns to UNUSED in setResolvedRgb, do not perform transformations
555  if( meMode != COLOR_UNUSED )
556  {
557  for (auto const& transform : maTransforms)
558  {
559  switch( transform.mnToken )
560  {
561  case XML_red: toCrgb(); lclSetValue( mnC1, transform.mnValue ); break;
562  case XML_redMod: toCrgb(); lclModValue( mnC1, transform.mnValue ); break;
563  case XML_redOff: toCrgb(); lclOffValue( mnC1, transform.mnValue ); break;
564  case XML_green: toCrgb(); lclSetValue( mnC2, transform.mnValue ); break;
565  case XML_greenMod: toCrgb(); lclModValue( mnC2, transform.mnValue ); break;
566  case XML_greenOff: toCrgb(); lclOffValue( mnC2, transform.mnValue ); break;
567  case XML_blue: toCrgb(); lclSetValue( mnC3, transform.mnValue ); break;
568  case XML_blueMod: toCrgb(); lclModValue( mnC3, transform.mnValue ); break;
569  case XML_blueOff: toCrgb(); lclOffValue( mnC3, transform.mnValue ); break;
570 
571  case XML_hue: toHsl(); lclSetValue( mnC1, transform.mnValue, MAX_DEGREE ); break;
572  case XML_hueMod: toHsl(); lclModValue( mnC1, transform.mnValue, MAX_DEGREE ); break;
573  case XML_hueOff: toHsl(); lclOffValue( mnC1, transform.mnValue, MAX_DEGREE ); break;
574  case XML_sat: toHsl(); lclSetValue( mnC2, transform.mnValue ); break;
575  case XML_satMod: toHsl(); lclModValue( mnC2, transform.mnValue ); break;
576  case XML_satOff: toHsl(); lclOffValue( mnC2, transform.mnValue ); break;
577 
578  case XML_lum:
579  toHsl();
580  lclSetValue( mnC3, transform.mnValue );
581  // if color changes to black or white, it will stay gray if luminance changes again
582  if( (mnC3 == 0) || (mnC3 == MAX_PERCENT) ) mnC2 = 0;
583  break;
584  case XML_lumMod:
585  toHsl();
586  lclModValue( mnC3, transform.mnValue );
587  // if color changes to black or white, it will stay gray if luminance changes again
588  if( (mnC3 == 0) || (mnC3 == MAX_PERCENT) ) mnC2 = 0;
589  break;
590  case XML_lumOff:
591  toHsl();
592  lclOffValue( mnC3, transform.mnValue );
593  // if color changes to black or white, it will stay gray if luminance changes again
594  if( (mnC3 == 0) || (mnC3 == MAX_PERCENT) ) mnC2 = 0;
595  break;
596 
597  case XML_shade:
598  // shade: 0% = black, 100% = original color
599  toCrgb();
600  OSL_ENSURE( (0 <= transform.mnValue) && (transform.mnValue <= MAX_PERCENT), "Color::getColor - invalid shade value" );
601  if( (0 <= transform.mnValue) && (transform.mnValue <= MAX_PERCENT) )
602  {
603  double fFactor = static_cast< double >( transform.mnValue ) / MAX_PERCENT;
604  mnC1 = static_cast< sal_Int32 >( mnC1 * fFactor );
605  mnC2 = static_cast< sal_Int32 >( mnC2 * fFactor );
606  mnC3 = static_cast< sal_Int32 >( mnC3 * fFactor );
607  }
608  break;
609  case XML_tint:
610  // tint: 0% = white, 100% = original color
611  toCrgb();
612  OSL_ENSURE( (0 <= transform.mnValue) && (transform.mnValue <= MAX_PERCENT), "Color::getColor - invalid tint value" );
613  if( (0 <= transform.mnValue) && (transform.mnValue <= MAX_PERCENT) )
614  {
615  double fFactor = static_cast< double >( transform.mnValue ) / MAX_PERCENT;
616  mnC1 = static_cast< sal_Int32 >( MAX_PERCENT - (MAX_PERCENT - mnC1) * fFactor );
617  mnC2 = static_cast< sal_Int32 >( MAX_PERCENT - (MAX_PERCENT - mnC2) * fFactor );
618  mnC3 = static_cast< sal_Int32 >( MAX_PERCENT - (MAX_PERCENT - mnC3) * fFactor );
619  }
620  break;
621  case XLS_TOKEN( tint ):
622  // Excel tint: move luminance relative to current value
623  toHsl();
624  OSL_ENSURE( (-MAX_PERCENT <= transform.mnValue) && (transform.mnValue <= MAX_PERCENT), "Color::getColor - invalid tint value" );
625  if( (-MAX_PERCENT <= transform.mnValue) && (transform.mnValue < 0) )
626  {
627  // negative: luminance towards 0% (black)
628  lclModValue( mnC3, transform.mnValue + MAX_PERCENT );
629  }
630  else if( (0 < transform.mnValue) && (transform.mnValue <= MAX_PERCENT) )
631  {
632  // positive: luminance towards 100% (white)
633  mnC3 = MAX_PERCENT - mnC3;
634  lclModValue( mnC3, MAX_PERCENT - transform.mnValue );
635  mnC3 = MAX_PERCENT - mnC3;
636  }
637  break;
638 
639  case XML_gray:
640  // change color to gray, weighted RGB: 22% red, 72% green, 6% blue
641  toRgb();
642  mnC1 = mnC2 = mnC3 = (mnC1 * 22 + mnC2 * 72 + mnC3 * 6) / 100;
643  break;
644 
645  case XML_comp:
646  // comp: rotate hue by 180 degrees, do not change lum/sat
647  toHsl();
648  mnC1 = (mnC1 + (180 * PER_DEGREE)) % MAX_DEGREE;
649  break;
650  case XML_inv:
651  // invert percentual RGB values
652  toCrgb();
653  mnC1 = MAX_PERCENT - mnC1;
654  mnC2 = MAX_PERCENT - mnC2;
655  mnC3 = MAX_PERCENT - mnC3;
656  break;
657 
658  case XML_gamma:
659  // increase gamma of color
660  toCrgb();
661  mnC1 = lclGamma( mnC1, INC_GAMMA );
662  mnC2 = lclGamma( mnC2, INC_GAMMA );
663  mnC3 = lclGamma( mnC3, INC_GAMMA );
664  break;
665  case XML_invGamma:
666  // decrease gamma of color
667  toCrgb();
668  mnC1 = lclGamma( mnC1, DEC_GAMMA );
669  mnC2 = lclGamma( mnC2, DEC_GAMMA );
670  mnC3 = lclGamma( mnC3, DEC_GAMMA );
671  break;
672  }
673  }
674 
675  // store resulting RGB value in mnC1
676  toRgb();
677  mnC1 = lclRgbComponentsToRgb( mnC1, mnC2, mnC3 );
678  }
679  else // if( meMode != COLOR_UNUSED )
680  {
681  mnC1 = sal_Int32(API_RGB_TRANSPARENT);
682  }
683 
684  sal_Int32 nRet = mnC1;
685  // Restore the original values when the color depends on one of the input
686  // parameters (rGraphicHelper or nPhClr)
687  if( eTempMode >= COLOR_SCHEME && eTempMode <= COLOR_PH )
688  {
689  mnC1 = nTempC1;
690  mnC2 = nTempC2;
691  mnC3 = nTempC3;
692  meMode = eTempMode;
693  }
694  else
695  {
697  }
698  if( meMode == COLOR_FINAL )
699  maTransforms.clear();
700  return ::Color(ColorTransparency, nRet);
701 }
702 
704 {
705  return mnAlpha < MAX_PERCENT;
706 }
707 
708 sal_Int16 Color::getTransparency() const
709 {
710  return sal_Int16(std::round( (1.0 * (MAX_PERCENT - mnAlpha)) / PER_PERCENT) );
711 }
712 
713 sal_Int16 Color::getSchemeColorIndex() const
714 {
715  static std::map<OUString, sal_Int32> const aSchemeColorNameToIndex{
716  { "dk1", 0 }, { "lt1", 1 }, { "dk2", 2 }, { "lt2", 3 },
717  { "accent1", 4 }, { "accent2", 5 }, { "accent3", 6 }, { "accent4", 7 },
718  { "accent5", 8 }, { "accent6", 9 }, { "hlink", 10 }, { "folHlink", 11 }
719  };
720 
721  auto aIt = aSchemeColorNameToIndex.find(msSchemeName);
722  if( aIt == aSchemeColorNameToIndex.end() )
723  return -1;
724  else
725  return aIt->second;
726 }
727 
728 // private --------------------------------------------------------------------
729 
730 void Color::setResolvedRgb( ::Color nRgb ) const
731 {
732  meMode = (sal_Int32(nRgb) < 0) ? COLOR_UNUSED : COLOR_RGB;
733  lclRgbToRgbComponents( mnC1, mnC2, mnC3, nRgb );
734 }
735 
736 void Color::toRgb() const
737 {
738  switch( meMode )
739  {
740  case COLOR_RGB:
741  // nothing to do
742  break;
743  case COLOR_CRGB:
744  meMode = COLOR_RGB;
745  mnC1 = lclCrgbCompToRgbComp( lclGamma( mnC1, INC_GAMMA ) );
746  mnC2 = lclCrgbCompToRgbComp( lclGamma( mnC2, INC_GAMMA ) );
747  mnC3 = lclCrgbCompToRgbComp( lclGamma( mnC3, INC_GAMMA ) );
748  break;
749  case COLOR_HSL:
750  {
751  meMode = COLOR_RGB;
752  double fR = 0.0, fG = 0.0, fB = 0.0;
753  if( (mnC2 == 0) || (mnC3 == MAX_PERCENT) )
754  {
755  fR = fG = fB = static_cast< double >( mnC3 ) / MAX_PERCENT;
756  }
757  else if( mnC3 > 0 )
758  {
759  // base color from hue
760  double fHue = static_cast< double >( mnC1 ) / MAX_DEGREE * 6.0; // interval [0.0, 6.0)
761  if( fHue <= 1.0 ) { fR = 1.0; fG = fHue; } // red...yellow
762  else if( fHue <= 2.0 ) { fR = 2.0 - fHue; fG = 1.0; } // yellow...green
763  else if( fHue <= 3.0 ) { fG = 1.0; fB = fHue - 2.0; } // green...cyan
764  else if( fHue <= 4.0 ) { fG = 4.0 - fHue; fB = 1.0; } // cyan...blue
765  else if( fHue <= 5.0 ) { fR = fHue - 4.0; fB = 1.0; } // blue...magenta
766  else { fR = 1.0; fB = 6.0 - fHue; } // magenta...red
767 
768  // apply saturation
769  double fSat = static_cast< double >( mnC2 ) / MAX_PERCENT;
770  fR = (fR - 0.5) * fSat + 0.5;
771  fG = (fG - 0.5) * fSat + 0.5;
772  fB = (fB - 0.5) * fSat + 0.5;
773 
774  // apply luminance
775  double fLum = 2.0 * static_cast< double >( mnC3 ) / MAX_PERCENT - 1.0; // interval [-1.0, 1.0]
776  if( fLum < 0.0 )
777  {
778  double fShade = fLum + 1.0; // interval [0.0, 1.0] (black...full color)
779  fR *= fShade;
780  fG *= fShade;
781  fB *= fShade;
782  }
783  else if( fLum > 0.0 )
784  {
785  double fTint = 1.0 - fLum; // interval [0.0, 1.0] (white...full color)
786  fR = 1.0 - ((1.0 - fR) * fTint);
787  fG = 1.0 - ((1.0 - fG) * fTint);
788  fB = 1.0 - ((1.0 - fB) * fTint);
789  }
790  }
791  mnC1 = static_cast< sal_Int32 >( fR * 255.0 + 0.5 );
792  mnC2 = static_cast< sal_Int32 >( fG * 255.0 + 0.5 );
793  mnC3 = static_cast< sal_Int32 >( fB * 255.0 + 0.5 );
794  }
795  break;
796  default:
797  OSL_FAIL( "Color::toRgb - unexpected color mode" );
798  }
799 }
800 
801 void Color::toCrgb() const
802 {
803  switch( meMode )
804  {
805  case COLOR_HSL:
806  toRgb();
807  [[fallthrough]];
808  case COLOR_RGB:
809  meMode = COLOR_CRGB;
810  mnC1 = lclGamma( lclRgbCompToCrgbComp( mnC1 ), DEC_GAMMA );
811  mnC2 = lclGamma( lclRgbCompToCrgbComp( mnC2 ), DEC_GAMMA );
812  mnC3 = lclGamma( lclRgbCompToCrgbComp( mnC3 ), DEC_GAMMA );
813  break;
814  case COLOR_CRGB:
815  // nothing to do
816  break;
817  default:
818  OSL_FAIL( "Color::toCrgb - unexpected color mode" );
819  }
820 }
821 
822 void Color::toHsl() const
823 {
824  switch( meMode )
825  {
826  case COLOR_CRGB:
827  toRgb();
828  [[fallthrough]];
829  case COLOR_RGB:
830  {
831  meMode = COLOR_HSL;
832  double fR = static_cast< double >( mnC1 ) / 255.0; // red [0.0, 1.0]
833  double fG = static_cast< double >( mnC2 ) / 255.0; // green [0.0, 1.0]
834  double fB = static_cast< double >( mnC3 ) / 255.0; // blue [0.0, 1.0]
835  double fMin = ::std::min( ::std::min( fR, fG ), fB );
836  double fMax = ::std::max( ::std::max( fR, fG ), fB );
837  double fD = fMax - fMin;
838 
839  using ::rtl::math::approxEqual;
840 
841  // hue: 0deg = red, 120deg = green, 240deg = blue
842  if( fD == 0.0 ) // black/gray/white
843  mnC1 = 0;
844  else if( approxEqual(fMax, fR, 64) ) // magenta...red...yellow
845  mnC1 = static_cast< sal_Int32 >( ((fG - fB) / fD * 60.0 + 360.0) * PER_DEGREE + 0.5 ) % MAX_DEGREE;
846  else if( approxEqual(fMax, fG, 64) ) // yellow...green...cyan
847  mnC1 = static_cast< sal_Int32 >( ((fB - fR) / fD * 60.0 + 120.0) * PER_DEGREE + 0.5 );
848  else // cyan...blue...magenta
849  mnC1 = static_cast< sal_Int32 >( ((fR - fG) / fD * 60.0 + 240.0) * PER_DEGREE + 0.5 );
850 
851  // luminance: 0% = black, 50% = full color, 100% = white
852  mnC3 = static_cast< sal_Int32 >( (fMin + fMax) / 2.0 * MAX_PERCENT + 0.5 );
853 
854  // saturation: 0% = gray, 100% = full color
855  if( (mnC3 == 0) || (mnC3 == MAX_PERCENT) ) // black/white
856  mnC2 = 0;
857  else if( mnC3 <= 50 * PER_PERCENT ) // dark...full color
858  mnC2 = static_cast< sal_Int32 >( fD / (fMin + fMax) * MAX_PERCENT + 0.5 );
859  else // full color...light
860  mnC2 = static_cast< sal_Int32 >( fD / (2.0 - fMax - fMin) * MAX_PERCENT + 0.5 );
861  }
862  break;
863  case COLOR_HSL:
864  // nothing to do
865  break;
866  default:
867  OSL_FAIL( "Color::toHsl - unexpected color mode" );
868  }
869 }
870 
871 } // namespace oox
872 
873 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Relative RGB (r/g/b: 0...100000).
Definition: color.hxx:134
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
bool hasTransparency() const
Returns true, if the color is transparent.
Definition: color.cxx:703
Absolute RGB (r/g/b: 0...255).
Definition: color.hxx:133
virtual ::Color getSchemeColor(sal_Int32 nToken) const
Derived classes may implement to resolve a scheme color from the passed XML token identifier...
const char * sName
Definition: olehelper.cxx:92
sal_Int16 getTintOrShade()
Definition: color.cxx:482
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Transparent color for API calls.
sal_Int16 getLumMod()
Definition: color.cxx:499
void setSysClr(sal_Int32 nToken, sal_Int32 nLastRgb)
Sets a system color from the a:sysClr element.
Definition: color.cxx:319
void setSchemeClr(sal_Int32 nToken)
Sets a scheme color from the a:schemeClr element.
Definition: color.cxx:305
sal_uInt8 GetRed() const
const sal_Int32 PER_DEGREE
void setHighlight(sal_Int32 nToken)
Sets a predefined color from the w:highlight element.
Definition: color.cxx:297
static const VectorType::value_type * getVectorElement(const VectorType &rVector, sal_Int32 nIndex)
Returns the pointer to an existing element of the passed vector, or a null pointer, if the passed index is out of bounds.
const sal_Int32 PER_PERCENT
void setPaletteClr(sal_Int32 nPaletteIdx)
Sets a palette color index.
Definition: color.cxx:312
::Color getSystemColor(sal_Int32 nToken,::Color nDefaultRgb=API_RGB_TRANSPARENT) const
Returns a system color specified by the passed XML token identifier.
Placeholder color in theme style lists.
Definition: color.hxx:139
sal_Int32 mnC3
Green, green%, saturation, or system default RGB.
Definition: color.hxx:155
sal_Int32 mnC2
Red, red%, hue, scheme token, palette index, system token, or final RGB.
Definition: color.hxx:154
bool equals(const Color &rOther, const GraphicHelper &rGraphicHelper,::Color nPhClr) const
Compares this color with rOther.
Definition: color.cxx:469
std::vector< Transformation > maTransforms
Current color mode.
Definition: color.hxx:152
void setHslClr(sal_Int32 nHue, sal_Int32 nSat, sal_Int32 nLum)
Sets the HSL values from the a:hslClr element.
Definition: color.cxx:278
css::uno::Sequence< css::beans::PropertyValue > maInteropTransformations
Scheme name from the a:schemeClr element for interoperability purposes.
Definition: color.hxx:160
sal_Int16 getLumOff()
Definition: color.cxx:515
static sal_Int32 getColorTransformationToken(std::u16string_view sName)
Translates between color transformation token names and the corresponding token.
Definition: color.cxx:406
void toRgb() const
Converts the color components to RGB values.
Definition: color.cxx:736
XML_TOKEN_INVALID
HSL (hue: 0...21600000, sat/lum: 0...100000).
Definition: color.hxx:135
sal_uInt8 GetBlue() const
ColorMode meMode
void setScrgbClr(sal_Int32 nR, sal_Int32 nG, sal_Int32 nB)
Sets the percentual RGB values from the a:scrgbClr element.
Definition: color.cxx:267
::Color getDmlPresetColor(sal_Int32 nToken,::Color nDefaultRgb)
Returns the RGB value for the passed DrawingML color token, or nDefaultRgb on error.
Definition: color.cxx:223
sal_Int32 mnAlpha
Blue, blue%, or luminance.
Definition: color.hxx:156
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:531
void clearTransformations()
Removes all color transformations.
Definition: color.cxx:362
ColorVector maDmlColors
Definition: color.cxx:40
::Color getVmlPresetColor(sal_Int32 nToken,::Color nDefaultRgb)
Returns the RGB value for the passed VML color token, or nDefaultRgb on error.
Definition: color.cxx:232
const sal_Int32 MAX_PERCENT
::Color getHighlightColor(sal_Int32 nToken,::Color nDefaultRgb)
Returns the RGB value for the passed VML color token, or nDefaultRgb on error.
Definition: color.cxx:241
void toCrgb() const
Converts the color components to CRGB values (gamma corrected percentage).
Definition: color.cxx:801
float u
const sal_Int32 MAX_DEGREE
void addTransformation(sal_Int32 nElement, sal_Int32 nValue=-1)
Inserts the passed color transformation.
Definition: color.cxx:327
void setResolvedRgb(::Color nRgb) const
Internal helper for getColor().
Definition: color.cxx:730
ColorTransparency
void clearTransparence()
Removes transparence from the color.
Definition: color.cxx:477
ColorVector maHighlightColors
Predefined colors in VML, indexed by XML token.
Definition: color.cxx:42
void setPrstClr(sal_Int32 nToken)
Sets a predefined color from the a:prstClr element.
Definition: color.cxx:289
virtual ::Color getPaletteColor(sal_Int32 nPaletteIdx) const
Derived classes may implement to resolve a palette index to an RGB color.
sal_uInt8 GetGreen() const
void addChartTintTransformation(double fTint)
Inserts Chart specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint).
Definition: color.cxx:347
DefTokenId nToken
Color from application defined palette.
Definition: color.hxx:137
sal_Int16 getSchemeColorIndex() const
Definition: color.cxx:713
void setSrgbClr(sal_Int32 nRgb)
Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element.
Definition: color.cxx:260
void addExcelTintTransformation(double fTint)
Inserts Excel specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint).
Definition: color.cxx:356
sal_Int32 mnC1
Color transformations.
Definition: color.hxx:153
static OUString getColorTransformationName(sal_Int32 nElement)
Translates between color transformation tokens and their names.
Definition: color.cxx:369
ColorMode meMode
Definition: color.hxx:150
void setUnused()
Sets the color to unused state.
Definition: color.cxx:250
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
Definition: color.cxx:708
OUString msSchemeName
Alpha value (color opacity).
Definition: color.hxx:158
#define SAL_WARN(area, stream)
Color is not used, or undefined.
Definition: color.hxx:132
Color from system palette.
Definition: color.hxx:138
ColorVector maVmlColors
Predefined colors in DrawingML, indexed by XML token.
Definition: color.cxx:41
constexpr Color()
sal_Int16 nValue
void toHsl() const
Converts the color components to HSL values.
Definition: color.cxx:822