LCOV - code coverage report
Current view: top level - vbahelper/source/vbahelper - vbafontbase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 81 122 66.4 %
Date: 2015-06-13 12:38:46 Functions: 17 23 73.9 %
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             : #include <com/sun/star/beans/XProperty.hpp>
      20             : #include <com/sun/star/awt/FontWeight.hpp>
      21             : #include <com/sun/star/awt/FontUnderline.hpp>
      22             : #include <com/sun/star/awt/FontStrikeout.hpp>
      23             : #include <com/sun/star/awt/FontSlant.hpp>
      24             : #include <com/sun/star/text/XSimpleText.hpp>
      25             : #include <vbahelper/vbafontbase.hxx>
      26             : 
      27             : using namespace ::ooo::vba;
      28             : using namespace ::com::sun::star;
      29             : 
      30             : 
      31             : // form controls use other property name as the remaining OOo API
      32             : #define VBAFONTBASE_PROPNAME( ascii_normal, ascii_control ) \
      33             :     mbFormControl ? OUString( ascii_control ) : OUString( ascii_normal )
      34             : 
      35          10 : VbaFontBase::VbaFontBase(
      36             :         const uno::Reference< XHelperInterface >& xParent,
      37             :         const uno::Reference< uno::XComponentContext >& xContext,
      38             :         const uno::Reference< css::container::XIndexAccess >& xPalette,
      39             :         const uno::Reference< beans::XPropertySet >& xPropertySet,
      40             :         bool bFormControl ) throw ( uno::RuntimeException ) :
      41             :     VbaFontBase_BASE( xParent, xContext ),
      42             :     mxFont( xPropertySet, uno::UNO_SET_THROW ),
      43             :     mxPalette( xPalette, uno::UNO_SET_THROW ),
      44          10 :     mbFormControl( bFormControl )
      45             : {
      46          10 : }
      47             : 
      48          10 : VbaFontBase::~VbaFontBase()
      49             : {
      50          10 : }
      51             : 
      52             : void SAL_CALL
      53           0 : VbaFontBase::setSuperscript( const uno::Any& aValue ) throw ( uno::RuntimeException, std::exception )
      54             : {
      55             :     // not supported in form controls
      56           0 :     if( mbFormControl )
      57           0 :         return;
      58             : 
      59           0 :     bool bValue = false;
      60           0 :     aValue >>= bValue;
      61           0 :     sal_Int16 nValue = NORMAL;
      62           0 :     sal_Int8 nValue2 = NORMALHEIGHT;
      63             : 
      64           0 :     if( bValue )
      65             :     {
      66           0 :         nValue = SUPERSCRIPT;
      67           0 :         nValue2 = SUPERSCRIPTHEIGHT;
      68             :     }
      69           0 :     mxFont->setPropertyValue( "CharEscapement" , uno::Any(nValue) );
      70           0 :     mxFont->setPropertyValue( "CharEscapementHeight" , uno::Any(nValue2) );
      71             : }
      72             : 
      73             : uno::Any SAL_CALL
      74           0 : VbaFontBase::getSuperscript() throw ( uno::RuntimeException, std::exception )
      75             : {
      76           0 :     short nValue = NORMAL;
      77             :     // not supported in form controls
      78           0 :     if( !mbFormControl )
      79           0 :        mxFont->getPropertyValue( "CharEscapement" ) >>= nValue;
      80           0 :     return uno::makeAny( ( nValue == SUPERSCRIPT ) );
      81             : }
      82             : 
      83             : void SAL_CALL
      84           0 : VbaFontBase::setSubscript( const uno::Any& aValue ) throw ( uno::RuntimeException, std::exception )
      85             : {
      86             :     // not supported in form controls
      87           0 :     if( mbFormControl )
      88           0 :         return;
      89             : 
      90           0 :     bool bValue = false;
      91           0 :     aValue >>= bValue;
      92           0 :     sal_Int16 nValue = NORMAL;
      93           0 :     sal_Int8 nValue2 = NORMALHEIGHT;
      94             : 
      95           0 :     if( bValue )
      96             :     {
      97           0 :         nValue= SUBSCRIPT;
      98           0 :         nValue2 = SUBSCRIPTHEIGHT;
      99             :     }
     100             : 
     101           0 :      mxFont->setPropertyValue( "CharEscapementHeight" , uno::Any(nValue2) );
     102           0 :     mxFont->setPropertyValue( "CharEscapement" , uno::Any(nValue) );
     103             : 
     104             : }
     105             : 
     106             : uno::Any SAL_CALL
     107           0 : VbaFontBase::getSubscript() throw ( uno::RuntimeException, std::exception )
     108             : {
     109           0 :     short nValue = NORMAL;
     110             :     // not supported in form controls
     111           0 :     if( !mbFormControl )
     112           0 :        mxFont->getPropertyValue( "CharEscapement" ) >>= nValue;
     113           0 :     return uno::makeAny( ( nValue == SUBSCRIPT ) );
     114             : }
     115             : 
     116             : void SAL_CALL
     117           1 : VbaFontBase::setSize( const uno::Any& aValue ) throw( uno::RuntimeException, std::exception )
     118             : {
     119             :     // form controls need a sal_Int16 containing points, other APIs need a float
     120           1 :     uno::Any aVal( aValue );
     121           1 :     if( mbFormControl )
     122             :     {
     123           0 :         float fVal = 0.0;
     124           0 :         aVal >>= fVal;
     125           0 :         aVal <<= static_cast< sal_Int16 >( fVal );
     126             :     }
     127           1 :     mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharHeight", "FontHeight" ), aVal );
     128           1 : }
     129             : 
     130             : uno::Any SAL_CALL
     131           2 : VbaFontBase::getSize() throw ( uno::RuntimeException, std::exception )
     132             : {
     133           2 :     return mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharHeight", "FontHeight" ) );
     134             : }
     135             : 
     136             : void SAL_CALL
     137           1 : VbaFontBase::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException, std::exception )
     138             : {
     139           1 :     sal_Int32 nIndex = 0;
     140           1 :     _colorindex >>= nIndex;
     141             : 
     142           1 :     --nIndex; // OOo indices are zero bases
     143             : 
     144             :     // setColor expects colors in XL RGB values
     145             :     // #FIXME this is daft we convert OO RGB val to XL RGB val and
     146             :     // then back again to OO RGB value
     147           1 :     setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) );
     148           1 : }
     149             : 
     150             : 
     151             : uno::Any SAL_CALL
     152           2 : VbaFontBase::getColorIndex() throw ( uno::RuntimeException, std::exception )
     153             : {
     154           2 :     sal_Int32 nColor = 0;
     155             : 
     156           2 :     XLRGBToOORGB( getColor() ) >>= nColor;
     157           2 :     sal_Int32 nElems = mxPalette->getCount();
     158           2 :     sal_Int32 nIndex = -1;
     159           7 :     for ( sal_Int32 count=0; count<nElems; ++count )
     160             :            {
     161           7 :         sal_Int32 nPaletteColor = 0;
     162           7 :         mxPalette->getByIndex( count ) >>= nPaletteColor;
     163           7 :         if ( nPaletteColor == nColor )
     164             :         {
     165           2 :             nIndex = count + 1; // 1 based
     166           2 :             break;
     167             :         }
     168             :     }
     169           2 :     return uno::makeAny( nIndex );
     170             : }
     171             : 
     172             : void SAL_CALL
     173           2 : VbaFontBase::setBold( const uno::Any& aValue ) throw( uno::RuntimeException, std::exception )
     174             : {
     175           2 :     bool bValue = false;
     176           2 :     aValue >>= bValue;
     177           2 :     double fBoldValue = awt::FontWeight::NORMAL;
     178           2 :     if( bValue )
     179           2 :         fBoldValue = awt::FontWeight::BOLD;
     180           2 :     mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharWeight", "FontWeight" ), uno::Any( fBoldValue ) );
     181             : 
     182           2 : }
     183             : 
     184             : uno::Any SAL_CALL
     185          10 : VbaFontBase::getBold() throw ( uno::RuntimeException, std::exception )
     186             : {
     187          10 :     double fValue = 0.0;
     188          10 :     mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharWeight", "FontWeight" ) ) >>= fValue;
     189          10 :     return uno::makeAny( fValue == awt::FontWeight::BOLD );
     190             : }
     191             : 
     192             : void SAL_CALL
     193           1 : VbaFontBase::setStrikethrough( const uno::Any& aValue ) throw ( uno::RuntimeException, std::exception )
     194             : {
     195           1 :     bool bValue = false;
     196           1 :     aValue >>= bValue;
     197           1 :     short nValue = awt::FontStrikeout::NONE;
     198           1 :     if( bValue )
     199           1 :         nValue = awt::FontStrikeout::SINGLE;
     200           1 :     mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharStrikeout", "FontStrikeout" ), uno::Any( nValue ) );
     201           1 : }
     202             : 
     203             : uno::Any SAL_CALL
     204           2 : VbaFontBase::getStrikethrough() throw ( uno::RuntimeException, std::exception )
     205             : {
     206           2 :     short nValue = 0;
     207           2 :     mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharStrikeout", "FontStrikeout" ) ) >>= nValue;
     208           2 :     return uno::Any( nValue == awt::FontStrikeout::SINGLE );
     209             : }
     210             : 
     211             : void  SAL_CALL
     212           1 : VbaFontBase::setShadow( const uno::Any& aValue ) throw ( uno::RuntimeException, std::exception )
     213             : {
     214           1 :     if( !mbFormControl )
     215           1 :        mxFont->setPropertyValue( "CharShadowed" , aValue );
     216           1 : }
     217             : 
     218             : uno::Any SAL_CALL
     219           2 : VbaFontBase::getShadow() throw (uno::RuntimeException, std::exception)
     220             : {
     221           2 :     return mbFormControl ? uno::Any( false ) : mxFont->getPropertyValue( "CharShadowed" );
     222             : }
     223             : 
     224             : void  SAL_CALL
     225           1 : VbaFontBase::setItalic( const uno::Any& aValue ) throw ( uno::RuntimeException, std::exception )
     226             : {
     227           1 :     bool bValue = false;
     228           1 :     aValue >>= bValue;
     229           1 :     short nValue = awt::FontSlant_NONE;
     230           1 :     if( bValue )
     231           1 :         nValue = awt::FontSlant_ITALIC;
     232           1 :     mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharPosture", "FontSlant" ), uno::Any( nValue ) );
     233           1 : }
     234             : 
     235             : uno::Any SAL_CALL
     236           3 : VbaFontBase::getItalic() throw ( uno::RuntimeException, std::exception )
     237             : {
     238             :     awt::FontSlant aFS;
     239           3 :     mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharPosture", "FontSlant" ) ) >>= aFS;
     240           3 :     return uno::makeAny( aFS == awt::FontSlant_ITALIC );
     241             : }
     242             : 
     243             : void  SAL_CALL
     244           1 : VbaFontBase::setName( const uno::Any& aValue ) throw ( uno::RuntimeException, std::exception )
     245             : {
     246           1 :     OUString sString;
     247           1 :     aValue >>= sString;
     248           1 :     mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharFontName", "FontName" ), aValue );
     249           1 : }
     250             : 
     251             : uno::Any SAL_CALL
     252           2 : VbaFontBase::getName() throw ( uno::RuntimeException, std::exception )
     253             : {
     254           2 :     return mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharFontName", "FontName" ) );
     255             : }
     256             : 
     257             : uno::Any
     258           0 : VbaFontBase::getColor() throw (uno::RuntimeException, std::exception)
     259             : {
     260           0 :     uno::Any aAny;
     261           0 :     aAny = OORGBToXLRGB( mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharColor", "TextColor" ) ) );
     262           0 :     return aAny;
     263             : }
     264             : 
     265             : void
     266           3 : VbaFontBase::setColor( const uno::Any& _color  ) throw (uno::RuntimeException, std::exception)
     267             : {
     268           3 :     mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharColor", "TextColor" ), XLRGBToOORGB(_color) );
     269           3 : }
     270             : 
     271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11