LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbafont.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 98 3.1 %
Date: 2015-06-13 12:38:46 Functions: 2 21 9.5 %
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 "vbafont.hxx"
      21             : #include <com/sun/star/awt/FontUnderline.hpp>
      22             : #include <ooo/vba/word/WdUnderline.hpp>
      23             : #include <sal/macros.h>
      24             : #include <ooo/vba/word/WdColorIndex.hpp>
      25             : #include <unordered_map>
      26             : 
      27             : using namespace ::ooo::vba;
      28             : using namespace ::com::sun::star;
      29             : 
      30           1 : const uno::Any aLongAnyTrue( sal_Int16(-1) );
      31           1 : const uno::Any aLongAnyFalse( sal_Int16( 0 ) );
      32             : 
      33             : struct MapPair
      34             : {
      35             :     sal_Int32 nMSOConst;
      36             :     sal_Int32 nOOOConst;
      37             : };
      38             : 
      39             : static MapPair UnderLineTable[] = {
      40             :         { word::WdUnderline::wdUnderlineNone, com::sun::star::awt::FontUnderline::NONE },
      41             :         { word::WdUnderline::wdUnderlineSingle, com::sun::star::awt::FontUnderline::SINGLE },
      42             :         { word::WdUnderline::wdUnderlineWords, com::sun::star::awt::FontUnderline::SINGLE },
      43             :         { word::WdUnderline::wdUnderlineDouble, com::sun::star::awt::FontUnderline::DOUBLE },
      44             :         { word::WdUnderline::wdUnderlineDotted, com::sun::star::awt::FontUnderline::DOTTED },
      45             :         { word::WdUnderline::wdUnderlineThick, com::sun::star::awt::FontUnderline::BOLDDASH },
      46             :         { word::WdUnderline::wdUnderlineDash, com::sun::star::awt::FontUnderline::DASH },
      47             :     { word::WdUnderline::wdUnderlineDotDash, com::sun::star::awt::FontUnderline::DASHDOT },
      48             :     { word::WdUnderline::wdUnderlineDotDotDash, com::sun::star::awt::FontUnderline::DASHDOTDOT },
      49             :         { word::WdUnderline::wdUnderlineWavy, com::sun::star::awt::FontUnderline::WAVE },
      50             :         { word::WdUnderline::wdUnderlineDottedHeavy, com::sun::star::awt::FontUnderline::BOLDDOTTED },
      51             :         { word::WdUnderline::wdUnderlineDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASH },
      52             :         { word::WdUnderline::wdUnderlineDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOT },
      53             :         { word::WdUnderline::wdUnderlineDotDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOTDOT },
      54             :         { word::WdUnderline::wdUnderlineWavyHeavy, com::sun::star::awt::FontUnderline::BOLDWAVE },
      55             :         { word::WdUnderline::wdUnderlineDashLong, com::sun::star::awt::FontUnderline::LONGDASH },
      56             :         { word::WdUnderline::wdUnderlineWavyDouble, com::sun::star::awt::FontUnderline::DOUBLEWAVE },
      57             :         { word::WdUnderline::wdUnderlineDashLongHeavy, com::sun::star::awt::FontUnderline::BOLDLONGDASH },
      58             : };
      59             : 
      60             : typedef std::unordered_map< sal_Int32, sal_Int32 > ConstToConst;
      61           0 : class UnderLineMapper
      62             : {
      63             :     ConstToConst MSO2OOO;
      64             :     ConstToConst OOO2MSO;
      65             : private:
      66           0 :     UnderLineMapper()
      67           0 :     {
      68           0 :         sal_Int32 nLen = SAL_N_ELEMENTS( UnderLineTable );
      69             : 
      70           0 :         for ( sal_Int32 index=0; index<nLen; ++index )
      71             :         {
      72           0 :             MSO2OOO[ UnderLineTable[ index ].nMSOConst ] = UnderLineTable[ index ].nOOOConst;
      73           0 :             OOO2MSO[ UnderLineTable[ index ].nOOOConst ] = UnderLineTable[ index ].nMSOConst;
      74             :         }
      75           0 :     }
      76             : public:
      77           0 :     static OUString propName()
      78             :     {
      79           0 :         return OUString("CharUnderline");
      80             :     }
      81             : 
      82           0 :     static UnderLineMapper& instance()
      83             :     {
      84           0 :         static  UnderLineMapper theMapper;
      85           0 :         return theMapper;
      86             :     }
      87             : 
      88           0 :     sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst ) throw( lang::IllegalArgumentException )
      89             :     {
      90           0 :         ConstToConst::iterator it = MSO2OOO.find( nMSOConst );
      91           0 :         if ( it == MSO2OOO.end() )
      92           0 :             throw lang::IllegalArgumentException();
      93           0 :         return it->second;
      94             :     }
      95           0 :     sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst ) throw( lang::IllegalArgumentException )
      96             :     {
      97           0 :         ConstToConst::iterator it = OOO2MSO.find( nOOOConst );
      98           0 :         if ( it == OOO2MSO.end() )
      99           0 :             throw lang::IllegalArgumentException();
     100           0 :         return it->second;
     101             :     }
     102             : };
     103             : 
     104           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 )
     105             : {
     106           0 : }
     107             : 
     108             : uno::Any SAL_CALL
     109           0 : SwVbaFont::getUnderline() throw (uno::RuntimeException, std::exception)
     110             : {
     111           0 :     sal_Int32 nOOVal = 0;
     112           0 :     mxFont->getPropertyValue(  UnderLineMapper::propName() ) >>= nOOVal;
     113           0 :     return uno::makeAny( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) );
     114             : }
     115             : 
     116             : void SAL_CALL
     117           0 : SwVbaFont::setUnderline( const uno::Any& _underline ) throw (uno::RuntimeException, std::exception)
     118             : {
     119           0 :     sal_Int32 nMSOVal = 0;
     120             : 
     121           0 :     if ( _underline >>= nMSOVal )
     122             :     {
     123           0 :         sal_Int32 nOOVal =  UnderLineMapper::instance().getOOOFromMSO( nMSOVal );
     124           0 :         mxFont->setPropertyValue(  UnderLineMapper::propName(), uno::makeAny( nOOVal ) );
     125             :     }
     126           0 : }
     127             : 
     128             : OUString
     129           0 : SwVbaFont::getServiceImplName()
     130             : {
     131           0 :     return OUString("SwVbaFont");
     132             : }
     133             : 
     134             : void SAL_CALL
     135           0 : SwVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException, std::exception )
     136             : {
     137           0 :         sal_Int32 nIndex = 0;
     138           0 :         _colorindex >>= nIndex;
     139           0 :         return setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) );
     140             : }
     141             : 
     142             : uno::Any SAL_CALL
     143           0 : SwVbaFont::getColorIndex() throw ( uno::RuntimeException, std::exception )
     144             : {
     145           0 :         sal_Int32 nColor = 0;
     146             : 
     147           0 :     XLRGBToOORGB( getColor() ) >>= nColor;
     148           0 :     sal_Int32 nElems = mxPalette->getCount();
     149           0 :     sal_Int32 nIndex = 0;
     150           0 :     for ( sal_Int32 count=0; count<nElems; ++count )
     151             :            {
     152           0 :         sal_Int32 nPaletteColor = 0;
     153           0 :         mxPalette->getByIndex( count ) >>= nPaletteColor;
     154           0 :         if ( nPaletteColor == nColor )
     155             :         {
     156           0 :             nIndex = count;
     157           0 :             break;
     158             :         }
     159             :     }
     160           0 :     return uno::makeAny( nIndex );
     161             : }
     162             : uno::Any SAL_CALL
     163           0 : SwVbaFont::getSubscript() throw ( uno::RuntimeException, std::exception )
     164             : {
     165           0 :     bool bRes = false;
     166           0 :     SwVbaFont_BASE::getSubscript() >>= bRes;
     167           0 :     if ( bRes )
     168           0 :         return aLongAnyTrue;
     169           0 :     return aLongAnyFalse;
     170             : }
     171             : 
     172             : uno::Any SAL_CALL
     173           0 : SwVbaFont::getSuperscript() throw ( uno::RuntimeException, std::exception )
     174             : {
     175           0 :     bool bRes = false;
     176           0 :     SwVbaFont_BASE::getSuperscript() >>= bRes;
     177           0 :     if ( bRes )
     178           0 :         return aLongAnyTrue;
     179           0 :     return aLongAnyFalse;
     180             : }
     181             : 
     182             : uno::Any SAL_CALL
     183           0 : SwVbaFont::getBold() throw (uno::RuntimeException, std::exception)
     184             : {
     185           0 :     bool bRes = false;
     186           0 :     SwVbaFont_BASE::getBold() >>= bRes;
     187           0 :     if ( bRes )
     188           0 :         return aLongAnyTrue;
     189           0 :     return aLongAnyFalse;
     190             : }
     191             : 
     192             : uno::Any SAL_CALL
     193           0 : SwVbaFont::getItalic() throw (uno::RuntimeException, std::exception)
     194             : {
     195           0 :     bool bRes = false;
     196           0 :     SwVbaFont_BASE::getItalic() >>= bRes;
     197           0 :     if ( bRes )
     198           0 :         return aLongAnyTrue;
     199           0 :     return aLongAnyFalse;
     200             : }
     201             : 
     202             : uno::Any SAL_CALL
     203           0 : SwVbaFont::getStrikethrough() throw (css::uno::RuntimeException, std::exception)
     204             : {
     205           0 :     bool bRes = false;
     206           0 :     SwVbaFont_BASE::getStrikethrough() >>= bRes;
     207           0 :     if ( bRes )
     208           0 :         return aLongAnyTrue;
     209           0 :     return aLongAnyFalse;
     210             : }
     211             : 
     212             : uno::Any SAL_CALL
     213           0 : SwVbaFont::getShadow() throw (uno::RuntimeException, std::exception)
     214             : {
     215           0 :     bool bRes = false;
     216           0 :     SwVbaFont_BASE::getShadow() >>= bRes;
     217           0 :     if ( bRes )
     218           0 :         return aLongAnyTrue;
     219           0 :     return aLongAnyFalse;
     220             : }
     221             : 
     222             : uno::Sequence< OUString >
     223           0 : SwVbaFont::getServiceNames()
     224             : {
     225           0 :         static uno::Sequence< OUString > aServiceNames;
     226           0 :         if ( aServiceNames.getLength() == 0 )
     227             :         {
     228           0 :                 aServiceNames.realloc( 1 );
     229           0 :                 aServiceNames[ 0 ] = "ooo.vba.word.Font";
     230             :         }
     231           0 :         return aServiceNames;
     232           3 : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11