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>
30#include <oox/helper/helper.hxx>
34#include <oox/token/properties.hxx>
35#include <oox/token/tokens.hxx>
36
37using ::oox::core::XmlFilterBase;
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::beans;
41
42namespace oox::drawingml {
43
45{
46 // overwrite all properties existing in rSourceProps
48 maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
50 maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
57 assignIfUsed( moLang, rSourceProps.moLang );
58 assignIfUsed( moHeight, rSourceProps.moHeight );
59 assignIfUsed( moFontScale, rSourceProps.moFontScale);
60 assignIfUsed( moSpacing, rSourceProps.moSpacing );
61 assignIfUsed( moUnderline, rSourceProps.moUnderline );
62 assignIfUsed( moBaseline, rSourceProps.moBaseline );
63 assignIfUsed( moStrikeout, rSourceProps.moStrikeout );
64 assignIfUsed( moCaseMap, rSourceProps.moCaseMap );
65 assignIfUsed( moBold, rSourceProps.moBold );
66 assignIfUsed( moItalic, rSourceProps.moItalic );
70
73}
74
76{
77 OUString aFontName;
78 sal_Int16 nFontPitch = 0;
79 sal_Int16 nFontFamily = 0;
80
81 bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
82 if (!bRet)
83 // In case there is no direct font, try to look it up as a theme reference.
84 bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
85 if (bRet)
86 {
87 rPropMap.setProperty( PROP_CharFontName, aFontName);
88 rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
89 rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
90 }
91
92 bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
93 if (!bRet)
94 bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
95 if (bRet)
96 {
97 rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
98 rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
99 rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
100 }
101
102 bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
103 if (!bRet)
104 bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
105 if (bRet)
106 {
107 rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
108 rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
109 rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
110 }
111
112 if ( maFillProperties.moFillType.has_value() )
113 {
115 bool bContoured = false;
116
117 // noFill doesn't exist for characters. Map noFill to 99% transparency
118 if (maFillProperties.moFillType.value() == XML_noFill)
119 aColor.addTransformation(XML_alpha, 1000);
120
121 // tdf#137438 Emulate text outline color/transparency.
122 // If the outline color dominates, then use it as the text color.
123 if (moTextOutlineProperties.has_value()
124 && moTextOutlineProperties.value().maLineFill.moFillType.has_value()
125 && moTextOutlineProperties.value().maLineFill.moFillType.value() != XML_noFill)
126 {
127 Color aLineColor = moTextOutlineProperties.value().maLineFill.getBestSolidColor();
128 sal_Int16 nLineTransparency = aLineColor.getTransparency();
129
130 // tdf#127696 If the text color is white (and the outline color doesn't dominate),
131 // then this is contoured text in LO.
132 if (nLineTransparency < aColor.getTransparency()
133 || (bContoured = aColor.getColor(rFilter.getGraphicHelper()) == COL_WHITE))
134 aColor = aLineColor;
135 }
136 rPropMap.setProperty(PROP_CharColor, aColor.getColor(rFilter.getGraphicHelper()));
137
138 // set theme color
139 model::ComplexColor aComplexColor = aColor.getComplexColor();
141 rPropMap.setProperty(PROP_CharContoured, bContoured);
142
143 if (aColor.hasTransparency())
144 {
145 const auto nTransparency = aColor.getTransparency();
146 rPropMap.setProperty(PROP_CharTransparence, nTransparency);
147
148 // WORKAROUND: Fully transparent white has the same value as COL_AUTO, avoid collision
149 if (nTransparency == 100
150 && aColor.getColor(rFilter.getGraphicHelper()).GetRGBColor() == COL_AUTO.GetRGBColor())
151 rPropMap.setProperty(PROP_CharColor, ::Color(ColorTransparency, 0xFFFFFFFE));
152 }
153 }
154
155 if( moLang.has_value() && !moLang.value().isEmpty() )
156 {
157 LanguageTag aTag(moLang.value());
158 lang::Locale aLocale(aTag.getLocale());
160 {
161 case css::i18n::ScriptType::LATIN:
162 rPropMap.setProperty( PROP_CharLocale, aLocale);break;
163 case css::i18n::ScriptType::ASIAN:
164 rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);break;
165 case css::i18n::ScriptType::COMPLEX:
166 rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);break;
167 }
168 }
169
170 if( moHeight.has_value() )
171 {
172 float fHeight = GetFontHeight( moHeight.value() );
173 if (moFontScale.has_value())
174 fHeight *= (moFontScale.value() / 100000);
175 rPropMap.setProperty( PROP_CharHeight, fHeight);
176 rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
177 rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
178 }
179
180 rPropMap.setProperty( PROP_CharKerning, static_cast<sal_Int16>(GetTextSpacingPoint( moSpacing.value_or( 0 ) )));
181
183 rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.value_or( XML_noStrike ) ));
184 rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.value_or( XML_none ) ));
185
186 if( moBaseline.has_value() ) {
187 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.value_or( 0 ) / 1000));
189 } else {
190 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
191 rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
192 }
193
194 float fWeight = moBold.value_or( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
195 rPropMap.setProperty( PROP_CharWeight, fWeight);
196 rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
197 rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
198
199 awt::FontSlant eSlant = moItalic.value_or( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
200 rPropMap.setProperty( PROP_CharPosture, eSlant);
201 rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
202 rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
203
204 bool bUnderlineFillFollowText = moUnderlineFillFollowText.value_or( false );
205 if( moUnderline.has_value() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
206 {
210 rPropMap.setProperty( PROP_CharUnderlineComplexColor, model::color::createXComplexColor(aComplexColor));
211 }
212 else
213 {
214 rPropMap.setProperty( PROP_CharUnderlineHasColor, false);
215 rPropMap.setProperty( PROP_CharUnderlineColor, sal_Int32(-1));
216 }
217
219 {
222 rPropMap.setProperty(PROP_CharBackgroundComplexColor, model::color::createXComplexColor(aComplexColor));
223 }
224 else
225 rPropMap.setProperty( PROP_CharBackColor, sal_Int32(-1));
226}
227
228static void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfPropertyValues )
229{
230 if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfPropertyValues.empty())
231 return;
233 Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
234 aAnyGrabBag >>= aGrabBag;
235
236 rPropSet.setAnyProperty(PROP_CharInteropGrabBag, Any(comphelper::concatSequences(aGrabBag, aVectorOfPropertyValues)));
237}
238
240{
241 PropertyMap aPropMap;
242 pushToPropMap( aPropMap, rFilter );
243 rPropSet.setProperties( aPropMap );
245}
246
248{
249 return moHeight.has_value() ? GetFontHeight( moHeight.value() ) : fDefault;
250}
251
252} // namespace oox::drawingml
253
254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Color GetRGBColor() const
LanguageType getLanguageType(bool bResolveSystem=true) const
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
static sal_Int16 getScriptType(LanguageType nLang)
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
void assignUsed(const PropertyMap &rPropMap)
Inserts all properties contained in the passed property map.
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:72
A wrapper for a UNO property set.
Definition: propertyset.hxx:58
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
Gets the specified property from the property set.
Definition: propertyset.cxx:62
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
Puts the passed properties into the property set.
bool setAnyProperty(sal_Int32 nPropId, const css::uno::Any &rValue)
Puts the passed any into the property set.
Definition: propertyset.cxx:70
bool hasProperty(sal_Int32 nPropId) const
Returns true, if the specified property is supported by the property set.
Definition: propertyset.cxx:47
GraphicHelper & getGraphicHelper() const
Returns a helper for the handling of graphics and graphic objects.
Definition: filterbase.cxx:346
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
Definition: color.cxx:804
void addTransformation(sal_Int32 nElement, sal_Int32 nValue=-1)
Inserts the passed color transformation.
Definition: color.cxx:408
void assignIfUsed(const Color &rColor)
Overwrites this color with the passed color, if it is used.
Definition: color.hxx:89
bool isUsed() const
Returns true, if the color is initialized.
Definition: color.hxx:92
model::ComplexColor getComplexColor() const
Definition: color.cxx:620
bool hasTransparency() const
Returns true, if the color is transparent.
Definition: color.cxx:799
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:644
void assignIfUsed(const TextFont &rTextFont)
Overwrites this text font with the passed text font, if it is used.
Definition: textfont.cxx:73
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,...
Definition: textfont.cxx:79
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
ColorTransparency
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define DFLT_ESC_PROP
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
uno::Reference< util::XComplexColor > createXComplexColor(model::ComplexColor const &rColor)
float GetFontHeight(sal_Int32 nHeight)
sal_Int16 GetCaseMap(sal_Int32 nToken)
sal_Int16 GetFontUnderline(sal_Int32 nToken)
static void pushToGrabBag(PropertySet &rPropSet, const std::vector< PropertyValue > &aVectorOfPropertyValues)
sal_Int32 GetTextSpacingPoint(std::u16string_view sValue)
converts the ST_TextSpacingPoint to 1/100mm
sal_Int16 GetFontStrikeout(sal_Int32 nToken)
void assignIfUsed(std::optional< Type > &rDestValue, const std::optional< Type > &rSourceValue)
Definition: helper.hxx:174
XML_none
void assignUsed(const FillProperties &rSourceProps)
Properties for bitmap fills.
Color getBestSolidColor() const
Tries to resolve current settings to a solid color, e.g.
std::optional< sal_Int32 > moFillType
void pushToPropMap(PropertyMap &rPropMap, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property map.
void pushToPropSet(PropertySet &rPropSet, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property set.
std::optional< double > moFontScale
If a font scale has to be applied manually to moHeight.
std::vector< css::beans::PropertyValue > maTextEffectsProperties
float getCharHeightPoints(float fDefault) const
Returns the current character size.
void assignUsed(const TextCharacterProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
std::optional< LineProperties > moTextOutlineProperties
signed char sal_Int8
constexpr OUStringLiteral PROP_CharHeightComplex
constexpr OUStringLiteral PROP_CharHeight
constexpr OUStringLiteral PROP_CharComplexColor
constexpr OUStringLiteral PROP_CharPostureComplex
constexpr OUStringLiteral PROP_CharLocale
constexpr OUStringLiteral PROP_CharContoured
constexpr OUStringLiteral PROP_CharPosture
constexpr OUStringLiteral PROP_CharWeight
constexpr OUStringLiteral PROP_CharFontNameComplex
constexpr OUStringLiteral PROP_CharUnderline
constexpr OUStringLiteral PROP_CharTransparence
constexpr OUStringLiteral PROP_CharColor
constexpr OUStringLiteral PROP_CharCaseMap
constexpr OUStringLiteral PROP_CharWeightComplex
constexpr OUStringLiteral PROP_CharEscapement
constexpr OUStringLiteral PROP_CharFontPitchAsian
constexpr OUStringLiteral PROP_CharStrikeout
constexpr OUStringLiteral PROP_CharKerning
constexpr OUStringLiteral PROP_CharFontPitchComplex
constexpr OUStringLiteral PROP_CharBackColor
constexpr OUStringLiteral PROP_CharLocaleAsian
constexpr OUStringLiteral PROP_CharLocaleComplex
constexpr OUStringLiteral PROP_CharHeightAsian
constexpr OUStringLiteral PROP_CharFontFamilyAsian
constexpr OUStringLiteral PROP_CharWeightAsian
constexpr OUStringLiteral PROP_CharFontNameAsian
constexpr OUStringLiteral PROP_CharFontFamilyComplex
constexpr OUStringLiteral PROP_CharFontPitch
constexpr OUStringLiteral PROP_CharUnderlineHasColor
constexpr OUStringLiteral PROP_CharEscapementHeight
constexpr OUStringLiteral PROP_CharFontName
constexpr OUStringLiteral PROP_CharPostureAsian
constexpr OUStringLiteral PROP_CharFontFamily
constexpr OUStringLiteral PROP_CharUnderlineColor