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