/src/libreoffice/oox/source/drawingml/effectproperties.cxx
Line | Count | Source |
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 <drawingml/effectproperties.hxx> |
11 | | #include <oox/drawingml/drawingmltypes.hxx> |
12 | | #include <oox/helper/graphichelper.hxx> |
13 | | #include <oox/token/properties.hxx> |
14 | | |
15 | | #include <basegfx/numeric/ftools.hxx> |
16 | | #include <comphelper/propertyvalue.hxx> |
17 | | #include <docmodel/theme/FormatScheme.hxx> |
18 | | |
19 | | #include <algorithm> |
20 | | |
21 | | namespace oox::drawingml { |
22 | | |
23 | | void EffectGlowProperties ::assignUsed(const EffectGlowProperties& rSourceProps) |
24 | 9.38M | { |
25 | 9.38M | assignIfUsed( moGlowRad, rSourceProps.moGlowRad ); |
26 | 9.38M | moGlowColor.assignIfUsed( rSourceProps.moGlowColor ); |
27 | 9.38M | } |
28 | | |
29 | | void EffectSoftEdgeProperties::assignUsed(const EffectSoftEdgeProperties& rSourceProps) |
30 | 9.38M | { |
31 | 9.38M | assignIfUsed(moRad, rSourceProps.moRad); |
32 | 9.38M | } |
33 | | |
34 | | void EffectShadowProperties::assignUsed(const EffectShadowProperties& rSourceProps) |
35 | 9.38M | { |
36 | 9.38M | assignIfUsed( moShadowDist, rSourceProps.moShadowDist ); |
37 | 9.38M | assignIfUsed( moShadowDir, rSourceProps.moShadowDir ); |
38 | 9.38M | assignIfUsed( moShadowSx, rSourceProps.moShadowSx ); |
39 | 9.38M | assignIfUsed( moShadowSy, rSourceProps.moShadowSy ); |
40 | 9.38M | moShadowColor.assignIfUsed( rSourceProps.moShadowColor ); |
41 | 9.38M | assignIfUsed( moShadowBlur, rSourceProps.moShadowBlur ); |
42 | 9.38M | assignIfUsed( moShadowAlignment, rSourceProps.moShadowAlignment ); |
43 | | |
44 | 9.38M | } |
45 | | |
46 | | void EffectProperties::assignUsed( const EffectProperties& rSourceProps ) |
47 | 9.38M | { |
48 | 9.38M | maShadow.assignUsed(rSourceProps.maShadow); |
49 | 9.38M | maGlow.assignUsed(rSourceProps.maGlow); |
50 | 9.38M | maSoftEdge.assignUsed(rSourceProps.maSoftEdge); |
51 | 9.38M | if (!rSourceProps.m_Effects.empty()) |
52 | 502 | { |
53 | 502 | m_Effects.clear(); |
54 | 502 | m_Effects.reserve(rSourceProps.m_Effects.size()); |
55 | 502 | for (auto const& it : rSourceProps.m_Effects) |
56 | 502 | { |
57 | 502 | m_Effects.push_back(std::make_unique<Effect>(*it)); |
58 | 502 | } |
59 | 502 | } |
60 | 9.38M | } |
61 | | |
62 | | void EffectProperties::pushToPropMap( PropertyMap& rPropMap, |
63 | | const GraphicHelper& rGraphicHelper ) const |
64 | 63.3k | { |
65 | 63.3k | for (auto const& it : m_Effects) |
66 | 121 | { |
67 | 121 | if( it->msName == "outerShdw" ) |
68 | 121 | { |
69 | 121 | sal_Int32 nAttrDir = 0, nAttrDist = 0; |
70 | 121 | 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 | 121 | sal_Int32 nAttrBlur = 0; |
73 | | |
74 | 121 | std::map< OUString, css::uno::Any >::const_iterator attribIt = it->maAttribs.find( u"dir"_ustr ); |
75 | 121 | if( attribIt != it->maAttribs.end() ) |
76 | 121 | attribIt->second >>= nAttrDir; |
77 | | |
78 | 121 | attribIt = it->maAttribs.find( u"dist"_ustr ); |
79 | 121 | if( attribIt != it->maAttribs.end() ) |
80 | 121 | attribIt->second >>= nAttrDist; |
81 | | |
82 | 121 | attribIt = it->maAttribs.find( u"sx"_ustr ); |
83 | 121 | if( attribIt != it->maAttribs.end() ) |
84 | 4 | attribIt->second >>= nAttrSizeX; |
85 | | |
86 | 121 | attribIt = it->maAttribs.find( u"sy"_ustr ); |
87 | 121 | if( attribIt != it->maAttribs.end() ) |
88 | 4 | attribIt->second >>= nAttrSizeY; |
89 | | |
90 | 121 | attribIt = it->maAttribs.find( u"blurRad"_ustr ); |
91 | 121 | if( attribIt != it->maAttribs.end() ) |
92 | 91 | 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 | 121 | double nAngle = basegfx::deg2rad(static_cast<double>(nAttrDir) / PER_DEGREE); |
97 | 121 | sal_Int32 nDist = convertEmuToHmm( nAttrDist ); |
98 | 121 | sal_Int32 nXDist = cos(nAngle) * nDist; |
99 | 121 | sal_Int32 nYDist = sin(nAngle) * nDist; |
100 | | |
101 | | |
102 | 121 | rPropMap.setProperty( PROP_Shadow, true ); |
103 | 121 | rPropMap.setProperty( PROP_ShadowXDistance, nXDist); |
104 | 121 | rPropMap.setProperty( PROP_ShadowYDistance, nYDist); |
105 | 121 | rPropMap.setProperty( PROP_ShadowSizeX, nAttrSizeX); |
106 | 121 | rPropMap.setProperty( PROP_ShadowSizeY, nAttrSizeY); |
107 | 121 | rPropMap.setProperty( PROP_ShadowColor, it->moColor.getColor(rGraphicHelper ) ); |
108 | 121 | rPropMap.setProperty( PROP_ShadowTransparence, it->moColor.getTransparency()); |
109 | 121 | rPropMap.setProperty( PROP_ShadowBlur, convertEmuToHmm(nAttrBlur)); |
110 | 121 | rPropMap.setProperty( |
111 | 121 | PROP_ShadowAlignment, |
112 | 121 | static_cast<sal_Int32>(maShadow.moShadowAlignment.value_or(model::RectangleAlignment::Bottom))); |
113 | | |
114 | 121 | } |
115 | 121 | } |
116 | 63.3k | } |
117 | | |
118 | | css::beans::PropertyValue Effect::getEffect() |
119 | 118 | { |
120 | 118 | css::beans::PropertyValue aRet; |
121 | 118 | if( msName.isEmpty() ) |
122 | 0 | return aRet; |
123 | | |
124 | 118 | css::uno::Sequence< css::beans::PropertyValue > aSeq( maAttribs.size() ); |
125 | 118 | std::transform(maAttribs.begin(), maAttribs.end(), aSeq.getArray(), |
126 | 118 | [](const auto& attrib) |
127 | 456 | { return comphelper::makePropertyValue(attrib.first, attrib.second); }); |
128 | | |
129 | 118 | aRet.Name = msName; |
130 | 118 | aRet.Value <<= aSeq; |
131 | | |
132 | 118 | return aRet; |
133 | 118 | } |
134 | | |
135 | | } // namespace oox::drawingml |
136 | | |
137 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |