Line data Source code
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 :
20 : #include "drawingml/textcharacterpropertiescontext.hxx"
21 :
22 : #include "oox/helper/attributelist.hxx"
23 : #include "oox/drawingml/drawingmltypes.hxx"
24 : #include "drawingml/colorchoicecontext.hxx"
25 : #include "drawingml/texteffectscontext.hxx"
26 : #include "oox/drawingml/lineproperties.hxx"
27 : #include "drawingml/textparagraphproperties.hxx"
28 : #include "oox/core/relations.hxx"
29 : #include "hyperlinkcontext.hxx"
30 :
31 : using namespace ::oox::core;
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::xml::sax;
34 : using namespace ::com::sun::star::awt;
35 :
36 : namespace oox { namespace drawingml {
37 :
38 : // CT_TextCharacterProperties
39 8656 : TextCharacterPropertiesContext::TextCharacterPropertiesContext(
40 : ContextHandler2Helper& rParent,
41 : const AttributeList& rAttribs,
42 : TextCharacterProperties& rTextCharacterProperties )
43 : : ContextHandler2( rParent )
44 8656 : , mrTextCharacterProperties( rTextCharacterProperties )
45 : {
46 8656 : if ( rAttribs.hasAttribute( XML_lang ) )
47 4958 : mrTextCharacterProperties.moLang = rAttribs.getString( XML_lang );
48 8656 : if ( rAttribs.hasAttribute( XML_sz ) )
49 4455 : mrTextCharacterProperties.moHeight = rAttribs.getInteger( XML_sz );
50 8656 : if ( rAttribs.hasAttribute( XML_spc ) )
51 505 : mrTextCharacterProperties.moSpacing = rAttribs.getInteger( XML_spc );
52 8656 : if ( rAttribs.hasAttribute( XML_u ) )
53 176 : mrTextCharacterProperties.moUnderline = rAttribs.getToken( XML_u );
54 8656 : if ( rAttribs.hasAttribute( XML_strike ) )
55 288 : mrTextCharacterProperties.moStrikeout = rAttribs.getToken( XML_strike );
56 8656 : if ( rAttribs.hasAttribute( XML_baseline ) && rAttribs.getInteger( XML_baseline ).get() != 0 )
57 6 : mrTextCharacterProperties.moBaseline = rAttribs.getInteger( XML_baseline );
58 :
59 8656 : if ( rAttribs.hasAttribute( XML_b ) )
60 1474 : mrTextCharacterProperties.moBold = rAttribs.getBool( XML_b );
61 8656 : if ( rAttribs.hasAttribute( XML_i ) )
62 246 : mrTextCharacterProperties.moItalic = rAttribs.getBool( XML_i );
63 8656 : if( rAttribs.hasAttribute( XML_cap ) )
64 88 : mrTextCharacterProperties.moCaseMap = rAttribs.getToken( XML_cap );
65 :
66 : /* TODO / unhandled so far:
67 : A_TOKEN( kern )
68 : XML_altLang
69 : A_TOKEN( kumimoji )
70 : A_TOKEN( spc )
71 : A_TOKEN( normalizeH )
72 : A_TOKEN( noProof )
73 : A_TOKEN( dirty )
74 : A_TOKEN( err )
75 : A_TOKEN( smtClean )
76 : A_TOKEN( smtId )
77 : */
78 8656 : }
79 :
80 17312 : TextCharacterPropertiesContext::~TextCharacterPropertiesContext()
81 : {
82 17312 : }
83 :
84 12777 : ContextHandlerRef TextCharacterPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
85 : {
86 12777 : switch( aElementToken )
87 : {
88 : // TODO unsupported yet
89 : // case A_TOKEN( ln ): // CT_LineProperties
90 : // return new LinePropertiesContext( getHandler(), rAttribs, maTextOutlineProperties );
91 :
92 : case A_TOKEN( solidFill ): // EG_FillProperties
93 3942 : return new ColorContext( *this, mrTextCharacterProperties.maCharColor );
94 :
95 : // EG_EffectProperties
96 : case A_TOKEN( effectDag ): // CT_EffectContainer 5.1.10.25
97 : case A_TOKEN( effectLst ): // CT_EffectList 5.1.10.26
98 83 : break;
99 :
100 : case A_TOKEN( highlight ): // CT_Color
101 0 : return new ColorContext( *this, mrTextCharacterProperties.maHighlightColor );
102 :
103 : // EG_TextUnderlineLine
104 : case A_TOKEN( uLnTx ): // CT_TextUnderlineLineFollowText
105 8 : mrTextCharacterProperties.moUnderlineLineFollowText = true;
106 8 : break;
107 : // TODO unsupported yet
108 : // case A_TOKEN( uLn ): // CT_LineProperties
109 : // return new LinePropertiesContext( getHandler(), rAttribs, maUnderlineProperties );
110 :
111 : // EG_TextUnderlineFill
112 : case A_TOKEN( uFillTx ): // CT_TextUnderlineFillFollowText
113 8 : mrTextCharacterProperties.moUnderlineFillFollowText = true;
114 8 : break;
115 : case A_TOKEN( uFill ): // CT_TextUnderlineFillGroupWrapper->EG_FillProperties (not supported)
116 119 : return new SimpleFillPropertiesContext( *this, mrTextCharacterProperties.maUnderlineColor );
117 :
118 : // CT_FontCollection
119 : case A_TOKEN( latin ): // CT_TextFont
120 2900 : mrTextCharacterProperties.maLatinFont.setAttributes( rAttribs );
121 2900 : break;
122 : case A_TOKEN( ea ): // CT_TextFont
123 2232 : mrTextCharacterProperties.maAsianFont.setAttributes( rAttribs );
124 2232 : break;
125 : case A_TOKEN( cs ): // CT_TextFont
126 2268 : mrTextCharacterProperties.maComplexFont.setAttributes( rAttribs );
127 2268 : break;
128 : case A_TOKEN( sym ): // CT_TextFont
129 0 : mrTextCharacterProperties.maSymbolFont.setAttributes( rAttribs );
130 0 : break;
131 :
132 : case A_TOKEN( hlinkClick ): // CT_Hyperlink
133 : case A_TOKEN( hlinkMouseOver ): // CT_Hyperlink
134 0 : return new HyperLinkContext( *this, rAttribs, mrTextCharacterProperties.maHyperlinkPropertyMap );
135 :
136 : case A_TOKEN( gradFill ):
137 1 : return new GradientFillContext( *this, rAttribs, mrTextCharacterProperties.maGradientProps );
138 :
139 : case W_TOKEN( rFonts ):
140 63 : if( rAttribs.hasAttribute(W_TOKEN(ascii)) )
141 : {
142 39 : mrTextCharacterProperties.maLatinFont.setAttributes(rAttribs.getString(W_TOKEN(ascii), OUString()));
143 : }
144 63 : if (rAttribs.hasAttribute(W_TOKEN(asciiTheme)))
145 : {
146 8 : mrTextCharacterProperties.maLatinThemeFont.setAttributes(rAttribs.getString(W_TOKEN(asciiTheme), OUString()));
147 : }
148 63 : if( rAttribs.hasAttribute(W_TOKEN(cs)) )
149 : {
150 43 : mrTextCharacterProperties.maComplexFont.setAttributes(rAttribs.getString(W_TOKEN(cs), OUString()));
151 : }
152 63 : if (rAttribs.hasAttribute(W_TOKEN(cstheme)))
153 : {
154 6 : mrTextCharacterProperties.maComplexThemeFont.setAttributes(rAttribs.getString(W_TOKEN(cstheme), OUString()));
155 : }
156 63 : if( rAttribs.hasAttribute(W_TOKEN(eastAsia)) )
157 : {
158 12 : mrTextCharacterProperties.maAsianFont.setAttributes(rAttribs.getString(W_TOKEN(eastAsia), OUString()));
159 : }
160 63 : if (rAttribs.hasAttribute(W_TOKEN(eastAsiaTheme)))
161 : {
162 6 : mrTextCharacterProperties.maAsianThemeFont.setAttributes(rAttribs.getString(W_TOKEN(eastAsiaTheme), OUString()));
163 : }
164 63 : break;
165 : case W_TOKEN( b ):
166 48 : mrTextCharacterProperties.moBold = rAttribs.getBool(W_TOKEN( val ), true);
167 48 : break;
168 : case W_TOKEN( i ):
169 50 : mrTextCharacterProperties.moItalic = rAttribs.getBool(W_TOKEN( val ), true);
170 50 : break;
171 : case W_TOKEN( bCs ):
172 40 : break;
173 : case W_TOKEN( color ):
174 130 : if (rAttribs.getInteger(W_TOKEN(val)).has())
175 : {
176 130 : mrTextCharacterProperties.maCharColor.setSrgbClr(rAttribs.getIntegerHex(W_TOKEN(val)).get());
177 : }
178 130 : break;
179 : case W_TOKEN( sz ):
180 161 : if (rAttribs.getInteger(W_TOKEN(val)).has())
181 : {
182 161 : sal_Int32 nVal = rAttribs.getInteger(W_TOKEN(val)).get();
183 : // wml has half points, dml has hundred points
184 161 : mrTextCharacterProperties.moHeight = nVal * 50;
185 : }
186 161 : break;
187 : case W_TOKEN( szCs ):
188 62 : break;
189 : case W_TOKEN( caps ):
190 : {
191 33 : if( rAttribs.getBool(W_TOKEN( val ), true) )
192 8 : mrTextCharacterProperties.moCaseMap = XML_all;
193 : else
194 25 : mrTextCharacterProperties.moCaseMap = XML_none;
195 : }
196 33 : break;
197 : case W_TOKEN( smallCaps ):
198 : {
199 26 : if( rAttribs.getBool(W_TOKEN( val ), true) )
200 1 : mrTextCharacterProperties.moCaseMap = XML_small;
201 : else
202 25 : mrTextCharacterProperties.moCaseMap = XML_none;
203 : }
204 26 : break;
205 : case OOX_TOKEN(w14, glow):
206 : case OOX_TOKEN(w14, shadow):
207 : case OOX_TOKEN(w14, reflection):
208 : case OOX_TOKEN(w14, textOutline):
209 : case OOX_TOKEN(w14, textFill):
210 : case OOX_TOKEN(w14, scene3d):
211 : case OOX_TOKEN(w14, props3d):
212 : case OOX_TOKEN(w14, ligatures):
213 : case OOX_TOKEN(w14, numForm):
214 : case OOX_TOKEN(w14, numSpacing):
215 : case OOX_TOKEN(w14, stylisticSets):
216 : case OOX_TOKEN(w14, cntxtAlts):
217 : {
218 30 : return new TextEffectsContext( *this, aElementToken, mrTextCharacterProperties.maTextEffectsProperties );
219 : }
220 : break;
221 : default:
222 : SAL_WARN("oox", "TextCharacterPropertiesContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
223 573 : break;
224 : }
225 :
226 8685 : return this;
227 : }
228 :
229 : } }
230 :
231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|