LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/attribute - lineattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 58 67.2 %
Date: 2012-12-17 Functions: 16 19 84.2 %
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/lineattribute.hxx>
      21             : #include <basegfx/color/bcolor.hxx>
      22             : 
      23             : //////////////////////////////////////////////////////////////////////////////
      24             : 
      25             : namespace drawinglayer
      26             : {
      27             :     namespace attribute
      28             :     {
      29         266 :         class ImpLineAttribute
      30             :         {
      31             :         public:
      32             :             // refcounter
      33             :             sal_uInt32                              mnRefCount;
      34             : 
      35             :             // data definitions
      36             :             basegfx::BColor                         maColor;                // color
      37             :             double                                  mfWidth;                // absolute line width
      38             :             basegfx::B2DLineJoin                    meLineJoin;             // type of LineJoin
      39             :             com::sun::star::drawing::LineCap        meLineCap;              // BUTT, ROUND, or SQUARE
      40             : 
      41         338 :             ImpLineAttribute(
      42             :                 const basegfx::BColor& rColor,
      43             :                 double fWidth,
      44             :                 basegfx::B2DLineJoin aB2DLineJoin,
      45             :                 com::sun::star::drawing::LineCap aLineCap)
      46             :             :   mnRefCount(0),
      47             :                 maColor(rColor),
      48             :                 mfWidth(fWidth),
      49             :                 meLineJoin(aB2DLineJoin),
      50         338 :                 meLineCap(aLineCap)
      51             :             {
      52         338 :             }
      53             : 
      54             :             // data read access
      55         252 :             const basegfx::BColor& getColor() const { return maColor; }
      56         962 :             double getWidth() const { return mfWidth; }
      57         432 :             basegfx::B2DLineJoin getLineJoin() const { return meLineJoin; }
      58         272 :             com::sun::star::drawing::LineCap getLineCap() const { return meLineCap; }
      59             : 
      60           0 :             bool operator==(const ImpLineAttribute& rCandidate) const
      61             :             {
      62           0 :                 return (getColor() == rCandidate.getColor()
      63           0 :                     && getWidth() == rCandidate.getWidth()
      64           0 :                     && getLineJoin() == rCandidate.getLineJoin()
      65           0 :                     && getLineCap() == rCandidate.getLineCap());
      66             :             }
      67             : 
      68         218 :             static ImpLineAttribute* get_global_default()
      69             :             {
      70             :                 static ImpLineAttribute* pDefault = 0;
      71             : 
      72         218 :                 if(!pDefault)
      73             :                 {
      74             :                     pDefault = new ImpLineAttribute(
      75             :                         basegfx::BColor(),
      76             :                         0.0,
      77             :                         basegfx::B2DLINEJOIN_ROUND,
      78          24 :                         com::sun::star::drawing::LineCap_BUTT);
      79             : 
      80             :                     // never delete; start with RefCount 1, not 0
      81          24 :                     pDefault->mnRefCount++;
      82             :                 }
      83             : 
      84         218 :                 return pDefault;
      85             :             }
      86             :         };
      87             : 
      88         314 :         LineAttribute::LineAttribute(
      89             :             const basegfx::BColor& rColor,
      90             :             double fWidth,
      91             :             basegfx::B2DLineJoin aB2DLineJoin,
      92             :             com::sun::star::drawing::LineCap aLineCap)
      93             :         :   mpLineAttribute(
      94             :                 new ImpLineAttribute(
      95             :                     rColor,
      96             :                     fWidth,
      97             :                     aB2DLineJoin,
      98         314 :                     aLineCap))
      99             :         {
     100         314 :         }
     101             : 
     102          22 :         LineAttribute::LineAttribute()
     103          22 :         :   mpLineAttribute(ImpLineAttribute::get_global_default())
     104             :         {
     105          22 :             mpLineAttribute->mnRefCount++;
     106          22 :         }
     107             : 
     108         362 :         LineAttribute::LineAttribute(const LineAttribute& rCandidate)
     109         362 :         :   mpLineAttribute(rCandidate.mpLineAttribute)
     110             :         {
     111         362 :             mpLineAttribute->mnRefCount++;
     112         362 :         }
     113             : 
     114         626 :         LineAttribute::~LineAttribute()
     115             :         {
     116         626 :             if(mpLineAttribute->mnRefCount)
     117             :             {
     118         360 :                 mpLineAttribute->mnRefCount--;
     119             :             }
     120             :             else
     121             :             {
     122         266 :                 delete mpLineAttribute;
     123             :             }
     124         626 :         }
     125             : 
     126         196 :         bool LineAttribute::isDefault() const
     127             :         {
     128         196 :             return mpLineAttribute == ImpLineAttribute::get_global_default();
     129             :         }
     130             : 
     131           0 :         LineAttribute& LineAttribute::operator=(const LineAttribute& rCandidate)
     132             :         {
     133           0 :             if(rCandidate.mpLineAttribute != mpLineAttribute)
     134             :             {
     135           0 :                 if(mpLineAttribute->mnRefCount)
     136             :                 {
     137           0 :                     mpLineAttribute->mnRefCount--;
     138             :                 }
     139             :                 else
     140             :                 {
     141           0 :                     delete mpLineAttribute;
     142             :                 }
     143             : 
     144           0 :                 mpLineAttribute = rCandidate.mpLineAttribute;
     145           0 :                 mpLineAttribute->mnRefCount++;
     146             :             }
     147             : 
     148           0 :             return *this;
     149             :         }
     150             : 
     151           0 :         bool LineAttribute::operator==(const LineAttribute& rCandidate) const
     152             :         {
     153           0 :             if(rCandidate.mpLineAttribute == mpLineAttribute)
     154             :             {
     155           0 :                 return true;
     156             :             }
     157             : 
     158           0 :             if(rCandidate.isDefault() != isDefault())
     159             :             {
     160           0 :                 return false;
     161             :             }
     162             : 
     163           0 :             return (*rCandidate.mpLineAttribute == *mpLineAttribute);
     164             :         }
     165             : 
     166         252 :         const basegfx::BColor& LineAttribute::getColor() const
     167             :         {
     168         252 :             return mpLineAttribute->getColor();
     169             :         }
     170             : 
     171         962 :         double LineAttribute::getWidth() const
     172             :         {
     173         962 :             return mpLineAttribute->getWidth();
     174             :         }
     175             : 
     176         432 :         basegfx::B2DLineJoin LineAttribute::getLineJoin() const
     177             :         {
     178         432 :             return mpLineAttribute->getLineJoin();
     179             :         }
     180             : 
     181         272 :         com::sun::star::drawing::LineCap LineAttribute::getLineCap() const
     182             :         {
     183         272 :             return mpLineAttribute->getLineCap();
     184             :         }
     185             : 
     186             :     } // end of namespace attribute
     187             : } // end of namespace drawinglayer
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10