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