1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <vbanewfont.hxx>
25 #include <com/sun/star/awt/FontWeight.hpp>
26 #include <com/sun/star/awt/FontSlant.hpp>
27 #include <com/sun/star/awt/FontStrikeout.hpp>
28 #include <com/sun/star/awt/FontUnderline.hpp>
29 
30 using namespace ::com::sun::star;
31 using namespace ::ooo::vba;
32 
33 // ============================================================================
34 
VbaNewFont(const uno::Reference<XHelperInterface> & rxParent,const uno::Reference<uno::XComponentContext> & rxContext,const uno::Reference<beans::XPropertySet> & rxModelProps)35 VbaNewFont::VbaNewFont(
36         const uno::Reference< XHelperInterface >& rxParent,
37         const uno::Reference< uno::XComponentContext >& rxContext,
38         const uno::Reference< beans::XPropertySet >& rxModelProps ) throw (uno::RuntimeException) :
39     VbaNewFont_BASE( rxParent, rxContext ),
40     mxProps( rxModelProps, uno::UNO_SET_THROW )
41 {
42 }
43 
44 // XNewFont attributes
45 
getName()46 ::rtl::OUString SAL_CALL VbaNewFont::getName() throw (uno::RuntimeException)
47 {
48     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ) );
49     return aAny.get< ::rtl::OUString >();
50 }
51 
setName(const::rtl::OUString & rName)52 void SAL_CALL VbaNewFont::setName( const ::rtl::OUString& rName ) throw (uno::RuntimeException)
53 {
54     mxProps->setPropertyValue(
55         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ),
56         uno::Any( rName ) );
57 }
58 
getSize()59 double SAL_CALL VbaNewFont::getSize() throw (uno::RuntimeException)
60 {
61     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ) );
62     return aAny.get< float >();
63 }
64 
setSize(double fSize)65 void SAL_CALL VbaNewFont::setSize( double fSize ) throw (uno::RuntimeException)
66 {
67     mxProps->setPropertyValue(
68         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ),
69         uno::Any( static_cast< float >( fSize ) ) );
70 }
71 
getCharset()72 sal_Int16 SAL_CALL VbaNewFont::getCharset() throw (uno::RuntimeException)
73 {
74     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ) );
75     return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding >( aAny.get< sal_Int16 >() ) );
76 }
77 
setCharset(sal_Int16 nCharset)78 void SAL_CALL VbaNewFont::setCharset( sal_Int16 nCharset ) throw (uno::RuntimeException)
79 {
80     rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW;
81     if( (0 <= nCharset) && (nCharset <= SAL_MAX_UINT8) )
82         eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( nCharset ) );
83     if( eFontEnc == RTL_TEXTENCODING_DONTKNOW )
84         throw uno::RuntimeException();
85     mxProps->setPropertyValue(
86         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ),
87         uno::Any( static_cast< sal_Int16 >( eFontEnc ) ) );
88 }
89 
getWeight()90 sal_Int16 SAL_CALL VbaNewFont::getWeight() throw (uno::RuntimeException)
91 {
92     return getBold() ? 700 : 400;
93 }
94 
setWeight(sal_Int16 nWeight)95 void SAL_CALL VbaNewFont::setWeight( sal_Int16 nWeight ) throw (uno::RuntimeException)
96 {
97     setBold( nWeight >= 700 );
98 }
99 
getBold()100 sal_Bool SAL_CALL VbaNewFont::getBold() throw (uno::RuntimeException)
101 {
102     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ) );
103     return aAny.get< float >() > awt::FontWeight::NORMAL;
104 }
105 
setBold(sal_Bool bBold)106 void SAL_CALL VbaNewFont::setBold( sal_Bool bBold ) throw (uno::RuntimeException)
107 {
108     mxProps->setPropertyValue(
109         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ),
110         uno::Any( bBold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) );
111 }
112 
getItalic()113 sal_Bool SAL_CALL VbaNewFont::getItalic() throw (uno::RuntimeException)
114 {
115     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ) );
116     return aAny.get< awt::FontSlant >() != awt::FontSlant_NONE;
117 }
118 
setItalic(sal_Bool bItalic)119 void SAL_CALL VbaNewFont::setItalic( sal_Bool bItalic ) throw (uno::RuntimeException)
120 {
121     mxProps->setPropertyValue(
122         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ),
123         uno::Any( bItalic ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) );
124 }
125 
getUnderline()126 sal_Bool SAL_CALL VbaNewFont::getUnderline() throw (uno::RuntimeException)
127 {
128     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ) );
129     return aAny.get< sal_Int16 >() != awt::FontUnderline::NONE;
130 }
131 
setUnderline(sal_Bool bUnderline)132 void SAL_CALL VbaNewFont::setUnderline( sal_Bool bUnderline ) throw (uno::RuntimeException)
133 {
134     mxProps->setPropertyValue(
135         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ),
136         uno::Any( bUnderline ? awt::FontUnderline::SINGLE : awt::FontUnderline::NONE ) );
137 }
138 
getStrikethrough()139 sal_Bool SAL_CALL VbaNewFont::getStrikethrough() throw (uno::RuntimeException)
140 {
141     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ) );
142     return aAny.get< sal_Int16 >() != awt::FontStrikeout::NONE;
143 }
144 
setStrikethrough(sal_Bool bStrikethrough)145 void SAL_CALL VbaNewFont::setStrikethrough( sal_Bool bStrikethrough ) throw (uno::RuntimeException)
146 {
147     mxProps->setPropertyValue(
148         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ),
149         uno::Any( bStrikethrough ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) );
150 }
151 
152 // XHelperInterface
153 
154 VBAHELPER_IMPL_XHELPERINTERFACE( VbaNewFont, "ooo.vba.msforms.NewFont" )
155 
156 // ============================================================================
157