/src/libreoffice/drawinglayer/source/primitive2d/PolyPolygonGradientPrimitive2D.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 <drawinglayer/primitive2d/PolyPolygonGradientPrimitive2D.hxx> |
21 | | |
22 | | #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> |
23 | | #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx> |
24 | | #include <drawinglayer/primitive2d/maskprimitive2d.hxx> |
25 | | #include <rtl/ref.hxx> |
26 | | #include <utility> |
27 | | |
28 | | using namespace com::sun::star; |
29 | | |
30 | | namespace drawinglayer::primitive2d |
31 | | { |
32 | | Primitive2DReference PolyPolygonGradientPrimitive2D::create2DDecomposition( |
33 | | const geometry::ViewInformation2D& /*rViewInformation*/) const |
34 | 0 | { |
35 | 0 | if (!getFillGradient().isDefault()) |
36 | 0 | { |
37 | | // create SubSequence with FillGradientPrimitive2D |
38 | 0 | const basegfx::B2DRange aPolyPolygonRange(getB2DPolyPolygon().getB2DRange()); |
39 | 0 | rtl::Reference<FillGradientPrimitive2D> pNewGradient = new FillGradientPrimitive2D( |
40 | 0 | aPolyPolygonRange, getDefinitionRange(), getFillGradient(), |
41 | 0 | hasAlphaGradient() ? &getAlphaGradient() : nullptr, getTransparency()); |
42 | 0 | Primitive2DContainer aSubSequence{ pNewGradient }; |
43 | | |
44 | | // create mask primitive |
45 | 0 | return new MaskPrimitive2D(getB2DPolyPolygon(), std::move(aSubSequence)); |
46 | 0 | } |
47 | 0 | return nullptr; |
48 | 0 | } |
49 | | |
50 | | PolyPolygonGradientPrimitive2D::PolyPolygonGradientPrimitive2D( |
51 | | const basegfx::B2DPolyPolygon& rPolyPolygon, |
52 | | const attribute::FillGradientAttribute& rFillGradient) |
53 | 0 | : maPolyPolygon(rPolyPolygon) |
54 | 0 | , maDefinitionRange(rPolyPolygon.getB2DRange()) |
55 | 0 | , maFillGradient(rFillGradient) |
56 | 0 | , maAlphaGradient() |
57 | 0 | , mfTransparency(0.0) |
58 | 0 | { |
59 | 0 | } |
60 | | |
61 | | PolyPolygonGradientPrimitive2D::PolyPolygonGradientPrimitive2D( |
62 | | basegfx::B2DPolyPolygon aPolyPolygon, const basegfx::B2DRange& rDefinitionRange, |
63 | | const attribute::FillGradientAttribute& rFillGradient, |
64 | | const attribute::FillGradientAttribute* pAlphaGradient, double fTransparency) |
65 | 0 | : maPolyPolygon(std::move(aPolyPolygon)) |
66 | 0 | , maDefinitionRange(rDefinitionRange) |
67 | 0 | , maFillGradient(rFillGradient) |
68 | 0 | , maAlphaGradient() |
69 | 0 | , mfTransparency(fTransparency) |
70 | 0 | { |
71 | | // copy alpha gradient if we got one |
72 | 0 | if (nullptr != pAlphaGradient) |
73 | 0 | maAlphaGradient = *pAlphaGradient; |
74 | 0 | } |
75 | | |
76 | | bool PolyPolygonGradientPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const |
77 | 0 | { |
78 | 0 | if (!(BufferedDecompositionPrimitive2D::operator==(rPrimitive))) |
79 | 0 | return false; |
80 | | |
81 | 0 | const PolyPolygonGradientPrimitive2D& rCompare( |
82 | 0 | static_cast<const PolyPolygonGradientPrimitive2D&>(rPrimitive)); |
83 | |
|
84 | 0 | if (getB2DPolyPolygon() != rCompare.getB2DPolyPolygon()) |
85 | 0 | return false; |
86 | | |
87 | 0 | if (getDefinitionRange() != rCompare.getDefinitionRange()) |
88 | 0 | return false; |
89 | | |
90 | 0 | if (getFillGradient() != rCompare.getFillGradient()) |
91 | 0 | return false; |
92 | | |
93 | 0 | if (maAlphaGradient != rCompare.maAlphaGradient) |
94 | 0 | return false; |
95 | | |
96 | 0 | if (!basegfx::fTools::equal(getTransparency(), rCompare.getTransparency())) |
97 | 0 | return false; |
98 | | |
99 | 0 | return true; |
100 | 0 | } |
101 | | |
102 | | // provide unique ID |
103 | | sal_uInt32 PolyPolygonGradientPrimitive2D::getPrimitive2DID() const |
104 | 0 | { |
105 | 0 | return PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D; |
106 | 0 | } |
107 | | } // end drawinglayer::primitive2d namespace |
108 | | |
109 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |