1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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:
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 );
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
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
));
108 // EG_TextUnderlineLine
109 case A_TOKEN( uLnTx
): // CT_TextUnderlineLineFollowText
110 mrTextCharacterProperties
.moUnderlineLineFollowText
= true;
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;
120 case A_TOKEN( uFill
): // CT_TextUnderlineFillGroupWrapper->EG_FillProperties (not supported)
121 return new SimpleFillPropertiesContext( *this, mrTextCharacterProperties
.maUnderlineColor
);
124 case A_TOKEN( latin
): // CT_TextFont
125 mrTextCharacterProperties
.maLatinFont
.setAttributes( rAttribs
);
127 case A_TOKEN( ea
): // CT_TextFont
128 mrTextCharacterProperties
.maAsianFont
.setAttributes( rAttribs
);
130 case A_TOKEN( cs
): // CT_TextFont
131 mrTextCharacterProperties
.maComplexFont
.setAttributes( rAttribs
);
133 case A_TOKEN( sym
): // CT_TextFont
134 mrTextCharacterProperties
.maSymbolFont
.setAttributes( rAttribs
);
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()));
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
;
213 case W_TOKEN( spacing
):
215 auto attrib
= rAttribs
.getInteger(W_TOKEN( val
), 0);
216 mrTextCharacterProperties
.moSpacing
= attrib
;
220 mrTextCharacterProperties
.moBold
= rAttribs
.getBool(W_TOKEN( val
), true);
223 mrTextCharacterProperties
.moItalic
= rAttribs
.getBool(W_TOKEN( val
), true);
227 case W_TOKEN( strike
):
228 if (rAttribs
.getBool(W_TOKEN(val
), true))
229 mrTextCharacterProperties
.moStrikeout
= XML_sngStrike
;
231 case W_TOKEN( dstrike
):
232 if (rAttribs
.getBool(W_TOKEN(val
), true))
233 mrTextCharacterProperties
.moStrikeout
= XML_dblStrike
;
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
);
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;
250 case W_TOKEN( szCs
):
252 case W_TOKEN( caps
):
254 if( rAttribs
.getBool(W_TOKEN( val
), true) )
255 mrTextCharacterProperties
.moCaseMap
= XML_all
;
257 mrTextCharacterProperties
.moCaseMap
= XML_none
;
260 case W_TOKEN( smallCaps
):
262 if( rAttribs
.getBool(W_TOKEN( val
), true) )
263 mrTextCharacterProperties
.moCaseMap
= XML_small
;
265 mrTextCharacterProperties
.moCaseMap
= XML_none
;
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;
280 mrTextCharacterProperties
.moLang
= rAttribs
.getString(W_TOKEN(val
), OUString());
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
);
299 SAL_WARN("oox", "TextCharacterPropertiesContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */