LCOV - code coverage report
Current view: top level - editeng/source/uno - unofdesc.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 32 127 25.2 %
Date: 2014-11-03 Functions: 4 8 50.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             : 
      21             : #include <editeng/eeitem.hxx>
      22             : #include <com/sun/star/uno/Any.hxx>
      23             : 
      24             : #include <toolkit/helper/vclunohelper.hxx>
      25             : #include <editeng/fontitem.hxx>
      26             : #include <editeng/fhgtitem.hxx>
      27             : #include <editeng/postitem.hxx>
      28             : #include <editeng/udlnitem.hxx>
      29             : #include <editeng/wghtitem.hxx>
      30             : #include <editeng/crossedoutitem.hxx>
      31             : #include <editeng/wrlmitem.hxx>
      32             : #include <editeng/memberids.hrc>
      33             : #include <svl/itempool.hxx>
      34             : 
      35             : #include <editeng/unofdesc.hxx>
      36             : #include <editeng/svxfont.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40             : 
      41        2760 : void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, vcl::Font& rFont )
      42             : {
      43        2760 :     rFont.SetName( rDesc.Name );
      44        2760 :     rFont.SetStyleName( rDesc.StyleName );
      45        2760 :     rFont.SetSize( Size( rDesc.Width, rDesc.Height ) );
      46        2760 :     rFont.SetFamily( (FontFamily)rDesc.Family );
      47        2760 :     rFont.SetCharSet( (rtl_TextEncoding)rDesc.CharSet );
      48        2760 :     rFont.SetPitch( (FontPitch)rDesc.Pitch );
      49        2760 :     rFont.SetOrientation( (short)(rDesc.Orientation*10) );
      50        2760 :     rFont.SetKerning( rDesc.Kerning );
      51        2760 :     rFont.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc.Weight) );
      52        2760 :     rFont.SetItalic( (FontItalic)rDesc.Slant );
      53        2760 :     rFont.SetUnderline( (FontUnderline)rDesc.Underline );
      54        2760 :     rFont.SetStrikeout( (FontStrikeout)rDesc.Strikeout );
      55        2760 :     rFont.SetWordLineMode( rDesc.WordLineMode );
      56        2760 : }
      57             : 
      58        5346 : void SvxUnoFontDescriptor::ConvertFromFont( const vcl::Font& rFont, awt::FontDescriptor& rDesc )
      59             : {
      60        5346 :     rDesc.Name = rFont.GetName();
      61        5346 :     rDesc.StyleName = rFont.GetStyleName();
      62        5346 :     rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Width());
      63        5346 :     rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Height());
      64        5346 :     rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
      65        5346 :     rDesc.CharSet = rFont.GetCharSet();
      66        5346 :     rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
      67        5346 :     rDesc.Orientation = static_cast< float >(rFont.GetOrientation() / 10);
      68        5346 :     rDesc.Kerning = rFont.IsKerning();
      69        5346 :     rDesc.Weight = VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
      70        5346 :     rDesc.Slant = VCLUnoHelper::ConvertFontSlant( rFont.GetItalic() );
      71        5346 :     rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
      72        5346 :     rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
      73        5346 :     rDesc.WordLineMode = rFont.IsWordLineMode();
      74        5346 : }
      75             : 
      76           0 : void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet )
      77             : {
      78           0 :     uno::Any aTemp;
      79             : 
      80             :     {
      81           0 :         SvxFontItem aFontItem( EE_CHAR_FONTINFO );
      82           0 :         aFontItem.SetFamilyName( rDesc.Name);
      83           0 :         aFontItem.SetStyleName( rDesc.StyleName);
      84           0 :         aFontItem.SetFamily( (FontFamily)rDesc.Family);
      85           0 :         aFontItem.SetCharSet( rDesc.CharSet );
      86           0 :         aFontItem.SetPitch( (FontPitch)rDesc.Pitch);
      87           0 :         rSet.Put(aFontItem);
      88             :     }
      89             : 
      90             :     {
      91           0 :         SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT );
      92           0 :         aTemp <<= (float)rDesc.Height;
      93           0 :         ((SfxPoolItem*)&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS );
      94           0 :         rSet.Put(aFontHeightItem);
      95             :     }
      96             : 
      97             :     {
      98           0 :         SvxPostureItem aPostureItem( (FontItalic)0, EE_CHAR_ITALIC );
      99           0 :         aTemp <<= rDesc.Slant;
     100           0 :         ((SfxPoolItem*)&aPostureItem)->PutValue( aTemp, MID_POSTURE );
     101           0 :         rSet.Put(aPostureItem);
     102             :     }
     103             : 
     104             :     {
     105           0 :         SvxUnderlineItem aUnderlineItem( (FontUnderline)0, EE_CHAR_UNDERLINE );
     106           0 :         aTemp <<= (sal_Int16)rDesc.Underline;
     107           0 :         ((SfxPoolItem*)&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE );
     108           0 :         rSet.Put( aUnderlineItem );
     109             :     }
     110             : 
     111             :     {
     112           0 :         SvxWeightItem aWeightItem( (FontWeight)0, EE_CHAR_WEIGHT );
     113           0 :         aTemp <<= rDesc.Weight;
     114           0 :         ((SfxPoolItem*)&aWeightItem)->PutValue( aTemp, MID_WEIGHT );
     115           0 :         rSet.Put( aWeightItem );
     116             :     }
     117             : 
     118             :     {
     119           0 :         SvxCrossedOutItem aCrossedOutItem( (FontStrikeout)0, EE_CHAR_STRIKEOUT );
     120           0 :         aTemp <<= rDesc.Strikeout;
     121           0 :         ((SfxPoolItem*)&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT );
     122           0 :         rSet.Put( aCrossedOutItem );
     123             :     }
     124             : 
     125             :     {
     126           0 :         SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM );
     127           0 :         rSet.Put( aWLMItem );
     128           0 :     }
     129           0 : }
     130             : 
     131           0 : void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc )
     132             : {
     133           0 :     const SfxPoolItem* pItem = NULL;
     134             :     {
     135           0 :         const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(&rSet.Get( EE_CHAR_FONTINFO, true ));
     136           0 :         rDesc.Name      = pFontItem->GetFamilyName();
     137           0 :         rDesc.StyleName = pFontItem->GetStyleName();
     138             :         rDesc.Family    = sal::static_int_cast< sal_Int16 >(
     139           0 :             pFontItem->GetFamily());
     140           0 :         rDesc.CharSet   = pFontItem->GetCharSet();
     141             :         rDesc.Pitch     = sal::static_int_cast< sal_Int16 >(
     142           0 :             pFontItem->GetPitch());
     143             :     }
     144             :     {
     145           0 :         pItem = &rSet.Get( EE_CHAR_FONTHEIGHT, true );
     146           0 :         uno::Any aHeight;
     147           0 :         if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) )
     148           0 :             aHeight >>= rDesc.Height;
     149             :     }
     150             :     {
     151           0 :         pItem = &rSet.Get( EE_CHAR_ITALIC, true );
     152           0 :         uno::Any aFontSlant;
     153           0 :         if(pItem->QueryValue( aFontSlant, MID_POSTURE ))
     154           0 :             aFontSlant >>= rDesc.Slant;
     155             :     }
     156             :     {
     157           0 :         pItem = &rSet.Get( EE_CHAR_UNDERLINE, true );
     158           0 :         uno::Any aUnderline;
     159           0 :         if(pItem->QueryValue( aUnderline, MID_TL_STYLE ))
     160           0 :             aUnderline >>= rDesc.Underline;
     161             :     }
     162             :     {
     163           0 :         pItem = &rSet.Get( EE_CHAR_WEIGHT, true );
     164           0 :         uno::Any aWeight;
     165           0 :         if(pItem->QueryValue( aWeight, MID_WEIGHT ))
     166           0 :             aWeight >>= rDesc.Weight;
     167             :     }
     168             :     {
     169           0 :         pItem = &rSet.Get( EE_CHAR_STRIKEOUT, true );
     170           0 :         uno::Any aStrikeOut;
     171           0 :         if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT ))
     172           0 :             aStrikeOut >>= rDesc.Strikeout;
     173             :     }
     174             :     {
     175           0 :         const SvxWordLineModeItem* pWLMItem = static_cast<const SvxWordLineModeItem*>(&rSet.Get( EE_CHAR_WLM, true ));
     176           0 :         rDesc.WordLineMode = pWLMItem->GetValue();
     177             :     }
     178           0 : }
     179             : 
     180           0 : void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet& rSet )
     181             : {
     182           0 :     rSet.InvalidateItem( EE_CHAR_FONTINFO );
     183           0 :     rSet.InvalidateItem( EE_CHAR_FONTHEIGHT );
     184           0 :     rSet.InvalidateItem( EE_CHAR_ITALIC );
     185           0 :     rSet.InvalidateItem( EE_CHAR_UNDERLINE );
     186           0 :     rSet.InvalidateItem( EE_CHAR_WEIGHT );
     187           0 :     rSet.InvalidateItem( EE_CHAR_STRIKEOUT );
     188           0 :     rSet.InvalidateItem( EE_CHAR_WLM );
     189           0 : }
     190             : 
     191           0 : uno::Any SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool* pPool )
     192             : {
     193             :     SfxItemSet aSet( *pPool, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
     194             :                              EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT,
     195             :                              EE_CHAR_ITALIC, EE_CHAR_ITALIC,
     196             :                              EE_CHAR_UNDERLINE, EE_CHAR_UNDERLINE,
     197             :                              EE_CHAR_WEIGHT, EE_CHAR_WEIGHT,
     198             :                              EE_CHAR_STRIKEOUT, EE_CHAR_STRIKEOUT,
     199           0 :                              EE_CHAR_WLM, EE_CHAR_WLM, 0 );
     200             : 
     201           0 :     uno::Any aAny;
     202             : 
     203           0 :     if(!SfxItemPool::IsWhich(EE_CHAR_FONTINFO)||
     204           0 :         !SfxItemPool::IsWhich(EE_CHAR_FONTHEIGHT)||
     205           0 :         !SfxItemPool::IsWhich(EE_CHAR_ITALIC)||
     206           0 :         !SfxItemPool::IsWhich(EE_CHAR_UNDERLINE)||
     207           0 :         !SfxItemPool::IsWhich(EE_CHAR_WEIGHT)||
     208           0 :         !SfxItemPool::IsWhich(EE_CHAR_STRIKEOUT)||
     209           0 :         !SfxItemPool::IsWhich(EE_CHAR_WLM))
     210           0 :         return aAny;
     211             : 
     212           0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTINFO));
     213           0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTHEIGHT));
     214           0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_ITALIC));
     215           0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_UNDERLINE));
     216           0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_WEIGHT));
     217           0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_STRIKEOUT));
     218           0 :     aSet.Put(pPool->GetDefaultItem(EE_CHAR_WLM));
     219             : 
     220           0 :     awt::FontDescriptor aDesc;
     221             : 
     222           0 :     FillFromItemSet( aSet, aDesc );
     223             : 
     224           0 :     aAny <<= aDesc;
     225             : 
     226           0 :     return aAny;
     227         669 : }
     228             : 
     229             : 
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10