[gtk+/wip/css-blur: 2/5] Add blur to text-shadow



commit 98d71d5371b456782c45845d68a4e35a97f89dcf
Author: Andrea Cimitan <andrea cimitan canonical com>
Date:   Fri Apr 13 21:28:19 2012 +0200

    Add blur to text-shadow

 gtk/gtkshadow.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkshadow.c b/gtk/gtkshadow.c
index 4216864..52804af 100644
--- a/gtk/gtkshadow.c
+++ b/gtk/gtkshadow.c
@@ -21,6 +21,7 @@
 
 #include "gtkshadowprivate.h"
 
+#include "gtkcairoblur.h"
 #include "gtkstylecontextprivate.h"
 #include "gtkthemingengineprivate.h"
 #include "gtkpango.h"
@@ -267,8 +268,51 @@ _gtk_text_shadow_paint_layout (GtkShadow       *shadow,
       cairo_save (cr);
 
       cairo_rel_move_to (cr, element->hoffset, element->voffset);
-      gdk_cairo_set_source_rgba (cr, &element->color);
-      _gtk_pango_fill_layout (cr, layout);
+
+      if (element->radius > 0)
+        {
+          PangoRectangle ink_rect;
+          cairo_t *cr_surface;
+          cairo_surface_t *surface;
+          gint bradius, padding;
+          gdouble x, y;
+
+          bradius = element->radius;
+          padding = 1; /* Padding seems to help on blur edges, please verify. */
+          pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
+
+          cairo_get_current_point (cr, &x, &y);
+
+          surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                                ink_rect.width + bradius * 2 + padding * 2,
+                                                ink_rect.height + bradius * 2 + padding * 2);
+          cr_surface = cairo_create (surface); 
+
+          cairo_translate (cr_surface,
+                           - ink_rect.x + bradius + padding,
+                           - ink_rect.y + bradius + padding);
+
+          /* Create the path on the surface to blur. */
+          gdk_cairo_set_source_rgba (cr_surface, &element->color);
+          _gtk_pango_fill_layout (cr_surface, layout);
+
+          /* Blur the surface. */
+          _gtk_cairo_blur_surface (surface, bradius);
+
+          /* Paint the blurred surface to cr. */
+          cairo_set_source_surface (cr, surface,
+                                    x + ink_rect.x - bradius - padding,
+                                    y + ink_rect.y - bradius - padding); 
+          cairo_paint (cr);
+
+          cairo_destroy (cr_surface);
+          cairo_surface_destroy (surface); 
+        }
+      else
+        {
+          gdk_cairo_set_source_rgba (cr, &element->color);
+          _gtk_pango_fill_layout (cr, layout);
+        }
 
       cairo_rel_move_to (cr, -element->hoffset, -element->voffset);
       cairo_restore (cr);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]