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/baseprimitive2d.hxx> 25 #include <drawinglayer/attribute/fillgradientattribute.hxx> 26 27 28 // predefines 29 30 namespace basegfx { class B2DPolygon; } 31 namespace drawinglayer::texture { struct B2DHomMatrixAndBColor; } 32 33 34 // FillGradientPrimitive2D class 35 36 namespace drawinglayer::primitive2d 37 { 38 /** FillGradientPrimitive2D class 39 40 This class defines a gradient filling for a rectangular area. The 41 Range is defined by the Transformation, the gradient by the FillGradientAttribute. 42 43 The decomposition will deliver the decomposed gradient, e.g. for an ellipse 44 gradient the various ellipses in various color steps will be created. 45 46 I have added functionality to create both versions of filled decompositions: 47 Those who overlap and non-overlapping ones. The overlapping version is the 48 default one since it works with and without AntiAliasing. The non-overlapping 49 version is used in the MetafilePrimitive2D decomposition when the old XOR 50 paint was recorded. 51 */ 52 class DRAWINGLAYER_DLLPUBLIC FillGradientPrimitive2D : public BufferedDecompositionPrimitive2D 53 { 54 private: 55 /// the geometrically visible area 56 basegfx::B2DRange maOutputRange; 57 58 /// the area the gradient definition is based on 59 /// in the simplest case identical to OutputRange 60 basegfx::B2DRange maDefinitionRange; 61 62 /// the gradient definition 63 attribute::FillGradientAttribute maFillGradient; 64 65 /// local helpers 66 void generateMatricesAndColors( 67 std::vector< drawinglayer::texture::B2DHomMatrixAndBColor >& rEntries, 68 basegfx::BColor& rOuterColor) const; 69 void createOverlappingFill( 70 Primitive2DContainer& rContainer, 71 const std::vector< drawinglayer::texture::B2DHomMatrixAndBColor >& rEntries, 72 const basegfx::BColor& rOuterColor, 73 const basegfx::B2DPolygon& rUnitPolygon) const; 74 void createNonOverlappingFill( 75 Primitive2DContainer& rContainer, 76 const std::vector< drawinglayer::texture::B2DHomMatrixAndBColor >& rEntries, 77 const basegfx::BColor& rOuterColor, 78 const basegfx::B2DPolygon& rUnitPolygon) const; 79 80 protected: 81 /// local helper 82 void createFill(Primitive2DContainer& rContainer, bool bOverlapping) const; 83 84 /// local decomposition. 85 virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const override; 86 87 public: 88 /// constructors. The one without definition range will use output range as definition range 89 FillGradientPrimitive2D( 90 const basegfx::B2DRange& rOutputRange, 91 const attribute::FillGradientAttribute& rFillGradient); 92 FillGradientPrimitive2D( 93 const basegfx::B2DRange& rOutputRange, 94 const basegfx::B2DRange& rDefinitionRange, 95 const attribute::FillGradientAttribute& rFillGradient); 96 97 /// data read access getOutputRange() const98 const basegfx::B2DRange& getOutputRange() const { return maOutputRange; } getDefinitionRange() const99 const basegfx::B2DRange& getDefinitionRange() const { return maDefinitionRange; } getFillGradient() const100 const attribute::FillGradientAttribute& getFillGradient() const { return maFillGradient; } 101 102 /// compare operator 103 virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; 104 105 /// get range 106 virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override; 107 108 /// provide unique ID 109 virtual sal_uInt32 getPrimitive2DID() const override; 110 }; 111 } // end of namespace drawinglayer::primitive2d 112 113 114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 115