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 <helper/characterattributeshelper.hxx>
21 #include <tools/gen.hxx>
22 #include <vcl/unohelp.hxx>
23 #include <comphelper/sequence.hxx>
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::beans
;
29 CharacterAttributesHelper::CharacterAttributesHelper( const vcl::Font
& rFont
, sal_Int32 nBackColor
, sal_Int32 nColor
)
31 m_aAttributeMap
.emplace( u
"CharBackColor"_ustr
, Any( nBackColor
) );
32 m_aAttributeMap
.emplace( u
"CharColor"_ustr
, Any( nColor
) );
33 m_aAttributeMap
.emplace( u
"CharFontCharSet"_ustr
, Any( static_cast<sal_Int16
>(rFont
.GetCharSet()) ) );
34 m_aAttributeMap
.emplace( u
"CharFontFamily"_ustr
, Any( static_cast<sal_Int16
>(rFont
.GetFamilyType()) ) );
35 m_aAttributeMap
.emplace( u
"CharFontName"_ustr
, Any( rFont
.GetFamilyName() ) );
36 m_aAttributeMap
.emplace( u
"CharFontPitch"_ustr
, Any( static_cast<sal_Int16
>(rFont
.GetPitch()) ) );
37 m_aAttributeMap
.emplace( u
"CharFontStyleName"_ustr
, Any( rFont
.GetStyleName() ) );
38 m_aAttributeMap
.emplace( u
"CharHeight"_ustr
, Any( static_cast<sal_Int16
>(rFont
.GetFontSize().Height()) ) );
39 m_aAttributeMap
.emplace( u
"CharScaleWidth"_ustr
, Any( static_cast<sal_Int16
>(rFont
.GetFontSize().Width()) ) );
40 m_aAttributeMap
.emplace( u
"CharStrikeout"_ustr
, Any( static_cast<sal_Int16
>(rFont
.GetStrikeout()) ) );
41 m_aAttributeMap
.emplace( u
"CharUnderline"_ustr
, Any( static_cast<sal_Int16
>(rFont
.GetUnderline()) ) );
42 m_aAttributeMap
.emplace( u
"CharWeight"_ustr
, Any( static_cast<float>(rFont
.GetWeight()) ) );
43 m_aAttributeMap
.emplace( u
"CharPosture"_ustr
, Any( vcl::unohelper::ConvertFontSlant(rFont
.GetItalic()) ) );
47 std::vector
< PropertyValue
> CharacterAttributesHelper::GetCharacterAttributes()
49 std::vector
< PropertyValue
> aValues
;
50 aValues
.reserve( m_aAttributeMap
.size() );
52 for ( const auto& aIt
: m_aAttributeMap
)
54 aValues
.emplace_back(aIt
.first
, sal_Int32(-1), aIt
.second
, PropertyState_DIRECT_VALUE
);
61 Sequence
< PropertyValue
> CharacterAttributesHelper::GetCharacterAttributes( const css::uno::Sequence
< OUString
>& aRequestedAttributes
)
63 if ( !aRequestedAttributes
.hasElements() )
64 return comphelper::containerToSequence(GetCharacterAttributes());
66 std::vector
< PropertyValue
> aValues
;
68 for ( const auto& aRequestedAttribute
: aRequestedAttributes
)
70 AttributeMap::iterator aFound
= m_aAttributeMap
.find( aRequestedAttribute
);
71 if ( aFound
!= m_aAttributeMap
.end() )
72 aValues
.emplace_back(aFound
->first
, sal_Int32(-1), aFound
->second
, PropertyState_DIRECT_VALUE
);
75 return comphelper::containerToSequence(aValues
);
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */