update dev300-m58
[ooovba.git] / oox / source / drawingml / textcharacterproperties.cxx
bloba5ef7558701ff910a32a15682b08ebe9c08bc57e
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: textcharacterproperties.cxx,v $
10 * $Revision: 1.6 $
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 #include "oox/drawingml/textcharacterproperties.hxx"
32 #include <com/sun/star/lang/Locale.hpp>
33 #include <com/sun/star/awt/FontSlant.hpp>
34 #include <com/sun/star/awt/FontWeight.hpp>
35 #include "oox/helper/helper.hxx"
36 #include "oox/helper/propertyset.hxx"
37 #include "oox/drawingml/drawingmltypes.hxx"
38 #include "properties.hxx"
39 #include "tokens.hxx"
41 using ::rtl::OUString;
42 using ::oox::core::XmlFilterBase;
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
47 namespace oox {
48 namespace drawingml {
50 // ============================================================================
52 void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
54 // overwrite all properties exisiting in rSourceProps
55 maHyperlinkPropertyMap.insert( rSourceProps.maHyperlinkPropertyMap.begin(), rSourceProps.maHyperlinkPropertyMap.end() );
56 maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
57 maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
58 maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
59 maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
60 maCharColor.assignIfUsed( rSourceProps.maCharColor );
61 maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
62 maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
63 moHeight.assignIfUsed( rSourceProps.moHeight );
64 moUnderline.assignIfUsed( rSourceProps.moUnderline );
65 moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
66 moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
67 moBold.assignIfUsed( rSourceProps.moBold );
68 moItalic.assignIfUsed( rSourceProps.moItalic );
69 moUnderlineLineFollowText.assignIfUsed( rSourceProps.moUnderlineLineFollowText );
70 moUnderlineFillFollowText.assignIfUsed( rSourceProps.moUnderlineFillFollowText );
73 void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
75 OUString aFontName;
76 sal_Int16 nFontPitch = 0;
77 sal_Int16 nFontFamily = 0;
79 if( maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
81 rPropMap[ PROP_CharFontName ] <<= aFontName;
82 rPropMap[ PROP_CharFontPitch ] <<= nFontPitch;
83 rPropMap[ PROP_CharFontFamily ] <<= nFontFamily;
86 if( maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
88 rPropMap[ PROP_CharFontNameAsian ] <<= aFontName;
89 rPropMap[ PROP_CharFontPitchAsian ] <<= nFontFamily;
90 rPropMap[ PROP_CharFontFamilyAsian ] <<= nFontPitch;
93 if( maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
95 rPropMap[ PROP_CharFontNameComplex ] <<= aFontName;
96 rPropMap[ PROP_CharFontPitchComplex ] <<= nFontPitch;
97 rPropMap[ PROP_CharFontFamilyComplex ] <<= nFontFamily;
100 // symbol font not supported
102 if( maCharColor.isUsed() )
103 rPropMap[ PROP_CharColor ] <<= maCharColor.getColor( rFilter );
105 if( moLang.has() && (moLang.get().getLength() > 0) )
107 lang::Locale aLocale;
108 sal_Int32 nSepPos = moLang.get().indexOf( sal_Unicode( '-' ), 0 );
109 if ( nSepPos >= 0 )
111 aLocale.Language = moLang.get().copy( 0, nSepPos );
112 aLocale.Country = moLang.get().copy( nSepPos + 1 );
114 else
116 aLocale.Language = moLang.get();
118 rPropMap[ PROP_CharLocale ] <<= aLocale;
119 rPropMap[ PROP_CharLocaleAsian ] <<= aLocale;
120 rPropMap[ PROP_CharLocaleComplex ] <<= aLocale;
123 if( moHeight.has() )
125 float fHeight = GetFontHeight( moHeight.get() );
126 rPropMap[ PROP_CharHeight ] <<= fHeight;
127 rPropMap[ PROP_CharHeightAsian ] <<= fHeight;
128 rPropMap[ PROP_CharHeightComplex ] <<= fHeight;
131 rPropMap[ PROP_CharUnderline ] <<= GetFontUnderline( moUnderline.get( XML_none ) );
132 rPropMap[ PROP_CharStrikeout ] <<= GetFontStrikeout( moStrikeout.get( XML_noStrike ) );
133 rPropMap[ PROP_CharCaseMap ] <<= GetCaseMap( moCaseMap.get( XML_none ) );
135 float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
136 rPropMap[ PROP_CharWeight ] <<= fWeight;
137 rPropMap[ PROP_CharWeightAsian ] <<= fWeight;
138 rPropMap[ PROP_CharWeightComplex ] <<= fWeight;
140 awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
141 rPropMap[ PROP_CharPosture ] <<= eSlant;
142 rPropMap[ PROP_CharPostureAsian ] <<= eSlant;
143 rPropMap[ PROP_CharPostureComplex ] <<= eSlant;
145 bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
146 if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
148 rPropMap[ PROP_CharUnderlineHasColor ] <<= true;
149 rPropMap[ PROP_CharUnderlineColor ] <<= maUnderlineColor.getColor( rFilter );
153 void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
155 PropertyMap aPropMap;
156 pushToPropMap( aPropMap, rFilter );
157 rPropSet.setProperties( aPropMap );
160 float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
162 return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
165 // ============================================================================
167 } // namespace drawingml
168 } // namespace oox