LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbafont.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 98 3.1 %
Date: 2012-08-25 Functions: 2 21 9.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 144 2.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : #include "vbafont.hxx"
       3                 :            : #include <com/sun/star/awt/FontUnderline.hpp>
       4                 :            : #include <ooo/vba/word/WdUnderline.hpp>
       5                 :            : #include <boost/unordered_map.hpp>
       6                 :            : #include <sal/macros.h>
       7                 :            : #include <ooo/vba/word/WdColorIndex.hpp>
       8                 :            : 
       9                 :            : using namespace ::ooo::vba;
      10                 :            : using namespace ::com::sun::star;
      11                 :            : 
      12         [ +  - ]:          3 : const uno::Any aLongAnyTrue( sal_Int16(-1) );
      13         [ +  - ]:          3 : const uno::Any aLongAnyFalse( sal_Int16( 0 ) );
      14                 :            : 
      15                 :            : struct MapPair
      16                 :            : {
      17                 :            :     sal_Int32 nMSOConst;
      18                 :            :     sal_Int32 nOOOConst;
      19                 :            : };
      20                 :            : 
      21                 :            : static MapPair UnderLineTable[] = {
      22                 :            :         { word::WdUnderline::wdUnderlineNone, com::sun::star::awt::FontUnderline::NONE },
      23                 :            :         { word::WdUnderline::wdUnderlineSingle, com::sun::star::awt::FontUnderline::SINGLE },
      24                 :            :         { word::WdUnderline::wdUnderlineWords, com::sun::star::awt::FontUnderline::SINGLE },
      25                 :            :         { word::WdUnderline::wdUnderlineDouble, com::sun::star::awt::FontUnderline::DOUBLE },
      26                 :            :         { word::WdUnderline::wdUnderlineDotted, com::sun::star::awt::FontUnderline::DOTTED },
      27                 :            :         { word::WdUnderline::wdUnderlineThick, com::sun::star::awt::FontUnderline::BOLDDASH },
      28                 :            :         { word::WdUnderline::wdUnderlineDash, com::sun::star::awt::FontUnderline::DASH },
      29                 :            :     { word::WdUnderline::wdUnderlineDotDash, com::sun::star::awt::FontUnderline::DASHDOT },
      30                 :            :     { word::WdUnderline::wdUnderlineDotDotDash, com::sun::star::awt::FontUnderline::DASHDOTDOT },
      31                 :            :         { word::WdUnderline::wdUnderlineWavy, com::sun::star::awt::FontUnderline::WAVE },
      32                 :            :         { word::WdUnderline::wdUnderlineDottedHeavy, com::sun::star::awt::FontUnderline::BOLDDOTTED },
      33                 :            :         { word::WdUnderline::wdUnderlineDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASH },
      34                 :            :         { word::WdUnderline::wdUnderlineDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOT },
      35                 :            :         { word::WdUnderline::wdUnderlineDotDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOTDOT },
      36                 :            :         { word::WdUnderline::wdUnderlineWavyHeavy, com::sun::star::awt::FontUnderline::BOLDWAVE },
      37                 :            :         { word::WdUnderline::wdUnderlineDashLong, com::sun::star::awt::FontUnderline::LONGDASH },
      38                 :            :         { word::WdUnderline::wdUnderlineWavyDouble, com::sun::star::awt::FontUnderline::DOUBLEWAVE },
      39                 :            :         { word::WdUnderline::wdUnderlineDashLongHeavy, com::sun::star::awt::FontUnderline::BOLDLONGDASH },
      40                 :            : };
      41                 :            : 
      42                 :            : typedef boost::unordered_map< sal_Int32, sal_Int32 > ConstToConst;
      43         [ #  # ]:          0 : class UnderLineMapper
      44                 :            : {
      45                 :            :     ConstToConst MSO2OOO;
      46                 :            :     ConstToConst OOO2MSO;
      47                 :            : private:
      48                 :          0 :     UnderLineMapper()
      49 [ #  # ][ #  # ]:          0 :     {
      50                 :          0 :         sal_Int32 nLen = SAL_N_ELEMENTS( UnderLineTable );
      51                 :            : 
      52         [ #  # ]:          0 :         for ( sal_Int32 index=0; index<nLen; ++index )
      53                 :            :         {
      54         [ #  # ]:          0 :             MSO2OOO[ UnderLineTable[ index ].nMSOConst ] = UnderLineTable[ index ].nOOOConst;
      55         [ #  # ]:          0 :             OOO2MSO[ UnderLineTable[ index ].nOOOConst ] = UnderLineTable[ index ].nMSOConst;
      56                 :            :         }
      57                 :          0 :     }
      58                 :            : public:
      59                 :          0 :     static rtl::OUString propName()
      60                 :            :     {
      61 [ #  # ][ #  # ]:          0 :         static rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("CharUnderline") );
         [ #  # ][ #  # ]
      62                 :          0 :         return sPropName;
      63                 :            :     }
      64                 :            : 
      65                 :          0 :     static UnderLineMapper& instance()
      66                 :            :     {
      67 [ #  # ][ #  # ]:          0 :         static  UnderLineMapper theMapper;
         [ #  # ][ #  # ]
      68                 :          0 :         return theMapper;
      69                 :            :     }
      70                 :            : 
      71                 :          0 :     sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst ) throw( lang::IllegalArgumentException )
      72                 :            :     {
      73         [ #  # ]:          0 :         ConstToConst::iterator it = MSO2OOO.find( nMSOConst );
      74 [ #  # ][ #  # ]:          0 :         if ( it == MSO2OOO.end() )
      75         [ #  # ]:          0 :             throw lang::IllegalArgumentException();
      76         [ #  # ]:          0 :         return it->second;
      77                 :            :     }
      78                 :          0 :     sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst ) throw( lang::IllegalArgumentException )
      79                 :            :     {
      80         [ #  # ]:          0 :         ConstToConst::iterator it = OOO2MSO.find( nOOOConst );
      81 [ #  # ][ #  # ]:          0 :         if ( it == OOO2MSO.end() )
      82         [ #  # ]:          0 :             throw lang::IllegalArgumentException();
      83         [ #  # ]:          0 :         return it->second;
      84                 :            :     }
      85                 :            : };
      86                 :            : 
      87                 :          0 : SwVbaFont::SwVbaFont( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xPalette, uno::Reference< css::beans::XPropertySet > xPropertySet ) throw ( css::uno::RuntimeException ) : SwVbaFont_BASE( xParent, xContext, xPalette, xPropertySet )
      88                 :            : {
      89                 :          0 : }
      90                 :            : 
      91                 :            : uno::Any SAL_CALL
      92                 :          0 : SwVbaFont::getUnderline() throw (uno::RuntimeException)
      93                 :            : {
      94                 :          0 :     sal_Int32 nOOVal = 0;
      95 [ #  # ][ #  # ]:          0 :     mxFont->getPropertyValue(  UnderLineMapper::propName() ) >>= nOOVal;
                 [ #  # ]
      96 [ #  # ][ #  # ]:          0 :     return uno::makeAny( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) );
                 [ #  # ]
      97                 :            : }
      98                 :            : 
      99                 :            : void SAL_CALL
     100                 :          0 : SwVbaFont::setUnderline( const uno::Any& _underline ) throw (uno::RuntimeException)
     101                 :            : {
     102                 :          0 :     sal_Int32 nMSOVal = 0;
     103                 :            : 
     104         [ #  # ]:          0 :     if ( _underline >>= nMSOVal )
     105                 :            :     {
     106 [ #  # ][ #  # ]:          0 :         sal_Int32 nOOVal =  UnderLineMapper::instance().getOOOFromMSO( nMSOVal );
     107 [ #  # ][ #  # ]:          0 :         mxFont->setPropertyValue(  UnderLineMapper::propName(), uno::makeAny( nOOVal ) );
         [ #  # ][ #  # ]
     108                 :            :     }
     109                 :          0 : }
     110                 :            : 
     111                 :            : rtl::OUString
     112                 :          0 : SwVbaFont::getServiceImplName()
     113                 :            : {
     114                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaFont"));
     115                 :            : }
     116                 :            : 
     117                 :            : void SAL_CALL
     118                 :          0 : SwVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException )
     119                 :            : {
     120                 :          0 :         sal_Int32 nIndex = 0;
     121                 :          0 :         _colorindex >>= nIndex;
     122 [ #  # ][ #  # ]:          0 :         return setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) );
         [ #  # ][ #  # ]
     123                 :            : }
     124                 :            : 
     125                 :            : uno::Any SAL_CALL
     126                 :          0 : SwVbaFont::getColorIndex() throw ( uno::RuntimeException )
     127                 :            : {
     128                 :          0 :         sal_Int32 nColor = 0;
     129                 :            : 
     130 [ #  # ][ #  # ]:          0 :     XLRGBToOORGB( getColor() ) >>= nColor;
     131 [ #  # ][ #  # ]:          0 :     sal_Int32 nElems = mxPalette->getCount();
     132                 :          0 :     sal_Int32 nIndex = 0;
     133         [ #  # ]:          0 :     for ( sal_Int32 count=0; count<nElems; ++count )
     134                 :            :            {
     135                 :          0 :         sal_Int32 nPaletteColor = 0;
     136 [ #  # ][ #  # ]:          0 :         mxPalette->getByIndex( count ) >>= nPaletteColor;
     137         [ #  # ]:          0 :         if ( nPaletteColor == nColor )
     138                 :            :         {
     139                 :          0 :             nIndex = count;
     140                 :            :             break;
     141                 :            :         }
     142                 :            :     }
     143         [ #  # ]:          0 :     return uno::makeAny( nIndex );
     144                 :            : }
     145                 :            : uno::Any SAL_CALL
     146                 :          0 : SwVbaFont::getSubscript() throw ( uno::RuntimeException )
     147                 :            : {
     148                 :          0 :     sal_Bool bRes = sal_False;
     149         [ #  # ]:          0 :     SwVbaFont_BASE::getSubscript() >>= bRes;
     150         [ #  # ]:          0 :     if ( bRes )
     151                 :          0 :         return aLongAnyTrue;
     152                 :          0 :     return aLongAnyFalse;
     153                 :            : }
     154                 :            : 
     155                 :            : uno::Any SAL_CALL
     156                 :          0 : SwVbaFont::getSuperscript() throw ( uno::RuntimeException )
     157                 :            : {
     158                 :          0 :     sal_Bool bRes = sal_False;
     159         [ #  # ]:          0 :     SwVbaFont_BASE::getSuperscript() >>= bRes;
     160         [ #  # ]:          0 :     if ( bRes )
     161                 :          0 :         return aLongAnyTrue;
     162                 :          0 :     return aLongAnyFalse;
     163                 :            : }
     164                 :            : 
     165                 :            : uno::Any SAL_CALL
     166                 :          0 : SwVbaFont::getBold() throw (uno::RuntimeException)
     167                 :            : {
     168                 :          0 :     sal_Bool bRes = sal_False;
     169         [ #  # ]:          0 :     SwVbaFont_BASE::getBold() >>= bRes;
     170         [ #  # ]:          0 :     if ( bRes )
     171                 :          0 :         return aLongAnyTrue;
     172                 :          0 :     return aLongAnyFalse;
     173                 :            : }
     174                 :            : 
     175                 :            : uno::Any SAL_CALL
     176                 :          0 : SwVbaFont::getItalic() throw (uno::RuntimeException)
     177                 :            : {
     178                 :          0 :     sal_Bool bRes = sal_False;
     179         [ #  # ]:          0 :     SwVbaFont_BASE::getItalic() >>= bRes;
     180         [ #  # ]:          0 :     if ( bRes )
     181                 :          0 :         return aLongAnyTrue;
     182                 :          0 :     return aLongAnyFalse;
     183                 :            : }
     184                 :            : 
     185                 :            : uno::Any SAL_CALL
     186                 :          0 : SwVbaFont::getStrikethrough() throw (css::uno::RuntimeException)
     187                 :            : {
     188                 :          0 :     sal_Bool bRes = sal_False;
     189         [ #  # ]:          0 :     SwVbaFont_BASE::getStrikethrough() >>= bRes;
     190         [ #  # ]:          0 :     if ( bRes )
     191                 :          0 :         return aLongAnyTrue;
     192                 :          0 :     return aLongAnyFalse;
     193                 :            : }
     194                 :            : 
     195                 :            : uno::Any SAL_CALL
     196                 :          0 : SwVbaFont::getShadow() throw (uno::RuntimeException)
     197                 :            : {
     198                 :          0 :     sal_Bool bRes = sal_False;
     199         [ #  # ]:          0 :     SwVbaFont_BASE::getShadow() >>= bRes;
     200         [ #  # ]:          0 :     if ( bRes )
     201                 :          0 :         return aLongAnyTrue;
     202                 :          0 :     return aLongAnyFalse;
     203                 :            : }
     204                 :            : 
     205                 :            : uno::Sequence< rtl::OUString >
     206                 :          0 : SwVbaFont::getServiceNames()
     207                 :            : {
     208 [ #  # ][ #  # ]:          0 :         static uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
     209         [ #  # ]:          0 :         if ( aServiceNames.getLength() == 0 )
     210                 :            :         {
     211                 :          0 :                 aServiceNames.realloc( 1 );
     212         [ #  # ]:          0 :                 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Font" ) );
     213                 :            :         }
     214                 :          0 :         return aServiceNames;
     215 [ +  - ][ +  - ]:          9 : }
     216                 :            : 
     217                 :            : 
     218                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10