1ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ca5ec200SAndrew Rist  * distributed with this work for additional information
6ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10ca5ec200SAndrew Rist  *
11ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ca5ec200SAndrew Rist  *
13ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18ca5ec200SAndrew Rist  * under the License.
19ca5ec200SAndrew Rist  *
20ca5ec200SAndrew Rist  *************************************************************/
21ca5ec200SAndrew Rist 
22ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/textcharacterproperties.hxx"
25cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
26cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp>
27cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp>
28cdf0e10cSrcweir #include "oox/helper/helper.hxx"
29cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
30cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
31cdf0e10cSrcweir #include "oox/drawingml/drawingmltypes.hxx"
32cdf0e10cSrcweir #include "oox/token/tokens.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using ::rtl::OUString;
35cdf0e10cSrcweir using ::oox::core::XmlFilterBase;
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::beans;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace oox {
41cdf0e10cSrcweir namespace drawingml {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // ============================================================================
44cdf0e10cSrcweir 
assignUsed(const TextCharacterProperties & rSourceProps)45cdf0e10cSrcweir void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     // overwrite all properties exisiting in rSourceProps
48cdf0e10cSrcweir     maHyperlinkPropertyMap.insert( rSourceProps.maHyperlinkPropertyMap.begin(), rSourceProps.maHyperlinkPropertyMap.end() );
49cdf0e10cSrcweir     maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
50cdf0e10cSrcweir     maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
51cdf0e10cSrcweir     maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
52cdf0e10cSrcweir     maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
53*f1574915SArmin Le Grand     // keep existing char color
54*f1574915SArmin Le Grand     if (!maCharColor.isUsed())
55*f1574915SArmin Le Grand         maCharColor.assignIfUsed( rSourceProps.maCharColor );
56*f1574915SArmin Le Grand 
57cdf0e10cSrcweir     maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
58cdf0e10cSrcweir     maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
59cdf0e10cSrcweir     moHeight.assignIfUsed( rSourceProps.moHeight );
60cdf0e10cSrcweir     moSpacing.assignIfUsed( rSourceProps.moSpacing );
61cdf0e10cSrcweir     moUnderline.assignIfUsed( rSourceProps.moUnderline );
62cdf0e10cSrcweir     moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
63cdf0e10cSrcweir     moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
64cdf0e10cSrcweir     moBold.assignIfUsed( rSourceProps.moBold );
65cdf0e10cSrcweir     moItalic.assignIfUsed( rSourceProps.moItalic );
66cdf0e10cSrcweir     moUnderlineLineFollowText.assignIfUsed( rSourceProps.moUnderlineLineFollowText );
67cdf0e10cSrcweir     moUnderlineFillFollowText.assignIfUsed( rSourceProps.moUnderlineFillFollowText );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
pushToPropMap(PropertyMap & rPropMap,const XmlFilterBase & rFilter) const70cdf0e10cSrcweir void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     OUString aFontName;
73cdf0e10cSrcweir     sal_Int16 nFontPitch = 0;
74cdf0e10cSrcweir     sal_Int16 nFontFamily = 0;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     if( maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir         rPropMap[ PROP_CharFontName ] <<= aFontName;
79cdf0e10cSrcweir         rPropMap[ PROP_CharFontPitch ] <<= nFontPitch;
80cdf0e10cSrcweir         rPropMap[ PROP_CharFontFamily ] <<= nFontFamily;
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     if( maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         rPropMap[ PROP_CharFontNameAsian ] <<= aFontName;
86cdf0e10cSrcweir         rPropMap[ PROP_CharFontPitchAsian ] <<= nFontFamily;
87cdf0e10cSrcweir         rPropMap[ PROP_CharFontFamilyAsian ] <<= nFontPitch;
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     if( maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         rPropMap[ PROP_CharFontNameComplex ] <<= aFontName;
93cdf0e10cSrcweir         rPropMap[ PROP_CharFontPitchComplex ] <<= nFontPitch;
94cdf0e10cSrcweir         rPropMap[ PROP_CharFontFamilyComplex ] <<= nFontFamily;
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // symbolfont, will now be ... textrun.cxx ... ausgewertet !!!i#113673
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     if( maCharColor.isUsed() )
100cdf0e10cSrcweir         rPropMap[ PROP_CharColor ] <<= maCharColor.getColor( rFilter.getGraphicHelper() );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     if( moLang.has() && (moLang.get().getLength() > 0) )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         lang::Locale aLocale;
105cdf0e10cSrcweir         sal_Int32 nSepPos = moLang.get().indexOf( sal_Unicode( '-' ), 0 );
106cdf0e10cSrcweir         if ( nSepPos >= 0 )
107cdf0e10cSrcweir         {
108cdf0e10cSrcweir             aLocale.Language = moLang.get().copy( 0, nSepPos );
109cdf0e10cSrcweir             aLocale.Country = moLang.get().copy( nSepPos + 1 );
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir         else
112cdf0e10cSrcweir         {
113cdf0e10cSrcweir             aLocale.Language = moLang.get();
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir         rPropMap[ PROP_CharLocale ] <<= aLocale;
116cdf0e10cSrcweir         rPropMap[ PROP_CharLocaleAsian ] <<= aLocale;
117cdf0e10cSrcweir         rPropMap[ PROP_CharLocaleComplex ] <<= aLocale;
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     if( moHeight.has() )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         float fHeight = GetFontHeight( moHeight.get() );
123cdf0e10cSrcweir         rPropMap[ PROP_CharHeight ] <<= fHeight;
124cdf0e10cSrcweir         rPropMap[ PROP_CharHeightAsian ] <<= fHeight;
125cdf0e10cSrcweir         rPropMap[ PROP_CharHeightComplex ] <<= fHeight;
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     rPropMap[ PROP_CharKerning ] <<= (sal_Int16) GetTextSpacingPoint( moSpacing.get( 0 ) );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     rPropMap[ PROP_CharUnderline ] <<= GetFontUnderline( moUnderline.get( XML_none ) );
131cdf0e10cSrcweir     rPropMap[ PROP_CharStrikeout ] <<= GetFontStrikeout( moStrikeout.get( XML_noStrike ) );
132cdf0e10cSrcweir     rPropMap[ PROP_CharCaseMap ] <<= GetCaseMap( moCaseMap.get( XML_none ) );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
135cdf0e10cSrcweir     rPropMap[ PROP_CharWeight ] <<= fWeight;
136cdf0e10cSrcweir     rPropMap[ PROP_CharWeightAsian ] <<= fWeight;
137cdf0e10cSrcweir     rPropMap[ PROP_CharWeightComplex ] <<= fWeight;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
140cdf0e10cSrcweir     rPropMap[ PROP_CharPosture ] <<= eSlant;
141cdf0e10cSrcweir     rPropMap[ PROP_CharPostureAsian ] <<= eSlant;
142cdf0e10cSrcweir     rPropMap[ PROP_CharPostureComplex ] <<= eSlant;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
145cdf0e10cSrcweir     if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         rPropMap[ PROP_CharUnderlineHasColor ] <<= true;
148cdf0e10cSrcweir         rPropMap[ PROP_CharUnderlineColor ] <<= maUnderlineColor.getColor( rFilter.getGraphicHelper() );
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
pushToPropSet(PropertySet & rPropSet,const XmlFilterBase & rFilter) const152cdf0e10cSrcweir void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     PropertyMap aPropMap;
155cdf0e10cSrcweir     pushToPropMap( aPropMap, rFilter );
156cdf0e10cSrcweir     rPropSet.setProperties( aPropMap );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
getCharHeightPoints(float fDefault) const159cdf0e10cSrcweir float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // ============================================================================
165cdf0e10cSrcweir 
166cdf0e10cSrcweir } // namespace drawingml
167cdf0e10cSrcweir } // namespace oox
168cdf0e10cSrcweir 
169