Coverage Report

Created: 2026-08-14 10:22

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