LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/attribute - fontattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 82 52.4 %
Date: 2012-12-17 Functions: 23 31 74.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/fontattribute.hxx>
      21             : #include <tools/string.hxx>
      22             : 
      23             : //////////////////////////////////////////////////////////////////////////////
      24             : 
      25             : namespace drawinglayer
      26             : {
      27             :     namespace attribute
      28             :     {
      29         420 :         class ImpFontAttribute
      30             :         {
      31             :         public:
      32             :             // refcounter
      33             :             sal_uInt32                              mnRefCount;
      34             : 
      35             :             /// core data
      36             :             String                                      maFamilyName;       // Font Family Name
      37             :             String                                      maStyleName;        // Font Style Name
      38             :             sal_uInt16                                  mnWeight;           // Font weight
      39             : 
      40             :             /// bitfield
      41             :             unsigned                                    mbSymbol : 1;       // Symbol Font Flag
      42             :             unsigned                                    mbVertical : 1;     // Vertical Text Flag
      43             :             unsigned                                    mbItalic : 1;       // Italic Flag
      44             :             unsigned                                    mbOutline : 1;      // Outline Flag
      45             :             unsigned                                    mbRTL : 1;          // RTL Flag
      46             :             unsigned                                    mbBiDiStrong : 1;   // BiDi Flag
      47             :             unsigned                                    mbMonospaced : 1;
      48             : 
      49         438 :             ImpFontAttribute(
      50             :                 const String& rFamilyName,
      51             :                 const String& rStyleName,
      52             :                 sal_uInt16 nWeight,
      53             :                 bool bSymbol,
      54             :                 bool bVertical,
      55             :                 bool bItalic,
      56             :                 bool bMonospaced,
      57             :                 bool bOutline,
      58             :                 bool bRTL,
      59             :                 bool bBiDiStrong)
      60             :             :   mnRefCount(0),
      61             :                 maFamilyName(rFamilyName),
      62             :                 maStyleName(rStyleName),
      63             :                 mnWeight(nWeight),
      64             :                 mbSymbol(bSymbol),
      65             :                 mbVertical(bVertical),
      66             :                 mbItalic(bItalic),
      67             :                 mbOutline(bOutline),
      68             :                 mbRTL(bRTL),
      69             :                 mbBiDiStrong(bBiDiStrong),
      70         438 :                 mbMonospaced(bMonospaced)
      71             :             {
      72         438 :             }
      73             : 
      74             :             // data read access
      75         438 :             const String& getFamilyName() const { return maFamilyName; }
      76         438 :             const String& getStyleName() const { return maStyleName; }
      77         438 :             sal_uInt16 getWeight() const { return mnWeight; }
      78         438 :             bool getSymbol() const { return mbSymbol; }
      79         438 :             bool getVertical() const { return mbVertical; }
      80         438 :             bool getItalic() const { return mbItalic; }
      81         438 :             bool getOutline() const { return mbOutline; }
      82           8 :             bool getRTL() const { return mbRTL; }
      83           0 :             bool getBiDiStrong() const { return mbBiDiStrong; }
      84         438 :             bool getMonospaced() const { return mbMonospaced; }
      85             : 
      86           0 :             bool operator==(const ImpFontAttribute& rCompare) const
      87             :             {
      88           0 :                 return (getFamilyName() == rCompare.getFamilyName()
      89           0 :                     && getStyleName() == rCompare.getStyleName()
      90           0 :                     && getWeight() == rCompare.getWeight()
      91           0 :                     && getSymbol() == rCompare.getSymbol()
      92           0 :                     && getVertical() == rCompare.getVertical()
      93           0 :                     && getItalic() == rCompare.getItalic()
      94           0 :                     && getOutline() == rCompare.getOutline()
      95           0 :                     && getRTL() == rCompare.getRTL()
      96           0 :                     && getBiDiStrong() == rCompare.getBiDiStrong()
      97           0 :                     && getMonospaced() == rCompare.getMonospaced());
      98             :             }
      99             : 
     100           0 :             static ImpFontAttribute* get_global_default()
     101             :             {
     102             :                 static ImpFontAttribute* pDefault = 0;
     103             : 
     104           0 :                 if(!pDefault)
     105             :                 {
     106             :                     pDefault = new ImpFontAttribute(
     107             :                         String(), String(),
     108             :                         0,
     109           0 :                         false, false, false, false, false, false, false);
     110             : 
     111             :                     // never delete; start with RefCount 1, not 0
     112           0 :                     pDefault->mnRefCount++;
     113             :                 }
     114             : 
     115           0 :                 return pDefault;
     116             :             }
     117             :         };
     118             : 
     119         438 :         FontAttribute::FontAttribute(
     120             :             const String& rFamilyName,
     121             :             const String& rStyleName,
     122             :             sal_uInt16 nWeight,
     123             :             bool bSymbol,
     124             :             bool bVertical,
     125             :             bool bItalic,
     126             :             bool bMonospaced,
     127             :             bool bOutline,
     128             :             bool bRTL,
     129             :             bool bBiDiStrong)
     130             :         :   mpFontAttribute(new ImpFontAttribute(
     131         438 :                 rFamilyName, rStyleName, nWeight, bSymbol, bVertical, bItalic, bMonospaced, bOutline, bRTL, bBiDiStrong))
     132             :         {
     133         438 :         }
     134             : 
     135           0 :         FontAttribute::FontAttribute()
     136           0 :         :   mpFontAttribute(ImpFontAttribute::get_global_default())
     137             :         {
     138           0 :             mpFontAttribute->mnRefCount++;
     139           0 :         }
     140             : 
     141         438 :         FontAttribute::FontAttribute(const FontAttribute& rCandidate)
     142         438 :         :   mpFontAttribute(rCandidate.mpFontAttribute)
     143             :         {
     144         438 :             mpFontAttribute->mnRefCount++;
     145         438 :         }
     146             : 
     147         858 :         FontAttribute::~FontAttribute()
     148             :         {
     149         858 :             if(mpFontAttribute->mnRefCount)
     150             :             {
     151         438 :                 mpFontAttribute->mnRefCount--;
     152             :             }
     153             :             else
     154             :             {
     155         420 :                 delete mpFontAttribute;
     156             :             }
     157         858 :         }
     158             : 
     159           0 :         bool FontAttribute::isDefault() const
     160             :         {
     161           0 :             return mpFontAttribute == ImpFontAttribute::get_global_default();
     162             :         }
     163             : 
     164           0 :         FontAttribute& FontAttribute::operator=(const FontAttribute& rCandidate)
     165             :         {
     166           0 :             if(rCandidate.mpFontAttribute != mpFontAttribute)
     167             :             {
     168           0 :                 if(mpFontAttribute->mnRefCount)
     169             :                 {
     170           0 :                     mpFontAttribute->mnRefCount--;
     171             :                 }
     172             :                 else
     173             :                 {
     174           0 :                     delete mpFontAttribute;
     175             :                 }
     176             : 
     177           0 :                 mpFontAttribute = rCandidate.mpFontAttribute;
     178           0 :                 mpFontAttribute->mnRefCount++;
     179             :             }
     180             : 
     181           0 :             return *this;
     182             :         }
     183             : 
     184           0 :         bool FontAttribute::operator==(const FontAttribute& rCandidate) const
     185             :         {
     186           0 :             if(rCandidate.mpFontAttribute == mpFontAttribute)
     187             :             {
     188           0 :                 return true;
     189             :             }
     190             : 
     191           0 :             if(rCandidate.isDefault() != isDefault())
     192             :             {
     193           0 :                 return false;
     194             :             }
     195             : 
     196           0 :             return (*rCandidate.mpFontAttribute == *mpFontAttribute);
     197             :         }
     198             : 
     199         438 :         const String& FontAttribute::getFamilyName() const
     200             :         {
     201         438 :             return mpFontAttribute->getFamilyName();
     202             :         }
     203             : 
     204         438 :         const String& FontAttribute::getStyleName() const
     205             :         {
     206         438 :             return mpFontAttribute->getStyleName();
     207             :         }
     208             : 
     209         438 :         sal_uInt16 FontAttribute::getWeight() const
     210             :         {
     211         438 :             return mpFontAttribute->getWeight();
     212             :         }
     213             : 
     214         438 :         bool FontAttribute::getSymbol() const
     215             :         {
     216         438 :             return mpFontAttribute->getSymbol();
     217             :         }
     218             : 
     219         438 :         bool FontAttribute::getVertical() const
     220             :         {
     221         438 :             return mpFontAttribute->getVertical();
     222             :         }
     223             : 
     224         438 :         bool FontAttribute::getItalic() const
     225             :         {
     226         438 :             return mpFontAttribute->getItalic();
     227             :         }
     228             : 
     229         438 :         bool FontAttribute::getOutline() const
     230             :         {
     231         438 :             return mpFontAttribute->getOutline();
     232             :         }
     233             : 
     234           8 :         bool FontAttribute::getRTL() const
     235             :         {
     236           8 :             return mpFontAttribute->getRTL();
     237             :         }
     238             : 
     239           0 :         bool FontAttribute::getBiDiStrong() const
     240             :         {
     241           0 :             return mpFontAttribute->getBiDiStrong();
     242             :         }
     243             : 
     244         438 :         bool FontAttribute::getMonospaced() const
     245             :         {
     246         438 :             return mpFontAttribute->getMonospaced();
     247             :         }
     248             : 
     249             : 
     250             :     } // end of namespace attribute
     251             : } // end of namespace drawinglayer
     252             : 
     253             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10