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