Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/inc/texture/texture.hxx
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
#pragma once
21
22
#include <basegfx/matrix/b2dhommatrix.hxx>
23
#include <basegfx/range/b2drange.hxx>
24
#include <basegfx/color/bcolor.hxx>
25
#include <basegfx/utils/gradienttools.hxx>
26
#include <vector>
27
#include <functional>
28
29
namespace drawinglayer::texture
30
{
31
        class GeoTexSvx
32
        {
33
        public:
34
            GeoTexSvx();
35
            virtual ~GeoTexSvx();
36
37
            // compare operator
38
            virtual bool operator==(const GeoTexSvx& rGeoTexSvx) const;
39
0
            bool operator!=(const GeoTexSvx& rGeoTexSvx) const { return !operator==(rGeoTexSvx); }
40
41
            // virtual base methods
42
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const;
43
            virtual void modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const;
44
        };
45
46
        class GeoTexSvxGradient : public GeoTexSvx
47
        {
48
        protected:
49
            basegfx::ODFGradientInfo            maGradientInfo;
50
            basegfx::B2DRange                   maDefinitionRange;
51
            sal_uInt32                          mnRequestedSteps;
52
            basegfx::BColorStops                mnColorStops;
53
            double                              mfBorder;
54
55
            // provide a single buffer entry used for gradient texture
56
            // mapping, see ::modifyBColor implementations
57
            mutable basegfx::BColorStops::BColorStopRange     maLastColorStopRange;
58
59
        public:
60
            GeoTexSvxGradient(
61
                const basegfx::B2DRange& rDefinitionRange,
62
                sal_uInt32 nRequestedSteps,
63
                const basegfx::BColorStops& rColorStops,
64
                double fBorder);
65
            virtual ~GeoTexSvxGradient() override;
66
67
            // compare operator
68
            virtual bool operator==(const GeoTexSvx& rGeoTexSvx) const override;
69
70
            // virtual base methods
71
            virtual void appendTransformationsAndColors(
72
                const std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)>& rCallback) = 0;
73
        };
74
75
        class GeoTexSvxGradientLinear final : public GeoTexSvxGradient
76
        {
77
            double                  mfUnitMinX;
78
            double                  mfUnitWidth;
79
            double                  mfUnitMaxY;
80
81
        public:
82
            GeoTexSvxGradientLinear(
83
                const basegfx::B2DRange& rDefinitionRange,
84
                const basegfx::B2DRange& rOutputRange,
85
                sal_uInt32 nRequestedSteps,
86
                const basegfx::BColorStops& rColorStops,
87
                double fBorder,
88
                double fAngle);
89
            virtual ~GeoTexSvxGradientLinear() override;
90
91
            virtual void appendTransformationsAndColors(
92
                const std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)>& rCallback) override;
93
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
94
        };
95
96
        class GeoTexSvxGradientAxial final : public GeoTexSvxGradient
97
        {
98
            double                  mfUnitMinX;
99
            double                  mfUnitWidth;
100
101
        public:
102
            GeoTexSvxGradientAxial(
103
                const basegfx::B2DRange& rDefinitionRange,
104
                const basegfx::B2DRange& rOutputRange,
105
                sal_uInt32 nRequestedSteps,
106
                const basegfx::BColorStops& rColorStops,
107
                double fBorder,
108
                double fAngle);
109
            virtual ~GeoTexSvxGradientAxial() override;
110
111
            virtual void appendTransformationsAndColors(
112
                const std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)>& rCallback) override;
113
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
114
        };
115
116
        class GeoTexSvxGradientRadial final : public GeoTexSvxGradient
117
        {
118
        public:
119
            GeoTexSvxGradientRadial(
120
                const basegfx::B2DRange& rDefinitionRange,
121
                sal_uInt32 nRequestedSteps,
122
                const basegfx::BColorStops& rColorStops,
123
                double fBorder,
124
                double fOffsetX,
125
                double fOffsetY);
126
            virtual ~GeoTexSvxGradientRadial() override;
127
128
            virtual void appendTransformationsAndColors(
129
                const std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)>& rCallback) override;
130
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
131
        };
132
133
        class GeoTexSvxGradientElliptical final : public GeoTexSvxGradient
134
        {
135
        public:
136
            GeoTexSvxGradientElliptical(
137
                const basegfx::B2DRange& rDefinitionRange,
138
                sal_uInt32 nRequestedSteps,
139
                const basegfx::BColorStops& rColorStops,
140
                double fBorder,
141
                double fOffsetX,
142
                double fOffsetY,
143
                double fAngle);
144
            virtual ~GeoTexSvxGradientElliptical() override;
145
146
            virtual void appendTransformationsAndColors(
147
                const std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)>& rCallback) override;
148
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
149
        };
150
151
        class GeoTexSvxGradientSquare final : public GeoTexSvxGradient
152
        {
153
        public:
154
            GeoTexSvxGradientSquare(
155
                const basegfx::B2DRange& rDefinitionRange,
156
                sal_uInt32 nRequestedSteps,
157
                const basegfx::BColorStops& rColorStops,
158
                double fBorder,
159
                double fOffsetX,
160
                double fOffsetY,
161
                double fAngle);
162
            virtual ~GeoTexSvxGradientSquare() override;
163
164
            virtual void appendTransformationsAndColors(
165
                const std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)>& rCallback) override;
166
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
167
        };
168
169
        class GeoTexSvxGradientRect final : public GeoTexSvxGradient
170
        {
171
        public:
172
            GeoTexSvxGradientRect(
173
                const basegfx::B2DRange& rDefinitionRange,
174
                sal_uInt32 nRequestedSteps,
175
                const basegfx::BColorStops& rColorStops,
176
                double fBorder,
177
                double fOffsetX,
178
                double fOffsetY,
179
                double fAngle);
180
            virtual ~GeoTexSvxGradientRect() override;
181
182
            virtual void appendTransformationsAndColors(
183
                const std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)>& rCallback) override;
184
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
185
        };
186
187
        class GeoTexSvxHatch final : public GeoTexSvx
188
        {
189
            basegfx::B2DRange                   maOutputRange;
190
            basegfx::B2DHomMatrix               maTextureTransform;
191
            basegfx::B2DHomMatrix               maBackTextureTransform;
192
            double                              mfDistance;
193
            double                              mfAngle;
194
            sal_uInt32                          mnSteps;
195
196
            bool                                mbDefinitionRangeEqualsOutputRange : 1;
197
198
        public:
199
            GeoTexSvxHatch(
200
                const basegfx::B2DRange& rDefinitionRange,
201
                const basegfx::B2DRange& rOutputRange,
202
                double fDistance,
203
                double fAngle);
204
            virtual ~GeoTexSvxHatch() override;
205
206
            // compare operator
207
            virtual bool operator==(const GeoTexSvx& rGeoTexSvx) const override;
208
209
            void appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices);
210
            double getDistanceToHatch(const basegfx::B2DPoint& rUV) const;
211
            const basegfx::B2DHomMatrix& getBackTextureTransform() const;
212
        };
213
214
        // This class applies a tiling to the unit range. The given range
215
        // will be repeated inside the unit range in X and Y and for each
216
        // tile a matrix will be created (by appendTransformations) that
217
        // represents the needed transformation to map a filling in unit
218
        // coordinates to that tile.
219
        // When offsetX is given, every 2nd line will be offsetted by the
220
        // given percentage value (offsetX has to be 0.0 <= offsetX <= 1.0).
221
        // Accordingly to offsetY. If both are given, offsetX is preferred
222
        // and offsetY is ignored.
223
        class GeoTexSvxTiled final : public GeoTexSvx
224
        {
225
            basegfx::B2DRange               maRange;
226
            double                          mfOffsetX;
227
            double                          mfOffsetY;
228
229
        public:
230
            GeoTexSvxTiled(
231
                const basegfx::B2DRange& rRange,
232
                double fOffsetX = 0.0,
233
                double fOffsetY = 0.0);
234
            virtual ~GeoTexSvxTiled() override;
235
236
            // compare operator
237
            virtual bool operator==(const GeoTexSvx& rGeoTexSvx) const override;
238
239
            // Iterate over created tiles with callback provided.
240
            void iterateTiles(std::function<void(double fPosX, double fPosY)> aFunc) const;
241
242
            void appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices) const;
243
            sal_uInt32 getNumberOfTiles() const;
244
        };
245
} // end of namespace drawinglayer::texture
246
247
248
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */