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