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 
CharacterAttributesHelper(const Font & rFont,sal_Int32 nBackColor,sal_Int32 nColor)36 CharacterAttributesHelper::CharacterAttributesHelper( const Font& rFont, sal_Int32 nBackColor, sal_Int32 nColor )
37 {
38 	// MT: IA2 CWS commented out CharFontCharSet, CharFontFamily, CharFontPitch, CharFontStyleName, CharScaleWidth - any AT interested in this?
39 
40     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharBackColor" ), makeAny( (sal_Int32) nBackColor ) ) );
41     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharColor" ), makeAny( (sal_Int32) nColor ) ) );
42     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontCharSet" ), makeAny( (sal_Int16) rFont.GetCharSet() ) ) );
43     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontFamily" ), makeAny( (sal_Int16) rFont.GetFamily() ) ) );
44     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontName" ), makeAny( (::rtl::OUString) rFont.GetName() ) ) );
45     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontPitch" ), makeAny( (sal_Int16) rFont.GetPitch() ) ) );
46     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontStyleName" ), makeAny( (::rtl::OUString) rFont.GetStyleName() ) ) );
47     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharHeight" ), makeAny( (sal_Int16) rFont.GetSize().Height() ) ) );
48     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharScaleWidth" ), makeAny( (sal_Int16) rFont.GetSize().Width() ) ) );
49     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharStrikeout" ), makeAny( (sal_Int16) rFont.GetStrikeout() ) ) );
50     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharUnderline" ), makeAny( (sal_Int16) rFont.GetUnderline() ) ) );
51     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharWeight" ), makeAny( (float) rFont.GetWeight() ) ) );
52     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharPosture" ), makeAny( (sal_Int16)rFont.GetItalic() ) ) );
53 	// MT: Introduced with IA2 CWS, but adjustment is not a char attr...
54     // m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "ParaAdjust" ), makeAny( nAjust ) ) );
55 }
56 
57 // -----------------------------------------------------------------------------
58 
~CharacterAttributesHelper()59 CharacterAttributesHelper::~CharacterAttributesHelper()
60 {
61     m_aAttributeMap.clear();
62 }
63 
64 // -----------------------------------------------------------------------------
65 
GetCharacterAttributes()66 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes()
67 {
68 	Sequence< PropertyValue > aValues( m_aAttributeMap.size() );
69 	PropertyValue* pValues = aValues.getArray();
70 
71     for ( AttributeMap::iterator aIt = m_aAttributeMap.begin(); aIt != m_aAttributeMap.end(); ++aIt, ++pValues )
72 	{
73 		pValues->Name   = aIt->first;
74 		pValues->Handle = (sal_Int32) -1;
75 		pValues->Value  = aIt->second;
76 		pValues->State  = PropertyState_DIRECT_VALUE;
77 	}
78 
79     return aValues;
80 }
81 
82 // -----------------------------------------------------------------------------
83 
GetCharacterAttributes(const Sequence<::rtl::OUString> & aRequestedAttributes)84 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes( const Sequence< ::rtl::OUString >& aRequestedAttributes )
85 {
86 	Sequence< PropertyValue > aValues;
87     sal_Int32 nLength = aRequestedAttributes.getLength();
88 
89     if ( nLength != 0 )
90     {
91         const ::rtl::OUString* pNames = aRequestedAttributes.getConstArray();
92         AttributeMap aAttributeMap;
93 
94         for ( sal_Int32 i = 0; i < nLength; ++i )
95         {
96             AttributeMap::iterator aFound = m_aAttributeMap.find( pNames[i] );
97             if ( aFound != m_aAttributeMap.end() )
98                 aAttributeMap.insert( *aFound );
99         }
100 
101         aValues.realloc( aAttributeMap.size() );
102         PropertyValue* pValues = aValues.getArray();
103 
104         for ( AttributeMap::iterator aIt = aAttributeMap.begin(); aIt != aAttributeMap.end(); ++aIt, ++pValues )
105 	    {
106 		    pValues->Name   = aIt->first;
107 		    pValues->Handle = (sal_Int32) -1;
108 		    pValues->Value  = aIt->second;
109 		    pValues->State  = PropertyState_DIRECT_VALUE;
110 	    }
111     }
112     else
113     {
114         aValues = GetCharacterAttributes();
115     }
116 
117     return aValues;
118 }
119 
120 // -----------------------------------------------------------------------------
121