LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/sdr/attribute - sdrformtextattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 151 14.6 %
Date: 2013-07-09 Functions: 8 43 18.6 %
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 <svx/sdr/attribute/sdrformtextattribute.hxx>
      21             : #include <basegfx/vector/b2enums.hxx>
      22             : #include <svl/itemset.hxx>
      23             : #include <svx/xftdiit.hxx>
      24             : #include <svx/xftstit.hxx>
      25             : #include <svx/xftshxy.hxx>
      26             : #include <svx/xftshtit.hxx>
      27             : #include <svx/xtextit0.hxx>
      28             : #include <svx/xftadit.hxx>
      29             : #include <svx/xftshit.hxx>
      30             : #include <svx/xftshcit.hxx>
      31             : #include <svx/xftmrit.hxx>
      32             : #include <svx/xftouit.hxx>
      33             : #include <svx/sdshtitm.hxx>
      34             : #include <svx/xlntrit.hxx>
      35             : #include <svx/sdshcitm.hxx>
      36             : #include <svx/xlnclit.hxx>
      37             : #include <svx/xlnwtit.hxx>
      38             : #include <svx/xlinjoit.hxx>
      39             : #include <svx/xlncapit.hxx>
      40             : #include <svx/xlineit0.hxx>
      41             : #include <svx/xdash.hxx>
      42             : #include <svx/xlndsit.hxx>
      43             : #include <drawinglayer/attribute/lineattribute.hxx>
      44             : #include <drawinglayer/attribute/strokeattribute.hxx>
      45             : #include <svx/sdr/attribute/sdrformtextoutlineattribute.hxx>
      46             : #include <com/sun/star/drawing/LineCap.hpp>
      47             : 
      48             : //////////////////////////////////////////////////////////////////////////////
      49             : // helper to get line, stroke and transparence attributes from SfxItemSet
      50             : 
      51             : namespace
      52             : {
      53           0 :     basegfx::B2DLineJoin impGetB2DLineJoin(com::sun::star::drawing::LineJoint eLineJoint)
      54             :     {
      55           0 :         switch(eLineJoint)
      56             :         {
      57             :             case com::sun::star::drawing::LineJoint_MIDDLE :
      58             :             {
      59           0 :                 return basegfx::B2DLINEJOIN_MIDDLE;
      60             :             }
      61             :             case com::sun::star::drawing::LineJoint_BEVEL :
      62             :             {
      63           0 :                 return basegfx::B2DLINEJOIN_BEVEL;
      64             :             }
      65             :             case com::sun::star::drawing::LineJoint_MITER :
      66             :             {
      67           0 :                 return basegfx::B2DLINEJOIN_MITER;
      68             :             }
      69             :             case com::sun::star::drawing::LineJoint_ROUND :
      70             :             {
      71           0 :                 return basegfx::B2DLINEJOIN_ROUND;
      72             :             }
      73             :             default : // com::sun::star::drawing::LineJoint_NONE
      74             :             {
      75           0 :                 return basegfx::B2DLINEJOIN_NONE; // XLINEJOINT_NONE
      76             :             }
      77             :         }
      78             :     }
      79             : 
      80           0 :     sal_uInt8 impGetStrokeTransparence(bool bShadow, const SfxItemSet& rSet)
      81             :     {
      82             :         sal_uInt8 nRetval;
      83             : 
      84           0 :         if(bShadow)
      85             :         {
      86           0 :             nRetval = (sal_uInt8)((((SdrShadowTransparenceItem&)(rSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue() * 255) / 100);
      87             :         }
      88             :         else
      89             :         {
      90           0 :             nRetval = (sal_uInt8)((((XLineTransparenceItem&)(rSet.Get(XATTR_LINETRANSPARENCE))).GetValue() * 255) / 100);
      91             :         }
      92             : 
      93           0 :         return nRetval;
      94             :     }
      95             : 
      96           0 :     drawinglayer::attribute::LineAttribute impGetLineAttribute(bool bShadow, const SfxItemSet& rSet)
      97             :     {
      98           0 :         basegfx::BColor aColorAttribute;
      99             : 
     100           0 :         if(bShadow)
     101             :         {
     102           0 :             const Color aShadowColor(((SdrShadowColorItem&)(rSet.Get(SDRATTR_SHADOWCOLOR))).GetColorValue());
     103           0 :             aColorAttribute = aShadowColor.getBColor();
     104             :         }
     105             :         else
     106             :         {
     107           0 :             const Color aLineColor(((XLineColorItem&)(rSet.Get(XATTR_LINECOLOR))).GetColorValue());
     108           0 :             aColorAttribute = aLineColor.getBColor();
     109             :         }
     110             : 
     111           0 :         const sal_uInt32 nLineWidth = ((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue();
     112           0 :         const com::sun::star::drawing::LineJoint eLineJoint = ((const XLineJointItem&)(rSet.Get(XATTR_LINEJOINT))).GetValue();
     113           0 :         const com::sun::star::drawing::LineCap eLineCap = ((const XLineCapItem&)(rSet.Get(XATTR_LINECAP))).GetValue();
     114             : 
     115             :         return drawinglayer::attribute::LineAttribute(
     116             :             aColorAttribute,
     117             :             (double)nLineWidth,
     118             :             impGetB2DLineJoin(eLineJoint),
     119           0 :             eLineCap);
     120             :     }
     121             : 
     122           0 :     drawinglayer::attribute::StrokeAttribute impGetStrokeAttribute(const SfxItemSet& rSet)
     123             :     {
     124           0 :         const XLineStyle eLineStyle = ((XLineStyleItem&)(rSet.Get(XATTR_LINESTYLE))).GetValue();
     125           0 :         double fFullDotDashLen(0.0);
     126           0 :         ::std::vector< double > aDotDashArray;
     127             : 
     128           0 :         if(XLINE_DASH == eLineStyle)
     129             :         {
     130           0 :             const XDash& rDash = ((const XLineDashItem&)(rSet.Get(XATTR_LINEDASH))).GetDashValue();
     131             : 
     132           0 :             if(rDash.GetDots() || rDash.GetDashes())
     133             :             {
     134           0 :                 const sal_uInt32 nLineWidth = ((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue();
     135           0 :                 fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, (double)nLineWidth);
     136             :             }
     137             :         }
     138             : 
     139           0 :         return drawinglayer::attribute::StrokeAttribute(aDotDashArray, fFullDotDashLen);
     140             :     }
     141             : } // end of anonymous namespace
     142             : 
     143             : //////////////////////////////////////////////////////////////////////////////
     144             : 
     145             : namespace drawinglayer
     146             : {
     147             :     namespace attribute
     148             :     {
     149           0 :         class ImpSdrFormTextAttribute
     150             :         {
     151             :         public:
     152             :             // refcounter
     153             :             sal_uInt32                              mnRefCount;
     154             : 
     155             :             // FormText (FontWork) Attributes
     156             :             sal_Int32                               mnFormTextDistance;     // distance from line in upright direction
     157             :             sal_Int32                               mnFormTextStart;        // shift from polygon start
     158             :             sal_Int32                               mnFormTextShdwXVal;     // shadow distance or 10th degrees
     159             :             sal_Int32                               mnFormTextShdwYVal;     // shadow distance or scaling
     160             :             sal_uInt16                              mnFormTextShdwTransp;   // shadow transparence
     161             :             XFormTextStyle                          meFormTextStyle;        // on/off and char orientation
     162             :             XFormTextAdjust                         meFormTextAdjust;       // adjustment (left/right/center) and scale
     163             :             XFormTextShadow                         meFormTextShadow;       // shadow mode
     164             :             Color                                   maFormTextShdwColor;    // shadow color
     165             : 
     166             :             // outline attributes; used when getFormTextOutline() is true and (for
     167             :             // shadow) when getFormTextShadow() != XFTSHADOW_NONE
     168             :             SdrFormTextOutlineAttribute             maOutline;
     169             :             SdrFormTextOutlineAttribute             maShadowOutline;
     170             : 
     171             :             // bitfield
     172             :             unsigned                                mbFormTextMirror : 1;   // change orientation
     173             :             unsigned                                mbFormTextOutline : 1;  // show contour of objects
     174             : 
     175           0 :             explicit ImpSdrFormTextAttribute(const SfxItemSet& rSet)
     176             :             :   mnRefCount(0),
     177           0 :                 mnFormTextDistance(((const XFormTextDistanceItem&)rSet.Get(XATTR_FORMTXTDISTANCE)).GetValue()),
     178           0 :                 mnFormTextStart(((const XFormTextStartItem&)rSet.Get(XATTR_FORMTXTSTART)).GetValue()),
     179           0 :                 mnFormTextShdwXVal(((const XFormTextShadowXValItem&)rSet.Get(XATTR_FORMTXTSHDWXVAL)).GetValue()),
     180           0 :                 mnFormTextShdwYVal(((const XFormTextShadowYValItem&)rSet.Get(XATTR_FORMTXTSHDWYVAL)).GetValue()),
     181           0 :                 mnFormTextShdwTransp(((const XFormTextShadowTranspItem&)rSet.Get(XATTR_FORMTXTSHDWTRANSP)).GetValue()),
     182           0 :                 meFormTextStyle(((const XFormTextStyleItem&)rSet.Get(XATTR_FORMTXTSTYLE)).GetValue()),
     183           0 :                 meFormTextAdjust(((const XFormTextAdjustItem&)rSet.Get(XATTR_FORMTXTADJUST)).GetValue()),
     184           0 :                 meFormTextShadow(((const XFormTextShadowItem&)rSet.Get(XATTR_FORMTXTSHADOW)).GetValue()),
     185           0 :                 maFormTextShdwColor(((const XFormTextShadowColorItem&)rSet.Get(XATTR_FORMTXTSHDWCOLOR)).GetColorValue()),
     186             :                 maOutline(),
     187             :                 maShadowOutline(),
     188           0 :                 mbFormTextMirror(((const XFormTextMirrorItem&)rSet.Get(XATTR_FORMTXTMIRROR)).GetValue()),
     189           0 :                 mbFormTextOutline(((const XFormTextOutlineItem&)rSet.Get(XATTR_FORMTXTOUTLINE)).GetValue())
     190             :             {
     191           0 :                 if(getFormTextOutline())
     192             :                 {
     193           0 :                     const StrokeAttribute aStrokeAttribute(impGetStrokeAttribute(rSet));
     194             : 
     195             :                     // also need to prepare attributes for outlines
     196             :                     {
     197           0 :                         const LineAttribute aLineAttribute(impGetLineAttribute(false, rSet));
     198           0 :                         const sal_uInt8 nTransparence(impGetStrokeTransparence(false, rSet));
     199             : 
     200           0 :                         maOutline = SdrFormTextOutlineAttribute(
     201           0 :                             aLineAttribute, aStrokeAttribute, nTransparence);
     202             :                     }
     203             : 
     204           0 :                     if(XFTSHADOW_NONE != getFormTextShadow())
     205             :                     {
     206             :                         // also need to prepare attributes for shadow outlines
     207           0 :                         const LineAttribute aLineAttribute(impGetLineAttribute(true, rSet));
     208           0 :                         const sal_uInt8 nTransparence(impGetStrokeTransparence(true, rSet));
     209             : 
     210           0 :                         maShadowOutline = SdrFormTextOutlineAttribute(
     211           0 :                             aLineAttribute, aStrokeAttribute, nTransparence);
     212           0 :                     }
     213             :                 }
     214           0 :             }
     215             : 
     216          31 :             ImpSdrFormTextAttribute()
     217             :             :   mnRefCount(0),
     218             :                 mnFormTextDistance(0),
     219             :                 mnFormTextStart(0),
     220             :                 mnFormTextShdwXVal(0),
     221             :                 mnFormTextShdwYVal(0),
     222             :                 mnFormTextShdwTransp(0),
     223             :                 meFormTextStyle(XFT_NONE),
     224             :                 meFormTextAdjust(XFT_CENTER),
     225             :                 meFormTextShadow(XFTSHADOW_NONE),
     226             :                 maFormTextShdwColor(),
     227             :                 maOutline(),
     228             :                 maShadowOutline(),
     229             :                 mbFormTextMirror(false),
     230          31 :                 mbFormTextOutline(false)
     231             :             {
     232          31 :             }
     233             : 
     234             :             // data read access
     235           0 :             sal_Int32 getFormTextDistance() const { return mnFormTextDistance; }
     236           0 :             sal_Int32 getFormTextStart() const { return mnFormTextStart; }
     237           0 :             sal_Int32 getFormTextShdwXVal() const { return mnFormTextShdwXVal; }
     238           0 :             sal_Int32 getFormTextShdwYVal() const { return mnFormTextShdwYVal; }
     239           0 :             sal_uInt16 getFormTextShdwTransp() const { return mnFormTextShdwTransp; }
     240           0 :             XFormTextStyle getFormTextStyle() const { return meFormTextStyle; }
     241           0 :             XFormTextAdjust getFormTextAdjust() const { return meFormTextAdjust; }
     242           0 :             XFormTextShadow getFormTextShadow() const { return meFormTextShadow; }
     243           0 :             Color getFormTextShdwColor() const { return maFormTextShdwColor; }
     244           0 :             const SdrFormTextOutlineAttribute& getOutline() const { return maOutline; }
     245           0 :             const SdrFormTextOutlineAttribute& getShadowOutline() const { return maShadowOutline; }
     246           0 :             bool getFormTextMirror() const { return mbFormTextMirror; }
     247           0 :             bool getFormTextOutline() const { return mbFormTextOutline; }
     248             : 
     249             :             // compare operator
     250           0 :             bool operator==(const ImpSdrFormTextAttribute& rCandidate) const
     251             :             {
     252           0 :                 return (getFormTextDistance() == rCandidate.getFormTextDistance()
     253           0 :                     && getFormTextStart() == rCandidate.getFormTextStart()
     254           0 :                     && getFormTextShdwXVal() == rCandidate.getFormTextShdwXVal()
     255           0 :                     && getFormTextShdwYVal() == rCandidate.getFormTextShdwYVal()
     256           0 :                     && getFormTextShdwTransp() == rCandidate.getFormTextShdwTransp()
     257           0 :                     && getFormTextStyle() == rCandidate.getFormTextStyle()
     258           0 :                     && getFormTextAdjust() == rCandidate.getFormTextAdjust()
     259           0 :                     && getFormTextShadow() == rCandidate.getFormTextShadow()
     260           0 :                     && getFormTextShdwColor() == rCandidate.getFormTextShdwColor()
     261           0 :                     && getOutline() == rCandidate.getOutline()
     262           0 :                     && getShadowOutline() == rCandidate.getShadowOutline()
     263           0 :                     && getFormTextMirror() == rCandidate.getFormTextMirror()
     264           0 :                     && getFormTextOutline() == rCandidate.getFormTextOutline());
     265             :             }
     266             : 
     267       59671 :             static ImpSdrFormTextAttribute* get_global_default()
     268             :             {
     269             :                 static ImpSdrFormTextAttribute* pDefault = 0;
     270             : 
     271       59671 :                 if(!pDefault)
     272             :                 {
     273          31 :                     pDefault = new ImpSdrFormTextAttribute();
     274             : 
     275             :                     // never delete; start with RefCount 1, not 0
     276          31 :                     pDefault->mnRefCount++;
     277             :                 }
     278             : 
     279       59671 :                 return pDefault;
     280             :             }
     281             :         };
     282             : 
     283           0 :         SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet& rSet)
     284           0 :         :   mpSdrFormTextAttribute(new ImpSdrFormTextAttribute(rSet))
     285             :         {
     286           0 :         }
     287             : 
     288       13719 :         SdrFormTextAttribute::SdrFormTextAttribute()
     289       13719 :         :   mpSdrFormTextAttribute(ImpSdrFormTextAttribute::get_global_default())
     290             :         {
     291       13719 :             mpSdrFormTextAttribute->mnRefCount++;
     292       13719 :         }
     293             : 
     294           0 :         SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute& rCandidate)
     295           0 :         :   mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute)
     296             :         {
     297           0 :             mpSdrFormTextAttribute->mnRefCount++;
     298           0 :         }
     299             : 
     300       13688 :         SdrFormTextAttribute::~SdrFormTextAttribute()
     301             :         {
     302       13688 :             if(mpSdrFormTextAttribute->mnRefCount)
     303             :             {
     304       13688 :                 mpSdrFormTextAttribute->mnRefCount--;
     305             :             }
     306             :             else
     307             :             {
     308           0 :                 delete mpSdrFormTextAttribute;
     309             :             }
     310       13688 :         }
     311             : 
     312       45952 :         bool SdrFormTextAttribute::isDefault() const
     313             :         {
     314       45952 :             return mpSdrFormTextAttribute == ImpSdrFormTextAttribute::get_global_default();
     315             :         }
     316             : 
     317           0 :         SdrFormTextAttribute& SdrFormTextAttribute::operator=(const SdrFormTextAttribute& rCandidate)
     318             :         {
     319           0 :             if(rCandidate.mpSdrFormTextAttribute != mpSdrFormTextAttribute)
     320             :             {
     321           0 :                 if(mpSdrFormTextAttribute->mnRefCount)
     322             :                 {
     323           0 :                     mpSdrFormTextAttribute->mnRefCount--;
     324             :                 }
     325             :                 else
     326             :                 {
     327           0 :                     delete mpSdrFormTextAttribute;
     328             :                 }
     329             : 
     330           0 :                 mpSdrFormTextAttribute = rCandidate.mpSdrFormTextAttribute;
     331           0 :                 mpSdrFormTextAttribute->mnRefCount++;
     332             :             }
     333             : 
     334           0 :             return *this;
     335             :         }
     336             : 
     337        7075 :         bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute& rCandidate) const
     338             :         {
     339        7075 :             if(rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute)
     340             :             {
     341        7075 :                 return true;
     342             :             }
     343             : 
     344           0 :             if(rCandidate.isDefault() != isDefault())
     345             :             {
     346           0 :                 return false;
     347             :             }
     348             : 
     349           0 :             return (*rCandidate.mpSdrFormTextAttribute == *mpSdrFormTextAttribute);
     350             :         }
     351             : 
     352           0 :         sal_Int32 SdrFormTextAttribute::getFormTextDistance() const
     353             :         {
     354           0 :             return mpSdrFormTextAttribute->getFormTextDistance();
     355             :         }
     356             : 
     357           0 :         sal_Int32 SdrFormTextAttribute::getFormTextStart() const
     358             :         {
     359           0 :             return mpSdrFormTextAttribute->getFormTextStart();
     360             :         }
     361             : 
     362           0 :         sal_Int32 SdrFormTextAttribute::getFormTextShdwXVal() const
     363             :         {
     364           0 :             return mpSdrFormTextAttribute->getFormTextShdwXVal();
     365             :         }
     366             : 
     367           0 :         sal_Int32 SdrFormTextAttribute::getFormTextShdwYVal() const
     368             :         {
     369           0 :             return mpSdrFormTextAttribute->getFormTextShdwYVal();
     370             :         }
     371             : 
     372           0 :         XFormTextStyle SdrFormTextAttribute::getFormTextStyle() const
     373             :         {
     374           0 :             return mpSdrFormTextAttribute->getFormTextStyle();
     375             :         }
     376             : 
     377           0 :         XFormTextAdjust SdrFormTextAttribute::getFormTextAdjust() const
     378             :         {
     379           0 :             return mpSdrFormTextAttribute->getFormTextAdjust();
     380             :         }
     381             : 
     382           0 :         XFormTextShadow SdrFormTextAttribute::getFormTextShadow() const
     383             :         {
     384           0 :             return mpSdrFormTextAttribute->getFormTextShadow();
     385             :         }
     386             : 
     387           0 :         Color SdrFormTextAttribute::getFormTextShdwColor() const
     388             :         {
     389           0 :             return mpSdrFormTextAttribute->getFormTextShdwColor();
     390             :         }
     391             : 
     392           0 :         const SdrFormTextOutlineAttribute& SdrFormTextAttribute::getOutline() const
     393             :         {
     394           0 :             return mpSdrFormTextAttribute->getOutline();
     395             :         }
     396             : 
     397           0 :         const SdrFormTextOutlineAttribute& SdrFormTextAttribute::getShadowOutline() const
     398             :         {
     399           0 :             return mpSdrFormTextAttribute->getShadowOutline();
     400             :         }
     401             : 
     402           0 :         bool SdrFormTextAttribute::getFormTextMirror() const
     403             :         {
     404           0 :             return mpSdrFormTextAttribute->getFormTextMirror();
     405             :         }
     406             : 
     407           0 :         bool SdrFormTextAttribute::getFormTextOutline() const
     408             :         {
     409           0 :             return mpSdrFormTextAttribute->getFormTextOutline();
     410             :         }
     411             :     } // end of namespace attribute
     412         258 : } // end of namespace drawinglayer
     413             : 
     414             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10