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

Generated by: LCOV version 1.10