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/.
11 #include "drawingml/texteffectscontext.hxx"
12 #include <oox/helper/attributelist.hxx>
13 #include <oox/token/namespaces.hxx>
14 #include <oox/token/tokens.hxx>
18 namespace oox
{ namespace drawingml
{
23 OUString
lclGetNameForElementId(sal_uInt32 aId
)
25 static std::map
<sal_uInt32
, OUString
> aIdMap
;
28 aIdMap
[OOX_TOKEN(w14
, srgbClr
)] = "srgbClr";
29 aIdMap
[OOX_TOKEN(w14
, schemeClr
)] = "schemeClr";
30 aIdMap
[OOX_TOKEN(w14
, tint
)] = "tint";
31 aIdMap
[OOX_TOKEN(w14
, shade
)] = "shade";
32 aIdMap
[OOX_TOKEN(w14
, alpha
)] = "alpha";
33 aIdMap
[OOX_TOKEN(w14
, hueMod
)] = "hueMod";
34 aIdMap
[OOX_TOKEN(w14
, sat
)] = "sat";
35 aIdMap
[OOX_TOKEN(w14
, satOff
)] = "satOff";
36 aIdMap
[OOX_TOKEN(w14
, satMod
)] = "satMod";
37 aIdMap
[OOX_TOKEN(w14
, lum
)] = "lum";
38 aIdMap
[OOX_TOKEN(w14
, lumOff
)] = "lumOff";
39 aIdMap
[OOX_TOKEN(w14
, lumMod
)] = "lumMod";
40 aIdMap
[OOX_TOKEN(w14
, noFill
)] = "noFill";
41 aIdMap
[OOX_TOKEN(w14
, solidFill
)] = "solidFill";
42 aIdMap
[OOX_TOKEN(w14
, gradFill
)] = "gradFill";
43 aIdMap
[OOX_TOKEN(w14
, gsLst
)] = "gsLst";
44 aIdMap
[OOX_TOKEN(w14
, gs
)] = "gs";
45 aIdMap
[OOX_TOKEN(w14
, pos
)] = "pos";
46 aIdMap
[OOX_TOKEN(w14
, lin
)] = "lin";
47 aIdMap
[OOX_TOKEN(w14
, path
)] = "path";
48 aIdMap
[OOX_TOKEN(w14
, fillToRect
)] = "fillToRect";
49 aIdMap
[OOX_TOKEN(w14
, prstDash
)] = "prstDash";
50 aIdMap
[OOX_TOKEN(w14
, round
)] = "round";
51 aIdMap
[OOX_TOKEN(w14
, bevel
)] = "bevel";
52 aIdMap
[OOX_TOKEN(w14
, miter
)] = "miter";
53 aIdMap
[OOX_TOKEN(w14
, camera
)] = "camera";
54 aIdMap
[OOX_TOKEN(w14
, lightRig
)] = "lightRig";
55 aIdMap
[OOX_TOKEN(w14
, rot
)] = "rot";
56 aIdMap
[OOX_TOKEN(w14
, bevelT
)] = "bevelT";
57 aIdMap
[OOX_TOKEN(w14
, bevelB
)] = "bevelB";
58 aIdMap
[OOX_TOKEN(w14
, extrusionClr
)] = "extrusionClr";
59 aIdMap
[OOX_TOKEN(w14
, contourClr
)] = "contourClr";
60 aIdMap
[OOX_TOKEN(w14
, styleSet
)] = "styleSet";
62 aIdMap
[OOX_TOKEN(w14
, glow
)] = "glow";
63 aIdMap
[OOX_TOKEN(w14
, shadow
)] = "shadow";
64 aIdMap
[OOX_TOKEN(w14
, reflection
)] = "reflection";
65 aIdMap
[OOX_TOKEN(w14
, textOutline
)] = "textOutline";
66 aIdMap
[OOX_TOKEN(w14
, textFill
)] = "textFill";
67 aIdMap
[OOX_TOKEN(w14
, scene3d
)] = "scene3d";
68 aIdMap
[OOX_TOKEN(w14
, props3d
)] = "props3d";
69 aIdMap
[OOX_TOKEN(w14
, ligatures
)] = "ligatures";
70 aIdMap
[OOX_TOKEN(w14
, numForm
)] = "numForm";
71 aIdMap
[OOX_TOKEN(w14
, numSpacing
)] = "numSpacing";
72 aIdMap
[OOX_TOKEN(w14
, stylisticSets
)]= "stylisticSets";
73 aIdMap
[OOX_TOKEN(w14
, cntxtAlts
)] = "cntxtAlts";
79 OUString
lclGetGrabBagName(sal_uInt32 aId
)
81 static std::map
<sal_uInt32
, OUString
> aGrabBagNameMap
;
82 if(aGrabBagNameMap
.empty())
84 aGrabBagNameMap
[OOX_TOKEN(w14
, glow
)] = "CharGlowTextEffect";
85 aGrabBagNameMap
[OOX_TOKEN(w14
, shadow
)] = "CharShadowTextEffect";
86 aGrabBagNameMap
[OOX_TOKEN(w14
, reflection
)] = "CharReflectionTextEffect";
87 aGrabBagNameMap
[OOX_TOKEN(w14
, textOutline
)] = "CharTextOutlineTextEffect";
88 aGrabBagNameMap
[OOX_TOKEN(w14
, textFill
)] = "CharTextFillTextEffect";
89 aGrabBagNameMap
[OOX_TOKEN(w14
, scene3d
)] = "CharScene3DTextEffect";
90 aGrabBagNameMap
[OOX_TOKEN(w14
, props3d
)] = "CharProps3DTextEffect";
91 aGrabBagNameMap
[OOX_TOKEN(w14
, ligatures
)] = "CharLigaturesTextEffect";
92 aGrabBagNameMap
[OOX_TOKEN(w14
, numForm
)] = "CharNumFormTextEffect";
93 aGrabBagNameMap
[OOX_TOKEN(w14
, numSpacing
)] = "CharNumSpacingTextEffect";
94 aGrabBagNameMap
[OOX_TOKEN(w14
, stylisticSets
)]= "CharStylisticSetsTextEffect";
95 aGrabBagNameMap
[OOX_TOKEN(w14
, cntxtAlts
)] = "CharCntxtAltsTextEffect";
98 return aGrabBagNameMap
[aId
];
103 using namespace oox::core
;
104 using namespace com::sun::star::uno
;
105 using namespace com::sun::star::beans
;
107 TextEffectsContext::TextEffectsContext(
108 ContextHandler2Helper
& rParent
,
109 sal_Int32 aElementToken
,
110 std::vector
<PropertyValue
>& rTextEffectsProperties
)
111 : ContextHandler2(rParent
)
112 , mrTextEffectsProperties(rTextEffectsProperties
)
113 , mpGrabBagStack(nullptr)
114 , mnCurrentElement(aElementToken
)
118 TextEffectsContext::~TextEffectsContext()
122 void TextEffectsContext::pushAttributeToGrabBag (sal_Int32 aAttributeId
, const OUString
& rElementName
, const AttributeList
& rAttribs
)
124 if (!rAttribs
.hasAttribute(aAttributeId
))
126 OUString aString
= rAttribs
.getString(aAttributeId
).get();
127 mpGrabBagStack
->addString(rElementName
, aString
);
130 void TextEffectsContext::processAttributes(const AttributeList
& rAttribs
)
132 mpGrabBagStack
->push("attributes");
133 switch(mnCurrentElement
)
135 case OOX_TOKEN(w14
, glow
):
137 pushAttributeToGrabBag(OOX_TOKEN(w14
, rad
), "rad", rAttribs
);
140 case OOX_TOKEN(w14
, srgbClr
):
141 case OOX_TOKEN(w14
, schemeClr
):
142 case OOX_TOKEN(w14
, tint
):
143 case OOX_TOKEN(w14
, shade
):
144 case OOX_TOKEN(w14
, alpha
):
145 case OOX_TOKEN(w14
, hueMod
):
146 case OOX_TOKEN(w14
, sat
):
147 case OOX_TOKEN(w14
, satOff
):
148 case OOX_TOKEN(w14
, satMod
):
149 case OOX_TOKEN(w14
, lum
):
150 case OOX_TOKEN(w14
, lumOff
):
151 case OOX_TOKEN(w14
, lumMod
):
153 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), "val", rAttribs
);
156 case OOX_TOKEN(w14
, shadow
):
158 pushAttributeToGrabBag(OOX_TOKEN(w14
, blurRad
), "blurRad", rAttribs
);
159 pushAttributeToGrabBag(OOX_TOKEN(w14
, dist
), "dist", rAttribs
);
160 pushAttributeToGrabBag(OOX_TOKEN(w14
, dir
), "dir", rAttribs
);
161 pushAttributeToGrabBag(OOX_TOKEN(w14
, sx
), "sx", rAttribs
);
162 pushAttributeToGrabBag(OOX_TOKEN(w14
, sy
), "sy", rAttribs
);
163 pushAttributeToGrabBag(OOX_TOKEN(w14
, kx
), "kx", rAttribs
);
164 pushAttributeToGrabBag(OOX_TOKEN(w14
, ky
), "ky", rAttribs
);
165 pushAttributeToGrabBag(OOX_TOKEN(w14
, algn
), "algn", rAttribs
);
168 case OOX_TOKEN(w14
, reflection
):
170 pushAttributeToGrabBag(OOX_TOKEN(w14
, blurRad
), "blurRad", rAttribs
);
171 pushAttributeToGrabBag(OOX_TOKEN(w14
, stA
), "stA", rAttribs
);
172 pushAttributeToGrabBag(OOX_TOKEN(w14
, stPos
), "stPos", rAttribs
);
173 pushAttributeToGrabBag(OOX_TOKEN(w14
, endA
), "endA", rAttribs
);
174 pushAttributeToGrabBag(OOX_TOKEN(w14
, endPos
), "endPos", rAttribs
);
175 pushAttributeToGrabBag(OOX_TOKEN(w14
, dist
), "dist", rAttribs
);
176 pushAttributeToGrabBag(OOX_TOKEN(w14
, dir
), "dir", rAttribs
);
177 pushAttributeToGrabBag(OOX_TOKEN(w14
, fadeDir
), "fadeDir", rAttribs
);
178 pushAttributeToGrabBag(OOX_TOKEN(w14
, sx
), "sx", rAttribs
);
179 pushAttributeToGrabBag(OOX_TOKEN(w14
, sy
), "sy", rAttribs
);
180 pushAttributeToGrabBag(OOX_TOKEN(w14
, kx
), "kx", rAttribs
);
181 pushAttributeToGrabBag(OOX_TOKEN(w14
, ky
), "ky", rAttribs
);
182 pushAttributeToGrabBag(OOX_TOKEN(w14
, algn
), "algn", rAttribs
);
185 case OOX_TOKEN(w14
, textOutline
):
187 pushAttributeToGrabBag(OOX_TOKEN(w14
, w
), "w", rAttribs
);
188 pushAttributeToGrabBag(OOX_TOKEN(w14
, cap
), "cap", rAttribs
);
189 pushAttributeToGrabBag(OOX_TOKEN(w14
, cmpd
), "cmpd", rAttribs
);
190 pushAttributeToGrabBag(OOX_TOKEN(w14
, algn
), "algn", rAttribs
);
193 case OOX_TOKEN(w14
, prstDash
):
195 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), "val", rAttribs
);
198 case OOX_TOKEN(w14
, gs
):
200 pushAttributeToGrabBag(OOX_TOKEN(w14
, pos
), "pos", rAttribs
);
203 case OOX_TOKEN(w14
, lin
):
205 pushAttributeToGrabBag(OOX_TOKEN(w14
, ang
), "ang", rAttribs
);
206 pushAttributeToGrabBag(OOX_TOKEN(w14
, scaled
), "scaled", rAttribs
);
209 case OOX_TOKEN(w14
, path
):
211 pushAttributeToGrabBag(OOX_TOKEN(w14
, path
), "path", rAttribs
);
214 case OOX_TOKEN(w14
, fillToRect
):
216 pushAttributeToGrabBag(OOX_TOKEN(w14
, l
), "l", rAttribs
);
217 pushAttributeToGrabBag(OOX_TOKEN(w14
, t
), "t", rAttribs
);
218 pushAttributeToGrabBag(OOX_TOKEN(w14
, r
), "r", rAttribs
);
219 pushAttributeToGrabBag(OOX_TOKEN(w14
, b
), "b", rAttribs
);
222 case OOX_TOKEN(w14
, miter
):
224 pushAttributeToGrabBag(OOX_TOKEN(w14
, lim
), "lim", rAttribs
);
227 case OOX_TOKEN(w14
, camera
):
229 pushAttributeToGrabBag(OOX_TOKEN(w14
, prst
), "prst", rAttribs
);
232 case OOX_TOKEN(w14
, lightRig
):
234 pushAttributeToGrabBag(OOX_TOKEN(w14
, rig
), "rig", rAttribs
);
235 pushAttributeToGrabBag(OOX_TOKEN(w14
, dir
), "dir", rAttribs
);
238 case OOX_TOKEN(w14
, rot
):
240 pushAttributeToGrabBag(OOX_TOKEN(w14
, lat
), "lat", rAttribs
);
241 pushAttributeToGrabBag(OOX_TOKEN(w14
, lon
), "lon", rAttribs
);
242 pushAttributeToGrabBag(OOX_TOKEN(w14
, rev
), "rev", rAttribs
);
245 case OOX_TOKEN(w14
, props3d
):
247 pushAttributeToGrabBag(OOX_TOKEN(w14
, extrusionH
), "extrusionH", rAttribs
);
248 pushAttributeToGrabBag(OOX_TOKEN(w14
, contourW
), "contourW", rAttribs
);
249 pushAttributeToGrabBag(OOX_TOKEN(w14
, prstMaterial
), "prstMaterial", rAttribs
);
252 case OOX_TOKEN(w14
, bevelT
):
253 case OOX_TOKEN(w14
, bevelB
):
255 pushAttributeToGrabBag(OOX_TOKEN(w14
, w
), "w", rAttribs
);
256 pushAttributeToGrabBag(OOX_TOKEN(w14
, h
), "h", rAttribs
);
257 pushAttributeToGrabBag(OOX_TOKEN(w14
, prst
), "prst", rAttribs
);
260 case OOX_TOKEN(w14
, ligatures
):
261 case OOX_TOKEN(w14
, numForm
):
262 case OOX_TOKEN(w14
, numSpacing
):
264 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), "val", rAttribs
);
267 case OOX_TOKEN(w14
, styleSet
):
269 pushAttributeToGrabBag(OOX_TOKEN(w14
, id
), "id", rAttribs
);
270 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), "val", rAttribs
);
273 case OOX_TOKEN(w14
, cntxtAlts
):
275 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), "val", rAttribs
);
282 mpGrabBagStack
->pop();
285 void TextEffectsContext::onStartElement(const oox::AttributeList
& rAttribs
)
287 if(mpGrabBagStack
.get() == nullptr)
289 OUString aGrabBagName
= lclGetGrabBagName(mnCurrentElement
);
290 mpGrabBagStack
.reset(new GrabBagStack(aGrabBagName
));
293 OUString aElementName
= lclGetNameForElementId(mnCurrentElement
);
294 mpGrabBagStack
->push(aElementName
);
295 processAttributes(rAttribs
);
298 void TextEffectsContext::onEndElement()
300 mpGrabBagStack
->pop();
302 if (mpGrabBagStack
->isStackEmpty())
304 Sequence
<PropertyValue
> aSeq
;
305 PropertyValue aPropertyValue
= mpGrabBagStack
->getRootProperty();
306 aPropertyValue
.Value
>>= aSeq
;
307 aPropertyValue
.Value
<<= aSeq
[0];
309 mrTextEffectsProperties
.push_back(aPropertyValue
);
314 ContextHandlerRef
TextEffectsContext::onCreateContext(sal_Int32 aElementToken
, const AttributeList
& /*rAttribs*/)
316 mnCurrentElement
= aElementToken
;
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */