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 "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>
28 using namespace ::ooo::vba
;
29 using namespace ::com::sun::star
;
31 const uno::Any
aLongAnyTrue( sal_Int16(-1) );
32 const uno::Any
aLongAnyFalse( sal_Int16( 0 ) );
44 MapPair
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
},
65 typedef std::unordered_map
< sal_Int32
, sal_Int32
> ConstToConst
;
71 ConstToConst m_MSO2OOO
;
72 ConstToConst m_OOO2MSO
;
76 for ( auto const & index
: UnderLineTable
)
78 m_MSO2OOO
[ index
.nMSOConst
] = index
.nOOOConst
;
79 m_OOO2MSO
[ index
.nOOOConst
] = index
.nMSOConst
;
83 static OUString
propName()
85 return "CharUnderline";
88 static UnderLineMapper
& instance()
90 static UnderLineMapper theMapper
;
94 /// @throws lang::IllegalArgumentException
95 sal_Int32
getOOOFromMSO( sal_Int32 nMSOConst
)
97 ConstToConst::iterator it
= m_MSO2OOO
.find( nMSOConst
);
98 if ( it
== m_MSO2OOO
.end() )
99 throw lang::IllegalArgumentException();
102 /// @throws lang::IllegalArgumentException
103 sal_Int32
getMSOFromOOO( sal_Int32 nOOOConst
)
105 ConstToConst::iterator it
= m_OOO2MSO
.find( nOOOConst
);
106 if ( it
== m_OOO2MSO
.end() )
107 throw lang::IllegalArgumentException();
114 SwVbaFont::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
)
120 SwVbaFont::getUnderline()
122 sal_Int32 nOOVal
= 0;
123 mxFont
->getPropertyValue( UnderLineMapper::propName() ) >>= nOOVal
;
124 return uno::Any( UnderLineMapper::instance().getMSOFromOOO( nOOVal
) );
128 SwVbaFont::setUnderline( const uno::Any
& _underline
)
130 sal_Int32 nMSOVal
= 0;
132 if ( _underline
>>= nMSOVal
)
134 sal_Int32 nOOVal
= UnderLineMapper::instance().getOOOFromMSO( nMSOVal
);
135 mxFont
->setPropertyValue( UnderLineMapper::propName(), uno::Any( nOOVal
) );
140 SwVbaFont::getServiceImplName()
146 SwVbaFont::getColorIndex()
148 sal_Int32 nColor
= 0;
150 getColor() >>= nColor
;
151 sal_Int32 nElems
= mxPalette
->getCount();
152 sal_Int32 nIndex
= 0;
153 for ( sal_Int32 count
=0; count
<nElems
; ++count
)
155 sal_Int32 nPaletteColor
= 0;
156 mxPalette
->getByIndex( count
) >>= nPaletteColor
;
157 if ( nPaletteColor
== nColor
)
163 return uno::Any( nIndex
);
166 SwVbaFont::getSubscript()
169 SwVbaFont_BASE::getSubscript() >>= bRes
;
172 return aLongAnyFalse
;
176 SwVbaFont::getSuperscript()
179 SwVbaFont_BASE::getSuperscript() >>= bRes
;
182 return aLongAnyFalse
;
189 SwVbaFont_BASE::getBold() >>= bRes
;
192 return aLongAnyFalse
;
196 SwVbaFont::getItalic()
199 SwVbaFont_BASE::getItalic() >>= bRes
;
202 return aLongAnyFalse
;
206 SwVbaFont::getStrikethrough()
209 SwVbaFont_BASE::getStrikethrough() >>= bRes
;
212 return aLongAnyFalse
;
216 SwVbaFont::getShadow()
219 SwVbaFont_BASE::getShadow() >>= bRes
;
222 return aLongAnyFalse
;
225 uno::Sequence
< OUString
>
226 SwVbaFont::getServiceNames()
228 static uno::Sequence
< OUString
> const aServiceNames
232 return aServiceNames
;
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */