Use correct object
[LibreOffice.git] / vbahelper / source / msforms / vbanewfont.cxx
blob63a1515692bfc25434fd1abebe53cb4f5705b0d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 using namespace ::com::sun::star;
29 using namespace ::ooo::vba;
32 VbaNewFont::VbaNewFont(
33 const uno::Reference< beans::XPropertySet >& rxModelProps ) :
34 mxProps( rxModelProps, uno::UNO_SET_THROW )
38 // XNewFont attributes
40 OUString SAL_CALL VbaNewFont::getName()
42 uno::Any aAny = mxProps->getPropertyValue( u"FontName"_ustr );
43 return aAny.get< OUString >();
46 void SAL_CALL VbaNewFont::setName( const OUString& rName )
48 mxProps->setPropertyValue( u"FontName"_ustr , uno::Any( rName ) );
51 double SAL_CALL VbaNewFont::getSize()
53 uno::Any aAny = mxProps->getPropertyValue( u"FontHeight"_ustr );
54 return aAny.get< float >();
57 void SAL_CALL VbaNewFont::setSize( double fSize )
59 mxProps->setPropertyValue( u"FontHeight"_ustr , uno::Any( static_cast< float >( fSize ) ) );
62 sal_Int16 SAL_CALL VbaNewFont::getCharset()
64 uno::Any aAny = mxProps->getPropertyValue( u"FontCharset"_ustr );
65 return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding >( aAny.get< sal_Int16 >() ) );
68 void SAL_CALL VbaNewFont::setCharset( sal_Int16 nCharset )
70 rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW;
71 if( (0 <= nCharset) && (nCharset <= SAL_MAX_UINT8) )
72 eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( nCharset ) );
73 if( eFontEnc == RTL_TEXTENCODING_DONTKNOW )
74 throw uno::RuntimeException(u"an unknown or missing encoding"_ustr);
75 mxProps->setPropertyValue( u"FontCharset"_ustr , uno::Any( static_cast< sal_Int16 >( eFontEnc ) ) );
78 sal_Int16 SAL_CALL VbaNewFont::getWeight()
80 return getBold() ? 700 : 400;
83 void SAL_CALL VbaNewFont::setWeight( sal_Int16 nWeight )
85 setBold( nWeight >= 700 );
88 sal_Bool SAL_CALL VbaNewFont::getBold()
90 uno::Any aAny = mxProps->getPropertyValue( u"FontWeight"_ustr );
91 return aAny.get< float >() > awt::FontWeight::NORMAL;
94 void SAL_CALL VbaNewFont::setBold( sal_Bool bBold )
96 mxProps->setPropertyValue( u"FontWeight"_ustr , uno::Any( bBold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) );
99 sal_Bool SAL_CALL VbaNewFont::getItalic()
101 uno::Any aAny = mxProps->getPropertyValue( u"FontSlant"_ustr );
102 return aAny.get< awt::FontSlant >() != awt::FontSlant_NONE;
105 void SAL_CALL VbaNewFont::setItalic( sal_Bool bItalic )
107 mxProps->setPropertyValue( u"FontSlant"_ustr , uno::Any( bItalic ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) );
110 sal_Bool SAL_CALL VbaNewFont::getUnderline()
112 uno::Any aAny = mxProps->getPropertyValue(u"FontUnderline"_ustr );
113 return aAny.get< sal_Int16 >() != awt::FontUnderline::NONE;
116 void SAL_CALL VbaNewFont::setUnderline( sal_Bool bUnderline )
118 mxProps->setPropertyValue(u"FontUnderline"_ustr , uno::Any( bUnderline ? awt::FontUnderline::SINGLE : awt::FontUnderline::NONE ) );
121 sal_Bool SAL_CALL VbaNewFont::getStrikethrough()
123 uno::Any aAny = mxProps->getPropertyValue( u"FontStrikeout"_ustr );
124 return aAny.get< sal_Int16 >() != awt::FontStrikeout::NONE;
127 void SAL_CALL VbaNewFont::setStrikethrough( sal_Bool bStrikethrough )
129 mxProps->setPropertyValue( u"FontStrikeout"_ustr ,uno::Any( bStrikethrough ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) );
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */