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/.
10 #include <oox/drawingml/effectproperties.hxx>
11 #include <oox/drawingml/drawingmltypes.hxx>
12 #include <oox/helper/graphichelper.hxx>
13 #include <oox/token/properties.hxx>
15 #include <basegfx/numeric/ftools.hxx>
16 #include <comphelper/propertyvalue.hxx>
17 #include <docmodel/theme/FormatScheme.hxx>
21 namespace oox::drawingml
{
23 void EffectGlowProperties ::assignUsed(const EffectGlowProperties
& rSourceProps
)
25 assignIfUsed( moGlowRad
, rSourceProps
.moGlowRad
);
26 moGlowColor
.assignIfUsed( rSourceProps
.moGlowColor
);
29 void EffectSoftEdgeProperties::assignUsed(const EffectSoftEdgeProperties
& rSourceProps
)
31 assignIfUsed(moRad
, rSourceProps
.moRad
);
34 void EffectShadowProperties::assignUsed(const EffectShadowProperties
& rSourceProps
)
36 assignIfUsed( moShadowDist
, rSourceProps
.moShadowDist
);
37 assignIfUsed( moShadowDir
, rSourceProps
.moShadowDir
);
38 assignIfUsed( moShadowSx
, rSourceProps
.moShadowSx
);
39 assignIfUsed( moShadowSy
, rSourceProps
.moShadowSy
);
40 moShadowColor
.assignIfUsed( rSourceProps
.moShadowColor
);
41 assignIfUsed( moShadowBlur
, rSourceProps
.moShadowBlur
);
42 assignIfUsed( moShadowAlignment
, rSourceProps
.moShadowAlignment
);
46 void EffectProperties::assignUsed( const EffectProperties
& rSourceProps
)
48 maShadow
.assignUsed(rSourceProps
.maShadow
);
49 maGlow
.assignUsed(rSourceProps
.maGlow
);
50 maSoftEdge
.assignUsed(rSourceProps
.maSoftEdge
);
51 if (!rSourceProps
.m_Effects
.empty())
54 m_Effects
.reserve(rSourceProps
.m_Effects
.size());
55 for (auto const& it
: rSourceProps
.m_Effects
)
57 m_Effects
.push_back(std::make_unique
<Effect
>(*it
));
62 void EffectProperties::pushToPropMap( PropertyMap
& rPropMap
,
63 const GraphicHelper
& rGraphicHelper
) const
65 for (auto const& it
: m_Effects
)
67 if( it
->msName
== "outerShdw" )
69 sal_Int32 nAttrDir
= 0, nAttrDist
= 0;
70 sal_Int32 nAttrSizeX
= 100000, nAttrSizeY
= 100000; // If shadow size is %100=100000 (means equal to object's size), sx sy is not exists,
71 // Default values of sx, sy should be 100000 in this case.
72 sal_Int32 nAttrBlur
= 0;
74 std::map
< OUString
, css::uno::Any
>::const_iterator attribIt
= it
->maAttribs
.find( u
"dir"_ustr
);
75 if( attribIt
!= it
->maAttribs
.end() )
76 attribIt
->second
>>= nAttrDir
;
78 attribIt
= it
->maAttribs
.find( u
"dist"_ustr
);
79 if( attribIt
!= it
->maAttribs
.end() )
80 attribIt
->second
>>= nAttrDist
;
82 attribIt
= it
->maAttribs
.find( u
"sx"_ustr
);
83 if( attribIt
!= it
->maAttribs
.end() )
84 attribIt
->second
>>= nAttrSizeX
;
86 attribIt
= it
->maAttribs
.find( u
"sy"_ustr
);
87 if( attribIt
!= it
->maAttribs
.end() )
88 attribIt
->second
>>= nAttrSizeY
;
90 attribIt
= it
->maAttribs
.find( u
"blurRad"_ustr
);
91 if( attribIt
!= it
->maAttribs
.end() )
92 attribIt
->second
>>= nAttrBlur
;
94 // Negative X or Y dist indicates left or up, respectively
95 // Negative X or Y dist indicates left or up, respectively
96 double nAngle
= basegfx::deg2rad(static_cast<double>(nAttrDir
) / PER_DEGREE
);
97 sal_Int32 nDist
= convertEmuToHmm( nAttrDist
);
98 sal_Int32 nXDist
= cos(nAngle
) * nDist
;
99 sal_Int32 nYDist
= sin(nAngle
) * nDist
;
102 rPropMap
.setProperty( PROP_Shadow
, true );
103 rPropMap
.setProperty( PROP_ShadowXDistance
, nXDist
);
104 rPropMap
.setProperty( PROP_ShadowYDistance
, nYDist
);
105 rPropMap
.setProperty( PROP_ShadowSizeX
, nAttrSizeX
);
106 rPropMap
.setProperty( PROP_ShadowSizeY
, nAttrSizeY
);
107 rPropMap
.setProperty( PROP_ShadowColor
, it
->moColor
.getColor(rGraphicHelper
) );
108 rPropMap
.setProperty( PROP_ShadowTransparence
, it
->moColor
.getTransparency());
109 rPropMap
.setProperty( PROP_ShadowBlur
, convertEmuToHmm(nAttrBlur
));
110 rPropMap
.setProperty(
111 PROP_ShadowAlignment
,
112 static_cast<sal_Int32
>(maShadow
.moShadowAlignment
.value_or(model::RectangleAlignment::Bottom
)));
118 css::beans::PropertyValue
Effect::getEffect()
120 css::beans::PropertyValue aRet
;
121 if( msName
.isEmpty() )
124 css::uno::Sequence
< css::beans::PropertyValue
> aSeq( maAttribs
.size() );
125 std::transform(maAttribs
.begin(), maAttribs
.end(), aSeq
.getArray(),
126 [](const auto& attrib
)
127 { return comphelper::makePropertyValue(attrib
.first
, attrib
.second
); });
135 } // namespace oox::drawingml
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */