[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - vcl/headless

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 28 11:26:23 UTC 2020


 vcl/headless/svpgdi.cxx |   64 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 47 insertions(+), 17 deletions(-)

New commits:
commit f1a5db2e54eed04430e9e4ec0967beba5869d044
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Sep 25 10:41:27 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Sep 28 13:25:49 2020 +0200

    headless/cairo drawGradient() fixes
    
    Change-Id: I53913262f8f856bf265ce50fc355244445499089
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103375
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
    (cherry picked from commit 141dfd653f1413cc5fae5a7b9ef356c095f21d3b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103426
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index e196c3b8b2cc..afcb9956c2cf 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -1602,43 +1602,73 @@ bool SvpSalGraphics::drawPolyPolygon(
 
 bool SvpSalGraphics::drawGradient(const tools::PolyPolygon& rPolyPolygon, const Gradient& rGradient)
 {
+    if (rGradient.GetStyle() != GradientStyle::Linear
+        && rGradient.GetStyle() != GradientStyle::Radial)
+        return false; // unsupported
+    if (rGradient.GetSteps() != 0)
+        return false; // We can't tell cairo how many colors to use in the gradient.
+
     cairo_t* cr = getCairoContext(true);
     clipRegion(cr);
 
-    basegfx::B2DPolyPolygon aB2DPolyPolygon(rPolyPolygon.getB2DPolyPolygon());
-
-    for (auto const & rPolygon : aB2DPolyPolygon)
+    tools::Rectangle aInputRect(rPolyPolygon.GetBoundRect());
+    if( rPolyPolygon.IsRect())
     {
+        // Rect->Polygon conversion loses the right and bottom edge, fix that.
+        aInputRect.AdjustRight( 1 );
+        aInputRect.AdjustBottom( 1 );
         basegfx::B2DHomMatrix rObjectToDevice;
-        AddPolygonToPath(cr, rPolygon, rObjectToDevice, !getAntiAliasB2DDraw(), false);
+        AddPolygonToPath(cr, tools::Polygon(aInputRect).getB2DPolygon(), rObjectToDevice, !getAntiAliasB2DDraw(), false);
+    }
+    else
+    {
+        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);
+    Color aStartColor = aGradient.GetStartColor();
+    Color aEndColor = aGradient.GetEndColor();
 
     cairo_pattern_t* pattern;
-    pattern = cairo_pattern_create_linear(aPoly[0].X(), aPoly[0].Y(), aPoly[1].X(), aPoly[1].Y());
+    if (rGradient.GetStyle() == GradientStyle::Linear)
+    {
+        tools::Polygon aPoly(aBoundRect);
+        aPoly.Rotate(aCenter, aGradient.GetAngle() % 3600);
+        pattern = cairo_pattern_create_linear(aPoly[0].X(), aPoly[0].Y(), aPoly[1].X(), aPoly[1].Y());
+    }
+    else
+    {
+        double radius = std::max(aBoundRect.GetWidth() / 2.0, aBoundRect.GetHeight() / 2.0);
+        // Move the center a bit to the top-left (the default VCL algorithm is a bit off-center that way,
+        // cairo is the opposite way).
+        pattern = cairo_pattern_create_radial(aCenter.X() - 0.5, aCenter.Y() - 0.5, 0,
+            aCenter.X() - 0.5, aCenter.Y() - 0.5, radius);
+        std::swap( aStartColor, aEndColor );
+    }
 
     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);
+        aStartColor.GetRed() * aGradient.GetStartIntensity()   / 25500.0,
+        aStartColor.GetGreen() * aGradient.GetStartIntensity() / 25500.0,
+        aStartColor.GetBlue() * aGradient.GetStartIntensity()  / 25500.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);
+        aEndColor.GetRed() * aGradient.GetEndIntensity()   / 25500.0,
+        aEndColor.GetGreen() * aGradient.GetEndIntensity() / 25500.0,
+        aEndColor.GetBlue() * aGradient.GetEndIntensity()  / 25500.0,
+        1.0);
+
     cairo_set_source(cr, pattern);
 
     basegfx::B2DRange extents = getClippedFillDamage(cr);


More information about the Libreoffice-commits mailing list