LibreOffice Module vbahelper (master) 1
vbanewfont.cxx
Go to the documentation of this file.
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#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>
27
28using namespace ::com::sun::star;
29using namespace ::ooo::vba;
30
31
33 const uno::Reference< beans::XPropertySet >& rxModelProps ) :
34 mxProps( rxModelProps, uno::UNO_SET_THROW )
35{
36}
37
38// XNewFont attributes
39
40OUString SAL_CALL VbaNewFont::getName()
41{
42 uno::Any aAny = mxProps->getPropertyValue( "FontName" );
43 return aAny.get< OUString >();
44}
45
46void SAL_CALL VbaNewFont::setName( const OUString& rName )
47{
48 mxProps->setPropertyValue( "FontName" , uno::Any( rName ) );
49}
50
51double SAL_CALL VbaNewFont::getSize()
52{
53 uno::Any aAny = mxProps->getPropertyValue( "FontHeight" );
54 return aAny.get< float >();
55}
56
57void SAL_CALL VbaNewFont::setSize( double fSize )
58{
59 mxProps->setPropertyValue( "FontHeight" , uno::Any( static_cast< float >( fSize ) ) );
60}
61
62sal_Int16 SAL_CALL VbaNewFont::getCharset()
63{
64 uno::Any aAny = mxProps->getPropertyValue( "FontCharset" );
65 return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding >( aAny.get< sal_Int16 >() ) );
66}
67
68void SAL_CALL VbaNewFont::setCharset( sal_Int16 nCharset )
69{
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("an unknown or missing encoding");
75 mxProps->setPropertyValue( "FontCharset" , uno::Any( static_cast< sal_Int16 >( eFontEnc ) ) );
76}
77
78sal_Int16 SAL_CALL VbaNewFont::getWeight()
79{
80 return getBold() ? 700 : 400;
81}
82
83void SAL_CALL VbaNewFont::setWeight( sal_Int16 nWeight )
84{
85 setBold( nWeight >= 700 );
86}
87
89{
90 uno::Any aAny = mxProps->getPropertyValue( "FontWeight" );
91 return aAny.get< float >() > awt::FontWeight::NORMAL;
92}
93
94void SAL_CALL VbaNewFont::setBold( sal_Bool bBold )
95{
96 mxProps->setPropertyValue( "FontWeight" , uno::Any( bBold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) );
97}
98
100{
101 uno::Any aAny = mxProps->getPropertyValue( "FontSlant" );
102 return aAny.get< awt::FontSlant >() != awt::FontSlant_NONE;
103}
104
105void SAL_CALL VbaNewFont::setItalic( sal_Bool bItalic )
106{
107 mxProps->setPropertyValue( "FontSlant" , uno::Any( bItalic ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) );
108}
109
111{
112 uno::Any aAny = mxProps->getPropertyValue("FontUnderline" );
113 return aAny.get< sal_Int16 >() != awt::FontUnderline::NONE;
114}
115
116void SAL_CALL VbaNewFont::setUnderline( sal_Bool bUnderline )
117{
118 mxProps->setPropertyValue("FontUnderline" , uno::Any( bUnderline ? awt::FontUnderline::SINGLE : awt::FontUnderline::NONE ) );
119}
120
122{
123 uno::Any aAny = mxProps->getPropertyValue( "FontStrikeout" );
124 return aAny.get< sal_Int16 >() != awt::FontStrikeout::NONE;
125}
126
127void SAL_CALL VbaNewFont::setStrikethrough( sal_Bool bStrikethrough )
128{
129 mxProps->setPropertyValue( "FontStrikeout" ,uno::Any( bStrikethrough ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) );
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setWeight(sal_Int16 nWeight) override
Definition: vbanewfont.cxx:83
css::uno::Reference< css::beans::XPropertySet > mxProps
Definition: vbanewfont.hxx:52
virtual void SAL_CALL setItalic(sal_Bool bItalic) override
Definition: vbanewfont.cxx:105
virtual sal_Bool SAL_CALL getUnderline() override
Definition: vbanewfont.cxx:110
virtual void SAL_CALL setSize(double fSize) override
Definition: vbanewfont.cxx:57
virtual void SAL_CALL setName(const OUString &rName) override
Definition: vbanewfont.cxx:46
virtual OUString SAL_CALL getName() override
Definition: vbanewfont.cxx:40
virtual void SAL_CALL setUnderline(sal_Bool bUnderline) override
Definition: vbanewfont.cxx:116
VbaNewFont(const css::uno::Reference< css::beans::XPropertySet > &rxModelProps)
Definition: vbanewfont.cxx:32
virtual void SAL_CALL setCharset(sal_Int16 nCharset) override
Definition: vbanewfont.cxx:68
virtual void SAL_CALL setStrikethrough(sal_Bool bStrikethrough) override
Definition: vbanewfont.cxx:127
virtual double SAL_CALL getSize() override
Definition: vbanewfont.cxx:51
virtual sal_Bool SAL_CALL getBold() override
Definition: vbanewfont.cxx:88
virtual sal_Int16 SAL_CALL getWeight() override
Definition: vbanewfont.cxx:78
virtual sal_Bool SAL_CALL getItalic() override
Definition: vbanewfont.cxx:99
virtual void SAL_CALL setBold(sal_Bool bBold) override
Definition: vbanewfont.cxx:94
virtual sal_Int16 SAL_CALL getCharset() override
Definition: vbanewfont.cxx:62
virtual sal_Bool SAL_CALL getStrikethrough() override
Definition: vbanewfont.cxx:121
#define SAL_MAX_UINT8
unsigned char sal_uInt8
unsigned char sal_Bool