1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawinglayer/primitive2d/PolyPolygonGradientPrimitive2D.hxx>
22 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
23 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
24 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
25 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
26 #include <basegfx/polygon/b2dpolypolygontools.hxx>
27 #include <rtl/ref.hxx>
30 using namespace com::sun::star
;
32 namespace drawinglayer::primitive2d
34 Primitive2DReference
PolyPolygonGradientPrimitive2D::create2DDecomposition(
35 const geometry::ViewInformation2D
& /*rViewInformation*/) const
37 if (!getFillGradient().isDefault())
39 // create SubSequence with FillGradientPrimitive2D
40 const basegfx::B2DRange
aPolyPolygonRange(getB2DPolyPolygon().getB2DRange());
41 rtl::Reference
<FillGradientPrimitive2D
> pNewGradient
= new FillGradientPrimitive2D(
42 aPolyPolygonRange
, getDefinitionRange(), getFillGradient(),
43 hasAlphaGradient() ? &getAlphaGradient() : nullptr, getTransparency());
44 Primitive2DContainer aSubSequence
{ pNewGradient
};
46 // create mask primitive
47 return new MaskPrimitive2D(getB2DPolyPolygon(), std::move(aSubSequence
));
52 PolyPolygonGradientPrimitive2D::PolyPolygonGradientPrimitive2D(
53 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
54 const attribute::FillGradientAttribute
& rFillGradient
)
55 : maPolyPolygon(rPolyPolygon
)
56 , maDefinitionRange(rPolyPolygon
.getB2DRange())
57 , maFillGradient(rFillGradient
)
63 PolyPolygonGradientPrimitive2D::PolyPolygonGradientPrimitive2D(
64 basegfx::B2DPolyPolygon aPolyPolygon
, const basegfx::B2DRange
& rDefinitionRange
,
65 const attribute::FillGradientAttribute
& rFillGradient
,
66 const attribute::FillGradientAttribute
* pAlphaGradient
, double fTransparency
)
67 : maPolyPolygon(std::move(aPolyPolygon
))
68 , maDefinitionRange(rDefinitionRange
)
69 , maFillGradient(rFillGradient
)
71 , mfTransparency(fTransparency
)
73 // copy alpha gradient if we got one
74 if (nullptr != pAlphaGradient
)
75 maAlphaGradient
= *pAlphaGradient
;
78 bool PolyPolygonGradientPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
80 if (!(BufferedDecompositionPrimitive2D::operator==(rPrimitive
)))
83 const PolyPolygonGradientPrimitive2D
& rCompare(
84 static_cast<const PolyPolygonGradientPrimitive2D
&>(rPrimitive
));
86 if (getB2DPolyPolygon() != rCompare
.getB2DPolyPolygon())
89 if (getDefinitionRange() != rCompare
.getDefinitionRange())
92 if (getFillGradient() != rCompare
.getFillGradient())
95 if (maAlphaGradient
!= rCompare
.maAlphaGradient
)
98 if (!basegfx::fTools::equal(getTransparency(), rCompare
.getTransparency()))
105 sal_uInt32
PolyPolygonGradientPrimitive2D::getPrimitive2DID() const
107 return PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D
;
109 } // end drawinglayer::primitive2d namespace
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */