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>
17 namespace oox::drawingml
{
22 OUString
const & lclGetNameForElementId(sal_uInt32 aId
)
24 static std::map
<sal_uInt32
, OUString
> const aIdMap
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" },
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" },
73 const auto iter
= aIdMap
.find(aId
);
74 assert(iter
!= aIdMap
.end());
78 OUString
const & lclGetGrabBagName(sal_uInt32 aId
)
80 static std::map
<sal_uInt32
, OUString
> const aGrabBagNameMap
82 { OOX_TOKEN(w14
, glow
) , "CharGlowTextEffect" },
83 { OOX_TOKEN(w14
, shadow
) , "CharShadowTextEffect" },
84 { OOX_TOKEN(w14
, reflection
) , "CharReflectionTextEffect" },
85 { OOX_TOKEN(w14
, textOutline
) , "CharTextOutlineTextEffect" },
86 { OOX_TOKEN(w14
, textFill
) , "CharTextFillTextEffect" },
87 { OOX_TOKEN(w14
, scene3d
) , "CharScene3DTextEffect" },
88 { OOX_TOKEN(w14
, props3d
) , "CharProps3DTextEffect" },
89 { OOX_TOKEN(w14
, ligatures
) , "CharLigaturesTextEffect" },
90 { OOX_TOKEN(w14
, numForm
) , "CharNumFormTextEffect" },
91 { OOX_TOKEN(w14
, numSpacing
) , "CharNumSpacingTextEffect" },
92 { OOX_TOKEN(w14
, stylisticSets
), "CharStylisticSetsTextEffect" },
93 { OOX_TOKEN(w14
, cntxtAlts
) , "CharCntxtAltsTextEffect" },
95 const auto iter
= aGrabBagNameMap
.find(aId
);
96 assert(iter
!= aGrabBagNameMap
.end());
102 using namespace oox::core
;
103 using namespace com::sun::star::uno
;
104 using namespace com::sun::star::beans
;
106 TextEffectsContext::TextEffectsContext(
107 ContextHandler2Helper
const & rParent
,
108 sal_Int32 aElementToken
,
109 std::vector
<PropertyValue
>& rTextEffectsProperties
)
110 : ContextHandler2(rParent
)
111 , mrTextEffectsProperties(rTextEffectsProperties
)
112 , mnCurrentElement(aElementToken
)
116 TextEffectsContext::~TextEffectsContext()
120 void TextEffectsContext::pushAttributeToGrabBag (sal_Int32 aAttributeId
, const OUString
& rElementName
, const AttributeList
& rAttribs
)
122 if (!rAttribs
.hasAttribute(aAttributeId
))
124 OUString aString
= rAttribs
.getStringDefaulted(aAttributeId
);
125 mpGrabBagStack
->addString(rElementName
, aString
);
128 void TextEffectsContext::processAttributes(const AttributeList
& rAttribs
)
130 mpGrabBagStack
->push(u
"attributes"_ustr
);
131 switch(mnCurrentElement
)
133 case OOX_TOKEN(w14
, glow
):
135 pushAttributeToGrabBag(OOX_TOKEN(w14
, rad
), u
"rad"_ustr
, rAttribs
);
138 case OOX_TOKEN(w14
, srgbClr
):
139 case OOX_TOKEN(w14
, schemeClr
):
140 case OOX_TOKEN(w14
, tint
):
141 case OOX_TOKEN(w14
, shade
):
142 case OOX_TOKEN(w14
, alpha
):
143 case OOX_TOKEN(w14
, hueMod
):
144 case OOX_TOKEN(w14
, sat
):
145 case OOX_TOKEN(w14
, satOff
):
146 case OOX_TOKEN(w14
, satMod
):
147 case OOX_TOKEN(w14
, lum
):
148 case OOX_TOKEN(w14
, lumOff
):
149 case OOX_TOKEN(w14
, lumMod
):
151 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), u
"val"_ustr
, rAttribs
);
154 case OOX_TOKEN(w14
, shadow
):
156 pushAttributeToGrabBag(OOX_TOKEN(w14
, blurRad
), u
"blurRad"_ustr
, rAttribs
);
157 pushAttributeToGrabBag(OOX_TOKEN(w14
, dist
), u
"dist"_ustr
, rAttribs
);
158 pushAttributeToGrabBag(OOX_TOKEN(w14
, dir
), u
"dir"_ustr
, rAttribs
);
159 pushAttributeToGrabBag(OOX_TOKEN(w14
, sx
), u
"sx"_ustr
, rAttribs
);
160 pushAttributeToGrabBag(OOX_TOKEN(w14
, sy
), u
"sy"_ustr
, rAttribs
);
161 pushAttributeToGrabBag(OOX_TOKEN(w14
, kx
), u
"kx"_ustr
, rAttribs
);
162 pushAttributeToGrabBag(OOX_TOKEN(w14
, ky
), u
"ky"_ustr
, rAttribs
);
163 pushAttributeToGrabBag(OOX_TOKEN(w14
, algn
), u
"algn"_ustr
, rAttribs
);
166 case OOX_TOKEN(w14
, reflection
):
168 pushAttributeToGrabBag(OOX_TOKEN(w14
, blurRad
), u
"blurRad"_ustr
, rAttribs
);
169 pushAttributeToGrabBag(OOX_TOKEN(w14
, stA
), u
"stA"_ustr
, rAttribs
);
170 pushAttributeToGrabBag(OOX_TOKEN(w14
, stPos
), u
"stPos"_ustr
, rAttribs
);
171 pushAttributeToGrabBag(OOX_TOKEN(w14
, endA
), u
"endA"_ustr
, rAttribs
);
172 pushAttributeToGrabBag(OOX_TOKEN(w14
, endPos
), u
"endPos"_ustr
, rAttribs
);
173 pushAttributeToGrabBag(OOX_TOKEN(w14
, dist
), u
"dist"_ustr
, rAttribs
);
174 pushAttributeToGrabBag(OOX_TOKEN(w14
, dir
), u
"dir"_ustr
, rAttribs
);
175 pushAttributeToGrabBag(OOX_TOKEN(w14
, fadeDir
), u
"fadeDir"_ustr
, rAttribs
);
176 pushAttributeToGrabBag(OOX_TOKEN(w14
, sx
), u
"sx"_ustr
, rAttribs
);
177 pushAttributeToGrabBag(OOX_TOKEN(w14
, sy
), u
"sy"_ustr
, rAttribs
);
178 pushAttributeToGrabBag(OOX_TOKEN(w14
, kx
), u
"kx"_ustr
, rAttribs
);
179 pushAttributeToGrabBag(OOX_TOKEN(w14
, ky
), u
"ky"_ustr
, rAttribs
);
180 pushAttributeToGrabBag(OOX_TOKEN(w14
, algn
), u
"algn"_ustr
, rAttribs
);
183 case OOX_TOKEN(w14
, textOutline
):
185 pushAttributeToGrabBag(OOX_TOKEN(w14
, w
), u
"w"_ustr
, rAttribs
);
186 pushAttributeToGrabBag(OOX_TOKEN(w14
, cap
), u
"cap"_ustr
, rAttribs
);
187 pushAttributeToGrabBag(OOX_TOKEN(w14
, cmpd
), u
"cmpd"_ustr
, rAttribs
);
188 pushAttributeToGrabBag(OOX_TOKEN(w14
, algn
), u
"algn"_ustr
, rAttribs
);
191 case OOX_TOKEN(w14
, prstDash
):
193 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), u
"val"_ustr
, rAttribs
);
196 case OOX_TOKEN(w14
, gs
):
198 pushAttributeToGrabBag(OOX_TOKEN(w14
, pos
), u
"pos"_ustr
, rAttribs
);
201 case OOX_TOKEN(w14
, lin
):
203 pushAttributeToGrabBag(OOX_TOKEN(w14
, ang
), u
"ang"_ustr
, rAttribs
);
204 pushAttributeToGrabBag(OOX_TOKEN(w14
, scaled
), u
"scaled"_ustr
, rAttribs
);
207 case OOX_TOKEN(w14
, path
):
209 pushAttributeToGrabBag(OOX_TOKEN(w14
, path
), u
"path"_ustr
, rAttribs
);
212 case OOX_TOKEN(w14
, fillToRect
):
214 pushAttributeToGrabBag(OOX_TOKEN(w14
, l
), u
"l"_ustr
, rAttribs
);
215 pushAttributeToGrabBag(OOX_TOKEN(w14
, t
), u
"t"_ustr
, rAttribs
);
216 pushAttributeToGrabBag(OOX_TOKEN(w14
, r
), u
"r"_ustr
, rAttribs
);
217 pushAttributeToGrabBag(OOX_TOKEN(w14
, b
), u
"b"_ustr
, rAttribs
);
220 case OOX_TOKEN(w14
, miter
):
222 pushAttributeToGrabBag(OOX_TOKEN(w14
, lim
), u
"lim"_ustr
, rAttribs
);
225 case OOX_TOKEN(w14
, camera
):
227 pushAttributeToGrabBag(OOX_TOKEN(w14
, prst
), u
"prst"_ustr
, rAttribs
);
230 case OOX_TOKEN(w14
, lightRig
):
232 pushAttributeToGrabBag(OOX_TOKEN(w14
, rig
), u
"rig"_ustr
, rAttribs
);
233 pushAttributeToGrabBag(OOX_TOKEN(w14
, dir
), u
"dir"_ustr
, rAttribs
);
236 case OOX_TOKEN(w14
, rot
):
238 pushAttributeToGrabBag(OOX_TOKEN(w14
, lat
), u
"lat"_ustr
, rAttribs
);
239 pushAttributeToGrabBag(OOX_TOKEN(w14
, lon
), u
"lon"_ustr
, rAttribs
);
240 pushAttributeToGrabBag(OOX_TOKEN(w14
, rev
), u
"rev"_ustr
, rAttribs
);
243 case OOX_TOKEN(w14
, props3d
):
245 pushAttributeToGrabBag(OOX_TOKEN(w14
, extrusionH
), u
"extrusionH"_ustr
, rAttribs
);
246 pushAttributeToGrabBag(OOX_TOKEN(w14
, contourW
), u
"contourW"_ustr
, rAttribs
);
247 pushAttributeToGrabBag(OOX_TOKEN(w14
, prstMaterial
), u
"prstMaterial"_ustr
, rAttribs
);
250 case OOX_TOKEN(w14
, bevelT
):
251 case OOX_TOKEN(w14
, bevelB
):
253 pushAttributeToGrabBag(OOX_TOKEN(w14
, w
), u
"w"_ustr
, rAttribs
);
254 pushAttributeToGrabBag(OOX_TOKEN(w14
, h
), u
"h"_ustr
, rAttribs
);
255 pushAttributeToGrabBag(OOX_TOKEN(w14
, prst
), u
"prst"_ustr
, rAttribs
);
258 case OOX_TOKEN(w14
, ligatures
):
259 case OOX_TOKEN(w14
, numForm
):
260 case OOX_TOKEN(w14
, numSpacing
):
262 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), u
"val"_ustr
, rAttribs
);
265 case OOX_TOKEN(w14
, styleSet
):
267 pushAttributeToGrabBag(OOX_TOKEN(w14
, id
), u
"id"_ustr
, rAttribs
);
268 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), u
"val"_ustr
, rAttribs
);
271 case OOX_TOKEN(w14
, cntxtAlts
):
273 pushAttributeToGrabBag(OOX_TOKEN(w14
, val
), u
"val"_ustr
, rAttribs
);
280 mpGrabBagStack
->pop();
283 void TextEffectsContext::onStartElement(const oox::AttributeList
& rAttribs
)
285 if (mpGrabBagStack
== nullptr)
287 OUString aGrabBagName
= lclGetGrabBagName(mnCurrentElement
);
288 mpGrabBagStack
.reset(new GrabBagStack(aGrabBagName
));
291 OUString aElementName
= lclGetNameForElementId(mnCurrentElement
);
292 mpGrabBagStack
->push(aElementName
);
293 processAttributes(rAttribs
);
296 void TextEffectsContext::onEndElement()
298 mpGrabBagStack
->pop();
300 if (mpGrabBagStack
->isStackEmpty())
302 Sequence
<PropertyValue
> aSeq
;
303 PropertyValue aPropertyValue
= mpGrabBagStack
->getRootProperty();
304 aPropertyValue
.Value
>>= aSeq
;
305 aPropertyValue
.Value
<<= aSeq
[0];
307 mrTextEffectsProperties
.push_back(aPropertyValue
);
312 ContextHandlerRef
TextEffectsContext::onCreateContext(sal_Int32 aElementToken
, const AttributeList
& /*rAttribs*/)
314 mnCurrentElement
= aElementToken
;
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */