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 
27 #include "hyperlinkcontext.hxx"
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 #include <sax/fastattribs.hxx>
31 #include <sax/fastparser.hxx>
32 
33 #include <sal/log.hxx>
34 
35 using namespace ::oox::core;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::xml::sax;
38 using namespace ::com::sun::star::awt;
39 
40 namespace 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 ) )
63  mrTextCharacterProperties.moHeight = rAttribs.getInteger( XML_sz );
64  if ( rAttribs.hasAttribute( XML_spc ) )
65  mrTextCharacterProperties.moSpacing = rAttribs.getInteger( 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 ).get() != 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 // TODO unsupported yet
117 // case A_TOKEN( ln ): // CT_LineProperties
118 // return new LinePropertiesContext( getHandler(), rAttribs, maTextOutlineProperties );
119  // EG_FillProperties
120  case A_TOKEN( noFill ):
121  case A_TOKEN( solidFill ):
122  case A_TOKEN( gradFill ):
123  case A_TOKEN( pattFill ):
125  // EG_EffectProperties
126  case A_TOKEN( effectDag ): // CT_EffectContainer 5.1.10.25
127  case A_TOKEN( effectLst ): // CT_EffectList 5.1.10.26
128  break;
129  case A_TOKEN( highlight ): // CT_Color
131  case W_TOKEN( highlight ):
133  break;
134  // EG_TextUnderlineLine
135  case A_TOKEN( uLnTx ): // CT_TextUnderlineLineFollowText
137  break;
138 // TODO unsupported yet
139 // case A_TOKEN( uLn ): // CT_LineProperties
140 // return new LinePropertiesContext( getHandler(), rAttribs, maUnderlineProperties );
141 
142  // EG_TextUnderlineFill
143  case A_TOKEN( uFillTx ): // CT_TextUnderlineFillFollowText
145  break;
146  case A_TOKEN( uFill ): // CT_TextUnderlineFillGroupWrapper->EG_FillProperties (not supported)
148 
149  // CT_FontCollection
150  case A_TOKEN( latin ): // CT_TextFont
152  break;
153  case A_TOKEN( ea ): // CT_TextFont
155  break;
156  case A_TOKEN( cs ): // CT_TextFont
158  break;
159  case A_TOKEN( sym ): // CT_TextFont
161  break;
162 
163  case A_TOKEN( hlinkClick ): // CT_Hyperlink
164  case A_TOKEN( hlinkMouseOver ): // CT_Hyperlink
166  case W_TOKEN( rFonts ):
167  if( rAttribs.hasAttribute(W_TOKEN(ascii)) )
168  {
169  mrTextCharacterProperties.maLatinFont.setAttributes(rAttribs.getString(W_TOKEN(ascii), OUString()));
170  }
171  if (rAttribs.hasAttribute(W_TOKEN(asciiTheme)))
172  {
173  mrTextCharacterProperties.maLatinThemeFont.setAttributes(rAttribs.getString(W_TOKEN(asciiTheme), OUString()));
174  }
175  if( rAttribs.hasAttribute(W_TOKEN(cs)) )
176  {
177  mrTextCharacterProperties.maComplexFont.setAttributes(rAttribs.getString(W_TOKEN(cs), OUString()));
178  }
179  if (rAttribs.hasAttribute(W_TOKEN(cstheme)))
180  {
181  mrTextCharacterProperties.maComplexThemeFont.setAttributes(rAttribs.getString(W_TOKEN(cstheme), OUString()));
182  }
183  if( rAttribs.hasAttribute(W_TOKEN(eastAsia)) )
184  {
185  mrTextCharacterProperties.maAsianFont.setAttributes(rAttribs.getString(W_TOKEN(eastAsia), OUString()));
186  }
187  if (rAttribs.hasAttribute(W_TOKEN(eastAsiaTheme)))
188  {
189  mrTextCharacterProperties.maAsianThemeFont.setAttributes(rAttribs.getString(W_TOKEN(eastAsiaTheme), OUString()));
190  }
191  break;
192  case W_TOKEN( u ):
193  {
194  // If you add here, check if it is in drawingmltypes.cxx 113.
195  auto attrib = rAttribs.getString(W_TOKEN(val), OUString());
196  if (attrib == "single" || attrib == "words") // TODO: implement words properly. Now it is a single line.
198  else if (attrib == "wavyHeavy")
199  mrTextCharacterProperties.moUnderline = XML_wavyHeavy;
200  else if (attrib == "wavyDouble")
202  else if (attrib == "wave")
204  else if (attrib == "thick")
206  else if (attrib == "dottedHeavy")
207  mrTextCharacterProperties.moUnderline = XML_dottedHeavy;
208  else if (attrib == "dotted")
210  else if (attrib == "dashDotDotHeavy")
211  mrTextCharacterProperties.moUnderline = XML_dotDotDashHeavy;
212  else if (attrib == "dotDotDash")
213  mrTextCharacterProperties.moUnderline = XML_dotDotDash;
214  else if (attrib == "dashDotHeavy")
215  mrTextCharacterProperties.moUnderline = XML_dotDashHeavy;
216  else if (attrib == "dotDash")
218  else if (attrib == "double")
220  else if (attrib == "dashLongHeavy")
221  mrTextCharacterProperties.moUnderline = XML_dashLongHeavy;
222  else if (attrib == "dashLong")
223  mrTextCharacterProperties.moUnderline = XML_dashLong;
224  else if (attrib == "dashedHeavy")
225  mrTextCharacterProperties.moUnderline = XML_dashHeavy;
226  else if (attrib == "dash")
228  else if (attrib == "none")
230  auto colorAttrib = rAttribs.getIntegerHex(W_TOKEN(color));
231  if (colorAttrib.has())
232  {
233  oox::drawingml::Color theColor;
234  theColor.setSrgbClr(colorAttrib.get());
236  }
237  break;
238  }
239  case W_TOKEN( spacing ):
240  {
241  auto attrib = rAttribs.getInteger(W_TOKEN( val ), 0);
243  break;
244  }
245  case W_TOKEN( b ):
246  mrTextCharacterProperties.moBold = rAttribs.getBool(W_TOKEN( val ), true);
247  break;
248  case W_TOKEN( i ):
249  mrTextCharacterProperties.moItalic = rAttribs.getBool(W_TOKEN( val ), true);
250  break;
251  case W_TOKEN( bCs ):
252  break;
253  case W_TOKEN( strike ):
254  if (rAttribs.getBool(W_TOKEN(val), true))
255  mrTextCharacterProperties.moStrikeout = XML_sngStrike;
256  break;
257  case W_TOKEN( dstrike ):
258  if (rAttribs.getBool(W_TOKEN(val), true))
259  mrTextCharacterProperties.moStrikeout = XML_dblStrike;
260  break;
261  case W_TOKEN( color ):
262  if (rAttribs.getInteger(W_TOKEN(val)).has())
263  {
266  }
267  break;
268  case W_TOKEN( sz ):
269  if (rAttribs.getInteger(W_TOKEN(val)).has())
270  {
271  sal_Int32 nVal = rAttribs.getInteger(W_TOKEN(val)).get();
272  // wml has half points, dml has hundred points
274  }
275  break;
276  case W_TOKEN( szCs ):
277  break;
278  case W_TOKEN( caps ):
279  {
280  if( rAttribs.getBool(W_TOKEN( val ), true) )
282  else
284  }
285  break;
286  case W_TOKEN( smallCaps ):
287  {
288  if( rAttribs.getBool(W_TOKEN( val ), true) )
290  else
292  }
293  break;
294  case W_TOKEN(vertAlign):
295  {
296  // Map wordprocessingML <w:vertAlign w:val="..."/> to drawingML
297  // <a:rPr baseline="...">.
298  sal_Int32 nVal = rAttribs.getToken(W_TOKEN(val), 0);
299  if (nVal == XML_superscript)
301  else if (nVal == XML_subscript)
303  break;
304  }
305  case W_TOKEN(lang):
306  mrTextCharacterProperties.moLang = rAttribs.getString(W_TOKEN(val), OUString());
307  break;
308  case OOX_TOKEN(w14, glow):
309  case OOX_TOKEN(w14, shadow):
310  case OOX_TOKEN(w14, reflection):
311  case OOX_TOKEN(w14, textOutline):
312  case OOX_TOKEN(w14, textFill):
313  case OOX_TOKEN(w14, scene3d):
314  case OOX_TOKEN(w14, props3d):
315  case OOX_TOKEN(w14, ligatures):
316  case OOX_TOKEN(w14, numForm):
317  case OOX_TOKEN(w14, numSpacing):
318  case OOX_TOKEN(w14, stylisticSets):
319  case OOX_TOKEN(w14, cntxtAlts):
320  {
321  return new TextEffectsContext( *this, aElementToken, mrTextCharacterProperties.maTextEffectsProperties );
322  }
323  break;
324  default:
325  SAL_WARN("oox", "TextCharacterPropertiesContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
326  break;
327  }
328 
329  return this;
330 }
331 
332 }
333 
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define ascii(x)
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
bool mbHasVisualRunProperties
Set if there was a property set that alters run visually during import.
OptValue< sal_Int32 > moFillType
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
oox::drawingml::Color getHighlightColor(sal_Int32 nAttrToken) const
Returns the Color object of highlight of the text.
std::vector< css::beans::PropertyValue > maTextEffectsProperties
void set(const Type &rValue)
Definition: helper.hxx:188
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
const Type & get() const
Definition: helper.hxx:185
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
Context handler for elements that contain a color value element (a:scrgbClr, a:srgbClr, a:hslClr, a:sysClr, a:schemeClr, a:prstClr).
float u
void setAttributes(const AttributeList &rAttribs)
Sets attributes from the passed attribute list.
Definition: textfont.cxx:56
Provides access to attribute values of an element.
exports com.sun.star. reflection
OptValue< sal_Int32 > getIntegerHex(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (hexadecimal). ...
void setSrgbClr(sal_Int32 nRgb)
Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element.
Definition: color.cxx:260
exports com.sun.star. lang
Context handler for elements that contain a fill property element (a:noFill, a:solidFill, a:gradFill, a:pattFill, a:blipFill, a:grpFill).
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
TextCharacterPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, TextCharacterProperties &rTextCharacterProperties)
::oox::core::ContextHandlerRef createFillContext(::oox::core::ContextHandler2Helper const &rParent, sal_Int32 nElement, const ::oox::AttributeList &rAttribs, FillProperties &rFillProps)
#define SAL_WARN(area, stream)
Color maFillColor
Fill type (OOXML token).
Helper class that provides a context stack.
bool has() const
Definition: helper.hxx:181
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.