Coverage Report

Created: 2026-04-09 11:41

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