tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / oox / source / drawingml / effectpropertiescontext.cxx
blob9e5fbd98368963f78323e05bddfcb83c861de596
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;
21 // CT_EffectProperties
23 namespace oox::drawingml {
25 EffectPropertiesContext::EffectPropertiesContext( ContextHandler2Helper const& rParent,
26 EffectProperties& rEffectProperties, model::EffectStyle* pEffectStyle) noexcept
27 : ContextHandler2(rParent)
28 , mpEffectStyle(pEffectStyle)
29 , mrEffectProperties(rEffectProperties)
33 EffectPropertiesContext::~EffectPropertiesContext()
37 void EffectPropertiesContext::saveUnsupportedAttribs( Effect& rEffect, const AttributeList& rAttribs )
39 if( rAttribs.hasAttribute( XML_algn ) )
40 rEffect.maAttribs[u"algn"_ustr] <<= rAttribs.getStringDefaulted( XML_algn);
41 if( rAttribs.hasAttribute( XML_blurRad ) )
42 rEffect.maAttribs[u"blurRad"_ustr] <<= rAttribs.getInteger( XML_blurRad, 0 );
43 if( rAttribs.hasAttribute( XML_dir ) )
44 rEffect.maAttribs[u"dir"_ustr] <<= rAttribs.getInteger( XML_dir, 0 );
45 if( rAttribs.hasAttribute( XML_dist ) )
46 rEffect.maAttribs[u"dist"_ustr] <<= rAttribs.getInteger( XML_dist, 0 );
47 if( rAttribs.hasAttribute( XML_kx ) )
48 rEffect.maAttribs[u"kx"_ustr] <<= rAttribs.getInteger( XML_kx, 0 );
49 if( rAttribs.hasAttribute( XML_ky ) )
50 rEffect.maAttribs[u"ky"_ustr] <<= rAttribs.getInteger( XML_ky, 0 );
51 if( rAttribs.hasAttribute( XML_rotWithShape ) )
52 rEffect.maAttribs[u"rotWithShape"_ustr] <<= rAttribs.getInteger( XML_rotWithShape, 0 );
53 if( rAttribs.hasAttribute( XML_sx ) )
54 rEffect.maAttribs[u"sx"_ustr] <<= rAttribs.getInteger( XML_sx, 0 );
55 if( rAttribs.hasAttribute( XML_sy ) )
56 rEffect.maAttribs[u"sy"_ustr] <<= rAttribs.getInteger( XML_sy, 0 );
57 if( rAttribs.hasAttribute( XML_rad ) )
58 rEffect.maAttribs[u"rad"_ustr] <<= rAttribs.getInteger( XML_rad, 0 );
59 if( rAttribs.hasAttribute( XML_endA ) )
60 rEffect.maAttribs[u"endA"_ustr] <<= rAttribs.getInteger( XML_endA, 0 );
61 if( rAttribs.hasAttribute( XML_endPos ) )
62 rEffect.maAttribs[u"endPos"_ustr] <<= rAttribs.getInteger( XML_endPos, 0 );
63 if( rAttribs.hasAttribute( XML_fadeDir ) )
64 rEffect.maAttribs[u"fadeDir"_ustr] <<= rAttribs.getInteger( XML_fadeDir, 0 );
65 if( rAttribs.hasAttribute( XML_stA ) )
66 rEffect.maAttribs[u"stA"_ustr] <<= rAttribs.getInteger( XML_stA, 0 );
67 if( rAttribs.hasAttribute( XML_stPos ) )
68 rEffect.maAttribs[u"stPos"_ustr] <<= rAttribs.getInteger( XML_stPos, 0 );
69 if( rAttribs.hasAttribute( XML_grow ) )
70 rEffect.maAttribs[u"grow"_ustr] <<= rAttribs.getInteger( XML_grow, 0 );
73 ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
75 sal_Int32 nPos = mrEffectProperties.m_Effects.size();
76 mrEffectProperties.m_Effects.push_back(std::make_unique<Effect>());
77 switch( nElement )
79 case A_TOKEN( outerShdw ):
81 mrEffectProperties.m_Effects[nPos]->msName = "outerShdw";
82 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
84 mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 );
85 mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 );
86 mrEffectProperties.maShadow.moShadowSx = rAttribs.getInteger( XML_sx, 0 );
87 mrEffectProperties.maShadow.moShadowSy = rAttribs.getInteger( XML_sy, 0 );
88 mrEffectProperties.maShadow.moShadowBlur = rAttribs.getInteger( XML_blurRad, 0 );
89 mrEffectProperties.maShadow.moShadowAlignment = convertToRectangleAlignment( rAttribs.getToken(XML_algn, XML_b) );
91 model::ComplexColor* pColor = nullptr;
92 if (mpEffectStyle)
94 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
95 rEffect.meType = model::EffectType::OuterShadow;
96 rEffect.mnBlurRadius = rAttribs.getInteger(XML_blurRad, 0); // ST_PositiveCoordinate, default 0
97 rEffect.mnDistance = rAttribs.getInteger(XML_dist, 0); // ST_PositiveCoordinate, default 0
98 rEffect.mnDirection = rAttribs.getInteger(XML_dir, 0); // ST_PositiveFixedAngle, default 0
99 rEffect.mnScaleX = GetPercent( rAttribs.getStringDefaulted(XML_sx)); // ST_Percentage, default 100%
100 rEffect.mnScaley = GetPercent( rAttribs.getStringDefaulted(XML_sy)); // ST_Percentage, default 100%
101 rEffect.mnScewX = rAttribs.getInteger(XML_kx, 0); // ST_FixedAngle, default 0
102 rEffect.mnScewY = rAttribs.getInteger(XML_ky, 0); // ST_FixedAngle, default 0
103 // ST_RectAlignment, default "b" - Bottom
104 rEffect.meAlignment = convertToRectangleAlignment(rAttribs.getToken(XML_algn, XML_b));
105 rEffect.mbRotateWithShape = rAttribs.getBool(XML_rotWithShape, true); // boolean, default "true"
106 pColor = &rEffect.maColor;
108 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
110 break;
111 case A_TOKEN( innerShdw ):
113 mrEffectProperties.m_Effects[nPos]->msName = "innerShdw";
114 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
116 mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 );
117 mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 );
119 model::ComplexColor* pColor = nullptr;
120 if (mpEffectStyle)
122 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
123 rEffect.meType = model::EffectType::InnerShadow;
124 rEffect.mnBlurRadius = rAttribs.getInteger(XML_blurRad, 0); // ST_PositiveCoordinate, default 0
125 rEffect.mnDistance = rAttribs.getInteger(XML_dist, 0); // ST_PositiveCoordinate, default 0
126 rEffect.mnDirection = rAttribs.getInteger(XML_dir, 0); // ST_PositiveFixedAngle, default 0
127 pColor = &rEffect.maColor;
129 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
131 break;
132 case A_TOKEN( glow ):
134 mrEffectProperties.maGlow.moGlowRad = rAttribs.getInteger( XML_rad, 0 );
135 // undo push_back to effects
136 mrEffectProperties.m_Effects.pop_back();
138 model::ComplexColor* pColor = nullptr;
139 if (mpEffectStyle)
141 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
142 rEffect.meType = model::EffectType::Glow;
143 rEffect.mnRadius = rAttribs.getInteger(XML_rad, 0); //ST_PositiveCoordinate, default 0
144 pColor = &rEffect.maColor;
146 return new ColorContext(*this, mrEffectProperties.maGlow.moGlowColor, pColor);
149 case A_TOKEN( softEdge ):
151 mrEffectProperties.maSoftEdge.moRad = rAttribs.getInteger(XML_rad, 0);
152 if (mpEffectStyle)
154 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
155 rEffect.meType = model::EffectType::SoftEdge;
156 rEffect.mnRadius = rAttribs.getInteger(XML_rad, 0); // ST_PositiveCoordinate, default 0
158 return this; // no inner elements
160 case A_TOKEN( reflection ):
162 mrEffectProperties.m_Effects[nPos]->msName = "reflection";
163 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
165 model::ComplexColor* pColor = nullptr;
166 if (mpEffectStyle)
168 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
169 rEffect.meType = model::EffectType::Reflection;
170 rEffect.mnBlurRadius = rAttribs.getInteger(XML_blurRad, 0); // ST_PositiveCoordinate, default 0
171 rEffect.mnDistance = rAttribs.getInteger(XML_dist, 0); // ST_PositiveCoordinate, default 0
172 rEffect.mnDirection = rAttribs.getInteger(XML_dir, 0); // ST_PositiveFixedAngle, default 0
173 rEffect.mnScaleX = GetPercent(rAttribs.getStringDefaulted(XML_sx)); // ST_Percentage, default 100%
174 rEffect.mnScaley = GetPercent(rAttribs.getStringDefaulted(XML_sy)); // ST_Percentage, default 100%
175 rEffect.mnScewX = rAttribs.getInteger(XML_kx, 0); // ST_FixedAngle, default 0
176 rEffect.mnScewY = rAttribs.getInteger(XML_ky, 0); // ST_FixedAngle, default 0
177 // ST_RectAlignment, default "b" - Bottom
178 rEffect.meAlignment = convertToRectangleAlignment(rAttribs.getToken(XML_algn, XML_b));
179 rEffect.mbRotateWithShape = rAttribs.getBool(XML_rotWithShape, true); // boolean, default "true"
181 rEffect.mnEndAlpha = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_endA)); // ST_PositiveFixedPercentage, default 100%
182 rEffect.mnEndPosition = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_endPos)); // ST_PositiveFixedPercentage, default 0%
183 rEffect.mnStartAlpha = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_stA)); // ST_PositiveFixedPercentage, default 0%
184 rEffect.mnStartPosition = GetPositiveFixedPercentage(rAttribs.getStringDefaulted(XML_stPos)); // ST_PositiveFixedPercentage, default 100%
185 rEffect.mnFadeDirection = rAttribs.getInteger(XML_fadeDir, 5400000); // ST_PositiveFixedAngle, default 5400000
187 pColor = &rEffect.maColor;
189 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
191 case A_TOKEN( blur ):
193 mrEffectProperties.m_Effects[nPos]->msName = "blur";
194 saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs);
196 model::ComplexColor* pColor = nullptr;
197 if (mpEffectStyle)
199 auto& rEffect = mpEffectStyle->maEffectList.emplace_back();
200 rEffect.meType = model::EffectType::Blur;
201 rEffect.mnRadius = rAttribs.getInteger(XML_rad, 0); // ST_PositiveCoordinate, default 0
202 rEffect.mbGrow = rAttribs.getBool(XML_grow, true); // boolean, default true
203 pColor = &rEffect.maColor;
205 return new ColorContext(*this, mrEffectProperties.m_Effects[nPos]->moColor, pColor);
207 break;
210 mrEffectProperties.m_Effects.pop_back();
211 return nullptr;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */