Line data Source code
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 : #ifndef INCLUDED_OOX_DRAWINGML_COLOR_HXX
21 : #define INCLUDED_OOX_DRAWINGML_COLOR_HXX
22 :
23 : #include <com/sun/star/beans/PropertyValue.hpp>
24 : #include <com/sun/star/uno/Sequence.hxx>
25 : #include <sal/types.h>
26 : #include <rtl/instance.hxx>
27 : #include <rtl/ustring.hxx>
28 : #include <oox/helper/helper.hxx>
29 : #include <oox/dllapi.h>
30 : #include <memory>
31 : #include <vector>
32 :
33 : namespace oox { class GraphicHelper; }
34 :
35 : namespace oox {
36 : namespace drawingml {
37 :
38 :
39 :
40 152831 : class OOX_DLLPUBLIC Color
41 : {
42 : public:
43 : Color();
44 : ~Color();
45 :
46 : /** Returns the RGB value for the passed DrawingML color token, or nDefaultRgb on error. */
47 : static sal_Int32 getDmlPresetColor( sal_Int32 nToken, sal_Int32 nDefaultRgb );
48 : /** Returns the RGB value for the passed VML color token, or nDefaultRgb on error. */
49 : static sal_Int32 getVmlPresetColor( sal_Int32 nToken, sal_Int32 nDefaultRgb );
50 :
51 : /** Sets the color to unused state. */
52 : void setUnused();
53 : /** Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element. */
54 : void setSrgbClr( sal_Int32 nRgb );
55 : /** Sets the percentual RGB values from the a:scrgbClr element. */
56 : void setScrgbClr( sal_Int32 nR, sal_Int32 nG, sal_Int32 nB );
57 : /** Sets the HSL values from the a:hslClr element. */
58 : void setHslClr( sal_Int32 nHue, sal_Int32 nSat, sal_Int32 nLum );
59 : /** Sets a predefined color from the a:prstClr element. */
60 : void setPrstClr( sal_Int32 nToken );
61 : /** Sets a scheme color from the a:schemeClr element. */
62 : void setSchemeClr( sal_Int32 nToken );
63 : /** Sets the scheme name from the a:schemeClr element for interoperability purposes */
64 35639 : void setSchemeName( const OUString& sSchemeName ) { msSchemeName = sSchemeName; }
65 : /** Sets a system color from the a:sysClr element. */
66 : void setSysClr( sal_Int32 nToken, sal_Int32 nLastRgb );
67 : /** Sets a palette color index. */
68 : void setPaletteClr( sal_Int32 nPaletteIdx );
69 :
70 : /** Inserts the passed color transformation. */
71 : void addTransformation( sal_Int32 nElement, sal_Int32 nValue = -1 );
72 : /** Inserts Chart specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint). */
73 : void addChartTintTransformation( double fTint );
74 : /** Inserts Excel specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint). */
75 : void addExcelTintTransformation( double fTint );
76 : /** Removes all color transformations. */
77 : void clearTransformations();
78 : /** Removes transparence from the color. */
79 : void clearTransparence();
80 :
81 : /** Overwrites this color with the passed color, if it is used. */
82 371787 : void assignIfUsed( const Color& rColor ) { if( rColor.isUsed() ) *this = rColor; }
83 :
84 : /** Returns true, if the color is initialized. */
85 466546 : bool isUsed() const { return meMode != COLOR_UNUSED; }
86 : /** Returns true, if the color is a placeholder color in theme style lists. */
87 5999 : bool isPlaceHolder() const { return meMode == COLOR_PH; }
88 : /** Returns the final RGB color value.
89 : @param nPhClr Actual color for the phClr placeholder color used in theme style lists. */
90 : sal_Int32 getColor( const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr = API_RGB_TRANSPARENT ) const;
91 :
92 : /** Returns true, if the color is transparent. */
93 : bool hasTransparency() const;
94 : /** Returns the transparency of the color (0 = opaque, 100 = full transparent). */
95 : sal_Int16 getTransparency() const;
96 :
97 : /** Returns the scheme name from the a:schemeClr element for interoperability purposes */
98 9565 : OUString getSchemeName() const { return msSchemeName; }
99 : /** Returns the unaltered list of transformations for interoperability purposes */
100 3291 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > getTransformations() const { return maInteropTransformations;}
101 :
102 : /** Translates between color transformation tokens and their names */
103 : static OUString getColorTransformationName( sal_Int32 nElement );
104 : /** Translates between color transformation token names and the corresponding token */
105 : static sal_Int32 getColorTransformationToken( const OUString& sName );
106 :
107 : private:
108 : /** Internal helper for getColor(). */
109 : void setResolvedRgb( sal_Int32 nRgb ) const;
110 :
111 : /** Converts the color components to RGB values. */
112 : void toRgb() const;
113 : /** Converts the color components to CRGB values (gamma corrected percentage). */
114 : void toCrgb() const;
115 : /** Converts the color components to HSL values. */
116 : void toHsl() const;
117 :
118 : private:
119 : enum ColorMode
120 : {
121 : COLOR_UNUSED, /// Color is not used, or undefined.
122 : COLOR_RGB, /// Absolute RGB (r/g/b: 0...255).
123 : COLOR_CRGB, /// Relative RGB (r/g/b: 0...100000).
124 : COLOR_HSL, /// HSL (hue: 0...21600000, sat/lum: 0...100000).
125 : COLOR_SCHEME, /// Color from scheme.
126 : COLOR_PALETTE, /// Color from application defined palette.
127 : COLOR_SYSTEM, /// Color from system palette.
128 : COLOR_PH, /// Placeholder color in theme style lists.
129 : COLOR_FINAL /// Finalized RGB color.
130 : };
131 :
132 : struct Transformation
133 : {
134 : sal_Int32 mnToken;
135 : sal_Int32 mnValue;
136 :
137 42464 : explicit Transformation( sal_Int32 nToken, sal_Int32 nValue ) : mnToken( nToken ), mnValue( nValue ) {}
138 : };
139 : typedef ::std::vector< Transformation > TransformVec;
140 :
141 : mutable ColorMode meMode; /// Current color mode.
142 : mutable TransformVec maTransforms; /// Color transformations.
143 : mutable sal_Int32 mnC1; /// Red, red%, hue, scheme token, palette index, system token, or final RGB.
144 : mutable sal_Int32 mnC2; /// Green, green%, saturation, or system default RGB.
145 : mutable sal_Int32 mnC3; /// Blue, blue%, or luminance.
146 : sal_Int32 mnAlpha; /// Alpha value (color opacity).
147 :
148 : OUString msSchemeName; /// Scheme name from the a:schemeClr element for interoperability purposes
149 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
150 : maInteropTransformations; /// Unaltered list of transformations for interoperability purposes
151 : };
152 :
153 : typedef std::shared_ptr< Color > ColorPtr;
154 :
155 :
156 :
157 : } // namespace drawingml
158 : } // namespace oox
159 :
160 : #endif
161 :
162 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|