Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / helper / characterattributeshelper.cxx
blobcf8cf794c2d5c0287786f5f9d6e9a1000472baac
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 <accessibility/helper/characterattributeshelper.hxx>
21 #include <tools/gen.hxx>
23 using namespace ::com::sun::star::uno;
24 using namespace ::com::sun::star::beans;
27 CharacterAttributesHelper::CharacterAttributesHelper( const vcl::Font& rFont, sal_Int32 nBackColor, sal_Int32 nColor )
29 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharBackColor" ), makeAny( (sal_Int32) nBackColor ) ) );
30 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharColor" ), makeAny( (sal_Int32) nColor ) ) );
31 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharFontCharSet" ), makeAny( (sal_Int16) rFont.GetCharSet() ) ) );
32 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharFontFamily" ), makeAny( (sal_Int16) rFont.GetFamily() ) ) );
33 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharFontName" ), makeAny( rFont.GetName() ) ) );
34 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharFontPitch" ), makeAny( (sal_Int16) rFont.GetPitch() ) ) );
35 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharFontStyleName" ), makeAny( rFont.GetStyleName() ) ) );
36 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharHeight" ), makeAny( (sal_Int16) rFont.GetSize().Height() ) ) );
37 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharScaleWidth" ), makeAny( (sal_Int16) rFont.GetSize().Width() ) ) );
38 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharStrikeout" ), makeAny( (sal_Int16) rFont.GetStrikeout() ) ) );
39 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharUnderline" ), makeAny( (sal_Int16) rFont.GetUnderline() ) ) );
40 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharWeight" ), makeAny( (float) rFont.GetWeight() ) ) );
41 m_aAttributeMap.insert( AttributeMap::value_type( OUString( "CharPosture" ), makeAny( (sal_Int16)rFont.GetItalic() ) ) );
45 CharacterAttributesHelper::~CharacterAttributesHelper()
47 m_aAttributeMap.clear();
51 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes()
53 Sequence< PropertyValue > aValues( m_aAttributeMap.size() );
54 PropertyValue* pValues = aValues.getArray();
56 for ( AttributeMap::iterator aIt = m_aAttributeMap.begin(); aIt != m_aAttributeMap.end(); ++aIt, ++pValues )
58 pValues->Name = aIt->first;
59 pValues->Handle = (sal_Int32) -1;
60 pValues->Value = aIt->second;
61 pValues->State = PropertyState_DIRECT_VALUE;
64 return aValues;
68 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes( const Sequence< OUString >& aRequestedAttributes )
70 Sequence< PropertyValue > aValues;
71 sal_Int32 nLength = aRequestedAttributes.getLength();
73 if ( nLength != 0 )
75 const OUString* pNames = aRequestedAttributes.getConstArray();
76 AttributeMap aAttributeMap;
78 for ( sal_Int32 i = 0; i < nLength; ++i )
80 AttributeMap::iterator aFound = m_aAttributeMap.find( pNames[i] );
81 if ( aFound != m_aAttributeMap.end() )
82 aAttributeMap.insert( *aFound );
85 aValues.realloc( aAttributeMap.size() );
86 PropertyValue* pValues = aValues.getArray();
88 for ( AttributeMap::iterator aIt = aAttributeMap.begin(); aIt != aAttributeMap.end(); ++aIt, ++pValues )
90 pValues->Name = aIt->first;
91 pValues->Handle = (sal_Int32) -1;
92 pValues->Value = aIt->second;
93 pValues->State = PropertyState_DIRECT_VALUE;
96 else
98 aValues = GetCharacterAttributes();
101 return aValues;
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */