Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / oox / source / drawingml / effectpropertiescontext.cxx
blobff5a046927dd66b6b8ecd4b67720b34c13d29594
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <drawingml/effectpropertiescontext.hxx>
11 #include "effectproperties.hxx"
12 #include <drawingml/colorchoicecontext.hxx>
13 #include <oox/helper/attributelist.hxx>
14 #include <oox/token/namespaces.hxx>
15 #include <oox/token/tokens.hxx>
16 #include <oox/drawingml/drawingmltypes.hxx>
18 using namespace ::oox::core;
19 using namespace ::com::sun::star::uno;
20 using namespace ::com::sun::star::xml::sax;
22 // CT_EffectProperties
24 namespace oox::drawingml {
26 EffectPropertiesContext::EffectPropertiesContext( ContextHandler2Helper const& rParent,
27 EffectProperties& rEffectProperties, model::EffectStyle* pEffectStyle) noexcept
28 : ContextHandler2(rParent)
29 , mpEffectStyle(pEffectStyle)
30 , mrEffectProperties(rEffectProperties)
34 EffectPropertiesContext::~EffectPropertiesContext()
38 void EffectPropertiesContext::saveUnsupportedAttribs( Effect& rEffect, const AttributeList& rAttribs )
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 );
74 ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
76 sal_Int32 nPos = mrEffectProperties.m_Effects.size();
77 mrEffectProperties.m_Effects.push_back(std::make_unique<Effect>());
78 switch( nElement )
80 case A_TOKEN( outerShdw ):
82 mrEffectProperties.m_Effects[nPos]->msName = "outerShdw";
83 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
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 );
90 mrEffectProperties.maShadow.moShadowAlignment = convertToRectangleAlignment( rAttribs.getToken(XML_algn, XML_b) );
92 model::ComplexColor* pColor = nullptr;
93 if (mpEffectStyle)
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;
109 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
111 break;
112 case A_TOKEN( innerShdw ):
114 mrEffectProperties.m_Effects[nPos]->msName = "innerShdw";
115 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
117 mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 );
118 mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 );
120 model::ComplexColor* pColor = nullptr;
121 if (mpEffectStyle)
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;
130 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
132 break;
133 case A_TOKEN( glow ):
135 mrEffectProperties.maGlow.moGlowRad = rAttribs.getInteger( XML_rad, 0 );
136 // undo push_back to effects
137 mrEffectProperties.m_Effects.pop_back();
139 model::ComplexColor* pColor = nullptr;
140 if (mpEffectStyle)
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;
147 return new ColorContext(*this, mrEffectProperties.maGlow.moGlowColor, pColor);
150 case A_TOKEN( softEdge ):
152 mrEffectProperties.maSoftEdge.moRad = rAttribs.getInteger(XML_rad, 0);
153 if (mpEffectStyle)
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
159 return this; // no inner elements
161 case A_TOKEN( reflection ):
163 mrEffectProperties.m_Effects[nPos]->msName = "reflection";
164 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
166 model::ComplexColor* pColor = nullptr;
167 if (mpEffectStyle)
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"
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
188 pColor = &rEffect.maColor;
190 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
192 case A_TOKEN( blur ):
194 mrEffectProperties.m_Effects[nPos]->msName = "blur";
195 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
197 model::ComplexColor* pColor = nullptr;
198 if (mpEffectStyle)
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;
206 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
208 break;
211 mrEffectProperties.m_Effects.pop_back();
212 return nullptr;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */