LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbafont.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 99 0.0 %
Date: 2014-04-14 Functions: 0 21 0.0 %
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 <boost/unordered_map.hpp>
      24             : #include <sal/macros.h>
      25             : #include <ooo/vba/word/WdColorIndex.hpp>
      26             : 
      27             : using namespace ::ooo::vba;
      28             : using namespace ::com::sun::star;
      29             : 
      30           0 : const uno::Any aLongAnyTrue( sal_Int16(-1) );
      31           0 : 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 boost::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 :         static OUString sPropName("CharUnderline");
      80           0 :         return sPropName;
      81             :     }
      82             : 
      83           0 :     static UnderLineMapper& instance()
      84             :     {
      85           0 :         static  UnderLineMapper theMapper;
      86           0 :         return theMapper;
      87             :     }
      88             : 
      89           0 :     sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst ) throw( lang::IllegalArgumentException )
      90             :     {
      91           0 :         ConstToConst::iterator it = MSO2OOO.find( nMSOConst );
      92           0 :         if ( it == MSO2OOO.end() )
      93           0 :             throw lang::IllegalArgumentException();
      94           0 :         return it->second;
      95             :     }
      96           0 :     sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst ) throw( lang::IllegalArgumentException )
      97             :     {
      98           0 :         ConstToConst::iterator it = OOO2MSO.find( nOOOConst );
      99           0 :         if ( it == OOO2MSO.end() )
     100           0 :             throw lang::IllegalArgumentException();
     101           0 :         return it->second;
     102             :     }
     103             : };
     104             : 
     105           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 )
     106             : {
     107           0 : }
     108             : 
     109             : uno::Any SAL_CALL
     110           0 : SwVbaFont::getUnderline() throw (uno::RuntimeException, std::exception)
     111             : {
     112           0 :     sal_Int32 nOOVal = 0;
     113           0 :     mxFont->getPropertyValue(  UnderLineMapper::propName() ) >>= nOOVal;
     114           0 :     return uno::makeAny( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) );
     115             : }
     116             : 
     117             : void SAL_CALL
     118           0 : SwVbaFont::setUnderline( const uno::Any& _underline ) throw (uno::RuntimeException, std::exception)
     119             : {
     120           0 :     sal_Int32 nMSOVal = 0;
     121             : 
     122           0 :     if ( _underline >>= nMSOVal )
     123             :     {
     124           0 :         sal_Int32 nOOVal =  UnderLineMapper::instance().getOOOFromMSO( nMSOVal );
     125           0 :         mxFont->setPropertyValue(  UnderLineMapper::propName(), uno::makeAny( nOOVal ) );
     126             :     }
     127           0 : }
     128             : 
     129             : OUString
     130           0 : SwVbaFont::getServiceImplName()
     131             : {
     132           0 :     return OUString("SwVbaFont");
     133             : }
     134             : 
     135             : void SAL_CALL
     136           0 : SwVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException, std::exception )
     137             : {
     138           0 :         sal_Int32 nIndex = 0;
     139           0 :         _colorindex >>= nIndex;
     140           0 :         return setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) );
     141             : }
     142             : 
     143             : uno::Any SAL_CALL
     144           0 : SwVbaFont::getColorIndex() throw ( uno::RuntimeException, std::exception )
     145             : {
     146           0 :         sal_Int32 nColor = 0;
     147             : 
     148           0 :     XLRGBToOORGB( getColor() ) >>= nColor;
     149           0 :     sal_Int32 nElems = mxPalette->getCount();
     150           0 :     sal_Int32 nIndex = 0;
     151           0 :     for ( sal_Int32 count=0; count<nElems; ++count )
     152             :            {
     153           0 :         sal_Int32 nPaletteColor = 0;
     154           0 :         mxPalette->getByIndex( count ) >>= nPaletteColor;
     155           0 :         if ( nPaletteColor == nColor )
     156             :         {
     157           0 :             nIndex = count;
     158           0 :             break;
     159             :         }
     160             :     }
     161           0 :     return uno::makeAny( nIndex );
     162             : }
     163             : uno::Any SAL_CALL
     164           0 : SwVbaFont::getSubscript() throw ( uno::RuntimeException, std::exception )
     165             : {
     166           0 :     sal_Bool bRes = sal_False;
     167           0 :     SwVbaFont_BASE::getSubscript() >>= bRes;
     168           0 :     if ( bRes )
     169           0 :         return aLongAnyTrue;
     170           0 :     return aLongAnyFalse;
     171             : }
     172             : 
     173             : uno::Any SAL_CALL
     174           0 : SwVbaFont::getSuperscript() throw ( uno::RuntimeException, std::exception )
     175             : {
     176           0 :     sal_Bool bRes = sal_False;
     177           0 :     SwVbaFont_BASE::getSuperscript() >>= bRes;
     178           0 :     if ( bRes )
     179           0 :         return aLongAnyTrue;
     180           0 :     return aLongAnyFalse;
     181             : }
     182             : 
     183             : uno::Any SAL_CALL
     184           0 : SwVbaFont::getBold() throw (uno::RuntimeException, std::exception)
     185             : {
     186           0 :     sal_Bool bRes = sal_False;
     187           0 :     SwVbaFont_BASE::getBold() >>= bRes;
     188           0 :     if ( bRes )
     189           0 :         return aLongAnyTrue;
     190           0 :     return aLongAnyFalse;
     191             : }
     192             : 
     193             : uno::Any SAL_CALL
     194           0 : SwVbaFont::getItalic() throw (uno::RuntimeException, std::exception)
     195             : {
     196           0 :     sal_Bool bRes = sal_False;
     197           0 :     SwVbaFont_BASE::getItalic() >>= bRes;
     198           0 :     if ( bRes )
     199           0 :         return aLongAnyTrue;
     200           0 :     return aLongAnyFalse;
     201             : }
     202             : 
     203             : uno::Any SAL_CALL
     204           0 : SwVbaFont::getStrikethrough() throw (css::uno::RuntimeException, std::exception)
     205             : {
     206           0 :     sal_Bool bRes = sal_False;
     207           0 :     SwVbaFont_BASE::getStrikethrough() >>= bRes;
     208           0 :     if ( bRes )
     209           0 :         return aLongAnyTrue;
     210           0 :     return aLongAnyFalse;
     211             : }
     212             : 
     213             : uno::Any SAL_CALL
     214           0 : SwVbaFont::getShadow() throw (uno::RuntimeException, std::exception)
     215             : {
     216           0 :     sal_Bool bRes = sal_False;
     217           0 :     SwVbaFont_BASE::getShadow() >>= bRes;
     218           0 :     if ( bRes )
     219           0 :         return aLongAnyTrue;
     220           0 :     return aLongAnyFalse;
     221             : }
     222             : 
     223             : uno::Sequence< OUString >
     224           0 : SwVbaFont::getServiceNames()
     225             : {
     226           0 :         static uno::Sequence< OUString > aServiceNames;
     227           0 :         if ( aServiceNames.getLength() == 0 )
     228             :         {
     229           0 :                 aServiceNames.realloc( 1 );
     230           0 :                 aServiceNames[ 0 ] = "ooo.vba.word.Font";
     231             :         }
     232           0 :         return aServiceNames;
     233           0 : }
     234             : 
     235             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10