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