Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / textcharacterproperties.cxx
blob71046841c60c1a0a3cd668a0cef7558222c32d60
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 <i18nlangtag/languagetag.hxx>
25 #include <editeng/escapementitem.hxx>
26 #include "oox/helper/helper.hxx"
27 #include "oox/helper/propertyset.hxx"
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "oox/drawingml/drawingmltypes.hxx"
30 #include <oox/token/properties.hxx>
31 #include "oox/token/tokens.hxx"
33 using ::oox::core::XmlFilterBase;
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
38 namespace oox {
39 namespace drawingml {
41 void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
43 // overwrite all properties exisiting in rSourceProps
44 maHyperlinkPropertyMap.assignUsed( rSourceProps.maHyperlinkPropertyMap );
45 maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
46 maLatinThemeFont.assignIfUsed( rSourceProps.maLatinThemeFont );
47 maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
48 maAsianThemeFont.assignIfUsed( rSourceProps.maAsianThemeFont );
49 maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
50 maComplexThemeFont.assignIfUsed( rSourceProps.maComplexThemeFont );
51 maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
52 maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
53 maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
54 moHeight.assignIfUsed( rSourceProps.moHeight );
55 moSpacing.assignIfUsed( rSourceProps.moSpacing );
56 moUnderline.assignIfUsed( rSourceProps.moUnderline );
57 moBaseline.assignIfUsed( rSourceProps.moBaseline );
58 moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
59 moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
60 moBold.assignIfUsed( rSourceProps.moBold );
61 moItalic.assignIfUsed( rSourceProps.moItalic );
62 moUnderlineLineFollowText.assignIfUsed( rSourceProps.moUnderlineLineFollowText );
63 moUnderlineFillFollowText.assignIfUsed( rSourceProps.moUnderlineFillFollowText );
65 maTextEffectsProperties = rSourceProps.maTextEffectsProperties;
66 maFillProperties.assignUsed( rSourceProps.maFillProperties );
69 void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
71 OUString aFontName;
72 sal_Int16 nFontPitch = 0;
73 sal_Int16 nFontFamily = 0;
75 bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
76 if (!bRet)
77 // In case there is no direct font, try to look it up as a theme reference.
78 bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
79 if (bRet)
81 rPropMap.setProperty( PROP_CharFontName, aFontName);
82 rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
83 rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
86 bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
87 if (!bRet)
88 bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
89 if (bRet)
91 rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
92 rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
93 rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
96 bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
97 if (!bRet)
98 bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
99 if (bRet)
101 rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
102 rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
103 rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
106 if ( maFillProperties.moFillType.has() )
107 rPropMap.setProperty( PROP_CharColor, maFillProperties.getBestSolidColor().getColor( rFilter.getGraphicHelper() ));
109 if( moLang.has() && !moLang.get().isEmpty() )
111 lang::Locale aLocale( LanguageTag( moLang.get()).getLocale());
112 rPropMap.setProperty( PROP_CharLocale, aLocale);
113 rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);
114 rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);
117 if( moHeight.has() )
119 float fHeight = GetFontHeight( moHeight.get() );
120 rPropMap.setProperty( PROP_CharHeight, fHeight);
121 rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
122 rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
125 rPropMap.setProperty( PROP_CharKerning, (sal_Int16) GetTextSpacingPoint( moSpacing.get( 0 ) ));
127 rPropMap.setProperty( PROP_CharUnderline, GetFontUnderline( moUnderline.get( XML_none ) ));
128 rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.get( XML_noStrike ) ));
129 rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.get( XML_none ) ));
131 if( moBaseline.has() ) {
132 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.get( 0 ) / 1000));
133 rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(DFLT_ESC_PROP));
134 } else {
135 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
136 rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
139 float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
140 rPropMap.setProperty( PROP_CharWeight, fWeight);
141 rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
142 rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
144 awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
145 rPropMap.setProperty( PROP_CharPosture, eSlant);
146 rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
147 rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
149 bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
150 if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
152 rPropMap.setProperty( PROP_CharUnderlineHasColor, true);
153 rPropMap.setProperty( PROP_CharUnderlineColor, maUnderlineColor.getColor( rFilter.getGraphicHelper() ));
155 // TODO If bUnderlineFillFollowText uFillTx (CT_TextUnderlineFillFollowText) is set, fill color of the underline should be the same color as the text
158 void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfProperyValues )
160 if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfProperyValues.empty())
161 return;
162 Sequence<PropertyValue> aGrabBag;
163 Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
164 aAnyGrabBag >>= aGrabBag;
166 sal_Int32 nLength = aGrabBag.getLength();
167 aGrabBag.realloc(nLength + aVectorOfProperyValues.size());
169 for (size_t i = 0; i < aVectorOfProperyValues.size(); i++)
171 PropertyValue aPropertyValue = aVectorOfProperyValues[i];
172 aGrabBag[nLength + i] = aPropertyValue;
175 rPropSet.setAnyProperty(PROP_CharInteropGrabBag, makeAny(aGrabBag));
178 void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
180 PropertyMap aPropMap;
181 pushToPropMap( aPropMap, rFilter );
182 rPropSet.setProperties( aPropMap );
183 pushToGrabBag(rPropSet, maTextEffectsProperties);
186 float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
188 return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
191 } // namespace drawingml
192 } // namespace oox
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */