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>
29#include <oox/helper/helper.hxx>
33#include <oox/token/properties.hxx>
34#include <oox/token/tokens.hxx>
35
36using ::oox::core::XmlFilterBase;
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::beans;
40
41namespace oox::drawingml {
42
44{
45 // overwrite all properties existing in rSourceProps
47 maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
49 maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
56 assignIfUsed( moLang, rSourceProps.moLang );
57 assignIfUsed( moHeight, rSourceProps.moHeight );
58 assignIfUsed( moFontScale, rSourceProps.moFontScale);
59 assignIfUsed( moSpacing, rSourceProps.moSpacing );
60 assignIfUsed( moUnderline, rSourceProps.moUnderline );
61 assignIfUsed( moBaseline, rSourceProps.moBaseline );
62 assignIfUsed( moStrikeout, rSourceProps.moStrikeout );
63 assignIfUsed( moCaseMap, rSourceProps.moCaseMap );
64 assignIfUsed( moBold, rSourceProps.moBold );
65 assignIfUsed( moItalic, rSourceProps.moItalic );
69
72}
73
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
111 if ( maFillProperties.moFillType.has_value() )
112 {
114 bool bContoured = false;
115
116 // noFill doesn't exist for characters. Map noFill to 99% transparency
117 if (maFillProperties.moFillType.value() == 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.value().maLineFill.moFillType.has_value()
124 && moTextOutlineProperties.value().maLineFill.moFillType.value() != XML_noFill)
125 {
126 Color aLineColor = moTextOutlineProperties.value().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
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 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 {
209 }
210 else
211 {
212 rPropMap.setProperty( PROP_CharUnderlineHasColor, false);
213 rPropMap.setProperty( PROP_CharUnderlineColor, sal_Int32(-1));
214 }
215
218 else
219 rPropMap.setProperty( PROP_CharBackColor, sal_Int32(-1));
220}
221
222static void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfPropertyValues )
223{
224 if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfPropertyValues.empty())
225 return;
227 Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
228 aAnyGrabBag >>= aGrabBag;
229
230 rPropSet.setAnyProperty(PROP_CharInteropGrabBag, Any(comphelper::concatSequences(aGrabBag, aVectorOfPropertyValues)));
231}
232
234{
235 PropertyMap aPropMap;
236 pushToPropMap( aPropMap, rFilter );
237 rPropSet.setProperties( aPropMap );
239}
240
242{
243 return moHeight.has_value() ? GetFontHeight( moHeight.value() ) : fDefault;
244}
245
246} // namespace oox::drawingml
247
248/* 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 getTintOrShade() const
Definition: color.cxx:482
sal_Int16 getLumMod() const
Definition: color.cxx:499
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
Definition: color.cxx:708
void addTransformation(sal_Int32 nElement, sal_Int32 nValue=-1)
Inserts the passed color transformation.
Definition: color.cxx:327
void assignIfUsed(const Color &rColor)
Overwrites this color with the passed color, if it is used.
Definition: color.hxx:84
sal_Int16 getLumOff() const
Definition: color.cxx:515
bool isUsed() const
Returns true, if the color is initialized.
Definition: color.hxx:87
bool hasTransparency() const
Returns true, if the color is transparent.
Definition: color.cxx:703
sal_Int16 getSchemeColorIndex() const
Definition: color.cxx:713
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:531
void assignIfUsed(const TextFont &rTextFont)
Overwrites this text font with the passed text font, if it is used.
Definition: textfont.cxx:72
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:78
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)
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_CharColorLumOff
constexpr OUStringLiteral PROP_CharHeightComplex
constexpr OUStringLiteral PROP_CharHeight
constexpr OUStringLiteral PROP_CharPostureComplex
constexpr OUStringLiteral PROP_CharLocale
constexpr OUStringLiteral PROP_CharContoured
constexpr OUStringLiteral PROP_CharPosture
constexpr OUStringLiteral PROP_CharColorTheme
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_CharColorLumMod
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