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
18
19#include <algorithm>
20
21namespace oox::drawingml {
22
24{
25 assignIfUsed( moGlowRad, rSourceProps.moGlowRad );
26 moGlowColor.assignIfUsed( rSourceProps.moGlowColor );
27}
28
30{
31 assignIfUsed(moRad, rSourceProps.moRad);
32}
33
35{
36 assignIfUsed( moShadowDist, rSourceProps.moShadowDist );
37 assignIfUsed( moShadowDir, rSourceProps.moShadowDir );
38 assignIfUsed( moShadowSx, rSourceProps.moShadowSx );
39 assignIfUsed( moShadowSy, rSourceProps.moShadowSy );
41 assignIfUsed( moShadowBlur, rSourceProps.moShadowBlur );
43
44}
45
47{
48 maShadow.assignUsed(rSourceProps.maShadow);
49 maGlow.assignUsed(rSourceProps.maGlow);
50 maSoftEdge.assignUsed(rSourceProps.maSoftEdge);
51 if (!rSourceProps.m_Effects.empty())
52 {
53 m_Effects.clear();
54 m_Effects.reserve(rSourceProps.m_Effects.size());
55 for (auto const& it : rSourceProps.m_Effects)
56 {
57 m_Effects.push_back(std::make_unique<Effect>(*it));
58 }
59 }
60}
61
63 const GraphicHelper& rGraphicHelper ) const
64{
65 for (auto const& it : m_Effects)
66 {
67 if( it->msName == "outerShdw" )
68 {
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;
73
74 std::map< OUString, css::uno::Any >::const_iterator attribIt = it->maAttribs.find( "dir" );
75 if( attribIt != it->maAttribs.end() )
76 attribIt->second >>= nAttrDir;
77
78 attribIt = it->maAttribs.find( "dist" );
79 if( attribIt != it->maAttribs.end() )
80 attribIt->second >>= nAttrDist;
81
82 attribIt = it->maAttribs.find( "sx" );
83 if( attribIt != it->maAttribs.end() )
84 attribIt->second >>= nAttrSizeX;
85
86 attribIt = it->maAttribs.find( "sy" );
87 if( attribIt != it->maAttribs.end() )
88 attribIt->second >>= nAttrSizeY;
89
90 attribIt = it->maAttribs.find( "blurRad" );
91 if( attribIt != it->maAttribs.end() )
92 attribIt->second >>= nAttrBlur;
93
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;
100
101
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)));
113
114 }
115 }
116}
117
118css::beans::PropertyValue Effect::getEffect()
119{
120 css::beans::PropertyValue aRet;
121 if( msName.isEmpty() )
122 return aRet;
123
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); });
128
129 aRet.Name = msName;
130 aRet.Value <<= aSeq;
131
132 return aRet;
133}
134
135} // namespace oox::drawingml
136
137/* 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:89
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
std::optional< model::RectangleAlignment > moShadowAlignment
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