LibreOffice Module oox (master) 1
effectpropertiescontext.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
11#include "effectproperties.hxx"
14#include <oox/token/namespaces.hxx>
15#include <oox/token/tokens.hxx>
17
18using namespace ::oox::core;
19using namespace ::com::sun::star::uno;
20using namespace ::com::sun::star::xml::sax;
21
22// CT_EffectProperties
23
24namespace oox::drawingml {
25
26EffectPropertiesContext::EffectPropertiesContext( ContextHandler2Helper const& rParent,
27 EffectProperties& rEffectProperties, model::EffectStyle* pEffectStyle) noexcept
28 : ContextHandler2(rParent)
29 , mpEffectStyle(pEffectStyle)
30 , mrEffectProperties(rEffectProperties)
31{
32}
33
35{
36}
37
39{
40 if( rAttribs.hasAttribute( XML_algn ) )
41 rEffect.maAttribs["algn"] <<= rAttribs.getStringDefaulted( XML_algn);
42 if( rAttribs.hasAttribute( XML_blurRad ) )
43 rEffect.maAttribs["blurRad"] <<= rAttribs.getInteger( XML_blurRad, 0 );
44 if( rAttribs.hasAttribute( XML_dir ) )
45 rEffect.maAttribs["dir"] <<= rAttribs.getInteger( XML_dir, 0 );
46 if( rAttribs.hasAttribute( XML_dist ) )
47 rEffect.maAttribs["dist"] <<= rAttribs.getInteger( XML_dist, 0 );
48 if( rAttribs.hasAttribute( XML_kx ) )
49 rEffect.maAttribs["kx"] <<= rAttribs.getInteger( XML_kx, 0 );
50 if( rAttribs.hasAttribute( XML_ky ) )
51 rEffect.maAttribs["ky"] <<= rAttribs.getInteger( XML_ky, 0 );
52 if( rAttribs.hasAttribute( XML_rotWithShape ) )
53 rEffect.maAttribs["rotWithShape"] <<= rAttribs.getInteger( XML_rotWithShape, 0 );
54 if( rAttribs.hasAttribute( XML_sx ) )
55 rEffect.maAttribs["sx"] <<= rAttribs.getInteger( XML_sx, 0 );
56 if( rAttribs.hasAttribute( XML_sy ) )
57 rEffect.maAttribs["sy"] <<= rAttribs.getInteger( XML_sy, 0 );
58 if( rAttribs.hasAttribute( XML_rad ) )
59 rEffect.maAttribs["rad"] <<= rAttribs.getInteger( XML_rad, 0 );
60 if( rAttribs.hasAttribute( XML_endA ) )
61 rEffect.maAttribs["endA"] <<= rAttribs.getInteger( XML_endA, 0 );
62 if( rAttribs.hasAttribute( XML_endPos ) )
63 rEffect.maAttribs["endPos"] <<= rAttribs.getInteger( XML_endPos, 0 );
64 if( rAttribs.hasAttribute( XML_fadeDir ) )
65 rEffect.maAttribs["fadeDir"] <<= rAttribs.getInteger( XML_fadeDir, 0 );
66 if( rAttribs.hasAttribute( XML_stA ) )
67 rEffect.maAttribs["stA"] <<= rAttribs.getInteger( XML_stA, 0 );
68 if( rAttribs.hasAttribute( XML_stPos ) )
69 rEffect.maAttribs["stPos"] <<= rAttribs.getInteger( XML_stPos, 0 );
70 if( rAttribs.hasAttribute( XML_grow ) )
71 rEffect.maAttribs["grow"] <<= rAttribs.getInteger( XML_grow, 0 );
72}
73
75{
76 sal_Int32 nPos = mrEffectProperties.m_Effects.size();
77 mrEffectProperties.m_Effects.push_back(std::make_unique<Effect>());
78 switch( nElement )
79 {
80 case A_TOKEN( outerShdw ):
81 {
82 mrEffectProperties.m_Effects[nPos]->msName = "outerShdw";
84
85 mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 );
86 mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 );
87 mrEffectProperties.maShadow.moShadowSx = rAttribs.getInteger( XML_sx, 0 );
88 mrEffectProperties.maShadow.moShadowSy = rAttribs.getInteger( XML_sy, 0 );
89 mrEffectProperties.maShadow.moShadowBlur = rAttribs.getInteger( XML_blurRad, 0 );
91
92 model::ComplexColor* pColor = nullptr;
93 if (mpEffectStyle)
94 {
95 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
96 rEffect.meType = model::EffectType::OuterShadow;
97 rEffect.mnBlurRadius = rAttribs.getInteger(XML_blurRad, 0); // ST_PositiveCoordinate, default 0
98 rEffect.mnDistance = rAttribs.getInteger(XML_dist, 0); // ST_PositiveCoordinate, default 0
99 rEffect.mnDirection = rAttribs.getInteger(XML_dir, 0); // ST_PositiveFixedAngle, default 0
100 rEffect.mnScaleX = GetPercent( rAttribs.getStringDefaulted(XML_sx)); // ST_Percentage, default 100%
101 rEffect.mnScaley = GetPercent( rAttribs.getStringDefaulted(XML_sy)); // ST_Percentage, default 100%
102 rEffect.mnScewX = rAttribs.getInteger(XML_kx, 0); // ST_FixedAngle, default 0
103 rEffect.mnScewY = rAttribs.getInteger(XML_ky, 0); // ST_FixedAngle, default 0
104 // ST_RectAlignment, default "b" - Bottom
105 rEffect.meAlignment = convertToRectangleAlignment(rAttribs.getToken(XML_algn, XML_b));
106 rEffect.mbRotateWithShape = rAttribs.getBool(XML_rotWithShape, true); // boolean, default "true"
107 pColor = &rEffect.maColor;
108 }
109 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
110 }
111 break;
112 case A_TOKEN( innerShdw ):
113 {
114 mrEffectProperties.m_Effects[nPos]->msName = "innerShdw";
116
117 mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 );
118 mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 );
119
120 model::ComplexColor* pColor = nullptr;
121 if (mpEffectStyle)
122 {
123 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
124 rEffect.meType = model::EffectType::InnerShadow;
125 rEffect.mnBlurRadius = rAttribs.getInteger(XML_blurRad, 0); // ST_PositiveCoordinate, default 0
126 rEffect.mnDistance = rAttribs.getInteger(XML_dist, 0); // ST_PositiveCoordinate, default 0
127 rEffect.mnDirection = rAttribs.getInteger(XML_dir, 0); // ST_PositiveFixedAngle, default 0
128 pColor = &rEffect.maColor;
129 }
130 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
131 }
132 break;
133 case A_TOKEN( glow ):
134 {
135 mrEffectProperties.maGlow.moGlowRad = rAttribs.getInteger( XML_rad, 0 );
136 // undo push_back to effects
137 mrEffectProperties.m_Effects.pop_back();
138
139 model::ComplexColor* pColor = nullptr;
140 if (mpEffectStyle)
141 {
142 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
143 rEffect.meType = model::EffectType::Glow;
144 rEffect.mnRadius = rAttribs.getInteger(XML_rad, 0); //ST_PositiveCoordinate, default 0
145 pColor = &rEffect.maColor;
146 }
147 return new ColorContext(*this, mrEffectProperties.maGlow.moGlowColor, pColor);
148
149 }
150 case A_TOKEN( softEdge ):
151 {
152 mrEffectProperties.maSoftEdge.moRad = rAttribs.getInteger(XML_rad, 0);
153 if (mpEffectStyle)
154 {
155 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
156 rEffect.meType = model::EffectType::SoftEdge;
157 rEffect.mnRadius = rAttribs.getInteger(XML_rad, 0); // ST_PositiveCoordinate, default 0
158 }
159 return this; // no inner elements
160 }
161 case A_TOKEN( reflection ):
162 {
163 mrEffectProperties.m_Effects[nPos]->msName = "reflection";
165
166 model::ComplexColor* pColor = nullptr;
167 if (mpEffectStyle)
168 {
169 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
170 rEffect.meType = model::EffectType::Reflection;
171 rEffect.mnBlurRadius = rAttribs.getInteger(XML_blurRad, 0); // ST_PositiveCoordinate, default 0
172 rEffect.mnDistance = rAttribs.getInteger(XML_dist, 0); // ST_PositiveCoordinate, default 0
173 rEffect.mnDirection = rAttribs.getInteger(XML_dir, 0); // ST_PositiveFixedAngle, default 0
174 rEffect.mnScaleX = GetPercent(rAttribs.getStringDefaulted(XML_sx)); // ST_Percentage, default 100%
175 rEffect.mnScaley = GetPercent(rAttribs.getStringDefaulted(XML_sy)); // ST_Percentage, default 100%
176 rEffect.mnScewX = rAttribs.getInteger(XML_kx, 0); // ST_FixedAngle, default 0
177 rEffect.mnScewY = rAttribs.getInteger(XML_ky, 0); // ST_FixedAngle, default 0
178 // ST_RectAlignment, default "b" - Bottom
179 rEffect.meAlignment = convertToRectangleAlignment(rAttribs.getToken(XML_algn, XML_b));
180 rEffect.mbRotateWithShape = rAttribs.getBool(XML_rotWithShape, true); // boolean, default "true"
181
182 rEffect.mnEndAlpha = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_endA)); // ST_PositiveFixedPercentage, default 100%
183 rEffect.mnEndPosition = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_endPos)); // ST_PositiveFixedPercentage, default 0%
184 rEffect.mnStartAlpha = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_stA)); // ST_PositiveFixedPercentage, default 0%
185 rEffect.mnStartPosition = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_stPos)); // ST_PositiveFixedPercentage, default 100%
186 rEffect.mnFadeDirection = rAttribs.getInteger(XML_fadeDir, 5400000); // ST_PositiveFixedAngle, default 5400000
187
188 pColor = &rEffect.maColor;
189 }
190 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
191 }
192 case A_TOKEN( blur ):
193 {
194 mrEffectProperties.m_Effects[nPos]->msName = "blur";
196
197 model::ComplexColor* pColor = nullptr;
198 if (mpEffectStyle)
199 {
200 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
201 rEffect.meType = model::EffectType::Blur;
202 rEffect.mnRadius = rAttribs.getInteger(XML_rad, 0); // ST_PositiveCoordinate, default 0
203 rEffect.mbGrow = rAttribs.getBool(XML_grow, true); // boolean, default true
204 pColor = &rEffect.maColor;
205 }
206 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
207 }
208 break;
209 }
210
211 mrEffectProperties.m_Effects.pop_back();
212 return nullptr;
213}
214
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< Effect > maEffectList
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.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
Context handler for elements that contain a color value element (a:scrgbClr, a:srgbClr,...
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
static void saveUnsupportedAttribs(Effect &rEffect, const AttributeList &rAttribs)
EffectPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, EffectProperties &rEffectProperties, model::EffectStyle *pEffectStyle=nullptr) noexcept
sal_uInt16 nPos
model::RectangleAlignment convertToRectangleAlignment(sal_Int32 nToken)
double GetPositiveFixedPercentage(const OUString &sValue)
Converts a ST_PositiveFixedPercentage to a float.
sal_Int32 GetPercent(std::u16string_view sValue)
converts a ST_Percentage % string into 1/1000th of %
std::optional< sal_Int64 > moGlowRad
EffectSoftEdgeProperties maSoftEdge
std::vector< std::unique_ptr< Effect > > m_Effects
Stores all effect properties, including those not supported by core yet.
std::optional< sal_Int64 > moShadowDist
std::optional< sal_Int64 > moShadowSx
std::optional< sal_Int64 > moShadowBlur
std::optional< sal_Int64 > moShadowSy
std::optional< sal_Int64 > moShadowDir
std::optional< model::RectangleAlignment > moShadowAlignment
std::map< OUString, css::uno::Any > maAttribs
model::EffectStyle * mpEffectStyle