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 <vbanewfont.hxx>
21 #include <com/sun/star/awt/FontWeight.hpp>
22 #include <com/sun/star/awt/FontSlant.hpp>
23 #include <com/sun/star/awt/FontStrikeout.hpp>
24 #include <com/sun/star/awt/FontUnderline.hpp>
26 using namespace ::com::sun::star
;
27 using namespace ::ooo::vba
;
29 // ============================================================================
31 VbaNewFont::VbaNewFont(
32 const uno::Reference
< XHelperInterface
>& rxParent
,
33 const uno::Reference
< uno::XComponentContext
>& rxContext
,
34 const uno::Reference
< beans::XPropertySet
>& rxModelProps
) throw (uno::RuntimeException
) :
35 VbaNewFont_BASE( rxParent
, rxContext
),
36 mxProps( rxModelProps
, uno::UNO_SET_THROW
)
40 // XNewFont attributes
42 OUString SAL_CALL
VbaNewFont::getName() throw (uno::RuntimeException
)
44 uno::Any aAny
= mxProps
->getPropertyValue( "FontName" );
45 return aAny
.get
< OUString
>();
48 void SAL_CALL
VbaNewFont::setName( const OUString
& rName
) throw (uno::RuntimeException
)
50 mxProps
->setPropertyValue( "FontName" , uno::Any( rName
) );
53 double SAL_CALL
VbaNewFont::getSize() throw (uno::RuntimeException
)
55 uno::Any aAny
= mxProps
->getPropertyValue( "FontHeight" );
56 return aAny
.get
< float >();
59 void SAL_CALL
VbaNewFont::setSize( double fSize
) throw (uno::RuntimeException
)
61 mxProps
->setPropertyValue( "FontHeight" , uno::Any( static_cast< float >( fSize
) ) );
64 sal_Int16 SAL_CALL
VbaNewFont::getCharset() throw (uno::RuntimeException
)
66 uno::Any aAny
= mxProps
->getPropertyValue( "FontCharset" );
67 return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding
>( aAny
.get
< sal_Int16
>() ) );
70 void SAL_CALL
VbaNewFont::setCharset( sal_Int16 nCharset
) throw (uno::RuntimeException
)
72 rtl_TextEncoding eFontEnc
= RTL_TEXTENCODING_DONTKNOW
;
73 if( (0 <= nCharset
) && (nCharset
<= SAL_MAX_UINT8
) )
74 eFontEnc
= rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8
>( nCharset
) );
75 if( eFontEnc
== RTL_TEXTENCODING_DONTKNOW
)
76 throw uno::RuntimeException();
77 mxProps
->setPropertyValue( "FontCharset" , uno::Any( static_cast< sal_Int16
>( eFontEnc
) ) );
80 sal_Int16 SAL_CALL
VbaNewFont::getWeight() throw (uno::RuntimeException
)
82 return getBold() ? 700 : 400;
85 void SAL_CALL
VbaNewFont::setWeight( sal_Int16 nWeight
) throw (uno::RuntimeException
)
87 setBold( nWeight
>= 700 );
90 sal_Bool SAL_CALL
VbaNewFont::getBold() throw (uno::RuntimeException
)
92 uno::Any aAny
= mxProps
->getPropertyValue( "FontWeight" );
93 return aAny
.get
< float >() > awt::FontWeight::NORMAL
;
96 void SAL_CALL
VbaNewFont::setBold( sal_Bool bBold
) throw (uno::RuntimeException
)
98 mxProps
->setPropertyValue( "FontWeight" , uno::Any( bBold
? awt::FontWeight::BOLD
: awt::FontWeight::NORMAL
) );
101 sal_Bool SAL_CALL
VbaNewFont::getItalic() throw (uno::RuntimeException
)
103 uno::Any aAny
= mxProps
->getPropertyValue( "FontSlant" );
104 return aAny
.get
< awt::FontSlant
>() != awt::FontSlant_NONE
;
107 void SAL_CALL
VbaNewFont::setItalic( sal_Bool bItalic
) throw (uno::RuntimeException
)
109 mxProps
->setPropertyValue( "FontSlant" , uno::Any( bItalic
? awt::FontSlant_ITALIC
: awt::FontSlant_NONE
) );
112 sal_Bool SAL_CALL
VbaNewFont::getUnderline() throw (uno::RuntimeException
)
114 uno::Any aAny
= mxProps
->getPropertyValue("FontUnderline" );
115 return aAny
.get
< sal_Int16
>() != awt::FontUnderline::NONE
;
118 void SAL_CALL
VbaNewFont::setUnderline( sal_Bool bUnderline
) throw (uno::RuntimeException
)
120 mxProps
->setPropertyValue("FontUnderline" , uno::Any( bUnderline
? awt::FontUnderline::SINGLE
: awt::FontUnderline::NONE
) );
123 sal_Bool SAL_CALL
VbaNewFont::getStrikethrough() throw (uno::RuntimeException
)
125 uno::Any aAny
= mxProps
->getPropertyValue( "FontStrikeout" );
126 return aAny
.get
< sal_Int16
>() != awt::FontStrikeout::NONE
;
129 void SAL_CALL
VbaNewFont::setStrikethrough( sal_Bool bStrikethrough
) throw (uno::RuntimeException
)
131 mxProps
->setPropertyValue( "FontStrikeout" ,uno::Any( bStrikethrough
? awt::FontStrikeout::SINGLE
: awt::FontStrikeout::NONE
) );
136 VBAHELPER_IMPL_XHELPERINTERFACE( VbaNewFont
, "ooo.vba.msforms.NewFont" )
138 // ============================================================================
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */