LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/attribute - sdrlineattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 69 97.1 %
Date: 2012-12-17 Functions: 25 25 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             : #include <drawinglayer/attribute/sdrlineattribute.hxx>
      21             : #include <basegfx/color/bcolor.hxx>
      22             : 
      23             : //////////////////////////////////////////////////////////////////////////////
      24             : 
      25             : namespace drawinglayer
      26             : {
      27             :     namespace attribute
      28             :     {
      29         246 :         class ImpSdrLineAttribute
      30             :         {
      31             :         public:
      32             :             // refcounter
      33             :             sal_uInt32                              mnRefCount;
      34             : 
      35             :             // line definitions
      36             :             basegfx::B2DLineJoin                    meJoin;             // B2DLINEJOIN_* defines
      37             :             double                                  mfWidth;            // 1/100th mm, 0.0==hair
      38             :             double                                  mfTransparence;     // [0.0 .. 1.0], 0.0==no transp.
      39             :             basegfx::BColor                         maColor;            // color of line
      40             :             com::sun::star::drawing::LineCap        meCap;              // BUTT, ROUND, or SQUARE
      41             :             ::std::vector< double >                 maDotDashArray;     // array of double which defines the dot-dash pattern
      42             :             double                                  mfFullDotDashLen;   // sum of maDotDashArray (for convenience)
      43             : 
      44         292 :             ImpSdrLineAttribute(
      45             :                 basegfx::B2DLineJoin eJoin,
      46             :                 double fWidth,
      47             :                 double fTransparence,
      48             :                 const basegfx::BColor& rColor,
      49             :                 com::sun::star::drawing::LineCap eCap,
      50             :                 const ::std::vector< double >& rDotDashArray,
      51             :                 double fFullDotDashLen)
      52             :             :   mnRefCount(0),
      53             :                 meJoin(eJoin),
      54             :                 mfWidth(fWidth),
      55             :                 mfTransparence(fTransparence),
      56             :                 maColor(rColor),
      57             :                 meCap(eCap),
      58             :                 maDotDashArray(rDotDashArray),
      59         292 :                 mfFullDotDashLen(fFullDotDashLen)
      60             :             {
      61         292 :             }
      62             : 
      63             :             explicit ImpSdrLineAttribute(const basegfx::BColor& rColor)
      64             :             :   mnRefCount(0),
      65             :                 meJoin(basegfx::B2DLINEJOIN_NONE),
      66             :                 mfWidth(0.0),
      67             :                 mfTransparence(0.0),
      68             :                 maColor(rColor),
      69             :                 meCap(com::sun::star::drawing::LineCap_BUTT),
      70             :                 maDotDashArray(),
      71             :                 mfFullDotDashLen(0.0)
      72             :             {
      73             :             }
      74             : 
      75             :             // data read access
      76         314 :             basegfx::B2DLineJoin getJoin() const { return meJoin; }
      77         588 :             double getWidth() const { return mfWidth; }
      78         314 :             double getTransparence() const { return mfTransparence; }
      79         314 :             const basegfx::BColor& getColor() const { return maColor; }
      80         314 :             com::sun::star::drawing::LineCap getCap() const { return meCap; }
      81         314 :             const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; }
      82         242 :             double getFullDotDashLen() const { return mfFullDotDashLen; }
      83             : 
      84          36 :             bool operator==(const ImpSdrLineAttribute& rCandidate) const
      85             :             {
      86          36 :                 return (getJoin() == rCandidate.getJoin()
      87          36 :                     && getWidth() == rCandidate.getWidth()
      88          36 :                     && getTransparence() == rCandidate.getTransparence()
      89          36 :                     && getColor() == rCandidate.getColor()
      90          36 :                     && getCap() == rCandidate.getCap()
      91         180 :                     && getDotDashArray() == rCandidate.getDotDashArray());
      92             :             }
      93             : 
      94        3434 :             static ImpSdrLineAttribute* get_global_default()
      95             :             {
      96             :                 static ImpSdrLineAttribute* pDefault = 0;
      97             : 
      98        3434 :                 if(!pDefault)
      99             :                 {
     100             :                     pDefault = new ImpSdrLineAttribute(
     101             :                         basegfx::B2DLINEJOIN_ROUND,
     102             :                         0.0,
     103             :                         0.0,
     104             :                         basegfx::BColor(),
     105             :                         com::sun::star::drawing::LineCap_BUTT,
     106             :                         std::vector< double >(),
     107          18 :                         0.0);
     108             : 
     109             :                     // never delete; start with RefCount 1, not 0
     110          18 :                     pDefault->mnRefCount++;
     111             :                 }
     112             : 
     113        3434 :                 return pDefault;
     114             :             }
     115             :         };
     116             : 
     117         274 :         SdrLineAttribute::SdrLineAttribute(
     118             :             basegfx::B2DLineJoin eJoin,
     119             :             double fWidth,
     120             :             double fTransparence,
     121             :             const basegfx::BColor& rColor,
     122             :             com::sun::star::drawing::LineCap eCap,
     123             :             const ::std::vector< double >& rDotDashArray,
     124             :             double fFullDotDashLen)
     125             :         :   mpSdrLineAttribute(
     126             :                 new ImpSdrLineAttribute(
     127             :                     eJoin,
     128             :                     fWidth,
     129             :                     fTransparence,
     130             :                     rColor,
     131             :                     eCap,
     132             :                     rDotDashArray,
     133         274 :                     fFullDotDashLen))
     134             : 
     135             :         {
     136         274 :         }
     137             : 
     138        1322 :         SdrLineAttribute::SdrLineAttribute()
     139        1322 :         :   mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default())
     140             :         {
     141        1322 :             mpSdrLineAttribute->mnRefCount++;
     142        1322 :         }
     143             : 
     144        1062 :         SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate)
     145        1062 :         :   mpSdrLineAttribute(rCandidate.mpSdrLineAttribute)
     146             :         {
     147        1062 :             mpSdrLineAttribute->mnRefCount++;
     148        1062 :         }
     149             : 
     150        2618 :         SdrLineAttribute::~SdrLineAttribute()
     151             :         {
     152        2618 :             if(mpSdrLineAttribute->mnRefCount)
     153             :             {
     154        2372 :                 mpSdrLineAttribute->mnRefCount--;
     155             :             }
     156             :             else
     157             :             {
     158         246 :                 delete mpSdrLineAttribute;
     159             :             }
     160        2618 :         }
     161             : 
     162        2112 :         bool SdrLineAttribute::isDefault() const
     163             :         {
     164        2112 :             return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default();
     165             :         }
     166             : 
     167         660 :         SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate)
     168             :         {
     169         660 :             if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute)
     170             :             {
     171         274 :                 if(mpSdrLineAttribute->mnRefCount)
     172             :                 {
     173         274 :                     mpSdrLineAttribute->mnRefCount--;
     174             :                 }
     175             :                 else
     176             :                 {
     177           0 :                     delete mpSdrLineAttribute;
     178             :                 }
     179             : 
     180         274 :                 mpSdrLineAttribute = rCandidate.mpSdrLineAttribute;
     181         274 :                 mpSdrLineAttribute->mnRefCount++;
     182             :             }
     183             : 
     184         660 :             return *this;
     185             :         }
     186             : 
     187          76 :         bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const
     188             :         {
     189          76 :             if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute)
     190             :             {
     191          40 :                 return true;
     192             :             }
     193             : 
     194          36 :             if(rCandidate.isDefault() != isDefault())
     195             :             {
     196           0 :                 return false;
     197             :             }
     198             : 
     199          36 :             return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute);
     200             :         }
     201             : 
     202         242 :         basegfx::B2DLineJoin SdrLineAttribute::getJoin() const
     203             :         {
     204         242 :             return mpSdrLineAttribute->getJoin();
     205             :         }
     206             : 
     207         516 :         double SdrLineAttribute::getWidth() const
     208             :         {
     209         516 :             return mpSdrLineAttribute->getWidth();
     210             :         }
     211             : 
     212         242 :         double SdrLineAttribute::getTransparence() const
     213             :         {
     214         242 :             return mpSdrLineAttribute->getTransparence();
     215             :         }
     216             : 
     217         242 :         const basegfx::BColor& SdrLineAttribute::getColor() const
     218             :         {
     219         242 :             return mpSdrLineAttribute->getColor();
     220             :         }
     221             : 
     222         242 :         const ::std::vector< double >& SdrLineAttribute::getDotDashArray() const
     223             :         {
     224         242 :             return mpSdrLineAttribute->getDotDashArray();
     225             :         }
     226             : 
     227         242 :         double SdrLineAttribute::getFullDotDashLen() const
     228             :         {
     229         242 :             return mpSdrLineAttribute->getFullDotDashLen();
     230             :         }
     231             : 
     232         242 :         com::sun::star::drawing::LineCap SdrLineAttribute::getCap() const
     233             :         {
     234         242 :             return mpSdrLineAttribute->getCap();
     235             :         }
     236             : 
     237             :     } // end of namespace attribute
     238             : } // end of namespace drawinglayer
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10