LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / accessibility / source / helper / characterattributeshelper.cxx
blob9cbeaaee8a7c85cec4a10942da71f02a6c4ebb4c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <comphelper/sequence.hxx>
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::beans;
28 CharacterAttributesHelper::CharacterAttributesHelper( const vcl::Font& rFont, sal_Int32 nBackColor, sal_Int32 nColor )
30 m_aAttributeMap.emplace( OUString( "CharBackColor" ), Any( nBackColor ) );
31 m_aAttributeMap.emplace( OUString( "CharColor" ), Any( nColor ) );
32 m_aAttributeMap.emplace( OUString( "CharFontCharSet" ), Any( static_cast<sal_Int16>(rFont.GetCharSet()) ) );
33 m_aAttributeMap.emplace( OUString( "CharFontFamily" ), Any( static_cast<sal_Int16>(rFont.GetFamilyType()) ) );
34 m_aAttributeMap.emplace( OUString( "CharFontName" ), Any( rFont.GetFamilyName() ) );
35 m_aAttributeMap.emplace( OUString( "CharFontPitch" ), Any( static_cast<sal_Int16>(rFont.GetPitch()) ) );
36 m_aAttributeMap.emplace( OUString( "CharFontStyleName" ), Any( rFont.GetStyleName() ) );
37 m_aAttributeMap.emplace( OUString( "CharHeight" ), Any( static_cast<sal_Int16>(rFont.GetFontSize().Height()) ) );
38 m_aAttributeMap.emplace( OUString( "CharScaleWidth" ), Any( static_cast<sal_Int16>(rFont.GetFontSize().Width()) ) );
39 m_aAttributeMap.emplace( OUString( "CharStrikeout" ), Any( static_cast<sal_Int16>(rFont.GetStrikeout()) ) );
40 m_aAttributeMap.emplace( OUString( "CharUnderline" ), Any( static_cast<sal_Int16>(rFont.GetUnderline()) ) );
41 m_aAttributeMap.emplace( OUString( "CharWeight" ), Any( static_cast<float>(rFont.GetWeight()) ) );
42 m_aAttributeMap.emplace( OUString( "CharPosture" ), Any( static_cast<sal_Int16>(rFont.GetItalic()) ) );
46 std::vector< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes()
48 std::vector< PropertyValue > aValues;
49 aValues.reserve( m_aAttributeMap.size() );
51 for ( const auto& aIt : m_aAttributeMap)
53 aValues.emplace_back(aIt.first, sal_Int32(-1), aIt.second, PropertyState_DIRECT_VALUE);
56 return aValues;
60 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes( const css::uno::Sequence< OUString >& aRequestedAttributes )
62 if ( !aRequestedAttributes.hasElements() )
63 return comphelper::containerToSequence(GetCharacterAttributes());
65 std::vector< PropertyValue > aValues;
67 for ( const auto& aRequestedAttribute: aRequestedAttributes)
69 AttributeMap::iterator aFound = m_aAttributeMap.find( aRequestedAttribute );
70 if ( aFound != m_aAttributeMap.end() )
71 aValues.emplace_back(aFound->first, sal_Int32(-1), aFound->second, PropertyState_DIRECT_VALUE);
74 return comphelper::containerToSequence(aValues);
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */