LibreOffice Module sw (master) 1
vbafont.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 "vbafont.hxx"
21#include <com/sun/star/awt/FontUnderline.hpp>
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/container/XIndexAccess.hpp>
24#include <ooo/vba/word/WdUnderline.hpp>
25#include <sal/macros.h>
26#include <unordered_map>
27
28using namespace ::ooo::vba;
29using namespace ::com::sun::star;
30
31const uno::Any aLongAnyTrue( sal_Int16(-1) );
32const uno::Any aLongAnyFalse( sal_Int16( 0 ) );
33
34namespace {
35
36struct MapPair
37{
38 sal_Int32 nMSOConst;
39 sal_Int32 nOOOConst;
40};
41
42}
43
44MapPair const UnderLineTable[] = {
45 { word::WdUnderline::wdUnderlineNone, css::awt::FontUnderline::NONE },
46 { word::WdUnderline::wdUnderlineSingle, css::awt::FontUnderline::SINGLE },
47 { word::WdUnderline::wdUnderlineWords, css::awt::FontUnderline::SINGLE },
48 { word::WdUnderline::wdUnderlineDouble, css::awt::FontUnderline::DOUBLE },
49 { word::WdUnderline::wdUnderlineDotted, css::awt::FontUnderline::DOTTED },
50 { word::WdUnderline::wdUnderlineThick, css::awt::FontUnderline::BOLDDASH },
51 { word::WdUnderline::wdUnderlineDash, css::awt::FontUnderline::DASH },
52 { word::WdUnderline::wdUnderlineDotDash, css::awt::FontUnderline::DASHDOT },
53 { word::WdUnderline::wdUnderlineDotDotDash, css::awt::FontUnderline::DASHDOTDOT },
54 { word::WdUnderline::wdUnderlineWavy, css::awt::FontUnderline::WAVE },
55 { word::WdUnderline::wdUnderlineDottedHeavy, css::awt::FontUnderline::BOLDDOTTED },
56 { word::WdUnderline::wdUnderlineDashHeavy, css::awt::FontUnderline::BOLDDASH },
57 { word::WdUnderline::wdUnderlineDotDashHeavy, css::awt::FontUnderline::BOLDDASHDOT },
58 { word::WdUnderline::wdUnderlineDotDotDashHeavy, css::awt::FontUnderline::BOLDDASHDOTDOT },
59 { word::WdUnderline::wdUnderlineWavyHeavy, css::awt::FontUnderline::BOLDWAVE },
60 { word::WdUnderline::wdUnderlineDashLong, css::awt::FontUnderline::LONGDASH },
61 { word::WdUnderline::wdUnderlineWavyDouble, css::awt::FontUnderline::DOUBLEWAVE },
62 { word::WdUnderline::wdUnderlineDashLongHeavy, css::awt::FontUnderline::BOLDLONGDASH },
63};
64
65typedef std::unordered_map< sal_Int32, sal_Int32 > ConstToConst;
66
67namespace {
68
69class UnderLineMapper
70{
71 ConstToConst m_MSO2OOO;
72 ConstToConst m_OOO2MSO;
73private:
74 UnderLineMapper()
75 {
76 for ( auto const & index: UnderLineTable )
77 {
78 m_MSO2OOO[ index.nMSOConst ] = index.nOOOConst;
79 m_OOO2MSO[ index.nOOOConst ] = index.nMSOConst;
80 }
81 }
82public:
83 static OUString propName()
84 {
85 return "CharUnderline";
86 }
87
88 static UnderLineMapper& instance()
89 {
90 static UnderLineMapper theMapper;
91 return theMapper;
92 }
93
95 sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst )
96 {
97 ConstToConst::iterator it = m_MSO2OOO.find( nMSOConst );
98 if ( it == m_MSO2OOO.end() )
99 throw lang::IllegalArgumentException();
100 return it->second;
101 }
103 sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst )
104 {
105 ConstToConst::iterator it = m_OOO2MSO.find( nOOOConst );
106 if ( it == m_OOO2MSO.end() )
107 throw lang::IllegalArgumentException();
108 return it->second;
109 }
110};
111
112}
113
114SwVbaFont::SwVbaFont( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xPalette, uno::Reference< css::beans::XPropertySet > const & xPropertySet )
115 : SwVbaFont_BASE( xParent, xContext, xPalette, xPropertySet, Component::WORD )
116{
117}
118
119uno::Any SAL_CALL
121{
122 sal_Int32 nOOVal = 0;
123 mxFont->getPropertyValue( UnderLineMapper::propName() ) >>= nOOVal;
124 return uno::Any( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) );
125}
126
127void SAL_CALL
129{
130 sal_Int32 nMSOVal = 0;
131
132 if ( _underline >>= nMSOVal )
133 {
134 sal_Int32 nOOVal = UnderLineMapper::instance().getOOOFromMSO( nMSOVal );
135 mxFont->setPropertyValue( UnderLineMapper::propName(), uno::Any( nOOVal ) );
136 }
137}
138
139OUString
141{
142 return "SwVbaFont";
143}
144
145uno::Any SAL_CALL
147{
148 sal_Int32 nColor = 0;
149
150 getColor() >>= nColor;
151 sal_Int32 nElems = mxPalette->getCount();
152 sal_Int32 nIndex = 0;
153 for ( sal_Int32 count=0; count<nElems; ++count )
154 {
155 sal_Int32 nPaletteColor = 0;
156 mxPalette->getByIndex( count ) >>= nPaletteColor;
157 if ( nPaletteColor == nColor )
158 {
159 nIndex = count;
160 break;
161 }
162 }
163 return uno::Any( nIndex );
164}
165uno::Any SAL_CALL
167{
168 bool bRes = false;
169 SwVbaFont_BASE::getSubscript() >>= bRes;
170 if ( bRes )
171 return aLongAnyTrue;
172 return aLongAnyFalse;
173}
174
175uno::Any SAL_CALL
177{
178 bool bRes = false;
179 SwVbaFont_BASE::getSuperscript() >>= bRes;
180 if ( bRes )
181 return aLongAnyTrue;
182 return aLongAnyFalse;
183}
184
185uno::Any SAL_CALL
187{
188 bool bRes = false;
189 SwVbaFont_BASE::getBold() >>= bRes;
190 if ( bRes )
191 return aLongAnyTrue;
192 return aLongAnyFalse;
193}
194
195uno::Any SAL_CALL
197{
198 bool bRes = false;
199 SwVbaFont_BASE::getItalic() >>= bRes;
200 if ( bRes )
201 return aLongAnyTrue;
202 return aLongAnyFalse;
203}
204
205uno::Any SAL_CALL
207{
208 bool bRes = false;
209 SwVbaFont_BASE::getStrikethrough() >>= bRes;
210 if ( bRes )
211 return aLongAnyTrue;
212 return aLongAnyFalse;
213}
214
215uno::Any SAL_CALL
217{
218 bool bRes = false;
219 SwVbaFont_BASE::getShadow() >>= bRes;
220 if ( bRes )
221 return aLongAnyTrue;
222 return aLongAnyFalse;
223}
224
225uno::Sequence< OUString >
227{
228 static uno::Sequence< OUString > const aServiceNames
229 {
230 "ooo.vba.word.Font"
231 };
232 return aServiceNames;
233}
234
235/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any SAL_CALL getBold() override
Definition: vbafont.cxx:186
virtual void SAL_CALL setUnderline(const css::uno::Any &_underline) override
Definition: vbafont.cxx:128
virtual css::uno::Any SAL_CALL getColorIndex() override
Definition: vbafont.cxx:146
virtual css::uno::Any SAL_CALL getUnderline() override
Definition: vbafont.cxx:120
virtual css::uno::Any SAL_CALL getSubscript() override
Definition: vbafont.cxx:166
virtual css::uno::Any SAL_CALL getStrikethrough() override
Definition: vbafont.cxx:206
virtual OUString getServiceImplName() override
Definition: vbafont.cxx:140
virtual css::uno::Any SAL_CALL getShadow() override
Definition: vbafont.cxx:216
virtual css::uno::Any SAL_CALL getItalic() override
Definition: vbafont.cxx:196
SwVbaFont(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xPalette, css::uno::Reference< css::beans::XPropertySet > const &xPropertySet)
Definition: vbafont.cxx:114
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbafont.cxx:226
virtual css::uno::Any SAL_CALL getSuperscript() override
Definition: vbafont.cxx:176
Sequence< OUString > aServiceNames
sal_Int32 nIndex
unsigned short WORD
index
uno::Reference< rendering::XCanvasFont > mxFont
::std::pair< MetaAction *, int > Component
std::unordered_map< sal_Int32, sal_Int32 > ConstToConst
Definition: vbafont.cxx:65
const uno::Any aLongAnyTrue(sal_Int16(-1))
MapPair const UnderLineTable[]
Definition: vbafont.cxx:44
const uno::Any aLongAnyFalse(sal_Int16(0))
cppu::ImplInheritanceHelper< VbaFontBase, ov::word::XFont > SwVbaFont_BASE
Definition: vbafont.hxx:25