LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/oox/drawingml - color.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 5 100.0 %
Date: 2012-12-27 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10