[gtk+/wip/pango-shadow-cache] cssshadowvalue: Convert the current point into a translate



commit b152ca26a203ce88d3a686baa861a927d03d207f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Sep 3 09:32:45 2014 -0700

    cssshadowvalue: Convert the current point into a translate
    
    Pango uses the current point to determine where to paint the text, which
    is considerably inconvenient since it doesn't work well with
    translations.
    
    To make this simpler for us, turn the current point into a translation,
    which lets us merge the three different pieces of context setup into
    just one.

 gtk/gtkcssshadowvalue.c |   42 ++++++++++++++++--------------------------
 1 files changed, 16 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 89035cf..154d903 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -348,14 +348,7 @@ gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
   cairo_surface_set_device_offset (surface, clip_radius - clip_rect.x, clip_radius - clip_rect.y);
   blur_cr = cairo_create (surface);
   cairo_set_user_data (blur_cr, &original_cr_key, cairo_reference (cr), (cairo_destroy_func_t) 
cairo_destroy);
-
-  if (cairo_has_current_point (cr))
-    {
-      double x, y;
-
-      cairo_get_current_point (cr, &x, &y);
-      cairo_move_to (blur_cr, x, y);
-    }
+  cairo_new_sub_path (blur_cr);
 
   return blur_cr;
 }
@@ -421,29 +414,32 @@ _gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
                                     cairo_t           *cr,
                                     PangoLayout       *layout)
 {
+  double x, y;
+
   g_return_if_fail (shadow->class == &GTK_CSS_VALUE_SHADOW);
 
   cairo_save (cr);
 
+  cairo_get_current_point (cr, &x, &y);
+  cairo_translate (cr, x, y);
+  cairo_new_sub_path (cr);
+
+  cairo_translate (cr,
+                   _gtk_css_number_value_get (shadow->hoffset, 0),
+                   _gtk_css_number_value_get (shadow->voffset, 0));
+  gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
+
   if (needs_blur (shadow))
     {
       cairo_surface_t *cached_surface = get_cached_surface (layout, shadow);
       if (cached_surface)
         {
-          cairo_translate (cr,
-                           _gtk_css_number_value_get (shadow->hoffset, 0),
-                           _gtk_css_number_value_get (shadow->voffset, 0));
-          gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
           cairo_mask_surface (cr, cached_surface, 0, 0);
         }
       else
         {
           guint radius, serial;
 
-          cairo_rel_move_to (cr,
-                             _gtk_css_number_value_get (shadow->hoffset, 0),
-                             _gtk_css_number_value_get (shadow->voffset, 0));
-          gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
           cr = gtk_css_shadow_value_start_drawing (shadow, cr);
           _gtk_pango_fill_layout (cr, layout);
           cached_surface = cairo_get_target (cr);
@@ -451,9 +447,6 @@ _gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
                                    cairo_surface_reference (cached_surface),
                                    (GDestroyNotify) cairo_surface_destroy);
           cr = gtk_css_shadow_value_finish_drawing (shadow, cr);
-          cairo_rel_move_to (cr,
-                             - _gtk_css_number_value_get (shadow->hoffset, 0),
-                             - _gtk_css_number_value_get (shadow->voffset, 0));
 
           radius = _gtk_css_number_value_get (shadow->radius, 0);
           cairo_surface_set_user_data (cached_surface, &radius_key, GUINT_TO_POINTER (radius), NULL);
@@ -464,17 +457,14 @@ _gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
     }
   else
     {
-      cairo_rel_move_to (cr,
-                         _gtk_css_number_value_get (shadow->hoffset, 0),
-                         _gtk_css_number_value_get (shadow->voffset, 0));
-      gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
       _gtk_pango_fill_layout (cr, layout);
-      cairo_rel_move_to (cr,
-                         - _gtk_css_number_value_get (shadow->hoffset, 0),
-                         - _gtk_css_number_value_get (shadow->voffset, 0));
     }
 
   cairo_restore (cr);
+
+  /* Put the current point back where it was. */
+  cairo_new_sub_path (cr);
+  cairo_move_to (cr, x, y);
 }
 
 void


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