1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/tencinfo.h>
21 #include <vbanewfont.hxx>
22 #include <com/sun/star/awt/FontWeight.hpp>
23 #include <com/sun/star/awt/FontSlant.hpp>
24 #include <com/sun/star/awt/FontStrikeout.hpp>
25 #include <com/sun/star/awt/FontUnderline.hpp>
27 using namespace ::com::sun::star
;
28 using namespace ::ooo::vba
;
30 // ============================================================================
32 VbaNewFont::VbaNewFont(
33 const uno::Reference
< XHelperInterface
>& rxParent
,
34 const uno::Reference
< uno::XComponentContext
>& rxContext
,
35 const uno::Reference
< beans::XPropertySet
>& rxModelProps
) throw (uno::RuntimeException
) :
36 VbaNewFont_BASE( rxParent
, rxContext
),
37 mxProps( rxModelProps
, uno::UNO_SET_THROW
)
41 // XNewFont attributes
43 OUString SAL_CALL
VbaNewFont::getName() throw (uno::RuntimeException
)
45 uno::Any aAny
= mxProps
->getPropertyValue( "FontName" );
46 return aAny
.get
< OUString
>();
49 void SAL_CALL
VbaNewFont::setName( const OUString
& rName
) throw (uno::RuntimeException
)
51 mxProps
->setPropertyValue( "FontName" , uno::Any( rName
) );
54 double SAL_CALL
VbaNewFont::getSize() throw (uno::RuntimeException
)
56 uno::Any aAny
= mxProps
->getPropertyValue( "FontHeight" );
57 return aAny
.get
< float >();
60 void SAL_CALL
VbaNewFont::setSize( double fSize
) throw (uno::RuntimeException
)
62 mxProps
->setPropertyValue( "FontHeight" , uno::Any( static_cast< float >( fSize
) ) );
65 sal_Int16 SAL_CALL
VbaNewFont::getCharset() throw (uno::RuntimeException
)
67 uno::Any aAny
= mxProps
->getPropertyValue( "FontCharset" );
68 return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding
>( aAny
.get
< sal_Int16
>() ) );
71 void SAL_CALL
VbaNewFont::setCharset( sal_Int16 nCharset
) throw (uno::RuntimeException
)
73 rtl_TextEncoding eFontEnc
= RTL_TEXTENCODING_DONTKNOW
;
74 if( (0 <= nCharset
) && (nCharset
<= SAL_MAX_UINT8
) )
75 eFontEnc
= rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8
>( nCharset
) );
76 if( eFontEnc
== RTL_TEXTENCODING_DONTKNOW
)
77 throw uno::RuntimeException();
78 mxProps
->setPropertyValue( "FontCharset" , uno::Any( static_cast< sal_Int16
>( eFontEnc
) ) );
81 sal_Int16 SAL_CALL
VbaNewFont::getWeight() throw (uno::RuntimeException
)
83 return getBold() ? 700 : 400;
86 void SAL_CALL
VbaNewFont::setWeight( sal_Int16 nWeight
) throw (uno::RuntimeException
)
88 setBold( nWeight
>= 700 );
91 sal_Bool SAL_CALL
VbaNewFont::getBold() throw (uno::RuntimeException
)
93 uno::Any aAny
= mxProps
->getPropertyValue( "FontWeight" );
94 return aAny
.get
< float >() > awt::FontWeight::NORMAL
;
97 void SAL_CALL
VbaNewFont::setBold( sal_Bool bBold
) throw (uno::RuntimeException
)
99 mxProps
->setPropertyValue( "FontWeight" , uno::Any( bBold
? awt::FontWeight::BOLD
: awt::FontWeight::NORMAL
) );
102 sal_Bool SAL_CALL
VbaNewFont::getItalic() throw (uno::RuntimeException
)
104 uno::Any aAny
= mxProps
->getPropertyValue( "FontSlant" );
105 return aAny
.get
< awt::FontSlant
>() != awt::FontSlant_NONE
;
108 void SAL_CALL
VbaNewFont::setItalic( sal_Bool bItalic
) throw (uno::RuntimeException
)
110 mxProps
->setPropertyValue( "FontSlant" , uno::Any( bItalic
? awt::FontSlant_ITALIC
: awt::FontSlant_NONE
) );
113 sal_Bool SAL_CALL
VbaNewFont::getUnderline() throw (uno::RuntimeException
)
115 uno::Any aAny
= mxProps
->getPropertyValue("FontUnderline" );
116 return aAny
.get
< sal_Int16
>() != awt::FontUnderline::NONE
;
119 void SAL_CALL
VbaNewFont::setUnderline( sal_Bool bUnderline
) throw (uno::RuntimeException
)
121 mxProps
->setPropertyValue("FontUnderline" , uno::Any( bUnderline
? awt::FontUnderline::SINGLE
: awt::FontUnderline::NONE
) );
124 sal_Bool SAL_CALL
VbaNewFont::getStrikethrough() throw (uno::RuntimeException
)
126 uno::Any aAny
= mxProps
->getPropertyValue( "FontStrikeout" );
127 return aAny
.get
< sal_Int16
>() != awt::FontStrikeout::NONE
;
130 void SAL_CALL
VbaNewFont::setStrikethrough( sal_Bool bStrikethrough
) throw (uno::RuntimeException
)
132 mxProps
->setPropertyValue( "FontStrikeout" ,uno::Any( bStrikethrough
? awt::FontStrikeout::SINGLE
: awt::FontStrikeout::NONE
) );
137 VBAHELPER_IMPL_XHELPERINTERFACE( VbaNewFont
, "ooo.vba.msforms.NewFont" )
139 // ============================================================================
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */