diff options
author | Armin Le Grand (Collabora) <Armin.Le.Grand@me.com> | 2024-08-08 14:08:22 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2024-08-08 18:27:16 +0200 |
commit | ebe1543250b9729a6560545e58f50ea68e62be11 (patch) | |
tree | 8a95640098b09a669f3cad9e4404e2ba019b481c /include | |
parent | b1fcc20db80e7b1ba86594b3eef199965057d499 (diff) |
CairoSDPR: Support ColorPolygon with AlphaGradient
Cairo can render RGBA gradients directly and the
CairoSDPR supports that. If we have a PolyPolygon
filled with single color combined with a gradient
alpha the renderer could map RGB to that color
and combine with the real alpha gradient steps.
To support that I added another Primitive called
PolyPolygonAlphaGradientPrimitive2D. It decomposes
as needed (TransparencePrimitive2D if needed), so
no other renderers have to be touched.
The Cairo renderer supports it directly, though,
what makes it much faster.
Change-Id: Ie90c8bd84d6458d12443db815ced55bdea93c15c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171628
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'include')
4 files changed, 94 insertions, 2 deletions
diff --git a/include/drawinglayer/primitive2d/PolyPolygonAlphaGradientPrimitive2D.hxx b/include/drawinglayer/primitive2d/PolyPolygonAlphaGradientPrimitive2D.hxx new file mode 100644 index 000000000000..34f8c4dfb253 --- /dev/null +++ b/include/drawinglayer/primitive2d/PolyPolygonAlphaGradientPrimitive2D.hxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <drawinglayer/drawinglayerdllapi.h> + +#include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/color/bcolor.hxx> +#include <drawinglayer/attribute/fillgradientattribute.hxx> +// #include <basegfx/numeric/ftools.hxx> + +namespace drawinglayer::primitive2d +{ +/** PolyPolygonAlphaGradientPrimitive2D class + + This is a simple extension to PolyPolygonColorPrimitive2D + that allows to directly define an alpha gradient for the PolyPolygon + to be represented, additionally to the color. + + It will be decomposed simply to PolyPolygonColorPrimitive2D, + maybe embedded to a FillGradientPrimitive2D if + needed, so no changes have to be done to any primitive processor. + + OTOH e.g. SDPR implementations *may* use this directly if they + are capable to draw a filled PolyPolygon with transparency gradient + directly (e.g. CairoPixelProcessor2D) + */ +class DRAWINGLAYER_DLLPUBLIC PolyPolygonAlphaGradientPrimitive2D final + : public BufferedDecompositionPrimitive2D +{ +private: + /// the tools::PolyPolygon geometry + basegfx::B2DPolyPolygon maPolyPolygon; + + /// the polygon fill color + basegfx::BColor maBColor; + + /// alphaGradient definition + attribute::FillGradientAttribute maAlphaGradient; + + /// create local decomposition + virtual Primitive2DReference + create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const override; + +public: + /// constructor + PolyPolygonAlphaGradientPrimitive2D(const basegfx::B2DPolyPolygon& rPolyPolygon, + const basegfx::BColor& rBColor, + const attribute::FillGradientAttribute& rAlphaGradient); + + /// data read access + const basegfx::B2DPolyPolygon& getB2DPolyPolygon() const { return maPolyPolygon; } + const basegfx::BColor& getBColor() const { return maBColor; } + const attribute::FillGradientAttribute& getAlphaGradient() const { return maAlphaGradient; } + + /// compare operator + virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; + + /// get B2Drange + virtual basegfx::B2DRange + getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override; + + /// provide unique ID + virtual sal_uInt32 getPrimitive2DID() const override; +}; + +} // end of namespace drawinglayer::primitive2d + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/drawinglayer/primitive2d/PolyPolygonRGBAPrimitive2D.hxx b/include/drawinglayer/primitive2d/PolyPolygonRGBAPrimitive2D.hxx index 74ac76e4e3d1..f5502dee0fef 100644 --- a/include/drawinglayer/primitive2d/PolyPolygonRGBAPrimitive2D.hxx +++ b/include/drawinglayer/primitive2d/PolyPolygonRGBAPrimitive2D.hxx @@ -61,8 +61,8 @@ private: public: /// constructor - PolyPolygonRGBAPrimitive2D(basegfx::B2DPolyPolygon aPolyPolygon, const basegfx::BColor& rBColor, - double fTransparency = 0.0); + PolyPolygonRGBAPrimitive2D(const basegfx::B2DPolyPolygon& rPolyPolygon, + const basegfx::BColor& rBColor, double fTransparency = 0.0); /// data read access const basegfx::B2DPolyPolygon& getB2DPolyPolygon() const { return maPolyPolygon; } diff --git a/include/drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx b/include/drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx index 8f86167dc5f7..015d0befe32f 100644 --- a/include/drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx +++ b/include/drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx @@ -111,6 +111,7 @@ #define PRIMITIVE2D_ID_ANIMATEDGRAPHICPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 77) #define PRIMITIVE2D_ID_POLYPOLYGONRGBAPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 78) #define PRIMITIVE2D_ID_BITMAPALPHAPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 79) +#define PRIMITIVE2D_ID_POLYPOLYGONALPHAGRADIENTPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 80) // When you add a new primitive, please update the drawinglayer::primitive2d::idToString() function // in drawinglayer/source/primitive2d/Tools.cxx. diff --git a/include/drawinglayer/processor2d/cairopixelprocessor2d.hxx b/include/drawinglayer/processor2d/cairopixelprocessor2d.hxx index 21cffda24e7c..76b35d3530a0 100644 --- a/include/drawinglayer/processor2d/cairopixelprocessor2d.hxx +++ b/include/drawinglayer/processor2d/cairopixelprocessor2d.hxx @@ -38,6 +38,7 @@ class FillGradientPrimitive2D; class PolyPolygonRGBAGradientPrimitive2D; class FillGraphicPrimitive2D; class PolyPolygonRGBAPrimitive2D; +class PolyPolygonAlphaGradientPrimitive2D; class BitmapAlphaPrimitive2D; class TextSimplePortionPrimitive2D; } @@ -100,6 +101,9 @@ class UNLESS_MERGELIBS(DRAWINGLAYER_DLLPUBLIC) CairoPixelProcessor2D final : pub const primitive2d::FillGraphicPrimitive2D& rFillGraphicPrimitive2D); void processPolyPolygonRGBAPrimitive2D( const primitive2d::PolyPolygonRGBAPrimitive2D& rPolyPolygonRGBAPrimitive2D); + void processPolyPolygonAlphaGradientPrimitive2D( + const primitive2d::PolyPolygonAlphaGradientPrimitive2D& + rPolyPolygonAlphaGradientPrimitive2D); void paintBitmapAlpha(const BitmapEx& rBitmapEx, const basegfx::B2DHomMatrix& rTransform, double fTransparency = 0.0); void processBitmapAlphaPrimitive2D( |