1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_DRAWINGML_COLOR_HXX 25 #define OOX_DRAWINGML_COLOR_HXX 26 27 #include <vector> 28 #include <boost/shared_ptr.hpp> 29 #include <sal/types.h> 30 #include <rtl/instance.hxx> 31 #include <rtl/ustring.hxx> 32 #include "oox/helper/helper.hxx" 33 34 namespace oox { class GraphicHelper; } 35 36 namespace oox { 37 namespace drawingml { 38 39 // ============================================================================ 40 41 class Color 42 { 43 public: 44 Color(); 45 ~Color(); 46 47 /** Returns the RGB value for the passed DrawingML color token, or nDefaultRgb on error. */ 48 static sal_Int32 getDmlPresetColor( sal_Int32 nToken, sal_Int32 nDefaultRgb ); 49 /** Returns the RGB value for the passed VML color token, or nDefaultRgb on error. */ 50 static sal_Int32 getVmlPresetColor( sal_Int32 nToken, sal_Int32 nDefaultRgb ); 51 52 /** Sets the color to unused state. */ 53 void setUnused(); 54 /** Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element. */ 55 void setSrgbClr( sal_Int32 nRgb ); 56 /** Sets the percentual RGB values from the a:scrgbClr element. */ 57 void setScrgbClr( sal_Int32 nR, sal_Int32 nG, sal_Int32 nB ); 58 /** Sets the HSL values from the a:hslClr element. */ 59 void setHslClr( sal_Int32 nHue, sal_Int32 nSat, sal_Int32 nLum ); 60 /** Sets a predefined color from the a:prstClr element. */ 61 void setPrstClr( sal_Int32 nToken ); 62 /** Sets a scheme color from the a:schemeClr element. */ 63 void setSchemeClr( sal_Int32 nToken ); 64 /** Sets a system color from the a:sysClr element. */ 65 void setSysClr( sal_Int32 nToken, sal_Int32 nLastRgb ); 66 /** Sets a palette color index. */ 67 void setPaletteClr( sal_Int32 nPaletteIdx ); 68 69 /** Inserts the passed color transformation. */ 70 void addTransformation( sal_Int32 nElement, sal_Int32 nValue = -1 ); 71 /** Inserts Chart specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint). */ 72 void addChartTintTransformation( double fTint ); 73 /** Inserts Excel specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint). */ 74 void addExcelTintTransformation( double fTint ); 75 /** Removes all color transformations. */ 76 void clearTransformations(); 77 /** Removes transparence from the color. */ 78 void clearTransparence(); 79 80 /** Overwrites this color with the passed color, if it is used. */ assignIfUsed(const Color & rColor)81 inline void assignIfUsed( const Color& rColor ) { if( rColor.isUsed() ) *this = rColor; } 82 83 /** Returns true, if the color is initialized. */ isUsed() const84 bool isUsed() const { return meMode != COLOR_UNUSED; } 85 /** Returns true, if the color is a placeholder color in theme style lists. */ isPlaceHolder() const86 bool isPlaceHolder() const { return meMode == COLOR_PH; } 87 /** Returns the final RGB color value. 88 @param nPhClr Actual color for the phClr placeholder color used in theme style lists. */ 89 sal_Int32 getColor( const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr = API_RGB_TRANSPARENT ) const; 90 91 /** Returns true, if the color is transparent. */ 92 bool hasTransparency() const; 93 /** Returns the transparency of the color (0 = opaque, 100 = full transparent). */ 94 sal_Int16 getTransparency() const; 95 96 private: 97 /** Internal helper for getColor(). */ 98 void setResolvedRgb( sal_Int32 nRgb ) const; 99 100 /** Converts the color components to RGB values. */ 101 void toRgb() const; 102 /** Converts the color components to CRGB values (gamma corrected percentage). */ 103 void toCrgb() const; 104 /** Converts the color components to HSL values. */ 105 void toHsl() const; 106 107 private: 108 enum ColorMode 109 { 110 COLOR_UNUSED, /// Color is not used, or undefined. 111 COLOR_RGB, /// Absolute RGB (r/g/b: 0...255). 112 COLOR_CRGB, /// Relative RGB (r/g/b: 0...100000). 113 COLOR_HSL, /// HSL (hue: 0...21600000, sat/lum: 0...100000). 114 COLOR_SCHEME, /// Color from scheme. 115 COLOR_PALETTE, /// Color from application defined palette. 116 COLOR_SYSTEM, /// Color from system palette. 117 COLOR_PH, /// Placeholder color in theme style lists. 118 COLOR_FINAL /// Finalized RGB color. 119 }; 120 121 struct Transformation 122 { 123 sal_Int32 mnToken; 124 sal_Int32 mnValue; 125 Transformationoox::drawingml::Color::Transformation126 explicit Transformation( sal_Int32 nToken, sal_Int32 nValue ) : mnToken( nToken ), mnValue( nValue ) {} 127 }; 128 typedef ::std::vector< Transformation > TransformVec; 129 130 mutable ColorMode meMode; /// Current color mode. 131 mutable TransformVec maTransforms; /// Color transformations. 132 mutable sal_Int32 mnC1; /// Red, red%, hue, scheme token, palette index, system token, or final RGB. 133 mutable sal_Int32 mnC2; /// Green, green%, saturation, or system default RGB. 134 mutable sal_Int32 mnC3; /// Blue, blue%, or luminance. 135 sal_Int32 mnAlpha; /// Alpha value (color opacity). 136 }; 137 138 typedef boost::shared_ptr< Color > ColorPtr; 139 140 // ============================================================================ 141 142 } // namespace drawingml 143 } // namespace oox 144 145 #endif 146 147