Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / textcharacterproperties.cxx
blobe2f5cc63c0a2c504c9713d6a02f62f1eff72f433
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawingml/textcharacterproperties.hxx>
21 #include <com/sun/star/lang/Locale.hpp>
22 #include <com/sun/star/awt/FontSlant.hpp>
23 #include <com/sun/star/awt/FontWeight.hpp>
24 #include <com/sun/star/i18n/ScriptType.hpp>
25 #include <comphelper/sequence.hxx>
26 #include <i18nlangtag/languagetag.hxx>
27 #include <i18nlangtag/mslangid.hxx>
28 #include <editeng/escapementitem.hxx>
29 #include <oox/helper/helper.hxx>
30 #include <oox/helper/propertyset.hxx>
31 #include <oox/core/xmlfilterbase.hxx>
32 #include <oox/drawingml/drawingmltypes.hxx>
33 #include <oox/token/properties.hxx>
34 #include <oox/token/tokens.hxx>
36 using ::oox::core::XmlFilterBase;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
41 namespace oox {
42 namespace drawingml {
44 void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
46 // overwrite all properties existing in rSourceProps
47 maHyperlinkPropertyMap.assignUsed( rSourceProps.maHyperlinkPropertyMap );
48 maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
49 maLatinThemeFont.assignIfUsed( rSourceProps.maLatinThemeFont );
50 maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
51 maAsianThemeFont.assignIfUsed( rSourceProps.maAsianThemeFont );
52 maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
53 maComplexThemeFont.assignIfUsed( rSourceProps.maComplexThemeFont );
54 maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
55 maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
56 maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
57 moLang.assignIfUsed( rSourceProps.moLang );
58 moHeight.assignIfUsed( rSourceProps.moHeight );
59 moFontScale.assignIfUsed(rSourceProps.moFontScale);
60 moSpacing.assignIfUsed( rSourceProps.moSpacing );
61 moUnderline.assignIfUsed( rSourceProps.moUnderline );
62 moBaseline.assignIfUsed( rSourceProps.moBaseline );
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 );
70 maTextEffectsProperties = rSourceProps.maTextEffectsProperties;
71 maFillProperties.assignUsed( rSourceProps.maFillProperties );
74 void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
76 OUString aFontName;
77 sal_Int16 nFontPitch = 0;
78 sal_Int16 nFontFamily = 0;
80 bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
81 if (!bRet)
82 // In case there is no direct font, try to look it up as a theme reference.
83 bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
84 if (bRet)
86 rPropMap.setProperty( PROP_CharFontName, aFontName);
87 rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
88 rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
91 bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
92 if (!bRet)
93 bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
94 if (bRet)
96 rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
97 rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
98 rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
101 bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
102 if (!bRet)
103 bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
104 if (bRet)
106 rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
107 rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
108 rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
111 if ( maFillProperties.moFillType.has() )
112 rPropMap.setProperty( PROP_CharColor, maFillProperties.getBestSolidColor().getColor( rFilter.getGraphicHelper() ));
114 if( moLang.has() && !moLang.get().isEmpty() )
116 LanguageTag aTag(moLang.get());
117 lang::Locale aLocale(aTag.getLocale());
118 switch(MsLangId::getScriptType(aTag.getLanguageType()))
120 case css::i18n::ScriptType::LATIN:
121 rPropMap.setProperty( PROP_CharLocale, aLocale);break;
122 case css::i18n::ScriptType::ASIAN:
123 rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);break;
124 case css::i18n::ScriptType::COMPLEX:
125 rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);break;
129 if( moHeight.has() )
131 float fHeight = GetFontHeight( moHeight.get() );
132 if (moFontScale.has())
133 fHeight *= (moFontScale.get() / 100000);
134 rPropMap.setProperty( PROP_CharHeight, fHeight);
135 rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
136 rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
139 rPropMap.setProperty( PROP_CharKerning, static_cast<sal_Int16>(GetTextSpacingPoint( moSpacing.get( 0 ) )));
141 rPropMap.setProperty( PROP_CharUnderline, GetFontUnderline( moUnderline.get( XML_none ) ));
142 rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.get( XML_noStrike ) ));
143 rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.get( XML_none ) ));
145 if( moBaseline.has() ) {
146 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.get( 0 ) / 1000));
147 rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(DFLT_ESC_PROP));
148 } else {
149 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
150 rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
153 float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
154 rPropMap.setProperty( PROP_CharWeight, fWeight);
155 rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
156 rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
158 awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
159 rPropMap.setProperty( PROP_CharPosture, eSlant);
160 rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
161 rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
163 bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
164 if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
166 rPropMap.setProperty( PROP_CharUnderlineHasColor, true);
167 rPropMap.setProperty( PROP_CharUnderlineColor, maUnderlineColor.getColor( rFilter.getGraphicHelper() ));
169 // TODO If bUnderlineFillFollowText uFillTx (CT_TextUnderlineFillFollowText) is set, fill color of the underline should be the same color as the text
171 if( maHighlightColor.isUsed() )
172 rPropMap.setProperty( PROP_CharBackColor, maHighlightColor.getColor( rFilter.getGraphicHelper() ));
175 static void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfProperyValues )
177 if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfProperyValues.empty())
178 return;
179 Sequence<PropertyValue> aGrabBag;
180 Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
181 aAnyGrabBag >>= aGrabBag;
183 rPropSet.setAnyProperty(PROP_CharInteropGrabBag, makeAny(comphelper::concatSequences(aGrabBag, aVectorOfProperyValues)));
186 void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
188 PropertyMap aPropMap;
189 pushToPropMap( aPropMap, rFilter );
190 rPropSet.setProperties( aPropMap );
191 pushToGrabBag(rPropSet, maTextEffectsProperties);
194 float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
196 return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
199 } // namespace drawingml
200 } // namespace oox
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */