Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svx/source/sdr/primitive2d/sdrrectangleprimitive2d.cxx
Line
Count
Source (jump to first uncovered line)
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/sdrrectangleprimitive2d.hxx>
21
#include <basegfx/polygon/b2dpolygontools.hxx>
22
#include <sdr/primitive2d/sdrdecompositiontools.hxx>
23
#include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
24
#include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
25
#include <drawinglayer/primitive2d/groupprimitive2d.hxx>
26
#include <basegfx/polygon/b2dpolygon.hxx>
27
#include <basegfx/polygon/b2dpolypolygon.hxx>
28
#include <utility>
29
30
31
using namespace com::sun::star;
32
33
34
namespace drawinglayer::primitive2d
35
{
36
        Primitive2DReference SdrRectanglePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
37
5
        {
38
5
            Primitive2DContainer aRetval;
39
40
            // create unit outline polygon
41
5
            const basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromRect(
42
5
                basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
43
5
                getCornerRadiusX(),
44
5
                getCornerRadiusY()));
45
46
            // add fill
47
5
            if(!getSdrLFSTAttribute().getFill().isDefault())
48
5
            {
49
5
                basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
50
51
5
                aTransformed.transform(getTransform());
52
5
                aRetval.push_back(
53
5
                    createPolyPolygonFillPrimitive(
54
5
                        aTransformed,
55
5
                        getSdrLFSTAttribute().getFill(),
56
5
                        getSdrLFSTAttribute().getFillFloatTransGradient()));
57
5
            }
58
0
            else if(getForceFillForHitTest())
59
0
            {
60
                // if no fill and it's a text frame, create a fill for HitTest and
61
                // BoundRect fallback
62
0
                aRetval.push_back(
63
0
                    createHiddenGeometryPrimitives2D(
64
0
                        true,
65
0
                        basegfx::B2DPolyPolygon(aUnitOutline),
66
0
                        getTransform()));
67
0
            }
68
69
            // add line
70
5
            if(!getSdrLFSTAttribute().getLine().isDefault())
71
5
            {
72
5
                basegfx::B2DPolygon aTransformed(aUnitOutline);
73
74
5
                aTransformed.transform(getTransform());
75
5
                aRetval.push_back(
76
5
                    createPolygonLinePrimitive(
77
5
                        aTransformed,
78
5
                        getSdrLFSTAttribute().getLine(),
79
5
                        attribute::SdrLineStartEndAttribute()));
80
5
            }
81
0
            else if(!getForceFillForHitTest())
82
0
            {
83
                // if initially no line is defined and it's not a text frame, create
84
                // a line for HitTest and BoundRect
85
0
                aRetval.push_back(
86
0
                    createHiddenGeometryPrimitives2D(
87
0
                        false,
88
0
                        basegfx::B2DPolyPolygon(aUnitOutline),
89
0
                        getTransform()));
90
0
            }
91
92
            // Soft edges should be before text, since text is not affected by soft edges
93
5
            if (!aRetval.empty() && getSdrLFSTAttribute().getSoftEdgeRadius())
94
0
            {
95
0
                aRetval = createEmbeddedSoftEdgePrimitive(std::move(aRetval),
96
0
                    getSdrLFSTAttribute().getSoftEdgeRadius());
97
0
            }
98
99
            // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite
100
5
            if (!aRetval.empty() && !getSdrLFSTAttribute().getGlow().isDefault())
101
0
            {
102
                // glow
103
0
                aRetval = createEmbeddedGlowPrimitive(std::move(aRetval), getSdrLFSTAttribute().getGlow());
104
0
            }
105
106
            // add text
107
5
            if(!getSdrLFSTAttribute().getText().isDefault())
108
5
            {
109
5
                Primitive2DContainer aTempContentText;
110
5
                aTempContentText.push_back(
111
5
                    createTextPrimitive(
112
5
                        basegfx::B2DPolyPolygon(aUnitOutline),
113
5
                        getTransform(),
114
5
                        getSdrLFSTAttribute().getText(),
115
5
                        getSdrLFSTAttribute().getLine(),
116
5
                        false,
117
5
                        false));
118
119
                // put text glow before, shape glow and shadow
120
5
                if (!getSdrLFSTAttribute().getGlowText().isDefault())
121
0
                {
122
                    // add text glow
123
0
                    aTempContentText = createEmbeddedTextGlowPrimitive(std::move(aTempContentText), getSdrLFSTAttribute().getGlowText());
124
0
                }
125
5
                aRetval.append(std::move(aTempContentText));
126
5
            }
127
128
            // add shadow
129
5
            if(!getSdrLFSTAttribute().getShadow().isDefault())
130
0
            {
131
0
                aRetval = createEmbeddedShadowPrimitive(
132
0
                    std::move(aRetval),
133
0
                    getSdrLFSTAttribute().getShadow());
134
0
            }
135
136
5
            return new GroupPrimitive2D(std::move(aRetval));
137
5
        }
138
139
        SdrRectanglePrimitive2D::SdrRectanglePrimitive2D(
140
            basegfx::B2DHomMatrix aTransform,
141
            const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
142
            double fCornerRadiusX,
143
            double fCornerRadiusY,
144
            bool bForceFillForHitTest)
145
5
        :   maTransform(std::move(aTransform)),
146
5
            maSdrLFSTAttribute(rSdrLFSTAttribute),
147
5
            mfCornerRadiusX(fCornerRadiusX),
148
5
            mfCornerRadiusY(fCornerRadiusY),
149
5
            mbForceFillForHitTest(bForceFillForHitTest)
150
5
        {
151
5
        }
152
153
        bool SdrRectanglePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
154
0
        {
155
0
            if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
156
0
            {
157
0
                const SdrRectanglePrimitive2D& rCompare = static_cast<const SdrRectanglePrimitive2D&>(rPrimitive);
158
159
0
                return (getCornerRadiusX() == rCompare.getCornerRadiusX()
160
0
                    && getCornerRadiusY() == rCompare.getCornerRadiusY()
161
0
                    && getTransform() == rCompare.getTransform()
162
0
                    && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
163
0
                    && getForceFillForHitTest() == rCompare.getForceFillForHitTest());
164
0
            }
165
166
0
            return false;
167
0
        }
168
169
        // provide unique ID
170
        sal_uInt32 SdrRectanglePrimitive2D::getPrimitive2DID() const
171
5
        {
172
5
            return PRIMITIVE2D_ID_SDRRECTANGLEPRIMITIVE2D;
173
5
        }
174
175
} // end of namespace
176
177
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */