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 #include "effectproperties.hxx"
11 #include <oox/drawingml/drawingmltypes.hxx>
12 #include <oox/drawingml/shapepropertymap.hxx>
13 #include <oox/helper/graphichelper.hxx>
14 #include <oox/token/properties.hxx>
15 #include <oox/token/tokens.hxx>
16
17 #include <basegfx/numeric/ftools.hxx>
18
19 namespace oox {
20 namespace drawingml {
21
assignUsed(const EffectShadowProperties & rSourceProps)22 void EffectShadowProperties::assignUsed(const EffectShadowProperties& rSourceProps)
23 {
24 moShadowDist.assignIfUsed( rSourceProps.moShadowDist );
25 moShadowDir.assignIfUsed( rSourceProps.moShadowDir );
26 moShadowColor.assignIfUsed( rSourceProps.moShadowColor );
27 }
28
assignUsed(const EffectProperties & rSourceProps)29 void EffectProperties::assignUsed( const EffectProperties& rSourceProps )
30 {
31 maShadow.assignUsed(rSourceProps.maShadow);
32 if (!rSourceProps.m_Effects.empty())
33 {
34 m_Effects.clear();
35 m_Effects.reserve(rSourceProps.m_Effects.size());
36 for (auto const& it : rSourceProps.m_Effects)
37 {
38 m_Effects.push_back(std::make_unique<Effect>(*it));
39 }
40 }
41 }
42
pushToPropMap(PropertyMap & rPropMap,const GraphicHelper & rGraphicHelper) const43 void EffectProperties::pushToPropMap( PropertyMap& rPropMap,
44 const GraphicHelper& rGraphicHelper ) const
45 {
46 for (auto const& it : m_Effects)
47 {
48 if( it->msName == "outerShdw" )
49 {
50 sal_Int32 nAttrDir = 0, nAttrDist = 0;
51 std::map< OUString, css::uno::Any >::const_iterator attribIt = it->maAttribs.find( "dir" );
52 if( attribIt != it->maAttribs.end() )
53 attribIt->second >>= nAttrDir;
54
55 attribIt = it->maAttribs.find( "dist" );
56 if( attribIt != it->maAttribs.end() )
57 attribIt->second >>= nAttrDist;
58
59 // Negative X or Y dist indicates left or up, respectively
60 double nAngle = basegfx::deg2rad(static_cast<double>(nAttrDir) / PER_DEGREE);
61 sal_Int32 nDist = convertEmuToHmm( nAttrDist );
62 sal_Int32 nXDist = cos(nAngle) * nDist;
63 sal_Int32 nYDist = sin(nAngle) * nDist;
64
65 rPropMap.setProperty( PROP_Shadow, true );
66 rPropMap.setProperty( PROP_ShadowXDistance, nXDist);
67 rPropMap.setProperty( PROP_ShadowYDistance, nYDist);
68 rPropMap.setProperty( PROP_ShadowColor, it->moColor.getColor(rGraphicHelper ) );
69 rPropMap.setProperty( PROP_ShadowTransparence, it->moColor.getTransparency());
70 }
71 }
72 }
73
getEffect()74 css::beans::PropertyValue Effect::getEffect()
75 {
76 css::beans::PropertyValue aRet;
77 if( msName.isEmpty() )
78 return aRet;
79
80 css::uno::Sequence< css::beans::PropertyValue > aSeq( maAttribs.size() );
81 sal_uInt32 i = 0;
82 for (auto const& attrib : maAttribs)
83 {
84 aSeq[i].Name = attrib.first;
85 aSeq[i].Value = attrib.second;
86 i++;
87 }
88
89 aRet.Name = msName;
90 aRet.Value <<= aSeq;
91
92 return aRet;
93 }
94
95 } // namespace drawingml
96 } // namespace oox
97
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
99