Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sdr/primitive2d/sdrcustomshapeprimitive2d.hxx>
21
#include <basegfx/polygon/b2dpolygon.hxx>
22
#include <basegfx/polygon/b2dpolygontools.hxx>
23
#include <basegfx/polygon/b2dpolypolygon.hxx>
24
#include <sdr/primitive2d/sdrdecompositiontools.hxx>
25
#include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
26
#include <drawinglayer/attribute/sdrlineattribute.hxx>
27
#include <drawinglayer/primitive2d/groupprimitive2d.hxx>
28
#include <utility>
29
30
31
using namespace com::sun::star;
32
33
34
namespace drawinglayer::primitive2d
35
{
36
        Primitive2DReference SdrCustomShapePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
37
419
        {
38
419
            Primitive2DContainer aRetval(getSubPrimitives());
39
40
            // Soft edges should be before text, since text is not affected by soft edges
41
419
            if (!aRetval.empty() && getSdrSTAttribute().getSoftEdgeRadius())
42
0
            {
43
0
                aRetval = createEmbeddedSoftEdgePrimitive(std::move(aRetval),
44
0
                                                          getSdrSTAttribute().getSoftEdgeRadius());
45
0
            }
46
47
            // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite
48
419
            if (!aRetval.empty() && !getSdrSTAttribute().getGlow().isDefault())
49
0
            {
50
                // glow
51
0
                aRetval = createEmbeddedGlowPrimitive(std::move(aRetval), getSdrSTAttribute().getGlow());
52
0
            }
53
54
            // add text
55
419
            if(!getSdrSTAttribute().getText().isDefault())
56
349
            {
57
349
                const basegfx::B2DPolygon& aUnitOutline(basegfx::utils::createUnitPolygon());
58
59
349
                Primitive2DContainer aTempContentText;
60
349
                aTempContentText.push_back(
61
349
                    createTextPrimitive(
62
349
                        basegfx::B2DPolyPolygon(aUnitOutline),
63
349
                        getTextBox(),
64
349
                        getSdrSTAttribute().getText(),
65
349
                        attribute::SdrLineAttribute(),
66
349
                        false,
67
349
                        getWordWrap()));
68
69
                // put text glow before, shape glow and shadow
70
349
                if (!getSdrSTAttribute().getGlowText().isDefault())
71
0
                {
72
                    // add text glow
73
0
                    aTempContentText = createEmbeddedTextGlowPrimitive(std::move(aTempContentText), getSdrSTAttribute().getGlowText());
74
0
                }
75
349
                aRetval.append(std::move(aTempContentText));
76
349
            }
77
78
            // add shadow
79
419
            if(!aRetval.empty() && !getSdrSTAttribute().getShadow().isDefault())
80
0
            {
81
                // #i105323# add generic shadow only for 2D shapes. For
82
                // 3D shapes shadow will be set at the individual created
83
                // visualisation objects and be visualized by the 3d renderer
84
                // as a single shadow.
85
86
                // The shadow for AutoShapes could be handled uniformly by not setting any
87
                // shadow items at the helper model objects and only adding shadow here for
88
                // 2D and 3D (and it works, too), but this would lead to two 3D scenes for
89
                // the 3D object; one for the shadow and one for the content. The one for the
90
                // shadow will be correct (using ColorModifierStack), but expensive.
91
0
                if(!get3DShape())
92
0
                {
93
0
                    aRetval = createEmbeddedShadowPrimitive(std::move(aRetval), getSdrSTAttribute().getShadow(),
94
0
                                                            maTransform);
95
0
                }
96
0
            }
97
98
419
            return new GroupPrimitive2D(std::move(aRetval));
99
419
        }
100
101
        SdrCustomShapePrimitive2D::SdrCustomShapePrimitive2D(
102
            const attribute::SdrEffectsTextAttribute& rSdrSTAttribute,
103
            Primitive2DContainer&& rSubPrimitives,
104
            basegfx::B2DHomMatrix aTextBox,
105
            bool bWordWrap,
106
            bool b3DShape,
107
            basegfx::B2DHomMatrix aTransform)
108
838
        :   maSdrSTAttribute(rSdrSTAttribute),
109
838
            maSubPrimitives(std::move(rSubPrimitives)),
110
838
            maTextBox(std::move(aTextBox)),
111
838
            mbWordWrap(bWordWrap),
112
838
            mb3DShape(b3DShape),
113
838
            maTransform(std::move(aTransform))
114
838
        {
115
838
        }
116
117
        bool SdrCustomShapePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
118
419
        {
119
419
            if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
120
419
            {
121
419
                const SdrCustomShapePrimitive2D& rCompare = static_cast<const SdrCustomShapePrimitive2D&>(rPrimitive);
122
123
419
                return (getSdrSTAttribute() == rCompare.getSdrSTAttribute()
124
419
                    && getSubPrimitives() == rCompare.getSubPrimitives()
125
419
                    && getTextBox() == rCompare.getTextBox()
126
419
                    && getWordWrap() == rCompare.getWordWrap()
127
419
                    && get3DShape() == rCompare.get3DShape());
128
419
            }
129
130
0
            return false;
131
419
        }
132
133
        // provide unique ID
134
        sal_uInt32 SdrCustomShapePrimitive2D::getPrimitive2DID() const
135
1.52k
        {
136
1.52k
            return PRIMITIVE2D_ID_SDRCUSTOMSHAPEPRIMITIVE2D;
137
1.52k
        }
138
139
} // end of namespace
140
141
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */