LCOV - code coverage report
Current view: top level - editeng/source/uno - unofdesc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 125 24.8 %
Date: 2012-08-25 Functions: 2 6 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 162 1.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <editeng/eeitem.hxx>
      31                 :            : #include <com/sun/star/uno/Any.hxx>
      32                 :            : 
      33                 :            : #include <toolkit/helper/vclunohelper.hxx>
      34                 :            : #include <editeng/fontitem.hxx>
      35                 :            : #include <editeng/fhgtitem.hxx>
      36                 :            : #include <editeng/postitem.hxx>
      37                 :            : #include <editeng/udlnitem.hxx>
      38                 :            : #include <editeng/wghtitem.hxx>
      39                 :            : #include <editeng/crsditem.hxx>
      40                 :            : #include <editeng/wrlmitem.hxx>
      41                 :            : #include <editeng/memberids.hrc>
      42                 :            : #include <svl/itempool.hxx>
      43                 :            : 
      44                 :            : #include <editeng/unofdesc.hxx>
      45                 :            : 
      46                 :            : using namespace ::rtl;
      47                 :            : using namespace ::com::sun::star;
      48                 :            : 
      49                 :            : 
      50                 :        404 : void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, Font& rFont )
      51                 :            : {
      52                 :        404 :     rFont.SetName( rDesc.Name );
      53         [ +  - ]:        404 :     rFont.SetStyleName( rDesc.StyleName );
      54         [ +  - ]:        404 :     rFont.SetSize( Size( rDesc.Width, rDesc.Height ) );
      55                 :        404 :     rFont.SetFamily( (FontFamily)rDesc.Family );
      56                 :        404 :     rFont.SetCharSet( (CharSet)rDesc.CharSet );
      57                 :        404 :     rFont.SetPitch( (FontPitch)rDesc.Pitch );
      58                 :        404 :     rFont.SetOrientation( (short)(rDesc.Orientation*10) );
      59                 :        404 :     rFont.SetKerning( rDesc.Kerning );
      60                 :        404 :     rFont.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc.Weight) );
      61                 :        404 :     rFont.SetItalic( (FontItalic)rDesc.Slant );
      62                 :        404 :     rFont.SetUnderline( (FontUnderline)rDesc.Underline );
      63                 :        404 :     rFont.SetStrikeout( (FontStrikeout)rDesc.Strikeout );
      64                 :        404 :     rFont.SetWordLineMode( rDesc.WordLineMode );
      65                 :        404 : }
      66                 :            : 
      67                 :        341 : void SvxUnoFontDescriptor::ConvertFromFont( const Font& rFont, awt::FontDescriptor& rDesc )
      68                 :            : {
      69                 :        341 :     rDesc.Name = rFont.GetName();
      70                 :        341 :     rDesc.StyleName = rFont.GetStyleName();
      71                 :        341 :     rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Width());
      72                 :        341 :     rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Height());
      73                 :        341 :     rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
      74                 :        341 :     rDesc.CharSet = rFont.GetCharSet();
      75                 :        341 :     rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
      76                 :        341 :     rDesc.Orientation = static_cast< float >(rFont.GetOrientation() / 10);
      77                 :        341 :     rDesc.Kerning = rFont.IsKerning();
      78                 :        341 :     rDesc.Weight = VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
      79                 :        341 :     rDesc.Slant = (awt::FontSlant)rFont.GetItalic();
      80                 :        341 :     rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
      81                 :        341 :     rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
      82                 :        341 :     rDesc.WordLineMode = rFont.IsWordLineMode();
      83                 :        341 : }
      84                 :            : 
      85                 :          0 : void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet )
      86                 :            : {
      87                 :          0 :     uno::Any aTemp;
      88                 :            : 
      89                 :            :     {
      90         [ #  # ]:          0 :         SvxFontItem aFontItem( EE_CHAR_FONTINFO );
      91 [ #  # ][ #  # ]:          0 :         aFontItem.SetFamilyName( rDesc.Name);
                 [ #  # ]
      92 [ #  # ][ #  # ]:          0 :         aFontItem.SetStyleName( rDesc.StyleName);
                 [ #  # ]
      93                 :          0 :         aFontItem.SetFamily( (FontFamily)rDesc.Family);
      94                 :          0 :         aFontItem.SetCharSet( rDesc.CharSet );
      95                 :          0 :         aFontItem.SetPitch( (FontPitch)rDesc.Pitch);
      96 [ #  # ][ #  # ]:          0 :         rSet.Put(aFontItem);
      97                 :            :     }
      98                 :            : 
      99                 :            :     {
     100         [ #  # ]:          0 :         SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT );
     101         [ #  # ]:          0 :         aTemp <<= (float)rDesc.Height;
     102         [ #  # ]:          0 :         ((SfxPoolItem*)&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS );
     103 [ #  # ][ #  # ]:          0 :         rSet.Put(aFontHeightItem);
     104                 :            :     }
     105                 :            : 
     106                 :            :     {
     107         [ #  # ]:          0 :         SvxPostureItem aPostureItem( (FontItalic)0, EE_CHAR_ITALIC );
     108         [ #  # ]:          0 :         aTemp <<= rDesc.Slant;
     109         [ #  # ]:          0 :         ((SfxPoolItem*)&aPostureItem)->PutValue( aTemp, MID_POSTURE );
     110 [ #  # ][ #  # ]:          0 :         rSet.Put(aPostureItem);
     111                 :            :     }
     112                 :            : 
     113                 :            :     {
     114         [ #  # ]:          0 :         SvxUnderlineItem aUnderlineItem( (FontUnderline)0, EE_CHAR_UNDERLINE );
     115         [ #  # ]:          0 :         aTemp <<= (sal_Int16)rDesc.Underline;
     116         [ #  # ]:          0 :         ((SfxPoolItem*)&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE );
     117 [ #  # ][ #  # ]:          0 :         rSet.Put( aUnderlineItem );
     118                 :            :     }
     119                 :            : 
     120                 :            :     {
     121         [ #  # ]:          0 :         SvxWeightItem aWeightItem( (FontWeight)0, EE_CHAR_WEIGHT );
     122         [ #  # ]:          0 :         aTemp <<= rDesc.Weight;
     123         [ #  # ]:          0 :         ((SfxPoolItem*)&aWeightItem)->PutValue( aTemp, MID_WEIGHT );
     124 [ #  # ][ #  # ]:          0 :         rSet.Put( aWeightItem );
     125                 :            :     }
     126                 :            : 
     127                 :            :     {
     128         [ #  # ]:          0 :         SvxCrossedOutItem aCrossedOutItem( (FontStrikeout)0, EE_CHAR_STRIKEOUT );
     129         [ #  # ]:          0 :         aTemp <<= rDesc.Strikeout;
     130         [ #  # ]:          0 :         ((SfxPoolItem*)&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT );
     131 [ #  # ][ #  # ]:          0 :         rSet.Put( aCrossedOutItem );
     132                 :            :     }
     133                 :            : 
     134                 :            :     {
     135         [ #  # ]:          0 :         SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM );
     136 [ #  # ][ #  # ]:          0 :         rSet.Put( aWLMItem );
     137                 :          0 :     }
     138                 :          0 : }
     139                 :            : 
     140                 :          0 : void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc )
     141                 :            : {
     142                 :          0 :     const SfxPoolItem* pItem = NULL;
     143                 :            :     {
     144                 :          0 :         SvxFontItem* pFontItem = (SvxFontItem*)&rSet.Get( EE_CHAR_FONTINFO, sal_True );
     145                 :          0 :         rDesc.Name      = pFontItem->GetFamilyName();
     146                 :          0 :         rDesc.StyleName = pFontItem->GetStyleName();
     147                 :            :         rDesc.Family    = sal::static_int_cast< sal_Int16 >(
     148                 :          0 :             pFontItem->GetFamily());
     149                 :          0 :         rDesc.CharSet   = pFontItem->GetCharSet();
     150                 :            :         rDesc.Pitch     = sal::static_int_cast< sal_Int16 >(
     151                 :          0 :             pFontItem->GetPitch());
     152                 :            :     }
     153                 :            :     {
     154         [ #  # ]:          0 :         pItem = &rSet.Get( EE_CHAR_FONTHEIGHT, sal_True );
     155                 :          0 :         uno::Any aHeight;
     156 [ #  # ][ #  # ]:          0 :         if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) )
     157                 :          0 :             aHeight >>= rDesc.Height;
     158                 :            :     }
     159                 :            :     {
     160         [ #  # ]:          0 :         pItem = &rSet.Get( EE_CHAR_ITALIC, sal_True );
     161                 :          0 :         uno::Any aFontSlant;
     162 [ #  # ][ #  # ]:          0 :         if(pItem->QueryValue( aFontSlant, MID_POSTURE ))
     163         [ #  # ]:          0 :             aFontSlant >>= rDesc.Slant;
     164                 :            :     }
     165                 :            :     {
     166         [ #  # ]:          0 :         pItem = &rSet.Get( EE_CHAR_UNDERLINE, sal_True );
     167                 :          0 :         uno::Any aUnderline;
     168 [ #  # ][ #  # ]:          0 :         if(pItem->QueryValue( aUnderline, MID_TL_STYLE ))
     169                 :          0 :             aUnderline >>= rDesc.Underline;
     170                 :            :     }
     171                 :            :     {
     172         [ #  # ]:          0 :         pItem = &rSet.Get( EE_CHAR_WEIGHT, sal_True );
     173                 :          0 :         uno::Any aWeight;
     174 [ #  # ][ #  # ]:          0 :         if(pItem->QueryValue( aWeight, MID_WEIGHT ))
     175                 :          0 :             aWeight >>= rDesc.Weight;
     176                 :            :     }
     177                 :            :     {
     178         [ #  # ]:          0 :         pItem = &rSet.Get( EE_CHAR_STRIKEOUT, sal_True );
     179                 :          0 :         uno::Any aStrikeOut;
     180 [ #  # ][ #  # ]:          0 :         if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT ))
     181                 :          0 :             aStrikeOut >>= rDesc.Strikeout;
     182                 :            :     }
     183                 :            :     {
     184                 :          0 :         SvxWordLineModeItem* pWLMItem = (SvxWordLineModeItem*)&rSet.Get( EE_CHAR_WLM, sal_True );
     185                 :          0 :         rDesc.WordLineMode = pWLMItem->GetValue();
     186                 :            :     }
     187                 :          0 : }
     188                 :            : 
     189                 :          0 : void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet& rSet )
     190                 :            : {
     191                 :          0 :     rSet.InvalidateItem( EE_CHAR_FONTINFO );
     192                 :          0 :     rSet.InvalidateItem( EE_CHAR_FONTHEIGHT );
     193                 :          0 :     rSet.InvalidateItem( EE_CHAR_ITALIC );
     194                 :          0 :     rSet.InvalidateItem( EE_CHAR_UNDERLINE );
     195                 :          0 :     rSet.InvalidateItem( EE_CHAR_WEIGHT );
     196                 :          0 :     rSet.InvalidateItem( EE_CHAR_STRIKEOUT );
     197                 :          0 :     rSet.InvalidateItem( EE_CHAR_WLM );
     198                 :          0 : }
     199                 :            : 
     200                 :          0 : uno::Any SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool* pPool )
     201                 :            : {
     202                 :            :     SfxItemSet aSet( *pPool, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
     203                 :            :                              EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT,
     204                 :            :                              EE_CHAR_ITALIC, EE_CHAR_ITALIC,
     205                 :            :                              EE_CHAR_UNDERLINE, EE_CHAR_UNDERLINE,
     206                 :            :                              EE_CHAR_WEIGHT, EE_CHAR_WEIGHT,
     207                 :            :                              EE_CHAR_STRIKEOUT, EE_CHAR_STRIKEOUT,
     208         [ #  # ]:          0 :                              EE_CHAR_WLM, EE_CHAR_WLM, 0 );
     209                 :            : 
     210                 :          0 :     uno::Any aAny;
     211                 :            : 
     212 [ #  # ][ #  #  :          0 :     if(!pPool->IsWhich(EE_CHAR_FONTINFO)||
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     213                 :          0 :         !pPool->IsWhich(EE_CHAR_FONTHEIGHT)||
     214                 :          0 :         !pPool->IsWhich(EE_CHAR_ITALIC)||
     215                 :          0 :         !pPool->IsWhich(EE_CHAR_UNDERLINE)||
     216                 :          0 :         !pPool->IsWhich(EE_CHAR_WEIGHT)||
     217                 :          0 :         !pPool->IsWhich(EE_CHAR_STRIKEOUT)||
     218                 :          0 :         !pPool->IsWhich(EE_CHAR_WLM))
     219                 :            :         return aAny;
     220                 :            : 
     221 [ #  # ][ #  # ]:          0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTINFO));
     222 [ #  # ][ #  # ]:          0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTHEIGHT));
     223 [ #  # ][ #  # ]:          0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_ITALIC));
     224 [ #  # ][ #  # ]:          0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_UNDERLINE));
     225 [ #  # ][ #  # ]:          0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_WEIGHT));
     226 [ #  # ][ #  # ]:          0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_STRIKEOUT));
     227 [ #  # ][ #  # ]:          0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_WLM));
     228                 :            : 
     229                 :          0 :     awt::FontDescriptor aDesc;
     230                 :            : 
     231         [ #  # ]:          0 :     FillFromItemSet( aSet, aDesc );
     232                 :            : 
     233         [ #  # ]:          0 :     aAny <<= aDesc;
     234                 :            : 
     235         [ #  # ]:          0 :     return aAny;
     236                 :            : }
     237                 :            : 
     238                 :            : 
     239                 :            : 
     240                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10