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