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 #include "oox/drawingml/textcharacterproperties.hxx"
29 #include <com/sun/star/lang/Locale.hpp>
30 #include <com/sun/star/awt/FontSlant.hpp>
31 #include <com/sun/star/awt/FontWeight.hpp>
32 #include "oox/helper/helper.hxx"
33 #include "oox/helper/propertyset.hxx"
34 #include "oox/core/xmlfilterbase.hxx"
35 #include "oox/drawingml/drawingmltypes.hxx"
36 #include "oox/token/tokens.hxx"
37 
38 using ::rtl::OUString;
39 using ::oox::core::XmlFilterBase;
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::beans;
43 
44 namespace oox {
45 namespace drawingml {
46 
47 // ============================================================================
48 
49 void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
50 {
51     // overwrite all properties exisiting in rSourceProps
52     maHyperlinkPropertyMap.insert( rSourceProps.maHyperlinkPropertyMap.begin(), rSourceProps.maHyperlinkPropertyMap.end() );
53     maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
54     maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
55     maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
56     maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
57     maCharColor.assignIfUsed( rSourceProps.maCharColor );
58     maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
59     maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
60     moHeight.assignIfUsed( rSourceProps.moHeight );
61     moSpacing.assignIfUsed( rSourceProps.moSpacing );
62     moUnderline.assignIfUsed( rSourceProps.moUnderline );
63     moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
64     moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
65     moBold.assignIfUsed( rSourceProps.moBold );
66     moItalic.assignIfUsed( rSourceProps.moItalic );
67     moUnderlineLineFollowText.assignIfUsed( rSourceProps.moUnderlineLineFollowText );
68     moUnderlineFillFollowText.assignIfUsed( rSourceProps.moUnderlineFillFollowText );
69 }
70 
71 void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
72 {
73     OUString aFontName;
74     sal_Int16 nFontPitch = 0;
75     sal_Int16 nFontFamily = 0;
76 
77     if( maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
78     {
79         rPropMap[ PROP_CharFontName ] <<= aFontName;
80         rPropMap[ PROP_CharFontPitch ] <<= nFontPitch;
81         rPropMap[ PROP_CharFontFamily ] <<= nFontFamily;
82     }
83 
84     if( maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
85     {
86         rPropMap[ PROP_CharFontNameAsian ] <<= aFontName;
87         rPropMap[ PROP_CharFontPitchAsian ] <<= nFontFamily;
88         rPropMap[ PROP_CharFontFamilyAsian ] <<= nFontPitch;
89     }
90 
91     if( maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
92     {
93         rPropMap[ PROP_CharFontNameComplex ] <<= aFontName;
94         rPropMap[ PROP_CharFontPitchComplex ] <<= nFontPitch;
95         rPropMap[ PROP_CharFontFamilyComplex ] <<= nFontFamily;
96     }
97 
98     // symbolfont, will now be ... textrun.cxx ... ausgewertet !!!i#113673
99 
100     if( maCharColor.isUsed() )
101         rPropMap[ PROP_CharColor ] <<= maCharColor.getColor( rFilter.getGraphicHelper() );
102 
103     if( moLang.has() && (moLang.get().getLength() > 0) )
104     {
105         lang::Locale aLocale;
106         sal_Int32 nSepPos = moLang.get().indexOf( sal_Unicode( '-' ), 0 );
107         if ( nSepPos >= 0 )
108         {
109             aLocale.Language = moLang.get().copy( 0, nSepPos );
110             aLocale.Country = moLang.get().copy( nSepPos + 1 );
111         }
112         else
113         {
114             aLocale.Language = moLang.get();
115         }
116         rPropMap[ PROP_CharLocale ] <<= aLocale;
117         rPropMap[ PROP_CharLocaleAsian ] <<= aLocale;
118         rPropMap[ PROP_CharLocaleComplex ] <<= aLocale;
119     }
120 
121     if( moHeight.has() )
122     {
123         float fHeight = GetFontHeight( moHeight.get() );
124         rPropMap[ PROP_CharHeight ] <<= fHeight;
125         rPropMap[ PROP_CharHeightAsian ] <<= fHeight;
126         rPropMap[ PROP_CharHeightComplex ] <<= fHeight;
127     }
128 
129     rPropMap[ PROP_CharKerning ] <<= (sal_Int16) GetTextSpacingPoint( moSpacing.get( 0 ) );
130 
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 ) );
134 
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;
139 
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;
144 
145     bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
146     if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
147     {
148         rPropMap[ PROP_CharUnderlineHasColor ] <<= true;
149         rPropMap[ PROP_CharUnderlineColor ] <<= maUnderlineColor.getColor( rFilter.getGraphicHelper() );
150     }
151 }
152 
153 void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
154 {
155     PropertyMap aPropMap;
156     pushToPropMap( aPropMap, rFilter );
157     rPropSet.setProperties( aPropMap );
158 }
159 
160 float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
161 {
162     return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
163 }
164 
165 // ============================================================================
166 
167 } // namespace drawingml
168 } // namespace oox
169 
170