Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/drawinglayer/primitive2d/fillgradientprimitive2d.hxx
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
#pragma once
21
22
#include <drawinglayer/drawinglayerdllapi.h>
23
24
#include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx>
25
#include <drawinglayer/attribute/fillgradientattribute.hxx>
26
27
28
// predefines
29
30
namespace basegfx { class B2DPolygon; }
31
32
33
// FillGradientPrimitive2D class
34
35
namespace drawinglayer::primitive2d
36
{
37
        /** FillGradientPrimitive2D class
38
39
            This class defines a gradient filling for a rectangular area. The
40
            Range is defined by the Transformation, the gradient by the FillGradientAttribute.
41
42
            The decomposition will deliver the decomposed gradient, e.g. for an ellipse
43
            gradient the various ellipses in various color steps will be created.
44
45
            I have added functionality to create both versions of filled decompositions:
46
            Those who overlap and non-overlapping ones. The overlapping version is the
47
            default one since it works with and without AntiAliasing. The non-overlapping
48
            version is used in the MetafilePrimitive2D decomposition when the old XOR
49
            paint was recorded.
50
51
            SDPR: Have now added to directly support alpha in the definition so that
52
            all implementations of primitive renderers may use it. Be aware that if a
53
            renderer does not support using that alpha it is advised to use the
54
            decomposition which separates content and alpha in a TransparencePrimitive2D.
55
            That way all stuff being used to that before will work unchanged.
56
         */
57
        class DRAWINGLAYER_DLLPUBLIC FillGradientPrimitive2D : public BufferedDecompositionPrimitive2D
58
        {
59
        private:
60
            /// the geometrically visible area
61
            basegfx::B2DRange                       maOutputRange;
62
63
            /// the area the gradient definition is based on
64
            /// in the simplest case identical to OutputRange
65
            basegfx::B2DRange                       maDefinitionRange;
66
67
            /// the gradient definition
68
            attribute::FillGradientAttribute        maFillGradient;
69
70
            /// evtl. fitting alphaGradient definition
71
            attribute::FillGradientAttribute        maAlphaGradient;
72
73
            /// the transparency in range [0.0 .. 1.0]
74
            double mfTransparency;
75
76
        protected:
77
            /// local helper
78
            Primitive2DReference createFill(bool bOverlapping) const;
79
80
            /// local decomposition.
81
            virtual Primitive2DReference create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const override;
82
83
        public:
84
            /// helpers that support e.g. direct paint/geometry creation
85
            basegfx::B2DPolygon getUnitPolygon() const;
86
            basegfx::BColor getOuterColor() const;
87
            void generateMatricesAndColors(
88
                std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) const;
89
90
            /// constructors. The one without definition range will use output range as definition range
91
            FillGradientPrimitive2D(
92
                const basegfx::B2DRange& rOutputRange,
93
                const attribute::FillGradientAttribute& rFillGradient);
94
            FillGradientPrimitive2D(
95
                const basegfx::B2DRange& rOutputRange,
96
                const basegfx::B2DRange& rDefinitionRange,
97
                const attribute::FillGradientAttribute& rFillGradient,
98
                const attribute::FillGradientAttribute* pAlphaGradient = nullptr,
99
                double fTransparency = 0.0);
100
101
            /// data read access
102
0
            const basegfx::B2DRange& getOutputRange() const { return maOutputRange; }
103
0
            const basegfx::B2DRange& getDefinitionRange() const { return maDefinitionRange; }
104
0
            const attribute::FillGradientAttribute& getFillGradient() const { return maFillGradient; }
105
106
0
            const attribute::FillGradientAttribute& getAlphaGradient() const { return maAlphaGradient; }
107
0
            bool hasAlphaGradient() const { return !maAlphaGradient.isDefault(); }
108
109
0
            double getTransparency() const { return mfTransparency; }
110
0
            bool hasTransparency() const { return !basegfx::fTools::equalZero(mfTransparency); }
111
112
            /// compare operator
113
            virtual bool operator==(const BasePrimitive2D& rPrimitive) const override final;
114
115
            /// get range
116
            virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override final;
117
118
            /// provide unique ID
119
            virtual sal_uInt32 getPrimitive2DID() const override final;
120
        };
121
} // end of namespace drawinglayer::primitive2d
122
123
124
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */