LibreOffice Module oox (master) 1
textcharacterpropertiescontext.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
28#include "hyperlinkcontext.hxx"
29#include <oox/token/namespaces.hxx>
30#include <oox/token/tokens.hxx>
31#include <sax/fastattribs.hxx>
32
33#include <sal/log.hxx>
34
35using namespace ::oox::core;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::xml::sax;
38using namespace ::com::sun::star::awt;
39
40namespace oox::drawingml {
41
42// CT_TextCharacterProperties
44 ContextHandler2Helper const & rParent,
45 const AttributeList& rAttribs,
46 TextCharacterProperties& rTextCharacterProperties )
47: ContextHandler2( rParent )
48, mrTextCharacterProperties( rTextCharacterProperties )
49{
50 int nVisualTokenAmount = sax_fastparser::castToFastAttributeList(
51 rAttribs.getFastAttributeList() ).getFastAttributeTokens().size();
52
53 if ( rAttribs.hasAttribute( XML_lang ) )
54 {
55 mrTextCharacterProperties.moLang = rAttribs.getString( XML_lang );
56 --nVisualTokenAmount; // Not a visual attribute
57 }
58 if ( rAttribs.hasAttribute( XML_altLang ))
59 {
60 --nVisualTokenAmount; // Not a visual attribute
61 }
62 if ( rAttribs.hasAttribute( XML_sz ) )
64 if ( rAttribs.hasAttribute( XML_spc ) )
66 if ( rAttribs.hasAttribute( XML_u ) )
68 if ( rAttribs.hasAttribute( XML_strike ) )
69 mrTextCharacterProperties.moStrikeout = rAttribs.getToken( XML_strike );
70 if ( rAttribs.hasAttribute( XML_baseline ) && rAttribs.getInteger( XML_baseline, 0 ) != 0 )
71 mrTextCharacterProperties.moBaseline = rAttribs.getInteger( XML_baseline );
72
73 if ( rAttribs.hasAttribute( XML_b ) )
74 mrTextCharacterProperties.moBold = rAttribs.getBool( XML_b );
75 if ( rAttribs.hasAttribute( XML_i ) )
76 mrTextCharacterProperties.moItalic = rAttribs.getBool( XML_i );
77 if( rAttribs.hasAttribute( XML_cap ) )
78 mrTextCharacterProperties.moCaseMap = rAttribs.getToken( XML_cap );
79 if ( rAttribs.hasAttribute( XML_dirty ) )
80 {
81 --nVisualTokenAmount; // Not a visual attribute
82 }
83 if ( rAttribs.hasAttribute( XML_smtClean ) )
84 {
85 --nVisualTokenAmount; // Not a visual attribute
86 }
87
88 if ( nVisualTokenAmount > 0 )
90
91 /* TODO / unhandled so far:
92 A_TOKEN( kern )
93 XML_altLang
94 A_TOKEN( kumimoji )
95 A_TOKEN( spc )
96 A_TOKEN( normalizeH )
97 A_TOKEN( noProof )
98 A_TOKEN( dirty )
99 A_TOKEN( err )
100 A_TOKEN( smtClean )
101 A_TOKEN( smtId )
102 */
103}
104
106{
107}
108
110{
111 if( aElementToken != A_TOKEN(lang) )
113
114 switch( aElementToken )
115 {
116 case A_TOKEN(ln): // CT_LineProperties
117 // TODO still largely unsupported
121 // EG_FillProperties
122 case A_TOKEN( noFill ):
123 case A_TOKEN( solidFill ):
124 case A_TOKEN( gradFill ):
125 case A_TOKEN( pattFill ):
126 case A_TOKEN( blipFill ): // Fontwork uses blibFill.
127 return FillPropertiesContext::createFillContext(*this, aElementToken, rAttribs, mrTextCharacterProperties.maFillProperties, nullptr);
128 // EG_EffectProperties
129 case A_TOKEN( effectDag ): // CT_EffectContainer 5.1.10.25
130 case A_TOKEN( effectLst ): // CT_EffectList 5.1.10.26
131 break;
132 case A_TOKEN( highlight ): // CT_Color
134 case W_TOKEN( highlight ):
136 break;
137 // EG_TextUnderlineLine
138 case A_TOKEN( uLnTx ): // CT_TextUnderlineLineFollowText
140 break;
141// TODO unsupported yet
142// case A_TOKEN( uLn ): // CT_LineProperties
143// return new LinePropertiesContext( getHandler(), rAttribs, maUnderlineProperties );
144
145 // EG_TextUnderlineFill
146 case A_TOKEN( uFillTx ): // CT_TextUnderlineFillFollowText
148 break;
149 case A_TOKEN( uFill ): // CT_TextUnderlineFillGroupWrapper->EG_FillProperties (not supported)
151
152 // CT_FontCollection
153 case A_TOKEN( latin ): // CT_TextFont
155 break;
156 case A_TOKEN( ea ): // CT_TextFont
158 break;
159 case A_TOKEN( cs ): // CT_TextFont
161 break;
162 case A_TOKEN( sym ): // CT_TextFont
164 break;
165
166 case A_TOKEN( hlinkClick ): // CT_Hyperlink
167 case A_TOKEN( hlinkMouseOver ): // CT_Hyperlink
169 case W_TOKEN( rFonts ):
170 if( rAttribs.hasAttribute(W_TOKEN(ascii)) )
171 {
173 }
174 if (rAttribs.hasAttribute(W_TOKEN(asciiTheme)))
175 {
177 }
178 if( rAttribs.hasAttribute(W_TOKEN(cs)) )
179 {
181 }
182 if (rAttribs.hasAttribute(W_TOKEN(cstheme)))
183 {
185 }
186 if( rAttribs.hasAttribute(W_TOKEN(eastAsia)) )
187 {
189 }
190 if (rAttribs.hasAttribute(W_TOKEN(eastAsiaTheme)))
191 {
193 }
194 break;
195 case W_TOKEN( u ):
196 {
197 // If you add here, check if it is in drawingmltypes.cxx 113.
198 auto attrib = rAttribs.getStringDefaulted(W_TOKEN(val));
199 if (attrib == "single" || attrib == "words") // TODO: implement words properly. Now it is a single line.
201 else if (attrib == "wavyHeavy")
203 else if (attrib == "wavyDouble")
205 else if (attrib == "wave")
207 else if (attrib == "thick")
209 else if (attrib == "dottedHeavy")
210 mrTextCharacterProperties.moUnderline = XML_dottedHeavy;
211 else if (attrib == "dotted")
213 else if (attrib == "dashDotDotHeavy")
214 mrTextCharacterProperties.moUnderline = XML_dotDotDashHeavy;
215 else if (attrib == "dotDotDash")
216 mrTextCharacterProperties.moUnderline = XML_dotDotDash;
217 else if (attrib == "dashDotHeavy")
218 mrTextCharacterProperties.moUnderline = XML_dotDashHeavy;
219 else if (attrib == "dotDash")
221 else if (attrib == "double")
223 else if (attrib == "dashLongHeavy")
224 mrTextCharacterProperties.moUnderline = XML_dashLongHeavy;
225 else if (attrib == "dashLong")
227 else if (attrib == "dashedHeavy")
229 else if (attrib == "dash")
231 else if (attrib == "none")
233 auto colorAttrib = rAttribs.getIntegerHex(W_TOKEN(color));
234 if (colorAttrib.has_value())
235 {
236 oox::drawingml::Color theColor;
237 theColor.setSrgbClr(colorAttrib.value());
239 }
240 break;
241 }
242 case W_TOKEN( spacing ):
243 {
244 auto attrib = rAttribs.getInteger(W_TOKEN( val ), 0);
246 break;
247 }
248 case W_TOKEN( b ):
249 mrTextCharacterProperties.moBold = rAttribs.getBool(W_TOKEN( val ), true);
250 break;
251 case W_TOKEN( i ):
252 mrTextCharacterProperties.moItalic = rAttribs.getBool(W_TOKEN( val ), true);
253 break;
254 case W_TOKEN( bCs ):
255 break;
256 case W_TOKEN( strike ):
257 if (rAttribs.getBool(W_TOKEN(val), true))
259 break;
260 case W_TOKEN( dstrike ):
261 if (rAttribs.getBool(W_TOKEN(val), true))
263 break;
264 case W_TOKEN( color ):
265 if (rAttribs.getInteger(W_TOKEN(val)).has_value())
266 {
269 }
270 break;
271 case W_TOKEN( sz ):
272 if (rAttribs.getInteger(W_TOKEN(val)).has_value())
273 {
274 sal_Int32 nVal = rAttribs.getInteger(W_TOKEN(val), 0);
275 // wml has half points, dml has hundred points
277 }
278 break;
279 case W_TOKEN( szCs ):
280 break;
281 case W_TOKEN( caps ):
282 {
283 if( rAttribs.getBool(W_TOKEN( val ), true) )
285 else
287 }
288 break;
289 case W_TOKEN( smallCaps ):
290 {
291 if( rAttribs.getBool(W_TOKEN( val ), true) )
293 else
295 }
296 break;
297 case W_TOKEN(vertAlign):
298 {
299 // Map wordprocessingML <w:vertAlign w:val="..."/> to drawingML
300 // <a:rPr baseline="...">.
301 sal_Int32 nVal = rAttribs.getToken(W_TOKEN(val), 0);
302 if (nVal == XML_superscript)
304 else if (nVal == XML_subscript)
306 break;
307 }
308 case W_TOKEN(lang):
309 mrTextCharacterProperties.moLang = rAttribs.getStringDefaulted(W_TOKEN(val));
310 break;
311 case OOX_TOKEN(w14, glow):
312 case OOX_TOKEN(w14, shadow):
313 case OOX_TOKEN(w14, reflection):
314 case OOX_TOKEN(w14, textOutline):
315 case OOX_TOKEN(w14, textFill):
316 case OOX_TOKEN(w14, scene3d):
317 case OOX_TOKEN(w14, props3d):
318 case OOX_TOKEN(w14, ligatures):
319 case OOX_TOKEN(w14, numForm):
320 case OOX_TOKEN(w14, numSpacing):
321 case OOX_TOKEN(w14, stylisticSets):
322 case OOX_TOKEN(w14, cntxtAlts):
323 {
324 return new TextEffectsContext( *this, aElementToken, mrTextCharacterProperties.maTextEffectsProperties );
325 }
326 break;
327 default:
328 SAL_WARN("oox", "TextCharacterPropertiesContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
329 break;
330 }
331
332 return this;
333}
334
335}
336
337/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
oox::drawingml::Color getHighlightColor(sal_Int32 nAttrToken) const
Returns the Color object of highlight of the text.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
std::optional< sal_Int32 > getIntegerHex(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (hexadecimal).
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
std::optional< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
Context handler for elements that contain a color value element (a:scrgbClr, a:srgbClr,...
void setSrgbClr(sal_Int32 nRgb)
Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element.
Definition: color.cxx:339
::oox::core::ContextHandlerRef createFillContext(::oox::core::ContextHandler2Helper const &rParent, sal_Int32 nElement, const ::oox::AttributeList &rAttribs, FillProperties &rFillProps, model::FillStyle *pFillStyle)
Context handler for elements that contain a fill property element (a:noFill, a:solidFill,...
TextCharacterPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, TextCharacterProperties &rTextCharacterProperties)
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
void setAttributes(const AttributeList &rAttribs)
Sets attributes from the passed attribute list.
Definition: textfont.cxx:57
const std::vector< sal_Int32 > & getFastAttributeTokens() const
float u
#define SAL_WARN(area, stream)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_none
Color maFillColor
Fill type (OOXML token).
std::optional< sal_Int32 > moFillType
std::vector< css::beans::PropertyValue > maTextEffectsProperties
bool mbHasVisualRunProperties
Set if there was a property set that alters run visually during import.
std::optional< LineProperties > moTextOutlineProperties