LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/sdr/attribute - sdrtextattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 128 143 89.5 %
Date: 2013-07-09 Functions: 49 52 94.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             : 
      21             : #include <svx/sdr/attribute/sdrtextattribute.hxx>
      22             : #include <svx/sdr/attribute/sdrformtextattribute.hxx>
      23             : #include <svx/svdotext.hxx>
      24             : #include <editeng/outlobj.hxx>
      25             : #include <editeng/editobj.hxx>
      26             : #include <editeng/flditem.hxx>
      27             : #include <svx/sdr/properties/properties.hxx>
      28             : 
      29             : //////////////////////////////////////////////////////////////////////////////
      30             : 
      31             : namespace drawinglayer
      32             : {
      33             :     namespace attribute
      34             :     {
      35             :         class ImpSdrTextAttribute
      36             :         {
      37             :         public:
      38             :             // refcounter
      39             :             sal_uInt32                          mnRefCount;
      40             : 
      41             :             // all-text attributes. The SdrText itself and a copy
      42             :             // of te OPO
      43             :             const SdrText*                      mpSdrText;
      44             :             const OutlinerParaObject*           mpOutlinerParaObject;
      45             : 
      46             :             // Set when it's a FormText; contains all FormText attributes
      47             :             SdrFormTextAttribute                maSdrFormTextAttribute;
      48             : 
      49             :             // text distances
      50             :             sal_Int32                           maTextLeftDistance;
      51             :             sal_Int32                           maTextUpperDistance;
      52             :             sal_Int32                           maTextRightDistance;
      53             :             sal_Int32                           maTextLowerDistance;
      54             : 
      55             :             // #i101556# use versioning from text attributes to detect changes
      56             :             sal_uInt32                          maPropertiesVersion;
      57             : 
      58             :             // text alignments
      59             :             SdrTextHorzAdjust                   maSdrTextHorzAdjust;
      60             :             SdrTextVertAdjust                   maSdrTextVertAdjust;
      61             : 
      62             :             // bitfield
      63             :             unsigned                            mbContour : 1;
      64             :             unsigned                            mbFitToSize : 1;
      65             :             unsigned                            mbAutoFit : 1;
      66             :             unsigned                            mbHideContour : 1;
      67             :             unsigned                            mbBlink : 1;
      68             :             unsigned                            mbScroll : 1;
      69             :             unsigned                            mbInEditMode : 1;
      70             :             unsigned                            mbFixedCellHeight : 1;
      71             :             unsigned                            mbWrongSpell : 1;
      72             : 
      73             :         public:
      74       13688 :             ImpSdrTextAttribute(
      75             :                 const SdrText* pSdrText,
      76             :                 const OutlinerParaObject& rOutlinerParaObject,
      77             :                 XFormTextStyle eFormTextStyle,
      78             :                 sal_Int32 aTextLeftDistance,
      79             :                 sal_Int32 aTextUpperDistance,
      80             :                 sal_Int32 aTextRightDistance,
      81             :                 sal_Int32 aTextLowerDistance,
      82             :                 SdrTextHorzAdjust aSdrTextHorzAdjust,
      83             :                 SdrTextVertAdjust aSdrTextVertAdjust,
      84             :                 bool bContour,
      85             :                 bool bFitToSize,
      86             :                 bool bAutoFit,
      87             :                 bool bHideContour,
      88             :                 bool bBlink,
      89             :                 bool bScroll,
      90             :                 bool bInEditMode,
      91             :                 bool bFixedCellHeight,
      92             :                 bool bWrongSpell)
      93             :             :   mnRefCount(0),
      94             :                 mpSdrText(pSdrText),
      95       13688 :                 mpOutlinerParaObject(new OutlinerParaObject(rOutlinerParaObject)),
      96             :                 maSdrFormTextAttribute(),
      97             :                 maTextLeftDistance(aTextLeftDistance),
      98             :                 maTextUpperDistance(aTextUpperDistance),
      99             :                 maTextRightDistance(aTextRightDistance),
     100             :                 maTextLowerDistance(aTextLowerDistance),
     101             :                 maPropertiesVersion(0),
     102             :                 maSdrTextHorzAdjust(aSdrTextHorzAdjust),
     103             :                 maSdrTextVertAdjust(aSdrTextVertAdjust),
     104             :                 mbContour(bContour),
     105             :                 mbFitToSize(bFitToSize),
     106             :                 mbAutoFit(bAutoFit),
     107             :                 mbHideContour(bHideContour),
     108             :                 mbBlink(bBlink),
     109             :                 mbScroll(bScroll),
     110             :                 mbInEditMode(bInEditMode),
     111             :                 mbFixedCellHeight(bFixedCellHeight),
     112       27376 :                 mbWrongSpell(bWrongSpell)
     113             :             {
     114       13688 :                 if(pSdrText)
     115             :                 {
     116       13688 :                     if(XFT_NONE != eFormTextStyle)
     117             :                     {
     118             :                         // text on path. Create FormText attribute
     119           0 :                         const SfxItemSet& rSet = pSdrText->GetItemSet();
     120           0 :                         maSdrFormTextAttribute = SdrFormTextAttribute(rSet);
     121             :                     }
     122             : 
     123             :                     // #i101556# init with version number to detect changes of single text
     124             :                     // attribute and/or style sheets in primitive data without having to
     125             :                     // copy that data locally (which would be better from principle)
     126       13688 :                     maPropertiesVersion = pSdrText->GetObject().GetProperties().getVersion();
     127             :                 }
     128       13688 :             }
     129             : 
     130          31 :             ImpSdrTextAttribute()
     131             :             :   mnRefCount(0),
     132             :                 mpSdrText(0),
     133             :                 mpOutlinerParaObject(0),
     134             :                 maSdrFormTextAttribute(),
     135             :                 maTextLeftDistance(0),
     136             :                 maTextUpperDistance(0),
     137             :                 maTextRightDistance(0),
     138             :                 maTextLowerDistance(0),
     139             :                 maPropertiesVersion(0),
     140             :                 maSdrTextHorzAdjust(SDRTEXTHORZADJUST_LEFT),
     141             :                 maSdrTextVertAdjust(SDRTEXTVERTADJUST_TOP),
     142             :                 mbContour(false),
     143             :                 mbFitToSize(false),
     144             :                 mbAutoFit(false),
     145             :                 mbHideContour(false),
     146             :                 mbBlink(false),
     147             :                 mbScroll(false),
     148             :                 mbInEditMode(false),
     149             :                 mbFixedCellHeight(false),
     150          31 :                 mbWrongSpell(false)
     151             :             {
     152          31 :             }
     153             : 
     154       13688 :             ~ImpSdrTextAttribute()
     155       13688 :             {
     156       13688 :                 if(mpOutlinerParaObject)
     157             :                 {
     158       13688 :                     delete mpOutlinerParaObject;
     159             :                 }
     160       13688 :             }
     161             : 
     162             :             // data read access
     163        7008 :             const SdrText& getSdrText() const
     164             :             {
     165             :                 OSL_ENSURE(mpSdrText, "Access to text of default version of ImpSdrTextAttribute (!)");
     166        7008 :                 return *mpSdrText;
     167             :             }
     168       36840 :             const OutlinerParaObject& getOutlinerParaObject() const
     169             :             {
     170             :                 OSL_ENSURE(mpOutlinerParaObject, "Access to OutlinerParaObject of default version of ImpSdrTextAttribute (!)");
     171       36840 :                 return *mpOutlinerParaObject;
     172             :             }
     173       21125 :             bool isContour() const { return mbContour; }
     174       21125 :             bool isFitToSize() const { return mbFitToSize; }
     175       21125 :             bool isAutoFit() const { return mbAutoFit; }
     176       14118 :             bool isHideContour() const { return mbHideContour; }
     177       21125 :             bool isBlink() const { return mbBlink; }
     178       28117 :             bool isScroll() const { return mbScroll; }
     179       21125 :             bool isInEditMode() const { return mbInEditMode; }
     180       21109 :             bool isFixedCellHeight() const { return mbFixedCellHeight; }
     181       14118 :             bool isWrongSpell() const { return mbWrongSpell; }
     182       60102 :             const SdrFormTextAttribute& getSdrFormTextAttribute() const { return maSdrFormTextAttribute; }
     183       21157 :             sal_Int32 getTextLeftDistance() const { return maTextLeftDistance; }
     184       21157 :             sal_Int32 getTextUpperDistance() const { return maTextUpperDistance; }
     185       21158 :             sal_Int32 getTextRightDistance() const { return maTextRightDistance; }
     186       21158 :             sal_Int32 getTextLowerDistance() const { return maTextLowerDistance; }
     187       14150 :             sal_uInt32 getPropertiesVersion() const { return maPropertiesVersion; }
     188       21109 :             SdrTextHorzAdjust getSdrTextHorzAdjust() const { return maSdrTextHorzAdjust; }
     189       21109 :             SdrTextVertAdjust getSdrTextVertAdjust() const { return maSdrTextVertAdjust; }
     190             : 
     191             :             // compare operator
     192        7841 :             bool operator==(const ImpSdrTextAttribute& rCandidate) const
     193             :             {
     194        7841 :                 if(mpOutlinerParaObject != rCandidate.mpOutlinerParaObject)
     195             :                 {
     196        7841 :                     if(mpOutlinerParaObject && rCandidate.mpOutlinerParaObject)
     197             :                     {
     198             :                         // compares OPO and it's contents, but traditionally not the RedLining
     199             :                         // which is not seen as model, but as temporary information
     200        7841 :                         if(!(getOutlinerParaObject() == rCandidate.getOutlinerParaObject()))
     201             :                         {
     202         766 :                             return false;
     203             :                         }
     204             : 
     205             :                         // #i102062# for primitive visualisation, the WrongList (SpellChecking)
     206             :                         // is important, too, so use isWrongListEqual since there is no WrongList
     207             :                         // comparison in the regular OutlinerParaObject compare (since it's
     208             :                         // not-persistent data)
     209       14150 :                         if(!(getOutlinerParaObject().isWrongListEqual(rCandidate.getOutlinerParaObject())))
     210             :                         {
     211           0 :                             return false;
     212             :                         }
     213             :                     }
     214             :                     else
     215             :                     {
     216             :                         // only one is zero; not equal
     217           0 :                         return false;
     218             :                     }
     219             :                 }
     220             : 
     221             :                 return (
     222        7075 :                        getSdrFormTextAttribute() == rCandidate.getSdrFormTextAttribute()
     223        7075 :                     && getTextLeftDistance() == rCandidate.getTextLeftDistance()
     224        7075 :                     && getTextUpperDistance() == rCandidate.getTextUpperDistance()
     225        7075 :                     && getTextRightDistance() == rCandidate.getTextRightDistance()
     226        7075 :                     && getTextLowerDistance() == rCandidate.getTextLowerDistance()
     227        7075 :                     && getPropertiesVersion() == rCandidate.getPropertiesVersion()
     228             : 
     229        7059 :                     && getSdrTextHorzAdjust() == rCandidate.getSdrTextHorzAdjust()
     230        7059 :                     && getSdrTextVertAdjust() == rCandidate.getSdrTextVertAdjust()
     231             : 
     232        7059 :                     && isContour() == rCandidate.isContour()
     233        7059 :                     && isFitToSize() == rCandidate.isFitToSize()
     234        7059 :                     && isAutoFit() == rCandidate.isAutoFit()
     235        7059 :                     && isHideContour() == rCandidate.isHideContour()
     236        7059 :                     && isBlink() == rCandidate.isBlink()
     237        7059 :                     && isScroll() == rCandidate.isScroll()
     238        7059 :                     && isInEditMode() == rCandidate.isInEditMode()
     239        7059 :                     && isFixedCellHeight() == rCandidate.isFixedCellHeight()
     240       14134 :                     && isWrongSpell() == rCandidate.isWrongSpell());
     241             :             }
     242             : 
     243      123745 :             static ImpSdrTextAttribute* get_global_default()
     244             :             {
     245             :                 static ImpSdrTextAttribute* pDefault = 0;
     246             : 
     247      123745 :                 if(!pDefault)
     248             :                 {
     249             :                     // use default constructor
     250          31 :                     pDefault = new ImpSdrTextAttribute();
     251             : 
     252             :                     // never delete; start with RefCount 1, not 0
     253          31 :                     pDefault->mnRefCount++;
     254             :                 }
     255             : 
     256      123745 :                 return pDefault;
     257             :             }
     258             :         };
     259             : 
     260       13688 :         SdrTextAttribute::SdrTextAttribute(
     261             :             const SdrText& rSdrText,
     262             :             const OutlinerParaObject& rOutlinerParaObject,
     263             :             XFormTextStyle eFormTextStyle,
     264             :             sal_Int32 aTextLeftDistance,
     265             :             sal_Int32 aTextUpperDistance,
     266             :             sal_Int32 aTextRightDistance,
     267             :             sal_Int32 aTextLowerDistance,
     268             :             SdrTextHorzAdjust aSdrTextHorzAdjust,
     269             :             SdrTextVertAdjust aSdrTextVertAdjust,
     270             :             bool bContour,
     271             :             bool bFitToSize,
     272             :             bool bAutoFit,
     273             :             bool bHideContour,
     274             :             bool bBlink,
     275             :             bool bScroll,
     276             :             bool bInEditMode,
     277             :             bool bFixedCellHeight,
     278             :             bool bWrongSpell)
     279             :         :   mpSdrTextAttribute(new ImpSdrTextAttribute(
     280             :                 &rSdrText, rOutlinerParaObject, eFormTextStyle, aTextLeftDistance, aTextUpperDistance,
     281             :                 aTextRightDistance, aTextLowerDistance, aSdrTextHorzAdjust, aSdrTextVertAdjust, bContour,
     282       13688 :                 bFitToSize, bAutoFit, bHideContour, bBlink, bScroll, bInEditMode, bFixedCellHeight, bWrongSpell))
     283             :         {
     284       13688 :         }
     285             : 
     286       69994 :         SdrTextAttribute::SdrTextAttribute()
     287       69994 :         :   mpSdrTextAttribute(ImpSdrTextAttribute::get_global_default())
     288             :         {
     289       69994 :             mpSdrTextAttribute->mnRefCount++;
     290       69994 :         }
     291             : 
     292       73525 :         SdrTextAttribute::SdrTextAttribute(const SdrTextAttribute& rCandidate)
     293       73525 :         :   mpSdrTextAttribute(rCandidate.mpSdrTextAttribute)
     294             :         {
     295       73525 :             mpSdrTextAttribute->mnRefCount++;
     296       73525 :         }
     297             : 
     298      157206 :         SdrTextAttribute::~SdrTextAttribute()
     299             :         {
     300      157206 :             if(mpSdrTextAttribute->mnRefCount)
     301             :             {
     302      143518 :                 mpSdrTextAttribute->mnRefCount--;
     303             :             }
     304             :             else
     305             :             {
     306       13688 :                 delete mpSdrTextAttribute;
     307             :             }
     308      157206 :         }
     309             : 
     310       53751 :         bool SdrTextAttribute::isDefault() const
     311             :         {
     312       53751 :             return mpSdrTextAttribute == ImpSdrTextAttribute::get_global_default();
     313             :         }
     314             : 
     315       39346 :         SdrTextAttribute& SdrTextAttribute::operator=(const SdrTextAttribute& rCandidate)
     316             :         {
     317       39346 :             if(rCandidate.mpSdrTextAttribute != mpSdrTextAttribute)
     318             :             {
     319       13688 :                 if(mpSdrTextAttribute->mnRefCount)
     320             :                 {
     321       13688 :                     mpSdrTextAttribute->mnRefCount--;
     322             :                 }
     323             :                 else
     324             :                 {
     325           0 :                     delete mpSdrTextAttribute;
     326             :                 }
     327             : 
     328       13688 :                 mpSdrTextAttribute = rCandidate.mpSdrTextAttribute;
     329       13688 :                 mpSdrTextAttribute->mnRefCount++;
     330             :             }
     331             : 
     332       39346 :             return *this;
     333             :         }
     334             : 
     335       49378 :         bool SdrTextAttribute::operator==(const SdrTextAttribute& rCandidate) const
     336             :         {
     337       49378 :             if(rCandidate.mpSdrTextAttribute == mpSdrTextAttribute)
     338             :             {
     339       41501 :                 return true;
     340             :             }
     341             : 
     342        7877 :             if(rCandidate.isDefault() != isDefault())
     343             :             {
     344          36 :                 return false;
     345             :             }
     346             : 
     347        7841 :             return (*rCandidate.mpSdrTextAttribute == *mpSdrTextAttribute);
     348             :         }
     349             : 
     350        7008 :         const SdrText& SdrTextAttribute::getSdrText() const
     351             :         {
     352        7008 :             return mpSdrTextAttribute->getSdrText();
     353             :         }
     354             : 
     355        7008 :         const OutlinerParaObject& SdrTextAttribute::getOutlinerParaObject() const
     356             :         {
     357        7008 :             return mpSdrTextAttribute->getOutlinerParaObject();
     358             :         }
     359             : 
     360        7007 :         bool SdrTextAttribute::isContour() const
     361             :         {
     362        7007 :             return mpSdrTextAttribute->isContour();
     363             :         }
     364             : 
     365        7007 :         bool SdrTextAttribute::isFitToSize() const
     366             :         {
     367        7007 :             return mpSdrTextAttribute->isFitToSize();
     368             :         }
     369             : 
     370        7007 :         bool SdrTextAttribute::isAutoFit() const
     371             :         {
     372        7007 :             return mpSdrTextAttribute->isAutoFit();
     373             :         }
     374             : 
     375           0 :         bool SdrTextAttribute::isHideContour() const
     376             :         {
     377           0 :             return mpSdrTextAttribute->isHideContour();
     378             :         }
     379             : 
     380        7007 :         bool SdrTextAttribute::isBlink() const
     381             :         {
     382        7007 :             return mpSdrTextAttribute->isBlink();
     383             :         }
     384             : 
     385       13999 :         bool SdrTextAttribute::isScroll() const
     386             :         {
     387       13999 :             return mpSdrTextAttribute->isScroll();
     388             :         }
     389             : 
     390        7007 :         bool SdrTextAttribute::isInEditMode() const
     391             :         {
     392        7007 :             return mpSdrTextAttribute->isInEditMode();
     393             :         }
     394             : 
     395        6991 :         bool SdrTextAttribute::isFixedCellHeight() const
     396             :         {
     397        6991 :             return mpSdrTextAttribute->isFixedCellHeight();
     398             :         }
     399             : 
     400       45952 :         const SdrFormTextAttribute& SdrTextAttribute::getSdrFormTextAttribute() const
     401             :         {
     402       45952 :             return mpSdrTextAttribute->getSdrFormTextAttribute();
     403             :         }
     404             : 
     405        7007 :         sal_Int32 SdrTextAttribute::getTextLeftDistance() const
     406             :         {
     407        7007 :             return mpSdrTextAttribute->getTextLeftDistance();
     408             :         }
     409             : 
     410        7007 :         sal_Int32 SdrTextAttribute::getTextUpperDistance() const
     411             :         {
     412        7007 :             return mpSdrTextAttribute->getTextUpperDistance();
     413             :         }
     414             : 
     415        7008 :         sal_Int32 SdrTextAttribute::getTextRightDistance() const
     416             :         {
     417        7008 :             return mpSdrTextAttribute->getTextRightDistance();
     418             :         }
     419             : 
     420        7008 :         sal_Int32 SdrTextAttribute::getTextLowerDistance() const
     421             :         {
     422        7008 :             return mpSdrTextAttribute->getTextLowerDistance();
     423             :         }
     424             : 
     425        6991 :         SdrTextHorzAdjust SdrTextAttribute::getSdrTextHorzAdjust() const
     426             :         {
     427        6991 :             return mpSdrTextAttribute->getSdrTextHorzAdjust();
     428             :         }
     429             : 
     430        6991 :         SdrTextVertAdjust SdrTextAttribute::getSdrTextVertAdjust() const
     431             :         {
     432        6991 :             return mpSdrTextAttribute->getSdrTextVertAdjust();
     433             :         }
     434             : 
     435           0 :         void SdrTextAttribute::getBlinkTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList) const
     436             :         {
     437           0 :             if(isBlink())
     438             :             {
     439           0 :                 getSdrText().GetObject().impGetBlinkTextTiming(rAnimList);
     440             :             }
     441           0 :         }
     442             : 
     443           0 :         void SdrTextAttribute::getScrollTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList, double fFrameLength, double fTextLength) const
     444             :         {
     445           0 :             if(isScroll())
     446             :             {
     447           0 :                 getSdrText().GetObject().impGetScrollTextTiming(rAnimList, fFrameLength, fTextLength);
     448             :             }
     449           0 :         }
     450             :     } // end of namespace attribute
     451         258 : } // end of namespace drawinglayer
     452             : 
     453             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10