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  moTextOutlineProperties.assignIfUsed(rSourceProps.moTextOutlineProperties);
69 
72 }
73 
74 void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
75 {
76  OUString aFontName;
77  sal_Int16 nFontPitch = 0;
78  sal_Int16 nFontFamily = 0;
79 
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)
85  {
86  rPropMap.setProperty( PROP_CharFontName, aFontName);
87  rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
88  rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
89  }
90 
91  bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
92  if (!bRet)
93  bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
94  if (bRet)
95  {
96  rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
97  rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
98  rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
99  }
100 
101  bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
102  if (!bRet)
103  bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
104  if (bRet)
105  {
106  rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
107  rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
108  rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
109  }
110 
112  {
114  bool bContoured = false;
115 
116  // noFill doesn't exist for characters. Map noFill to 99% transparency
117  if (maFillProperties.moFillType.get() == XML_noFill)
118  aColor.addTransformation(XML_alpha, 1000);
119 
120  // tdf#137438 Emulate text outline color/transparency.
121  // If the outline color dominates, then use it as the text color.
122  if (moTextOutlineProperties.has_value()
123  && moTextOutlineProperties.get().maLineFill.moFillType.has_value()
124  && moTextOutlineProperties.get().maLineFill.moFillType.get() != XML_noFill)
125  {
126  Color aLineColor = moTextOutlineProperties.get().maLineFill.getBestSolidColor();
127  sal_Int16 nLineTransparency = aLineColor.getTransparency();
128 
129  // tdf#127696 If the text color is white (and the outline color doesn't dominate),
130  // then this is contoured text in LO.
131  if (nLineTransparency < aColor.getTransparency()
132  || (bContoured = aColor.getColor(rFilter.getGraphicHelper()) == COL_WHITE))
133  aColor = aLineColor;
134  }
135  rPropMap.setProperty(PROP_CharColor, aColor.getColor(rFilter.getGraphicHelper()));
136  // set color theme index
137  rPropMap.setProperty(PROP_CharColorTheme, aColor.getSchemeColorIndex());
138  rPropMap.setProperty(PROP_CharColorTintOrShade, aColor.getTintOrShade());
139  rPropMap.setProperty(PROP_CharColorLumMod, aColor.getLumMod());
140  rPropMap.setProperty(PROP_CharColorLumOff, aColor.getLumOff());
141  rPropMap.setProperty(PROP_CharContoured, bContoured);
142 
143  if (aColor.hasTransparency())
144  {
145  rPropMap.setProperty(PROP_CharTransparence, aColor.getTransparency());
146  }
147  }
148 
149  if( moLang.has_value() && !moLang.get().isEmpty() )
150  {
151  LanguageTag aTag(moLang.get());
152  lang::Locale aLocale(aTag.getLocale());
153  switch(MsLangId::getScriptType(aTag.getLanguageType()))
154  {
155  case css::i18n::ScriptType::LATIN:
156  rPropMap.setProperty( PROP_CharLocale, aLocale);break;
157  case css::i18n::ScriptType::ASIAN:
158  rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);break;
159  case css::i18n::ScriptType::COMPLEX:
160  rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);break;
161  }
162  }
163 
164  if( moHeight.has_value() )
165  {
166  float fHeight = GetFontHeight( moHeight.get() );
167  if (moFontScale.has_value())
168  fHeight *= (moFontScale.get() / 100000);
169  rPropMap.setProperty( PROP_CharHeight, fHeight);
170  rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
171  rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
172  }
173 
174  rPropMap.setProperty( PROP_CharKerning, static_cast<sal_Int16>(GetTextSpacingPoint( moSpacing.get( 0 ) )));
175 
176  rPropMap.setProperty( PROP_CharUnderline, GetFontUnderline( moUnderline.get( XML_none ) ));
177  rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.get( XML_noStrike ) ));
178  rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.get( XML_none ) ));
179 
180  if( moBaseline.has_value() ) {
181  rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.get( 0 ) / 1000));
182  rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(DFLT_ESC_PROP));
183  } else {
184  rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
185  rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
186  }
187 
188  float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
189  rPropMap.setProperty( PROP_CharWeight, fWeight);
190  rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
191  rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
192 
193  awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
194  rPropMap.setProperty( PROP_CharPosture, eSlant);
195  rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
196  rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
197 
198  bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
199  if( moUnderline.has_value() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
200  {
201  rPropMap.setProperty( PROP_CharUnderlineHasColor, true);
202  rPropMap.setProperty( PROP_CharUnderlineColor, maUnderlineColor.getColor( rFilter.getGraphicHelper() ));
203  }
204  else
205  {
206  rPropMap.setProperty( PROP_CharUnderlineHasColor, false);
207  rPropMap.setProperty( PROP_CharUnderlineColor, sal_Int32(-1));
208  }
209 
211  rPropMap.setProperty( PROP_CharBackColor, maHighlightColor.getColor( rFilter.getGraphicHelper() ));
212  else
213  rPropMap.setProperty( PROP_CharBackColor, sal_Int32(-1));
214 }
215 
216 static void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfPropertyValues )
217 {
218  if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfPropertyValues.empty())
219  return;
220  Sequence<PropertyValue> aGrabBag;
221  Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
222  aAnyGrabBag >>= aGrabBag;
223 
224  rPropSet.setAnyProperty(PROP_CharInteropGrabBag, Any(comphelper::concatSequences(aGrabBag, aVectorOfPropertyValues)));
225 }
226 
227 void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
228 {
229  PropertyMap aPropMap;
230  pushToPropMap( aPropMap, rFilter );
231  rPropSet.setProperties( aPropMap );
233 }
234 
235 float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
236 {
237  return moHeight.has_value() ? GetFontHeight( moHeight.get() ) : fDefault;
238 }
239 
240 } // namespace oox::drawingml
241 
242 /* 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:703
static void pushToGrabBag(PropertySet &rPropSet, const std::vector< PropertyValue > &aVectorOfPropertyValues)
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:51
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:72
bool has_value() const
Definition: helper.hxx:181
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:346
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:184
void assignUsed(const PropertyMap &rPropMap)
Inserts all properties contained in the passed property map.
sal_Int16 getLumOff() const
Definition: color.cxx:515
#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:531
bool isUsed() const
Returns true, if the color is initialized.
Definition: color.hxx:87
void assignIfUsed(const OptValue &rValue)
Definition: helper.hxx:194
sal_Int16 getTintOrShade() const
Definition: color.cxx:482
void addTransformation(sal_Int32 nElement, sal_Int32 nValue=-1)
Inserts the passed color transformation.
Definition: color.cxx:327
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 getSchemeColorIndex() const
Definition: color.cxx:713
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
sal_Int16 GetFontUnderline(sal_Int32 nToken)
XML_none
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
Definition: color.cxx:708
void assignUsed(const TextCharacterProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
void assignUsed(const FillProperties &rSourceProps)
Properties for bitmap fills.
sal_Int16 getLumMod() const
Definition: color.cxx:499
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