Coverage Report

Created: 2025-11-16 09:57

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