diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-09-22 15:20:57 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-09-25 19:35:35 +0200 |
commit | 20c09d351ee060bdde13d92d2bf86dd998cdb0cb (patch) | |
tree | 20be340a0da3f306fbd1312fcc431f93f21d35c6 /vcl/headless | |
parent | f3ca55e78799934c19ae66a822397d98b7997fa9 (diff) |
use vcl lin. gradient drawing in drawinglayer + cairo impl.
This adds a divert for drawing of linear gradients drawing, which
can be implemented natively with a much higher quality and speed.
This also adds a implementation of drawing linear gradients with
cairo.
Change-Id: I8c39915c3579e6eb88cdce8ae4ac9694ffdb4957
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103374
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/headless')
-rw-r--r-- | vcl/headless/svpgdi.cxx | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index 458ac9cb565a..e769474c3dd5 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -1910,6 +1910,55 @@ bool SvpSalGraphics::drawPolyPolygon( return true; } +bool SvpSalGraphics::drawGradient(const tools::PolyPolygon& rPolyPolygon, const Gradient& rGradient) +{ + cairo_t* cr = getCairoContext(true); + clipRegion(cr); + + basegfx::B2DPolyPolygon aB2DPolyPolygon(rPolyPolygon.getB2DPolyPolygon()); + + for (auto const & rPolygon : aB2DPolyPolygon) + { + basegfx::B2DHomMatrix rObjectToDevice; + AddPolygonToPath(cr, rPolygon, rObjectToDevice, !getAntiAliasB2DDraw(), false); + } + + Gradient aGradient(rGradient); + + tools::Rectangle aInputRect(rPolyPolygon.GetBoundRect()); + tools::Rectangle aBoundRect; + Point aCenter; + + aGradient.SetAngle(aGradient.GetAngle() + 2700); + aGradient.GetBoundRect(aInputRect, aBoundRect, aCenter); + + tools::Polygon aPoly(aBoundRect); + aPoly.Rotate(aCenter, aGradient.GetAngle() % 3600); + + cairo_pattern_t* pattern; + pattern = cairo_pattern_create_linear(aPoly[0].X(), aPoly[0].Y(), aPoly[1].X(), aPoly[1].Y()); + + cairo_pattern_add_color_stop_rgba(pattern, aGradient.GetBorder() / 100.0, + aGradient.GetStartColor().GetRed() / 255.0, + aGradient.GetStartColor().GetGreen() / 255.0, + aGradient.GetStartColor().GetBlue() / 255.0, + 1.0); + + cairo_pattern_add_color_stop_rgba(pattern, 1.0, + aGradient.GetEndColor().GetRed() / 255.0, + aGradient.GetEndColor().GetGreen() / 255.0, + aGradient.GetEndColor().GetBlue() / 255.0, + 1.0); + cairo_set_source(cr, pattern); + + basegfx::B2DRange extents = getClippedFillDamage(cr); + cairo_fill_preserve(cr); + + releaseCairoContext(cr, true, extents); + + return true; +} + bool SvpSalGraphics::implDrawGradient(basegfx::B2DPolyPolygon const & rPolyPolygon, SalGradient const & rGradient) { cairo_t* cr = getCairoContext(true); |