LibreOffice Module oox (master)  1
effectproperties.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 
10 #include "effectproperties.hxx"
13 #include <oox/token/properties.hxx>
14 
16 
17 namespace oox::drawingml {
18 
20 {
21  moGlowRad.assignIfUsed( rSourceProps.moGlowRad );
22  moGlowColor.assignIfUsed( rSourceProps.moGlowColor );
23 }
24 
26 {
27  moRad.assignIfUsed(rSourceProps.moRad);
28 }
29 
31 {
32  moShadowDist.assignIfUsed( rSourceProps.moShadowDist );
33  moShadowDir.assignIfUsed( rSourceProps.moShadowDir );
34  moShadowSx.assignIfUsed( rSourceProps.moShadowSx );
35  moShadowSy.assignIfUsed( rSourceProps.moShadowSy );
37  moShadowBlur.assignIfUsed( rSourceProps.moShadowBlur );
38 
39 }
40 
42 {
43  maShadow.assignUsed(rSourceProps.maShadow);
44  maGlow.assignUsed(rSourceProps.maGlow);
45  maSoftEdge.assignUsed(rSourceProps.maSoftEdge);
46  if (!rSourceProps.m_Effects.empty())
47  {
48  m_Effects.clear();
49  m_Effects.reserve(rSourceProps.m_Effects.size());
50  for (auto const& it : rSourceProps.m_Effects)
51  {
52  m_Effects.push_back(std::make_unique<Effect>(*it));
53  }
54  }
55 }
56 
58  const GraphicHelper& rGraphicHelper ) const
59 {
60  for (auto const& it : m_Effects)
61  {
62  if( it->msName == "outerShdw" )
63  {
64  sal_Int32 nAttrDir = 0, nAttrDist = 0;
65  sal_Int32 nAttrSizeX = 100000, nAttrSizeY = 100000; // If shadow size is %100=100000 (means equal to object's size), sx sy is not exists,
66  // Default values of sx, sy should be 100000 in this case.
67  sal_Int32 nAttrBlur = 0;
68 
69  std::map< OUString, css::uno::Any >::const_iterator attribIt = it->maAttribs.find( "dir" );
70  if( attribIt != it->maAttribs.end() )
71  attribIt->second >>= nAttrDir;
72 
73  attribIt = it->maAttribs.find( "dist" );
74  if( attribIt != it->maAttribs.end() )
75  attribIt->second >>= nAttrDist;
76 
77  attribIt = it->maAttribs.find( "sx" );
78  if( attribIt != it->maAttribs.end() )
79  attribIt->second >>= nAttrSizeX;
80 
81  attribIt = it->maAttribs.find( "sy" );
82  if( attribIt != it->maAttribs.end() )
83  attribIt->second >>= nAttrSizeY;
84 
85  attribIt = it->maAttribs.find( "blurRad" );
86  if( attribIt != it->maAttribs.end() )
87  attribIt->second >>= nAttrBlur;
88 
89  // Negative X or Y dist indicates left or up, respectively
90  // Negative X or Y dist indicates left or up, respectively
91  double nAngle = basegfx::deg2rad(static_cast<double>(nAttrDir) / PER_DEGREE);
92  sal_Int32 nDist = convertEmuToHmm( nAttrDist );
93  sal_Int32 nXDist = cos(nAngle) * nDist;
94  sal_Int32 nYDist = sin(nAngle) * nDist;
95 
96 
97  rPropMap.setProperty( PROP_Shadow, true );
98  rPropMap.setProperty( PROP_ShadowXDistance, nXDist);
99  rPropMap.setProperty( PROP_ShadowYDistance, nYDist);
100  rPropMap.setProperty( PROP_ShadowSizeX, nAttrSizeX);
101  rPropMap.setProperty( PROP_ShadowSizeY, nAttrSizeY);
102  rPropMap.setProperty( PROP_ShadowColor, it->moColor.getColor(rGraphicHelper ) );
103  rPropMap.setProperty( PROP_ShadowTransparence, it->moColor.getTransparency());
104  rPropMap.setProperty( PROP_ShadowBlur, convertEmuToHmm(nAttrBlur));
105 
106  }
107  }
108 }
109 
110 css::beans::PropertyValue Effect::getEffect()
111 {
112  css::beans::PropertyValue aRet;
113  if( msName.isEmpty() )
114  return aRet;
115 
116  css::uno::Sequence< css::beans::PropertyValue > aSeq( maAttribs.size() );
117  sal_uInt32 i = 0;
118  for (auto const& attrib : maAttribs)
119  {
120  aSeq[i].Name = attrib.first;
121  aSeq[i].Value = attrib.second;
122  i++;
123  }
124 
125  aRet.Name = msName;
126  aRet.Value <<= aSeq;
127 
128  return aRet;
129 }
130 
131 } // namespace oox::drawingml
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
sal_Int32 convertEmuToHmm(sal_Int64 nValue)
Converts the passed 64-bit integer value from EMUs to 1/100 mm.
std::vector< std::unique_ptr< Effect > > m_Effects
Stores all effect properties, including those not supported by core yet.
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
void assignUsed(const EffectGlowProperties &rSourceProps)
const sal_Int32 PER_DEGREE
void assignUsed(const EffectSoftEdgeProperties &rSourceProps)
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:70
void assignUsed(const EffectShadowProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
EffectSoftEdgeProperties maSoftEdge
void assignIfUsed(const OptValue &rValue)
Definition: helper.hxx:196
void pushToPropMap(PropertyMap &rPropMap, const GraphicHelper &rGraphicHelper) const
Writes the properties to the passed property map.
constexpr double deg2rad(double v)
void assignUsed(const EffectProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
Sequence< sal_Int8 > aSeq
css::beans::PropertyValue getEffect()
std::map< OUString, css::uno::Any > maAttribs
void assignIfUsed(const Color &rColor)
Overwrites this color with the passed color, if it is used.
Definition: color.hxx:84