nss: upgrade to release 3.73
[LibreOffice.git] / oox / source / drawingml / textcharacterpropertiescontext.cxx
blob8fecb8bd2735baad28efc9ed1c7732e59f401b2b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawingml/textcharacterpropertiescontext.hxx>
22 #include <oox/helper/attributelist.hxx>
23 #include <drawingml/colorchoicecontext.hxx>
24 #include <drawingml/misccontexts.hxx>
25 #include <drawingml/textcharacterproperties.hxx>
26 #include <drawingml/texteffectscontext.hxx>
27 #include "hyperlinkcontext.hxx"
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
31 #include <sal/log.hxx>
33 using namespace ::oox::core;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::xml::sax;
36 using namespace ::com::sun::star::awt;
38 namespace oox::drawingml {
40 // CT_TextCharacterProperties
41 TextCharacterPropertiesContext::TextCharacterPropertiesContext(
42 ContextHandler2Helper const & rParent,
43 const AttributeList& rAttribs,
44 TextCharacterProperties& rTextCharacterProperties )
45 : ContextHandler2( rParent )
46 , mrTextCharacterProperties( rTextCharacterProperties )
48 if ( rAttribs.hasAttribute( XML_lang ) )
49 mrTextCharacterProperties.moLang = rAttribs.getString( XML_lang );
50 if ( rAttribs.hasAttribute( XML_sz ) )
51 mrTextCharacterProperties.moHeight = rAttribs.getInteger( XML_sz );
52 if ( rAttribs.hasAttribute( XML_spc ) )
53 mrTextCharacterProperties.moSpacing = rAttribs.getInteger( XML_spc );
54 if ( rAttribs.hasAttribute( XML_u ) )
55 mrTextCharacterProperties.moUnderline = rAttribs.getToken( XML_u );
56 if ( rAttribs.hasAttribute( XML_strike ) )
57 mrTextCharacterProperties.moStrikeout = rAttribs.getToken( XML_strike );
58 if ( rAttribs.hasAttribute( XML_baseline ) && rAttribs.getInteger( XML_baseline ).get() != 0 )
59 mrTextCharacterProperties.moBaseline = rAttribs.getInteger( XML_baseline );
61 if ( rAttribs.hasAttribute( XML_b ) )
62 mrTextCharacterProperties.moBold = rAttribs.getBool( XML_b );
63 if ( rAttribs.hasAttribute( XML_i ) )
64 mrTextCharacterProperties.moItalic = rAttribs.getBool( XML_i );
65 if( rAttribs.hasAttribute( XML_cap ) )
66 mrTextCharacterProperties.moCaseMap = rAttribs.getToken( XML_cap );
68 /* TODO / unhandled so far:
69 A_TOKEN( kern )
70 XML_altLang
71 A_TOKEN( kumimoji )
72 A_TOKEN( spc )
73 A_TOKEN( normalizeH )
74 A_TOKEN( noProof )
75 A_TOKEN( dirty )
76 A_TOKEN( err )
77 A_TOKEN( smtClean )
78 A_TOKEN( smtId )
82 TextCharacterPropertiesContext::~TextCharacterPropertiesContext()
86 ContextHandlerRef TextCharacterPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
88 switch( aElementToken )
90 // TODO unsupported yet
91 // case A_TOKEN( ln ): // CT_LineProperties
92 // return new LinePropertiesContext( getHandler(), rAttribs, maTextOutlineProperties );
93 // EG_FillProperties
94 case A_TOKEN( noFill ):
95 case A_TOKEN( solidFill ):
96 case A_TOKEN( gradFill ):
97 case A_TOKEN( pattFill ):
98 return FillPropertiesContext::createFillContext( *this, aElementToken, rAttribs, mrTextCharacterProperties.maFillProperties );
99 // EG_EffectProperties
100 case A_TOKEN( effectDag ): // CT_EffectContainer 5.1.10.25
101 case A_TOKEN( effectLst ): // CT_EffectList 5.1.10.26
102 break;
103 case A_TOKEN( highlight ): // CT_Color
104 return new ColorContext(*this, mrTextCharacterProperties.maHighlightColor);
105 case W_TOKEN( highlight ):
106 mrTextCharacterProperties.maHighlightColor = rAttribs.getHighlightColor(W_TOKEN(val));
107 break;
108 // EG_TextUnderlineLine
109 case A_TOKEN( uLnTx ): // CT_TextUnderlineLineFollowText
110 mrTextCharacterProperties.moUnderlineLineFollowText = true;
111 break;
112 // TODO unsupported yet
113 // case A_TOKEN( uLn ): // CT_LineProperties
114 // return new LinePropertiesContext( getHandler(), rAttribs, maUnderlineProperties );
116 // EG_TextUnderlineFill
117 case A_TOKEN( uFillTx ): // CT_TextUnderlineFillFollowText
118 mrTextCharacterProperties.moUnderlineFillFollowText = true;
119 break;
120 case A_TOKEN( uFill ): // CT_TextUnderlineFillGroupWrapper->EG_FillProperties (not supported)
121 return new SimpleFillPropertiesContext( *this, mrTextCharacterProperties.maUnderlineColor );
123 // CT_FontCollection
124 case A_TOKEN( latin ): // CT_TextFont
125 mrTextCharacterProperties.maLatinFont.setAttributes( rAttribs );
126 break;
127 case A_TOKEN( ea ): // CT_TextFont
128 mrTextCharacterProperties.maAsianFont.setAttributes( rAttribs );
129 break;
130 case A_TOKEN( cs ): // CT_TextFont
131 mrTextCharacterProperties.maComplexFont.setAttributes( rAttribs );
132 break;
133 case A_TOKEN( sym ): // CT_TextFont
134 mrTextCharacterProperties.maSymbolFont.setAttributes( rAttribs );
135 break;
137 case A_TOKEN( hlinkClick ): // CT_Hyperlink
138 case A_TOKEN( hlinkMouseOver ): // CT_Hyperlink
139 return new HyperLinkContext( *this, rAttribs, mrTextCharacterProperties.maHyperlinkPropertyMap );
140 case W_TOKEN( rFonts ):
141 if( rAttribs.hasAttribute(W_TOKEN(ascii)) )
143 mrTextCharacterProperties.maLatinFont.setAttributes(rAttribs.getString(W_TOKEN(ascii), OUString()));
145 if (rAttribs.hasAttribute(W_TOKEN(asciiTheme)))
147 mrTextCharacterProperties.maLatinThemeFont.setAttributes(rAttribs.getString(W_TOKEN(asciiTheme), OUString()));
149 if( rAttribs.hasAttribute(W_TOKEN(cs)) )
151 mrTextCharacterProperties.maComplexFont.setAttributes(rAttribs.getString(W_TOKEN(cs), OUString()));
153 if (rAttribs.hasAttribute(W_TOKEN(cstheme)))
155 mrTextCharacterProperties.maComplexThemeFont.setAttributes(rAttribs.getString(W_TOKEN(cstheme), OUString()));
157 if( rAttribs.hasAttribute(W_TOKEN(eastAsia)) )
159 mrTextCharacterProperties.maAsianFont.setAttributes(rAttribs.getString(W_TOKEN(eastAsia), OUString()));
161 if (rAttribs.hasAttribute(W_TOKEN(eastAsiaTheme)))
163 mrTextCharacterProperties.maAsianThemeFont.setAttributes(rAttribs.getString(W_TOKEN(eastAsiaTheme), OUString()));
165 break;
166 case W_TOKEN( u ):
168 // If you add here, check if it is in drawingmltypes.cxx 113.
169 auto attrib = rAttribs.getString(W_TOKEN(val), OUString());
170 if (attrib == "single" || attrib == "words") // TODO: implement words properly. Now it is a single line.
171 mrTextCharacterProperties.moUnderline = XML_sng;
172 else if (attrib == "wavyHeavy")
173 mrTextCharacterProperties.moUnderline = XML_wavyHeavy;
174 else if (attrib == "wavyDouble")
175 mrTextCharacterProperties.moUnderline = XML_wavyDbl;
176 else if (attrib == "wave")
177 mrTextCharacterProperties.moUnderline = XML_wavy;
178 else if (attrib == "thick")
179 mrTextCharacterProperties.moUnderline = XML_heavy;
180 else if (attrib == "dottedHeavy")
181 mrTextCharacterProperties.moUnderline = XML_dottedHeavy;
182 else if (attrib == "dotted")
183 mrTextCharacterProperties.moUnderline = XML_dotted;
184 else if (attrib == "dashDotDotHeavy")
185 mrTextCharacterProperties.moUnderline = XML_dotDotDashHeavy;
186 else if (attrib == "dotDotDash")
187 mrTextCharacterProperties.moUnderline = XML_dotDotDash;
188 else if (attrib == "dashDotHeavy")
189 mrTextCharacterProperties.moUnderline = XML_dotDashHeavy;
190 else if (attrib == "dotDash")
191 mrTextCharacterProperties.moUnderline = XML_dotDash;
192 else if (attrib == "double")
193 mrTextCharacterProperties.moUnderline = XML_dbl;
194 else if (attrib == "dashLongHeavy")
195 mrTextCharacterProperties.moUnderline = XML_dashLongHeavy;
196 else if (attrib == "dashLong")
197 mrTextCharacterProperties.moUnderline = XML_dashLong;
198 else if (attrib == "dashedHeavy")
199 mrTextCharacterProperties.moUnderline = XML_dashHeavy;
200 else if (attrib == "dash")
201 mrTextCharacterProperties.moUnderline = XML_dash;
202 else if (attrib == "none")
203 mrTextCharacterProperties.moUnderline = XML_none;
204 auto colorAttrib = rAttribs.getIntegerHex(W_TOKEN(color));
205 if (colorAttrib.has())
207 oox::drawingml::Color theColor;
208 theColor.setSrgbClr(colorAttrib.get());
209 mrTextCharacterProperties.maUnderlineColor = theColor;
211 break;
213 case W_TOKEN( spacing ):
215 auto attrib = rAttribs.getInteger(W_TOKEN( val ), 0);
216 mrTextCharacterProperties.moSpacing = attrib;
217 break;
219 case W_TOKEN( b ):
220 mrTextCharacterProperties.moBold = rAttribs.getBool(W_TOKEN( val ), true);
221 break;
222 case W_TOKEN( i ):
223 mrTextCharacterProperties.moItalic = rAttribs.getBool(W_TOKEN( val ), true);
224 break;
225 case W_TOKEN( bCs ):
226 break;
227 case W_TOKEN( strike ):
228 if (rAttribs.getBool(W_TOKEN(val), true))
229 mrTextCharacterProperties.moStrikeout = XML_sngStrike;
230 break;
231 case W_TOKEN( dstrike ):
232 if (rAttribs.getBool(W_TOKEN(val), true))
233 mrTextCharacterProperties.moStrikeout = XML_dblStrike;
234 break;
235 case W_TOKEN( color ):
236 if (rAttribs.getInteger(W_TOKEN(val)).has())
238 mrTextCharacterProperties.maFillProperties.maFillColor.setSrgbClr(rAttribs.getIntegerHex(W_TOKEN(val)).get());
239 mrTextCharacterProperties.maFillProperties.moFillType.set(XML_solidFill);
241 break;
242 case W_TOKEN( sz ):
243 if (rAttribs.getInteger(W_TOKEN(val)).has())
245 sal_Int32 nVal = rAttribs.getInteger(W_TOKEN(val)).get();
246 // wml has half points, dml has hundred points
247 mrTextCharacterProperties.moHeight = nVal * 50;
249 break;
250 case W_TOKEN( szCs ):
251 break;
252 case W_TOKEN( caps ):
254 if( rAttribs.getBool(W_TOKEN( val ), true) )
255 mrTextCharacterProperties.moCaseMap = XML_all;
256 else
257 mrTextCharacterProperties.moCaseMap = XML_none;
259 break;
260 case W_TOKEN( smallCaps ):
262 if( rAttribs.getBool(W_TOKEN( val ), true) )
263 mrTextCharacterProperties.moCaseMap = XML_small;
264 else
265 mrTextCharacterProperties.moCaseMap = XML_none;
267 break;
268 case W_TOKEN(vertAlign):
270 // Map wordprocessingML <w:vertAlign w:val="..."/> to drawingML
271 // <a:rPr baseline="...">.
272 sal_Int32 nVal = rAttribs.getToken(W_TOKEN(val), 0);
273 if (nVal == XML_superscript)
274 mrTextCharacterProperties.moBaseline = 30000;
275 else if (nVal == XML_subscript)
276 mrTextCharacterProperties.moBaseline = -25000;
277 break;
279 case W_TOKEN(lang):
280 mrTextCharacterProperties.moLang = rAttribs.getString(W_TOKEN(val), OUString());
281 break;
282 case OOX_TOKEN(w14, glow):
283 case OOX_TOKEN(w14, shadow):
284 case OOX_TOKEN(w14, reflection):
285 case OOX_TOKEN(w14, textOutline):
286 case OOX_TOKEN(w14, textFill):
287 case OOX_TOKEN(w14, scene3d):
288 case OOX_TOKEN(w14, props3d):
289 case OOX_TOKEN(w14, ligatures):
290 case OOX_TOKEN(w14, numForm):
291 case OOX_TOKEN(w14, numSpacing):
292 case OOX_TOKEN(w14, stylisticSets):
293 case OOX_TOKEN(w14, cntxtAlts):
295 return new TextEffectsContext( *this, aElementToken, mrTextCharacterProperties.maTextEffectsProperties );
297 break;
298 default:
299 SAL_WARN("oox", "TextCharacterPropertiesContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
300 break;
303 return this;
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */