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 : */
10 :
11 : #include "oox/drawingml/texteffectscontext.hxx"
12 :
13 : #include <map>
14 :
15 : namespace oox { namespace drawingml {
16 :
17 : namespace
18 : {
19 :
20 0 : OUString lclGetNameForElementId(sal_uInt32 aId)
21 : {
22 0 : static std::map<sal_uInt32, OUString> aIdMap;
23 0 : if(aIdMap.empty())
24 : {
25 0 : aIdMap[OOX_TOKEN(w14, srgbClr)] = "srgbClr";
26 0 : aIdMap[OOX_TOKEN(w14, schemeClr)] = "schemeClr";
27 0 : aIdMap[OOX_TOKEN(w14, tint)] = "tint";
28 0 : aIdMap[OOX_TOKEN(w14, shade)] = "shade";
29 0 : aIdMap[OOX_TOKEN(w14, alpha)] = "alpha";
30 0 : aIdMap[OOX_TOKEN(w14, hueMod)] = "hueMod";
31 0 : aIdMap[OOX_TOKEN(w14, sat)] = "sat";
32 0 : aIdMap[OOX_TOKEN(w14, satOff)] = "satOff";
33 0 : aIdMap[OOX_TOKEN(w14, satMod)] = "satMod";
34 0 : aIdMap[OOX_TOKEN(w14, lum)] = "lum";
35 0 : aIdMap[OOX_TOKEN(w14, lumOff)] = "lumOff";
36 0 : aIdMap[OOX_TOKEN(w14, lumMod)] = "lumMod";
37 0 : aIdMap[OOX_TOKEN(w14, noFill)] = "noFill";
38 0 : aIdMap[OOX_TOKEN(w14, solidFill)] = "solidFill";
39 0 : aIdMap[OOX_TOKEN(w14, gradFill)] = "gradFill";
40 0 : aIdMap[OOX_TOKEN(w14, gsLst)] = "gsLst";
41 0 : aIdMap[OOX_TOKEN(w14, gs)] = "gs";
42 0 : aIdMap[OOX_TOKEN(w14, pos)] = "pos";
43 0 : aIdMap[OOX_TOKEN(w14, lin)] = "lin";
44 0 : aIdMap[OOX_TOKEN(w14, path)] = "path";
45 0 : aIdMap[OOX_TOKEN(w14, fillToRect)] = "fillToRect";
46 0 : aIdMap[OOX_TOKEN(w14, prstDash)] = "prstDash";
47 0 : aIdMap[OOX_TOKEN(w14, round)] = "round";
48 0 : aIdMap[OOX_TOKEN(w14, bevel)] = "bevel";
49 0 : aIdMap[OOX_TOKEN(w14, miter)] = "miter";
50 0 : aIdMap[OOX_TOKEN(w14, camera)] = "camera";
51 0 : aIdMap[OOX_TOKEN(w14, lightRig)] = "lightRig";
52 0 : aIdMap[OOX_TOKEN(w14, rot)] = "rot";
53 0 : aIdMap[OOX_TOKEN(w14, bevelT)] = "bevelT";
54 0 : aIdMap[OOX_TOKEN(w14, bevelB)] = "bevelB";
55 0 : aIdMap[OOX_TOKEN(w14, extrusionClr)] = "extrusionClr";
56 0 : aIdMap[OOX_TOKEN(w14, contourClr)] = "contourClr";
57 0 : aIdMap[OOX_TOKEN(w14, styleSet)] = "styleSet";
58 :
59 0 : aIdMap[OOX_TOKEN(w14, glow)] = "glow";
60 0 : aIdMap[OOX_TOKEN(w14, shadow)] = "shadow";
61 0 : aIdMap[OOX_TOKEN(w14, reflection)] = "reflection";
62 0 : aIdMap[OOX_TOKEN(w14, textOutline)] = "textOutline";
63 0 : aIdMap[OOX_TOKEN(w14, textFill)] = "textFill";
64 0 : aIdMap[OOX_TOKEN(w14, scene3d)] = "scene3d";
65 0 : aIdMap[OOX_TOKEN(w14, props3d)] = "props3d";
66 0 : aIdMap[OOX_TOKEN(w14, ligatures)] = "ligatures";
67 0 : aIdMap[OOX_TOKEN(w14, numForm)] = "numForm";
68 0 : aIdMap[OOX_TOKEN(w14, numSpacing)] = "numSpacing";
69 0 : aIdMap[OOX_TOKEN(w14, stylisticSets)]= "stylisticSets";
70 0 : aIdMap[OOX_TOKEN(w14, cntxtAlts)] = "cntxtAlts";
71 : }
72 :
73 0 : return aIdMap[aId];
74 : }
75 :
76 0 : OUString lclGetGrabBagName(sal_uInt32 aId)
77 : {
78 0 : static std::map<sal_uInt32, OUString> aGrabBagNameMap;
79 0 : if(aGrabBagNameMap.empty())
80 : {
81 0 : aGrabBagNameMap[OOX_TOKEN(w14, glow)] = "CharGlowTextEffect";
82 0 : aGrabBagNameMap[OOX_TOKEN(w14, shadow)] = "CharShadowTextEffect";
83 0 : aGrabBagNameMap[OOX_TOKEN(w14, reflection)] = "CharReflectionTextEffect";
84 0 : aGrabBagNameMap[OOX_TOKEN(w14, textOutline)] = "CharTextOutlineTextEffect";
85 0 : aGrabBagNameMap[OOX_TOKEN(w14, textFill)] = "CharTextFillTextEffect";
86 0 : aGrabBagNameMap[OOX_TOKEN(w14, scene3d)] = "CharScene3DTextEffect";
87 0 : aGrabBagNameMap[OOX_TOKEN(w14, props3d)] = "CharProps3DTextEffect";
88 0 : aGrabBagNameMap[OOX_TOKEN(w14, ligatures)] = "CharLigaturesTextEffect";
89 0 : aGrabBagNameMap[OOX_TOKEN(w14, numForm)] = "CharNumFormTextEffect";
90 0 : aGrabBagNameMap[OOX_TOKEN(w14, numSpacing)] = "CharNumSpacingTextEffect";
91 0 : aGrabBagNameMap[OOX_TOKEN(w14, stylisticSets)]= "CharStylisticSetsTextEffect";
92 0 : aGrabBagNameMap[OOX_TOKEN(w14, cntxtAlts)] = "CharCntxtAltsTextEffect";
93 : }
94 :
95 0 : return aGrabBagNameMap[aId];
96 : }
97 :
98 : const char constAttributesSequenceName[] = "attributes";
99 :
100 : }
101 :
102 : using namespace oox::core;
103 : using namespace com::sun::star::uno;
104 : using namespace com::sun::star::beans;
105 :
106 0 : TextEffectsContext::TextEffectsContext(
107 : ContextHandler2Helper& rParent,
108 : sal_Int32 aElementToken,
109 : std::vector<PropertyValue>& rTextEffectsProperties)
110 : : ContextHandler2(rParent)
111 : , mrTextEffectsProperties(rTextEffectsProperties)
112 : , mpGrabBagStack(NULL)
113 0 : , mnCurrentElement(aElementToken)
114 : {
115 0 : }
116 :
117 0 : TextEffectsContext::~TextEffectsContext()
118 : {
119 0 : }
120 :
121 0 : void TextEffectsContext::pushAttributeToGrabBag (const sal_Int32& aAttributeId, const OUString& rElementName, const AttributeList& rAttribs)
122 : {
123 0 : if (!rAttribs.hasAttribute(aAttributeId))
124 0 : return;
125 0 : OUString aString = rAttribs.getString(aAttributeId).get();
126 0 : mpGrabBagStack->addString(rElementName, aString);
127 : }
128 :
129 0 : void TextEffectsContext::processAttributes(const AttributeList& rAttribs)
130 : {
131 0 : mpGrabBagStack->push(constAttributesSequenceName);
132 0 : switch(mnCurrentElement)
133 : {
134 : case OOX_TOKEN(w14, glow):
135 : {
136 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, rad), "rad", rAttribs);
137 : }
138 0 : break;
139 : case OOX_TOKEN(w14, srgbClr):
140 : case OOX_TOKEN(w14, schemeClr):
141 : case OOX_TOKEN(w14, tint):
142 : case OOX_TOKEN(w14, shade):
143 : case OOX_TOKEN(w14, alpha):
144 : case OOX_TOKEN(w14, hueMod):
145 : case OOX_TOKEN(w14, sat):
146 : case OOX_TOKEN(w14, satOff):
147 : case OOX_TOKEN(w14, satMod):
148 : case OOX_TOKEN(w14, lum):
149 : case OOX_TOKEN(w14, lumOff):
150 : case OOX_TOKEN(w14, lumMod):
151 : {
152 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
153 : }
154 0 : break;
155 : case OOX_TOKEN(w14, shadow):
156 : {
157 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, blurRad), "blurRad", rAttribs);
158 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, dist), "dist", rAttribs);
159 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, dir), "dir", rAttribs);
160 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, sx), "sx", rAttribs);
161 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, sy), "sy", rAttribs);
162 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, kx), "kx", rAttribs);
163 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, ky), "ky", rAttribs);
164 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, algn), "algn", rAttribs);
165 : }
166 0 : break;
167 : case OOX_TOKEN(w14, reflection):
168 : {
169 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, blurRad), "blurRad", rAttribs);
170 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, stA), "stA", rAttribs);
171 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, stPos), "stPos", rAttribs);
172 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, endA), "endA", rAttribs);
173 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, endPos), "endPos", rAttribs);
174 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, dist), "dist", rAttribs);
175 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, dir), "dir", rAttribs);
176 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, fadeDir), "fadeDir", rAttribs);
177 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, sx), "sx", rAttribs);
178 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, sy), "sy", rAttribs);
179 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, kx), "kx", rAttribs);
180 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, ky), "ky", rAttribs);
181 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, algn), "algn", rAttribs);
182 : }
183 0 : break;
184 : case OOX_TOKEN(w14, textOutline):
185 : {
186 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, w), "w", rAttribs);
187 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, cap), "cap", rAttribs);
188 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, cmpd), "cmpd", rAttribs);
189 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, algn), "algn", rAttribs);
190 : }
191 0 : break;
192 : case OOX_TOKEN(w14, prstDash):
193 : {
194 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
195 : }
196 0 : break;
197 : case OOX_TOKEN(w14, gs):
198 : {
199 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, pos), "pos", rAttribs);
200 : }
201 0 : break;
202 : case OOX_TOKEN(w14, lin):
203 : {
204 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, ang), "ang", rAttribs);
205 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, scaled), "scaled", rAttribs);
206 : }
207 0 : break;
208 : case OOX_TOKEN(w14, path):
209 : {
210 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, path), "path", rAttribs);
211 : }
212 0 : break;
213 : case OOX_TOKEN(w14, fillToRect):
214 : {
215 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, l), "l", rAttribs);
216 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, t), "t", rAttribs);
217 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, r), "r", rAttribs);
218 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, b), "b", rAttribs);
219 : }
220 0 : break;
221 : case OOX_TOKEN(w14, miter):
222 : {
223 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, lim), "lim", rAttribs);
224 : }
225 0 : break;
226 : case OOX_TOKEN(w14, camera):
227 : {
228 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, prst), "prst", rAttribs);
229 : }
230 0 : break;
231 : case OOX_TOKEN(w14, lightRig):
232 : {
233 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, rig), "rig", rAttribs);
234 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, dir), "dir", rAttribs);
235 : }
236 0 : break;
237 : case OOX_TOKEN(w14, rot):
238 : {
239 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, lat), "lat", rAttribs);
240 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, lon), "lon", rAttribs);
241 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, rev), "rev", rAttribs);
242 : }
243 0 : break;
244 : case OOX_TOKEN(w14, props3d):
245 : {
246 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, extrusionH), "extrusionH", rAttribs);
247 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, contourW), "contourW", rAttribs);
248 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, prstMaterial), "prstMaterial", rAttribs);
249 : }
250 0 : break;
251 : case OOX_TOKEN(w14, bevelT):
252 : case OOX_TOKEN(w14, bevelB):
253 : {
254 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, w), "w", rAttribs);
255 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, h), "h", rAttribs);
256 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, prst), "prst", rAttribs);
257 : }
258 0 : break;
259 : case OOX_TOKEN(w14, ligatures):
260 : case OOX_TOKEN(w14, numForm):
261 : case OOX_TOKEN(w14, numSpacing):
262 : {
263 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
264 : }
265 0 : break;
266 : case OOX_TOKEN(w14, styleSet):
267 : {
268 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, id), "id", rAttribs);
269 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
270 : }
271 0 : break;
272 : case OOX_TOKEN(w14, cntxtAlts):
273 : {
274 0 : pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
275 : }
276 0 : break;
277 : default:
278 0 : break;
279 : }
280 :
281 0 : mpGrabBagStack->pop();
282 0 : }
283 :
284 0 : void TextEffectsContext::onStartElement(const oox::AttributeList& rAttribs)
285 : {
286 0 : if(mpGrabBagStack.get() == NULL)
287 : {
288 0 : OUString aGrabBagName = lclGetGrabBagName(mnCurrentElement);
289 0 : mpGrabBagStack.reset(new GrabBagStack(aGrabBagName));
290 : }
291 :
292 0 : OUString aElementName = lclGetNameForElementId(mnCurrentElement);
293 0 : mpGrabBagStack->push(aElementName);
294 0 : processAttributes(rAttribs);
295 0 : }
296 :
297 0 : void TextEffectsContext::onEndElement()
298 : {
299 0 : mpGrabBagStack->pop();
300 :
301 0 : if (mpGrabBagStack->isStackEmpty())
302 : {
303 0 : Sequence<PropertyValue> aSeq;
304 0 : PropertyValue aPropertyValue = mpGrabBagStack->getRootProperty();
305 0 : aPropertyValue.Value >>= aSeq;
306 0 : aPropertyValue.Value = makeAny(aSeq[0]);
307 :
308 0 : mrTextEffectsProperties.push_back(aPropertyValue);
309 : }
310 :
311 0 : }
312 :
313 0 : ContextHandlerRef TextEffectsContext::onCreateContext(sal_Int32 aElementToken, const AttributeList& /*rAttribs*/)
314 : {
315 0 : mnCurrentElement = aElementToken;
316 0 : return this;
317 : }
318 :
319 : } }
320 :
321 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|