1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_accessibility.hxx" 26 #include <accessibility/helper/characterattributeshelper.hxx> 27 28 using namespace ::com::sun::star::uno; 29 using namespace ::com::sun::star::beans; 30 31 32 // ----------------------------------------------------------------------------- 33 // CharacterAttributesHelper 34 // ----------------------------------------------------------------------------- 35 36 CharacterAttributesHelper::CharacterAttributesHelper( const Font& rFont, sal_Int32 nBackColor, sal_Int32 nColor ) 37 { 38 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharBackColor" ), makeAny( (sal_Int32) nBackColor ) ) ); 39 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharColor" ), makeAny( (sal_Int32) nColor ) ) ); 40 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontCharSet" ), makeAny( (sal_Int16) rFont.GetCharSet() ) ) ); 41 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontFamily" ), makeAny( (sal_Int16) rFont.GetFamily() ) ) ); 42 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontName" ), makeAny( (::rtl::OUString) rFont.GetName() ) ) ); 43 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontPitch" ), makeAny( (sal_Int16) rFont.GetPitch() ) ) ); 44 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontStyleName" ), makeAny( (::rtl::OUString) rFont.GetStyleName() ) ) ); 45 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharHeight" ), makeAny( (sal_Int16) rFont.GetSize().Height() ) ) ); 46 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharScaleWidth" ), makeAny( (sal_Int16) rFont.GetSize().Width() ) ) ); 47 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharStrikeout" ), makeAny( (sal_Int16) rFont.GetStrikeout() ) ) ); 48 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharUnderline" ), makeAny( (sal_Int16) rFont.GetUnderline() ) ) ); 49 m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharWeight" ), makeAny( (float) rFont.GetWeight() ) ) ); 50 } 51 52 // ----------------------------------------------------------------------------- 53 54 CharacterAttributesHelper::~CharacterAttributesHelper() 55 { 56 m_aAttributeMap.clear(); 57 } 58 59 // ----------------------------------------------------------------------------- 60 61 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes() 62 { 63 Sequence< PropertyValue > aValues( m_aAttributeMap.size() ); 64 PropertyValue* pValues = aValues.getArray(); 65 66 for ( AttributeMap::iterator aIt = m_aAttributeMap.begin(); aIt != m_aAttributeMap.end(); ++aIt, ++pValues ) 67 { 68 pValues->Name = aIt->first; 69 pValues->Handle = (sal_Int32) -1; 70 pValues->Value = aIt->second; 71 pValues->State = PropertyState_DIRECT_VALUE; 72 } 73 74 return aValues; 75 } 76 77 // ----------------------------------------------------------------------------- 78 79 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes( const Sequence< ::rtl::OUString >& aRequestedAttributes ) 80 { 81 Sequence< PropertyValue > aValues; 82 sal_Int32 nLength = aRequestedAttributes.getLength(); 83 84 if ( nLength != 0 ) 85 { 86 const ::rtl::OUString* pNames = aRequestedAttributes.getConstArray(); 87 AttributeMap aAttributeMap; 88 89 for ( sal_Int32 i = 0; i < nLength; ++i ) 90 { 91 AttributeMap::iterator aFound = m_aAttributeMap.find( pNames[i] ); 92 if ( aFound != m_aAttributeMap.end() ) 93 aAttributeMap.insert( *aFound ); 94 } 95 96 aValues.realloc( aAttributeMap.size() ); 97 PropertyValue* pValues = aValues.getArray(); 98 99 for ( AttributeMap::iterator aIt = aAttributeMap.begin(); aIt != aAttributeMap.end(); ++aIt, ++pValues ) 100 { 101 pValues->Name = aIt->first; 102 pValues->Handle = (sal_Int32) -1; 103 pValues->Value = aIt->second; 104 pValues->State = PropertyState_DIRECT_VALUE; 105 } 106 } 107 else 108 { 109 aValues = GetCharacterAttributes(); 110 } 111 112 return aValues; 113 } 114 115 // ----------------------------------------------------------------------------- 116