LibreOffice Module oox (master)  1
textcharacterproperties.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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>
27 #include <i18nlangtag/mslangid.hxx>
29 #include <oox/helper/helper.hxx>
33 #include <oox/token/properties.hxx>
34 #include <oox/token/tokens.hxx>
35 
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;
40 
41 namespace oox::drawingml {
42 
44 {
45  // overwrite all properties existing in rSourceProps
47  maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
49  maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
53  maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
56  moLang.assignIfUsed( rSourceProps.moLang );
57  moHeight.assignIfUsed( rSourceProps.moHeight );
58  moFontScale.assignIfUsed(rSourceProps.moFontScale);
59  moSpacing.assignIfUsed( rSourceProps.moSpacing );
60  moUnderline.assignIfUsed( rSourceProps.moUnderline );
61  moBaseline.assignIfUsed( rSourceProps.moBaseline );
62  moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
63  moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
64  moBold.assignIfUsed( rSourceProps.moBold );
65  moItalic.assignIfUsed( rSourceProps.moItalic );
68 
71 }
72 
73 void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
74 {
75  OUString aFontName;
76  sal_Int16 nFontPitch = 0;
77  sal_Int16 nFontFamily = 0;
78 
79  bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
80  if (!bRet)
81  // In case there is no direct font, try to look it up as a theme reference.
82  bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
83  if (bRet)
84  {
85  rPropMap.setProperty( PROP_CharFontName, aFontName);
86  rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
87  rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
88  }
89 
90  bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
91  if (!bRet)
92  bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
93  if (bRet)
94  {
95  rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
96  rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
97  rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
98  }
99 
100  bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
101  if (!bRet)
102  bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
103  if (bRet)
104  {
105  rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
106  rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
107  rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
108  }
109 
111  {
113  rPropMap.setProperty(PROP_CharColor, aColor.getColor(rFilter.getGraphicHelper()));
114 
115  if (aColor.hasTransparency())
116  {
117  rPropMap.setProperty(PROP_CharTransparence, aColor.getTransparency());
118  }
119  }
120 
121  if( moLang.has() && !moLang.get().isEmpty() )
122  {
123  LanguageTag aTag(moLang.get());
124  lang::Locale aLocale(aTag.getLocale());
125  switch(MsLangId::getScriptType(aTag.getLanguageType()))
126  {
127  case css::i18n::ScriptType::LATIN:
128  rPropMap.setProperty( PROP_CharLocale, aLocale);break;
129  case css::i18n::ScriptType::ASIAN:
130  rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);break;
131  case css::i18n::ScriptType::COMPLEX:
132  rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);break;
133  }
134  }
135 
136  if( moHeight.has() )
137  {
138  float fHeight = GetFontHeight( moHeight.get() );
139  if (moFontScale.has())
140  fHeight *= (moFontScale.get() / 100000);
141  rPropMap.setProperty( PROP_CharHeight, fHeight);
142  rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
143  rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
144  }
145 
146  rPropMap.setProperty( PROP_CharKerning, static_cast<sal_Int16>(GetTextSpacingPoint( moSpacing.get( 0 ) )));
147 
148  rPropMap.setProperty( PROP_CharUnderline, GetFontUnderline( moUnderline.get( XML_none ) ));
149  rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.get( XML_noStrike ) ));
150  rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.get( XML_none ) ));
151 
152  if( moBaseline.has() ) {
153  rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.get( 0 ) / 1000));
154  rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(DFLT_ESC_PROP));
155  } else {
156  rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
157  rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
158  }
159 
160  float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
161  rPropMap.setProperty( PROP_CharWeight, fWeight);
162  rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
163  rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
164 
165  awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
166  rPropMap.setProperty( PROP_CharPosture, eSlant);
167  rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
168  rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
169 
170  bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
171  if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
172  {
173  rPropMap.setProperty( PROP_CharUnderlineHasColor, true);
174  rPropMap.setProperty( PROP_CharUnderlineColor, maUnderlineColor.getColor( rFilter.getGraphicHelper() ));
175  }
176  // TODO If bUnderlineFillFollowText uFillTx (CT_TextUnderlineFillFollowText) is set, fill color of the underline should be the same color as the text
177 
178  if( maHighlightColor.isUsed() )
179  rPropMap.setProperty( PROP_CharBackColor, maHighlightColor.getColor( rFilter.getGraphicHelper() ));
180  else
181  rPropMap.setProperty( PROP_CharBackColor, sal_Int32(-1));
182 }
183 
184 static void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfPropertyValues )
185 {
186  if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfPropertyValues.empty())
187  return;
188  Sequence<PropertyValue> aGrabBag;
189  Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
190  aAnyGrabBag >>= aGrabBag;
191 
192  rPropSet.setAnyProperty(PROP_CharInteropGrabBag, makeAny(comphelper::concatSequences(aGrabBag, aVectorOfPropertyValues)));
193 }
194 
195 void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
196 {
197  PropertyMap aPropMap;
198  pushToPropMap( aPropMap, rFilter );
199  rPropSet.setProperties( aPropMap );
201 }
202 
203 float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
204 {
205  return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
206 }
207 
208 } // namespace oox::drawingml
209 
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptValue< double > moFontScale
If a font scale has to be applied manually to moHeight.
bool hasTransparency() const
Returns true, if the color is transparent.
Definition: color.cxx:653
static void pushToGrabBag(PropertySet &rPropSet, const std::vector< PropertyValue > &aVectorOfPropertyValues)
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
sal_Int16 GetFontStrikeout(sal_Int32 nToken)
sal_Int32 GetTextSpacingPoint(std::u16string_view sValue)
converts the ST_TextSpacingPoint to 1/100mm
signed char sal_Int8
OptValue< sal_Int32 > moFillType
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
Gets the specified property from the property set.
Definition: propertyset.cxx:62
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:70
Color getBestSolidColor() const
Tries to resolve current settings to a solid color, e.g.
bool hasProperty(sal_Int32 nPropId) const
Returns true, if the specified property is supported by the property set.
Definition: propertyset.cxx:47
bool getFontData(OUString &rFontName, sal_Int16 &rnFontPitch, sal_Int16 &rnFontFamily, const ::oox::core::XmlFilterBase &rFilter) const
Returns the font name, pitch, and family; tries to resolve theme placeholder names, e.g.
Definition: textfont.cxx:78
float getCharHeightPoints(float fDefault) const
Returns the current character size.
GraphicHelper & getGraphicHelper() const
Returns a helper for the handling of graphics and graphic objects.
Definition: filterbase.cxx:343
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
Puts the passed properties into the property set.
std::vector< css::beans::PropertyValue > maTextEffectsProperties
const Type & get() const
Definition: helper.hxx:185
void assignUsed(const PropertyMap &rPropMap)
Inserts all properties contained in the passed property map.
#define DFLT_ESC_PROP
bool setAnyProperty(sal_Int32 nPropId, const css::uno::Any &rValue)
Puts the passed any into the property set.
Definition: propertyset.cxx:70
float GetFontHeight(sal_Int32 nHeight)
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:481
bool isUsed() const
Returns true, if the color is initialized.
Definition: color.hxx:87
void assignIfUsed(const OptValue &rValue)
Definition: helper.hxx:196
A wrapper for a UNO property set.
Definition: propertyset.hxx:57
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
static sal_Int16 getScriptType(LanguageType nLang)
void pushToPropMap(PropertyMap &rPropMap, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property map.
sal_Int16 GetFontUnderline(sal_Int32 nToken)
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
Definition: color.cxx:658
void assignUsed(const TextCharacterProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
void assignUsed(const FillProperties &rSourceProps)
Properties for bitmap fills.
bool has() const
Definition: helper.hxx:181
void assignIfUsed(const TextFont &rTextFont)
Overwrites this text font with the passed text font, if it is used.
Definition: textfont.cxx:72
sal_Int16 GetCaseMap(sal_Int32 nToken)
void pushToPropSet(PropertySet &rPropSet, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property set.
void assignIfUsed(const Color &rColor)
Overwrites this color with the passed color, if it is used.
Definition: color.hxx:84
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)