1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 #include <accessibility/helper/characterattributeshelper.hxx>
31 
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 
35 
36 // -----------------------------------------------------------------------------
37 // CharacterAttributesHelper
38 // -----------------------------------------------------------------------------
39 
40 CharacterAttributesHelper::CharacterAttributesHelper( const Font& rFont, sal_Int32 nBackColor, sal_Int32 nColor )
41 {
42     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharBackColor" ), makeAny( (sal_Int32) nBackColor ) ) );
43     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharColor" ), makeAny( (sal_Int32) nColor ) ) );
44     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontCharSet" ), makeAny( (sal_Int16) rFont.GetCharSet() ) ) );
45     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontFamily" ), makeAny( (sal_Int16) rFont.GetFamily() ) ) );
46     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontName" ), makeAny( (::rtl::OUString) rFont.GetName() ) ) );
47     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontPitch" ), makeAny( (sal_Int16) rFont.GetPitch() ) ) );
48     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharFontStyleName" ), makeAny( (::rtl::OUString) rFont.GetStyleName() ) ) );
49     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharHeight" ), makeAny( (sal_Int16) rFont.GetSize().Height() ) ) );
50     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharScaleWidth" ), makeAny( (sal_Int16) rFont.GetSize().Width() ) ) );
51     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharStrikeout" ), makeAny( (sal_Int16) rFont.GetStrikeout() ) ) );
52     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharUnderline" ), makeAny( (sal_Int16) rFont.GetUnderline() ) ) );
53     m_aAttributeMap.insert( AttributeMap::value_type( ::rtl::OUString::createFromAscii( "CharWeight" ), makeAny( (float) rFont.GetWeight() ) ) );
54 }
55 
56 // -----------------------------------------------------------------------------
57 
58 CharacterAttributesHelper::~CharacterAttributesHelper()
59 {
60     m_aAttributeMap.clear();
61 }
62 
63 // -----------------------------------------------------------------------------
64 
65 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes()
66 {
67 	Sequence< PropertyValue > aValues( m_aAttributeMap.size() );
68 	PropertyValue* pValues = aValues.getArray();
69 
70     for ( AttributeMap::iterator aIt = m_aAttributeMap.begin(); aIt != m_aAttributeMap.end(); ++aIt, ++pValues )
71 	{
72 		pValues->Name   = aIt->first;
73 		pValues->Handle = (sal_Int32) -1;
74 		pValues->Value  = aIt->second;
75 		pValues->State  = PropertyState_DIRECT_VALUE;
76 	}
77 
78     return aValues;
79 }
80 
81 // -----------------------------------------------------------------------------
82 
83 Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes( const Sequence< ::rtl::OUString >& aRequestedAttributes )
84 {
85 	Sequence< PropertyValue > aValues;
86     sal_Int32 nLength = aRequestedAttributes.getLength();
87 
88     if ( nLength != 0 )
89     {
90         const ::rtl::OUString* pNames = aRequestedAttributes.getConstArray();
91         AttributeMap aAttributeMap;
92 
93         for ( sal_Int32 i = 0; i < nLength; ++i )
94         {
95             AttributeMap::iterator aFound = m_aAttributeMap.find( pNames[i] );
96             if ( aFound != m_aAttributeMap.end() )
97                 aAttributeMap.insert( *aFound );
98         }
99 
100         aValues.realloc( aAttributeMap.size() );
101         PropertyValue* pValues = aValues.getArray();
102 
103         for ( AttributeMap::iterator aIt = aAttributeMap.begin(); aIt != aAttributeMap.end(); ++aIt, ++pValues )
104 	    {
105 		    pValues->Name   = aIt->first;
106 		    pValues->Handle = (sal_Int32) -1;
107 		    pValues->Value  = aIt->second;
108 		    pValues->State  = PropertyState_DIRECT_VALUE;
109 	    }
110     }
111     else
112     {
113         aValues = GetCharacterAttributes();
114     }
115 
116     return aValues;
117 }
118 
119 // -----------------------------------------------------------------------------
120