Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/drawinglayer/source/attribute/fillgraphicattribute.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 <sal/config.h>
21
22
#include <algorithm>
23
24
#include <drawinglayer/attribute/fillgraphicattribute.hxx>
25
#include <utility>
26
#include <vcl/graph.hxx>
27
28
namespace drawinglayer::attribute
29
{
30
        class ImpFillGraphicAttribute
31
        {
32
        public:
33
            // data definitions
34
            Graphic                                 maGraphic;
35
            basegfx::B2DRange                       maGraphicRange;
36
37
            bool                                    mbTiling : 1;
38
39
            // tiling definitions, offsets in X/Y in percent for each 2nd row.
40
            // If both are set, Y is ignored (X has precedence)
41
            double                                  mfOffsetX;
42
            double                                  mfOffsetY;
43
44
            ImpFillGraphicAttribute(
45
                Graphic aGraphic,
46
                const basegfx::B2DRange& rGraphicRange,
47
                bool bTiling,
48
                double fOffsetX,
49
                double fOffsetY)
50
0
            :   maGraphic(std::move(aGraphic)),
51
0
                maGraphicRange(rGraphicRange),
52
0
                mbTiling(bTiling),
53
0
                mfOffsetX(fOffsetX),
54
0
                mfOffsetY(fOffsetY)
55
0
            {
56
                // access once to ensure that the buffered bitmap exists, else
57
                // the SolarMutex may be needed to create it. This may not be
58
                // available when a renderer works with multi-threading.
59
                // When changing this, please check if it is still possible to
60
                // use a metafile as texture for a 3D object
61
0
                maGraphic.GetBitmapEx();
62
0
            }
63
64
            ImpFillGraphicAttribute()
65
0
            :   mbTiling(false),
66
0
                mfOffsetX(0.0),
67
0
                mfOffsetY(0.0)
68
0
            {
69
0
            }
70
71
            // data read access
72
0
            const Graphic& getGraphic() const { return maGraphic; }
73
0
            const basegfx::B2DRange& getGraphicRange() const { return maGraphicRange; }
74
0
            bool getTiling() const { return mbTiling; }
75
0
            double getOffsetX() const { return mfOffsetX; }
76
0
            double getOffsetY() const { return mfOffsetY; }
77
78
            bool operator==(const ImpFillGraphicAttribute& rCandidate) const
79
0
            {
80
0
                return (getGraphic() == rCandidate.getGraphic()
81
0
                    && getGraphicRange() == rCandidate.getGraphicRange()
82
0
                    && getTiling() == rCandidate.getTiling()
83
0
                    && getOffsetX() == rCandidate.getOffsetX()
84
0
                    && getOffsetY() == rCandidate.getOffsetY());
85
0
            }
86
        };
87
88
        namespace
89
        {
90
            FillGraphicAttribute::ImplType& theGlobalDefault()
91
0
            {
92
0
                static FillGraphicAttribute::ImplType SINGLETON;
93
0
                return SINGLETON;
94
0
            }
95
        }
96
97
        FillGraphicAttribute::FillGraphicAttribute()
98
0
        :   mpFillGraphicAttribute(theGlobalDefault())
99
0
        {
100
0
        }
101
102
        FillGraphicAttribute::FillGraphicAttribute(
103
            const Graphic& rGraphic,
104
            const basegfx::B2DRange& rGraphicRange,
105
            bool bTiling,
106
            double fOffsetX,
107
            double fOffsetY)
108
0
        :   mpFillGraphicAttribute(ImpFillGraphicAttribute(
109
0
                rGraphic, rGraphicRange, bTiling,
110
0
                    std::clamp(fOffsetX, 0.0, 1.0),
111
0
                    std::clamp(fOffsetY, 0.0, 1.0)))
112
0
        {
113
0
        }
114
115
0
        FillGraphicAttribute::FillGraphicAttribute(const FillGraphicAttribute&) = default;
116
117
0
        FillGraphicAttribute::~FillGraphicAttribute() = default;
118
119
        bool FillGraphicAttribute::isDefault() const
120
0
        {
121
0
            return mpFillGraphicAttribute.same_object(theGlobalDefault());
122
0
        }
123
124
0
        FillGraphicAttribute& FillGraphicAttribute::operator=(const FillGraphicAttribute&) = default;
125
126
        bool FillGraphicAttribute::operator==(const FillGraphicAttribute& rCandidate) const
127
0
        {
128
            // tdf#87509 default attr is always != non-default attr, even with same values
129
0
            if(rCandidate.isDefault() != isDefault())
130
0
                return false;
131
132
0
            return rCandidate.mpFillGraphicAttribute == mpFillGraphicAttribute;
133
0
        }
134
135
        const Graphic& FillGraphicAttribute::getGraphic() const
136
0
        {
137
0
            return mpFillGraphicAttribute->getGraphic();
138
0
        }
139
140
        const basegfx::B2DRange& FillGraphicAttribute::getGraphicRange() const
141
0
        {
142
0
            return mpFillGraphicAttribute->getGraphicRange();
143
0
        }
144
145
        bool FillGraphicAttribute::getTiling() const
146
0
        {
147
0
            return mpFillGraphicAttribute->getTiling();
148
0
        }
149
150
        double FillGraphicAttribute::getOffsetX() const
151
0
        {
152
0
            return mpFillGraphicAttribute->getOffsetX();
153
0
        }
154
155
        double FillGraphicAttribute::getOffsetY() const
156
0
        {
157
0
            return mpFillGraphicAttribute->getOffsetY();
158
0
        }
159
160
} // end of namespace
161
162
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */