22#include <frozen/bits/defines.h>
23#include <frozen/bits/elsa_std.h>
24#include <frozen/unordered_map.h>
26#include <osl/diagnose.h>
31#include <oox/token/namespaces.hxx>
32#include <oox/token/tokens.hxx>
40constexpr frozen::unordered_map<sal_Int32, ::Color, 140> constDmlColors
42 {XML_aliceBlue,
::Color(0xF0F8FF)}, {XML_antiqueWhite,
::Color(0xFAEBD7)},
43 {XML_aqua,
::Color(0x00FFFF)}, {XML_aquamarine,
::Color(0x7FFFD4)},
46 {XML_blanchedAlmond,
::Color(0xFFEBCD)}, {XML_blue,
::Color(0x0000FF)},
47 {XML_blueViolet,
::Color(0x8A2BE2)}, {XML_brown,
::Color(0xA52A2A)},
48 {XML_burlyWood,
::Color(0xDEB887)}, {XML_cadetBlue,
::Color(0x5F9EA0)},
49 {XML_chartreuse,
::Color(0x7FFF00)}, {XML_chocolate,
::Color(0xD2691E)},
50 {XML_coral,
::Color(0xFF7F50)}, {XML_cornflowerBlue,
::Color(0x6495ED)},
51 {XML_cornsilk,
::Color(0xFFF8DC)}, {XML_crimson,
::Color(0xDC143C)},
53 {XML_deepSkyBlue,
::Color(0x00BFFF)}, {XML_dimGray,
::Color(0x696969)},
55 {XML_dkGoldenrod,
::Color(0xB8860B)}, {XML_dkGray,
::Color(0xA9A9A9)},
56 {XML_dkGreen,
::Color(0x006400)}, {XML_dkKhaki,
::Color(0xBDB76B)},
57 {XML_dkMagenta,
::Color(0x8B008B)}, {XML_dkOliveGreen,
::Color(0x556B2F)},
58 {XML_dkOrange,
::Color(0xFF8C00)}, {XML_dkOrchid,
::Color(0x9932CC)},
60 {XML_dkSeaGreen,
::Color(0x8FBC8B)}, {XML_dkSlateBlue,
::Color(0x483D8B)},
61 {XML_dkSlateGray,
::Color(0x2F4F4F)}, {XML_dkTurquoise,
::Color(0x00CED1)},
62 {XML_dkViolet,
::Color(0x9400D3)}, {XML_dodgerBlue,
::Color(0x1E90FF)},
63 {XML_firebrick,
::Color(0xB22222)}, {XML_floralWhite,
::Color(0xFFFAF0)},
64 {XML_forestGreen,
::Color(0x228B22)}, {XML_fuchsia,
::Color(0xFF00FF)},
65 {XML_gainsboro,
::Color(0xDCDCDC)}, {XML_ghostWhite,
::Color(0xF8F8FF)},
68 {XML_greenYellow,
::Color(0xADFF2F)}, {XML_honeydew,
::Color(0xF0FFF0)},
69 {XML_hotPink,
::Color(0xFF69B4)}, {XML_indianRed,
::Color(0xCD5C5C)},
72 {XML_lavenderBlush,
::Color(0xFFF0F5)}, {XML_lawnGreen,
::Color(0x7CFC00)},
73 {XML_lemonChiffon,
::Color(0xFFFACD)}, {XML_lime,
::Color(0x00FF00)},
74 {XML_limeGreen,
::Color(0x32CD32)}, {XML_linen,
::Color(0xFAF0E6)},
76 {XML_ltCyan,
::Color(0xE0FFFF)}, {XML_ltGoldenrodYellow,
::Color(0xFAFA78)},
78 {XML_ltPink,
::Color(0xFFB6C1)}, {XML_ltSalmon,
::Color(0xFFA07A)},
79 {XML_ltSeaGreen,
::Color(0x20B2AA)}, {XML_ltSkyBlue,
::Color(0x87CEFA)},
80 {XML_ltSlateGray,
::Color(0x778899)}, {XML_ltSteelBlue,
::Color(0xB0C4DE)},
81 {XML_ltYellow,
::Color(0xFFFFE0)}, {XML_magenta,
::Color(0xFF00FF)},
82 {XML_maroon,
::Color(0x800000)}, {XML_medAquamarine,
::Color(0x66CDAA)},
83 {XML_medBlue,
::Color(0x0000CD)}, {XML_medOrchid,
::Color(0xBA55D3)},
84 {XML_medPurple,
::Color(0x9370DB)}, {XML_medSeaGreen,
::Color(0x3CB371)},
85 {XML_medSlateBlue,
::Color(0x7B68EE)}, {XML_medSpringGreen,
::Color(0x00FA9A)},
86 {XML_medTurquoise,
::Color(0x48D1CC)}, {XML_medVioletRed,
::Color(0xC71585)},
87 {XML_midnightBlue,
::Color(0x191970)}, {XML_mintCream,
::Color(0xF5FFFA)},
88 {XML_mistyRose,
::Color(0xFFE4E1)}, {XML_moccasin,
::Color(0xFFE4B5)},
89 {XML_navajoWhite,
::Color(0xFFDEAD)}, {XML_navy,
::Color(0x000080)},
91 {XML_oliveDrab,
::Color(0x6B8E23)}, {XML_orange,
::Color(0xFFA500)},
92 {XML_orangeRed,
::Color(0xFF4500)}, {XML_orchid,
::Color(0xDA70D6)},
93 {XML_paleGoldenrod,
::Color(0xEEE8AA)}, {XML_paleGreen,
::Color(0x98FB98)},
94 {XML_paleTurquoise,
::Color(0xAFEEEE)}, {XML_paleVioletRed,
::Color(0xDB7093)},
95 {XML_papayaWhip,
::Color(0xFFEFD5)}, {XML_peachPuff,
::Color(0xFFDAB9)},
97 {XML_plum,
::Color(0xDDA0DD)}, {XML_powderBlue,
::Color(0xB0E0E6)},
99 {XML_rosyBrown,
::Color(0xBC8F8F)}, {XML_royalBlue,
::Color(0x4169E1)},
100 {XML_saddleBrown,
::Color(0x8B4513)}, {XML_salmon,
::Color(0xFA8072)},
101 {XML_sandyBrown,
::Color(0xF4A460)}, {XML_seaGreen,
::Color(0x2E8B57)},
102 {XML_seaShell,
::Color(0xFFF5EE)}, {XML_sienna,
::Color(0xA0522D)},
103 {XML_silver,
::Color(0xC0C0C0)}, {XML_skyBlue,
::Color(0x87CEEB)},
104 {XML_slateBlue,
::Color(0x6A5ACD)}, {XML_slateGray,
::Color(0x708090)},
105 {XML_snow,
::Color(0xFFFAFA)}, {XML_springGreen,
::Color(0x00FF7F)},
108 {XML_tomato,
::Color(0xFF6347)}, {XML_turquoise,
::Color(0x40E0D0)},
110 {XML_white,
::Color(0xFFFFFF)}, {XML_whiteSmoke,
::Color(0xF5F5F5)},
111 {XML_yellow,
::Color(0xFFFF00)}, {XML_yellowGreen,
::Color(0x9ACD32)}
114constexpr ::Color lookupDmlColor(sal_Int32 nToken)
116 auto iterator = constDmlColors.find(nToken);
117 if (iterator == constDmlColors.end())
119 return iterator->second;
122constexpr frozen::unordered_map<sal_Int32, ::Color, 16> constVmlColors
134constexpr ::Color lookupVmlColor(sal_Int32 nToken)
136 auto iterator = constVmlColors.find(nToken);
137 if (iterator == constVmlColors.end())
139 return iterator->second;
142constexpr frozen::unordered_map<sal_Int32, ::Color, 16> constHighlightColors
147 {XML_darkCyan,
::Color(0x008B8B)}, {XML_darkGray,
::Color(0xA9A9A9)},
148 {XML_darkGreen,
::Color(0x006400)}, {XML_darkMagenta,
::Color(0x800080)},
149 {XML_darkRed,
::Color(0x8B0000)}, {XML_darkYellow,
::Color(0x808000)},
150 {XML_green,
::Color(0x00FF00)}, {XML_lightGray,
::Color(0xD3D3D3)},
155constexpr ::Color lookupHighlightColor(sal_Int32 nToken)
157 auto iterator = constHighlightColors.find(nToken);
158 if (iterator == constHighlightColors.end())
160 return iterator->second;
163const double DEC_GAMMA = 2.3;
164const double INC_GAMMA = 1.0 / DEC_GAMMA;
166void lclRgbToRgbComponents( sal_Int32& ornR, sal_Int32& ornG, sal_Int32& ornB,
::Color nRgb )
173sal_Int32 lclRgbComponentsToRgb( sal_Int32 nR, sal_Int32 nG, sal_Int32 nB )
175 return static_cast< sal_Int32
>( (nR << 16) | (nG << 8) | nB );
178sal_Int32 lclRgbCompToCrgbComp( sal_Int32 nRgbComp )
180 return static_cast< sal_Int32
>( nRgbComp *
MAX_PERCENT / 255 );
183sal_Int32 lclCrgbCompToRgbComp( sal_Int32 nCrgbComp )
185 return static_cast< sal_Int32
>( nCrgbComp * 255 /
MAX_PERCENT );
188sal_Int32 lclGamma( sal_Int32 nComp,
double fGamma )
190 return static_cast< sal_Int32
>( pow(
static_cast< double >( nComp ) /
MAX_PERCENT, fGamma ) *
MAX_PERCENT + 0.5 );
193void lclSetValue( sal_Int32& ornValue, sal_Int32 nNew, sal_Int32 nMax =
MAX_PERCENT )
195 OSL_ENSURE( (0 <= nNew) && (nNew <= nMax),
"lclSetValue - invalid value" );
196 if( (0 <= nNew) && (nNew <= nMax) )
200void lclModValue( sal_Int32& ornValue, sal_Int32 nMod, sal_Int32 nMax =
MAX_PERCENT )
202 OSL_ENSURE( (0 <= nMod),
"lclModValue - invalid modificator" );
203 ornValue = getLimitedValue< sal_Int32, double >(
static_cast< double >( ornValue ) * nMod /
MAX_PERCENT, 0, nMax );
206void lclOffValue( sal_Int32& ornValue, sal_Int32 nOff, sal_Int32 nMax =
MAX_PERCENT )
208 OSL_ENSURE( (-nMax <= nOff) && (nOff <= nMax),
"lclOffValue - invalid offset" );
209 ornValue = getLimitedValue< sal_Int32, sal_Int32 >( ornValue + nOff, 0, nMax );
212constexpr frozen::unordered_map<std::u16string_view, model::ThemeColorType, 26> constSchemeColorNameToIndex
242constexpr frozen::unordered_map<sal_Int32, model::ThemeColorType, 26> constThemeColorTokenMap
276 auto aIterator = constSchemeColorNameToIndex.find(rSchemeName);
277 if (aIterator == constSchemeColorNameToIndex.end())
280 return aIterator->second;
285 auto aIterator = constThemeColorTokenMap.find(
nToken);
286 if (aIterator == constThemeColorTokenMap.end())
289 return aIterator->second;
308 return (sal_Int32(nRgbValue) >= 0) ? nRgbValue : nDefaultRgb;
317 return (sal_Int32(nRgbValue) >= 0) ? nRgbValue : nDefaultRgb;
326 return (sal_Int32(nRgbValue) >= 0) ? nRgbValue : nDefaultRgb;
341 OSL_ENSURE( (0 <= nRgb) && (nRgb <= 0xFFFFFF),
"Color::setSrgbClr - invalid RGB value" );
348 OSL_ENSURE( (0 <= nR) && (nR <=
MAX_PERCENT),
"Color::setScrgbClr - invalid red value" );
349 OSL_ENSURE( (0 <= nG) && (nG <=
MAX_PERCENT),
"Color::setScrgbClr - invalid green value" );
350 OSL_ENSURE( (0 <= nB) && (nB <=
MAX_PERCENT),
"Color::setScrgbClr - invalid blue value" );
359 OSL_ENSURE( (0 <= nHue) && (nHue <=
MAX_DEGREE),
"Color::setHslClr - invalid hue value" );
360 OSL_ENSURE( (0 <= nSat) && (nSat <=
MAX_PERCENT),
"Color::setHslClr - invalid saturation value" );
361 OSL_ENSURE( (0 <= nLum) && (nLum <=
MAX_PERCENT),
"Color::setHslClr - invalid luminance value" );
363 mnC1 = getLimitedValue< sal_Int32, sal_Int32 >( nHue, 0,
MAX_DEGREE );
364 mnC2 = getLimitedValue< sal_Int32, sal_Int32 >( nSat, 0,
MAX_PERCENT );
365 mnC3 = getLimitedValue< sal_Int32, sal_Int32 >( nLum, 0,
MAX_PERCENT );
371 OSL_ENSURE( sal_Int32(nRgbValue) >= 0,
"Color::setPrstClr - invalid preset color token" );
372 if( sal_Int32(nRgbValue) >= 0 )
379 OSL_ENSURE( sal_Int32(nRgbValue) >= 0,
"Color::setPrstClr - invalid preset color token" );
380 if ( sal_Int32(nRgbValue) >= 0 )
395 OSL_ENSURE( nPaletteIdx >= 0,
"Color::setPaletteClr - invalid palette index" );
402 OSL_ENSURE( (-1 <= nLastRgb) && (nLastRgb <= 0xFFFFFF),
"Color::setSysClr - invalid RGB value" );
413 sal_Int32
nToken = getBaseToken( nElement );
425 pInteropTransformations[nSize].Value <<=
nValue;
439 sal_Int32
nValue = std::round(std::abs(fTint) * 100'000.0);
445 else if (fTint < 0.0)
462 case XML_red:
return "red";
463 case XML_redMod:
return "redMod";
464 case XML_redOff:
return "redOff";
465 case XML_green:
return "green";
466 case XML_greenMod:
return "greenMod";
467 case XML_greenOff:
return "greenOff";
468 case XML_blue:
return "blue";
469 case XML_blueMod:
return "blueMod";
470 case XML_blueOff:
return "blueOff";
471 case XML_alpha:
return "alpha";
472 case XML_alphaMod:
return "alphaMod";
473 case XML_alphaOff:
return "alphaOff";
474 case XML_hue:
return "hue";
475 case XML_hueMod:
return "hueMod";
476 case XML_hueOff:
return "hueOff";
477 case XML_sat:
return "sat";
478 case XML_satMod:
return "satMod";
479 case XML_satOff:
return "satOff";
480 case XML_lum:
return "lum";
481 case XML_lumMod:
return "lumMod";
482 case XML_lumOff:
return "lumOff";
483 case XML_shade:
return "shade";
484 case XML_tint:
return "tint";
485 case XML_gray:
return "gray";
486 case XML_comp:
return "comp";
487 case XML_inv:
return "inv";
488 case XML_gamma:
return "gamma";
489 case XML_invGamma:
return "invGamma";
491 SAL_WARN(
"oox.drawingml",
"Color::getColorTransformationName - unexpected transformation type" );
499 else if(
sName ==
u"redMod" )
501 else if(
sName ==
u"redOff" )
503 else if(
sName ==
u"green" )
505 else if(
sName ==
u"greenMod" )
507 else if(
sName ==
u"greenOff" )
509 else if(
sName ==
u"blue" )
511 else if(
sName ==
u"blueMod" )
513 else if(
sName ==
u"blueOff" )
515 else if(
sName ==
u"alpha" )
517 else if(
sName ==
u"alphaMod" )
519 else if(
sName ==
u"alphaOff" )
521 else if(
sName ==
u"hue" )
523 else if(
sName ==
u"hueMod" )
525 else if(
sName ==
u"hueOff" )
527 else if(
sName ==
u"sat" )
529 else if(
sName ==
u"satMod" )
531 else if(
sName ==
u"satOff" )
533 else if(
sName ==
u"lum" )
535 else if(
sName ==
u"lumMod" )
537 else if(
sName ==
u"lumOff" )
539 else if(
sName ==
u"shade" )
541 else if(
sName ==
u"tint" )
543 else if(
sName ==
u"gray" )
545 else if(
sName ==
u"comp" )
547 else if(
sName ==
u"inv" )
549 else if(
sName ==
u"gamma" )
551 else if(
sName ==
u"invGamma" )
554 SAL_WARN(
"oox.drawingml",
"Color::getColorTransformationToken - unexpected transformation type" );
560 if (
getColor(rGraphicHelper, nPhClr) != rOther.
getColor(rGraphicHelper, nPhClr))
575 switch(aTransform.mnToken)
579 return aTransform.mnValue/10;
582 return -aTransform.mnValue/10;
592 if (rTransform.mnToken != XML_lumMod)
598 return rTransform.mnValue / 10;
608 if (rTransform.mnToken != XML_lumOff)
614 return rTransform.mnValue / 10;
641 return aComplexColor;
646 const sal_Int32 nTempC1 = mnC1;
647 const sal_Int32 nTempC2 = mnC2;
648 const sal_Int32 nTempC3 = mnC3;
655 case COLOR_RGB:
break;
656 case COLOR_CRGB:
break;
657 case COLOR_HSL:
break;
659 case COLOR_SCHEME: setResolvedRgb( rGraphicHelper.
getSchemeColor( mnC1 ) );
break;
660 case COLOR_PALETTE: setResolvedRgb( rGraphicHelper.
getPaletteColor( mnC1 ) );
break;
662 case COLOR_PH: setResolvedRgb( nPhClr );
break;
668 if(
meMode != COLOR_UNUSED )
670 for (
auto const& transform : maTransforms)
672 switch( transform.mnToken )
674 case XML_red: toCrgb(); lclSetValue( mnC1, transform.mnValue );
break;
675 case XML_redMod: toCrgb(); lclModValue( mnC1, transform.mnValue );
break;
676 case XML_redOff: toCrgb(); lclOffValue( mnC1, transform.mnValue );
break;
677 case XML_green: toCrgb(); lclSetValue( mnC2, transform.mnValue );
break;
678 case XML_greenMod: toCrgb(); lclModValue( mnC2, transform.mnValue );
break;
679 case XML_greenOff: toCrgb(); lclOffValue( mnC2, transform.mnValue );
break;
680 case XML_blue: toCrgb(); lclSetValue( mnC3, transform.mnValue );
break;
681 case XML_blueMod: toCrgb(); lclModValue( mnC3, transform.mnValue );
break;
682 case XML_blueOff: toCrgb(); lclOffValue( mnC3, transform.mnValue );
break;
684 case XML_hue: toHsl(); lclSetValue( mnC1, transform.mnValue,
MAX_DEGREE );
break;
685 case XML_hueMod: toHsl(); lclModValue( mnC1, transform.mnValue,
MAX_DEGREE );
break;
686 case XML_hueOff: toHsl(); lclOffValue( mnC1, transform.mnValue,
MAX_DEGREE );
break;
687 case XML_sat: toHsl(); lclSetValue( mnC2, transform.mnValue );
break;
688 case XML_satMod: toHsl(); lclModValue( mnC2, transform.mnValue );
break;
689 case XML_satOff: toHsl(); lclOffValue( mnC2, transform.mnValue );
break;
693 lclSetValue( mnC3, transform.mnValue );
695 if( (mnC3 == 0) || (mnC3 ==
MAX_PERCENT) ) mnC2 = 0;
699 lclModValue( mnC3, transform.mnValue );
701 if( (mnC3 == 0) || (mnC3 ==
MAX_PERCENT) ) mnC2 = 0;
705 lclOffValue( mnC3, transform.mnValue );
707 if( (mnC3 == 0) || (mnC3 ==
MAX_PERCENT) ) mnC2 = 0;
713 OSL_ENSURE( (0 <= transform.mnValue) && (transform.mnValue <=
MAX_PERCENT),
"Color::getColor - invalid shade value" );
714 if( (0 <= transform.mnValue) && (transform.mnValue <=
MAX_PERCENT) )
716 double fFactor =
static_cast< double >( transform.mnValue ) /
MAX_PERCENT;
717 mnC1 =
static_cast< sal_Int32
>( mnC1 * fFactor );
718 mnC2 =
static_cast< sal_Int32
>( mnC2 * fFactor );
719 mnC3 =
static_cast< sal_Int32
>( mnC3 * fFactor );
725 OSL_ENSURE( (0 <= transform.mnValue) && (transform.mnValue <=
MAX_PERCENT),
"Color::getColor - invalid tint value" );
726 if( (0 <= transform.mnValue) && (transform.mnValue <=
MAX_PERCENT) )
728 double fFactor =
static_cast< double >( transform.mnValue ) /
MAX_PERCENT;
738 mnC1 = mnC2 = mnC3 = (mnC1 * 22 + mnC2 * 72 + mnC3 * 6) / 100;
757 mnC1 = lclGamma( mnC1, INC_GAMMA );
758 mnC2 = lclGamma( mnC2, INC_GAMMA );
759 mnC3 = lclGamma( mnC3, INC_GAMMA );
764 mnC1 = lclGamma( mnC1, DEC_GAMMA );
765 mnC2 = lclGamma( mnC2, DEC_GAMMA );
766 mnC3 = lclGamma( mnC3, DEC_GAMMA );
773 mnC1 = lclRgbComponentsToRgb( mnC1, mnC2, mnC3 );
780 sal_Int32 nRet = mnC1;
783 if( eTempMode >= COLOR_SCHEME && eTempMode <= COLOR_PH )
794 if(
meMode == COLOR_FINAL )
795 maTransforms.clear();
799bool Color::hasTransparency()
const
804sal_Int16 Color::getTransparency()
const
809sal_Int16 Color::getSchemeColorIndex()
const
812 return sal_Int16(eThemeType);
823 else if (
meMode == COLOR_SCHEME)
825 auto eTheme = getThemeColorType();
831 return aNewComplexColor;
834 for(
auto const& aTransform : maTransforms)
836 sal_Int16
nValue = sal_Int16(aTransform.mnValue / 10);
838 switch (aTransform.mnToken)
859 return aNewComplexColor;
864void Color::setResolvedRgb(
::Color nRgb )
const
866 meMode = (sal_Int32(nRgb) < 0) ? COLOR_UNUSED : COLOR_RGB;
867 lclRgbToRgbComponents( mnC1, mnC2, mnC3, nRgb );
870void Color::toRgb()
const
879 mnC1 = lclCrgbCompToRgbComp( lclGamma( mnC1, INC_GAMMA ) );
880 mnC2 = lclCrgbCompToRgbComp( lclGamma( mnC2, INC_GAMMA ) );
881 mnC3 = lclCrgbCompToRgbComp( lclGamma( mnC3, INC_GAMMA ) );
886 double fR = 0.0, fG = 0.0, fB = 0.0;
889 fR = fG = fB =
static_cast< double >( mnC3 ) /
MAX_PERCENT;
894 double fHue =
static_cast< double >( mnC1 ) /
MAX_DEGREE * 6.0;
895 if( fHue <= 1.0 ) { fR = 1.0; fG = fHue; }
896 else if( fHue <= 2.0 ) { fR = 2.0 - fHue; fG = 1.0; }
897 else if( fHue <= 3.0 ) { fG = 1.0; fB = fHue - 2.0; }
898 else if( fHue <= 4.0 ) { fG = 4.0 - fHue; fB = 1.0; }
899 else if( fHue <= 5.0 ) { fR = fHue - 4.0; fB = 1.0; }
900 else { fR = 1.0; fB = 6.0 - fHue; }
903 double fSat =
static_cast< double >( mnC2 ) /
MAX_PERCENT;
904 fR = (fR - 0.5) * fSat + 0.5;
905 fG = (fG - 0.5) * fSat + 0.5;
906 fB = (fB - 0.5) * fSat + 0.5;
909 double fLum = 2.0 *
static_cast< double >( mnC3 ) /
MAX_PERCENT - 1.0;
912 double fShade = fLum + 1.0;
917 else if( fLum > 0.0 )
919 double fTint = 1.0 - fLum;
920 fR = 1.0 - ((1.0 - fR) * fTint);
921 fG = 1.0 - ((1.0 - fG) * fTint);
922 fB = 1.0 - ((1.0 - fB) * fTint);
925 mnC1 =
static_cast< sal_Int32
>( fR * 255.0 + 0.5 );
926 mnC2 =
static_cast< sal_Int32
>( fG * 255.0 + 0.5 );
927 mnC3 =
static_cast< sal_Int32
>( fB * 255.0 + 0.5 );
931 OSL_FAIL(
"Color::toRgb - unexpected color mode" );
935void Color::toCrgb()
const
944 mnC1 = lclGamma( lclRgbCompToCrgbComp( mnC1 ), DEC_GAMMA );
945 mnC2 = lclGamma( lclRgbCompToCrgbComp( mnC2 ), DEC_GAMMA );
946 mnC3 = lclGamma( lclRgbCompToCrgbComp( mnC3 ), DEC_GAMMA );
952 OSL_FAIL(
"Color::toCrgb - unexpected color mode" );
956void Color::toHsl()
const
966 double fR =
static_cast< double >( mnC1 ) / 255.0;
967 double fG =
static_cast< double >( mnC2 ) / 255.0;
968 double fB =
static_cast< double >( mnC3 ) / 255.0;
969 double fMin = ::std::min( ::std::min( fR, fG ), fB );
970 double fMax = ::std::max( ::std::max( fR, fG ), fB );
971 double fD = fMax - fMin;
973 using ::rtl::math::approxEqual;
978 else if( approxEqual(fMax, fR, 64) )
979 mnC1 =
static_cast< sal_Int32
>( ((fG - fB) / fD * 60.0 + 360.0) *
PER_DEGREE + 0.5 ) %
MAX_DEGREE;
980 else if( approxEqual(fMax, fG, 64) )
981 mnC1 =
static_cast< sal_Int32
>( ((fB - fR) / fD * 60.0 + 120.0) *
PER_DEGREE + 0.5 );
983 mnC1 =
static_cast< sal_Int32
>( ((fR - fG) / fD * 60.0 + 240.0) *
PER_DEGREE + 0.5 );
986 mnC3 =
static_cast< sal_Int32
>( (fMin + fMax) / 2.0 *
MAX_PERCENT + 0.5 );
992 mnC2 =
static_cast< sal_Int32
>( fD / (fMin + fMax) *
MAX_PERCENT + 0.5 );
994 mnC2 =
static_cast< sal_Int32
>( fD / (2.0 - fMax - fMin) *
MAX_PERCENT + 0.5 );
1001 OSL_FAIL(
"Color::toHsl - unexpected color mode" );
sal_uInt8 GetBlue() const
sal_uInt8 GetGreen() const
void setSchemeColor(ThemeColorType eType)
void addTransformation(Transformation const &rTransform)
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
virtual ::Color getPaletteColor(sal_Int32 nPaletteIdx) const
Derived classes may implement to resolve a palette index to an RGB color.
virtual ::Color getSchemeColor(sal_Int32 nToken) const
Derived classes may implement to resolve a scheme color from the passed XML token identifier.
::Color getSystemColor(sal_Int32 nToken, ::Color nDefaultRgb=API_RGB_TRANSPARENT) const
Returns a system color specified by the passed XML token identifier.
sal_Int16 getTintOrShade() const
sal_Int16 getLumMod() const
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
void addTransformation(sal_Int32 nElement, sal_Int32 nValue=-1)
Inserts the passed color transformation.
void setPrstClr(sal_Int32 nToken)
Sets a predefined color from the a:prstClr element.
void setPaletteClr(sal_Int32 nPaletteIdx)
Sets a palette color index.
void setScrgbClr(sal_Int32 nR, sal_Int32 nG, sal_Int32 nB)
Sets the percentual RGB values from the a:scrgbClr element.
@ COLOR_SYSTEM
Color from application defined palette.
@ COLOR_RGB
Color is not used, or undefined.
@ COLOR_HSL
Relative RGB (r/g/b: 0...100000).
@ COLOR_CRGB
Absolute RGB (r/g/b: 0...255).
@ COLOR_PALETTE
Color from scheme.
@ COLOR_SCHEME
HSL (hue: 0...21600000, sat/lum: 0...100000).
@ COLOR_PH
Color from system palette.
static OUString getColorTransformationName(sal_Int32 nElement)
Translates between color transformation tokens and their names.
void addExcelTintTransformation(double fTint)
Inserts Excel specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint).
void setSchemeClr(sal_Int32 nToken)
Sets a scheme color from the a:schemeClr element.
void addChartTintTransformation(double fTint)
Inserts Chart specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint).
void clearTransformations()
Removes all color transformations.
sal_Int32 mnC1
Color transformations.
void setUnused()
Sets the color to unused state.
void setHighlight(sal_Int32 nToken)
Sets a predefined color from the w:highlight element.
css::uno::Sequence< css::beans::PropertyValue > maInteropTransformations
sal_Int32 mnAlpha
Blue, blue%, or luminance.
void setHslClr(sal_Int32 nHue, sal_Int32 nSat, sal_Int32 nLum)
Sets the HSL values from the a:hslClr element.
sal_Int16 getLumOff() const
void clearTransparence()
Removes transparence from the color.
model::ThemeColorType meThemeColorType
Scheme name from the a:schemeClr element for interoperability purposes.
bool equals(const Color &rOther, const GraphicHelper &rGraphicHelper, ::Color nPhClr) const
Compares this color with rOther.
std::vector< Transformation > maTransforms
Current color mode.
void setSysClr(sal_Int32 nToken, sal_Int32 nLastRgb)
Sets a system color from the a:sysClr element.
sal_Int32 mnC2
Red, red%, hue, scheme token, palette index, system token, or final RGB.
model::ComplexColor getComplexColor() const
::Color getDmlPresetColor(sal_Int32 nToken, ::Color nDefaultRgb)
Returns the RGB value for the passed DrawingML color token, or nDefaultRgb on error.
sal_Int16 getSchemeColorIndex() const
static sal_Int32 getColorTransformationToken(std::u16string_view sName)
Translates between color transformation token names and the corresponding token.
sal_Int32 mnC3
Green, green%, saturation, or system default RGB.
::Color getHighlightColor(sal_Int32 nToken, ::Color nDefaultRgb)
Returns the RGB value for the passed VML color token, or nDefaultRgb on error.
::Color getVmlPresetColor(sal_Int32 nToken, ::Color nDefaultRgb)
Returns the RGB value for the passed VML color token, or nDefaultRgb on error.
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
void setSrgbClr(sal_Int32 nRgb)
Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element.
#define SAL_WARN(area, stream)
constexpr ThemeColorType convertToThemeColorType(sal_Int32 nIndex)
model::ThemeColorType schemeNameToThemeColorType(OUString const &rSchemeName)
model::ThemeColorType schemeTokenToThemeColorType(sal_uInt32 nToken)
const sal_Int32 MAX_DEGREE
const sal_Int32 MAX_PERCENT
const sal_Int32 PER_DEGREE
const sal_Int32 PER_PERCENT
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Transparent color for API calls.