LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/attribute - fillgradientattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 74 68.9 %
Date: 2012-12-17 Functions: 22 27 81.5 %
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             : #include <drawinglayer/attribute/fillgradientattribute.hxx>
      21             : #include <basegfx/color/bcolor.hxx>
      22             : 
      23             : //////////////////////////////////////////////////////////////////////////////
      24             : 
      25             : namespace drawinglayer
      26             : {
      27             :     namespace attribute
      28             :     {
      29          52 :         class ImpFillGradientAttribute
      30             :         {
      31             :         public:
      32             :             // refcounter
      33             :             sal_uInt32                              mnRefCount;
      34             : 
      35             :             // data definitions
      36             :             GradientStyle                           meStyle;
      37             :             double                                  mfBorder;
      38             :             double                                  mfOffsetX;
      39             :             double                                  mfOffsetY;
      40             :             double                                  mfAngle;
      41             :             basegfx::BColor                         maStartColor;
      42             :             basegfx::BColor                         maEndColor;
      43             :             sal_uInt16                              mnSteps;
      44             : 
      45          82 :             ImpFillGradientAttribute(
      46             :                 GradientStyle eStyle,
      47             :                 double fBorder,
      48             :                 double fOffsetX,
      49             :                 double fOffsetY,
      50             :                 double fAngle,
      51             :                 const basegfx::BColor& rStartColor,
      52             :                 const basegfx::BColor& rEndColor,
      53             :                 sal_uInt16 nSteps)
      54             :             :   mnRefCount(0),
      55             :                 meStyle(eStyle),
      56             :                 mfBorder(fBorder),
      57             :                 mfOffsetX(fOffsetX),
      58             :                 mfOffsetY(fOffsetY),
      59             :                 mfAngle(fAngle),
      60             :                 maStartColor(rStartColor),
      61             :                 maEndColor(rEndColor),
      62          82 :                 mnSteps(nSteps)
      63             :             {
      64          82 :             }
      65             : 
      66             :             // data read access
      67          32 :             GradientStyle getStyle() const { return meStyle; }
      68           8 :             double getBorder() const { return mfBorder; }
      69           0 :             double getOffsetX() const { return mfOffsetX; }
      70           0 :             double getOffsetY() const { return mfOffsetY; }
      71           8 :             double getAngle() const { return mfAngle; }
      72           8 :             const basegfx::BColor& getStartColor() const { return maStartColor; }
      73           8 :             const basegfx::BColor& getEndColor() const { return maEndColor; }
      74           8 :             sal_uInt16 getSteps() const { return mnSteps; }
      75             : 
      76           0 :             bool operator==(const ImpFillGradientAttribute& rCandidate) const
      77             :             {
      78           0 :                 return (getStyle() == rCandidate.getStyle()
      79           0 :                     && getBorder() == rCandidate.getBorder()
      80           0 :                     && getOffsetX() == rCandidate.getOffsetX()
      81           0 :                     && getOffsetY() == rCandidate.getOffsetY()
      82           0 :                     && getAngle() == rCandidate.getAngle()
      83           0 :                     && getStartColor() == rCandidate.getStartColor()
      84           0 :                     && getEndColor() == rCandidate.getEndColor()
      85           0 :                     && getSteps() == rCandidate.getSteps());
      86             :             }
      87             : 
      88        1230 :             static ImpFillGradientAttribute* get_global_default()
      89             :             {
      90             :                 static ImpFillGradientAttribute* pDefault = 0;
      91             : 
      92        1230 :                 if(!pDefault)
      93             :                 {
      94             :                     pDefault = new ImpFillGradientAttribute(
      95             :                         GRADIENTSTYLE_LINEAR,
      96             :                         0.0, 0.0, 0.0, 0.0,
      97             :                         basegfx::BColor(),
      98             :                         basegfx::BColor(),
      99          22 :                         0);
     100             : 
     101             :                     // never delete; start with RefCount 1, not 0
     102          22 :                     pDefault->mnRefCount++;
     103             :                 }
     104             : 
     105        1230 :                 return pDefault;
     106             :             }
     107             :         };
     108             : 
     109          60 :         FillGradientAttribute::FillGradientAttribute(
     110             :             GradientStyle eStyle,
     111             :             double fBorder,
     112             :             double fOffsetX,
     113             :             double fOffsetY,
     114             :             double fAngle,
     115             :             const basegfx::BColor& rStartColor,
     116             :             const basegfx::BColor& rEndColor,
     117             :             sal_uInt16 nSteps)
     118             :         :   mpFillGradientAttribute(new ImpFillGradientAttribute(
     119          60 :                 eStyle, fBorder, fOffsetX, fOffsetY, fAngle, rStartColor, rEndColor, nSteps))
     120             :         {
     121          60 :         }
     122             : 
     123        1070 :         FillGradientAttribute::FillGradientAttribute()
     124        1070 :         :   mpFillGradientAttribute(ImpFillGradientAttribute::get_global_default())
     125             :         {
     126        1070 :             mpFillGradientAttribute->mnRefCount++;
     127        1070 :         }
     128             : 
     129        1198 :         FillGradientAttribute::FillGradientAttribute(const FillGradientAttribute& rCandidate)
     130        1198 :         :   mpFillGradientAttribute(rCandidate.mpFillGradientAttribute)
     131             :         {
     132        1198 :             mpFillGradientAttribute->mnRefCount++;
     133        1198 :         }
     134             : 
     135        2248 :         FillGradientAttribute::~FillGradientAttribute()
     136             :         {
     137        2248 :             if(mpFillGradientAttribute->mnRefCount)
     138             :             {
     139        2196 :                 mpFillGradientAttribute->mnRefCount--;
     140             :             }
     141             :             else
     142             :             {
     143          52 :                 delete mpFillGradientAttribute;
     144             :             }
     145        2248 :         }
     146             : 
     147         160 :         bool FillGradientAttribute::isDefault() const
     148             :         {
     149         160 :             return mpFillGradientAttribute == ImpFillGradientAttribute::get_global_default();
     150             :         }
     151             : 
     152          70 :         FillGradientAttribute& FillGradientAttribute::operator=(const FillGradientAttribute& rCandidate)
     153             :         {
     154          70 :             if(rCandidate.mpFillGradientAttribute != mpFillGradientAttribute)
     155             :             {
     156           0 :                 if(mpFillGradientAttribute->mnRefCount)
     157             :                 {
     158           0 :                     mpFillGradientAttribute->mnRefCount--;
     159             :                 }
     160             :                 else
     161             :                 {
     162           0 :                     delete mpFillGradientAttribute;
     163             :                 }
     164             : 
     165           0 :                 mpFillGradientAttribute = rCandidate.mpFillGradientAttribute;
     166           0 :                 mpFillGradientAttribute->mnRefCount++;
     167             :             }
     168             : 
     169          70 :             return *this;
     170             :         }
     171             : 
     172          94 :         bool FillGradientAttribute::operator==(const FillGradientAttribute& rCandidate) const
     173             :         {
     174          94 :             if(rCandidate.mpFillGradientAttribute == mpFillGradientAttribute)
     175             :             {
     176          94 :                 return true;
     177             :             }
     178             : 
     179           0 :             if(rCandidate.isDefault() != isDefault())
     180             :             {
     181           0 :                 return false;
     182             :             }
     183             : 
     184           0 :             return (*rCandidate.mpFillGradientAttribute == *mpFillGradientAttribute);
     185             :         }
     186             : 
     187           8 :         const basegfx::BColor& FillGradientAttribute::getStartColor() const
     188             :         {
     189           8 :             return mpFillGradientAttribute->getStartColor();
     190             :         }
     191             : 
     192           8 :         const basegfx::BColor& FillGradientAttribute::getEndColor() const
     193             :         {
     194           8 :             return mpFillGradientAttribute->getEndColor();
     195             :         }
     196             : 
     197           8 :         double FillGradientAttribute::getBorder() const
     198             :         {
     199           8 :             return mpFillGradientAttribute->getBorder();
     200             :         }
     201             : 
     202           0 :         double FillGradientAttribute::getOffsetX() const
     203             :         {
     204           0 :             return mpFillGradientAttribute->getOffsetX();
     205             :         }
     206             : 
     207           0 :         double FillGradientAttribute::getOffsetY() const
     208             :         {
     209           0 :             return mpFillGradientAttribute->getOffsetY();
     210             :         }
     211             : 
     212           8 :         double FillGradientAttribute::getAngle() const
     213             :         {
     214           8 :             return mpFillGradientAttribute->getAngle();
     215             :         }
     216             : 
     217          32 :         GradientStyle FillGradientAttribute::getStyle() const
     218             :         {
     219          32 :             return mpFillGradientAttribute->getStyle();
     220             :         }
     221             : 
     222           8 :         sal_uInt16 FillGradientAttribute::getSteps() const
     223             :         {
     224           8 :             return mpFillGradientAttribute->getSteps();
     225             :         }
     226             : 
     227             :     } // end of namespace attribute
     228             : } // end of namespace drawinglayer
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10