From 0d2d60cf8a93b0599220fb44355d2965c3698852 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 1 Dec 2010 20:25:52 +0100 Subject: [PATCH] Gtk9Slice: Fix stretch rendering. "Nearest" filter used when scaling the image, so image borders aren't blurred. --- gtk/gtk9slice.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/gtk/gtk9slice.c b/gtk/gtk9slice.c index 62008998e1..c3e824b4d5 100644 --- a/gtk/gtk9slice.c +++ b/gtk/gtk9slice.c @@ -192,6 +192,7 @@ render_border (cairo_t *cr, gdouble height, GtkSliceSideModifier modifier) { + cairo_pattern_t *pattern; cairo_matrix_t matrix; cairo_save (cr); @@ -199,47 +200,47 @@ render_border (cairo_t *cr, cairo_rectangle (cr, x, y, width, height); cairo_clip (cr); + pattern = cairo_pattern_create_for_surface (surface); + if (modifier == GTK_SLICE_REPEAT) { - cairo_pattern_t *pattern; - - pattern = cairo_pattern_create_for_surface (surface); - cairo_matrix_init_translate (&matrix, - x, - y); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); } else { - gint d; + /* Use nearest filter so borders aren't blurred */ + cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); if (side == SIDE_TOP || side == SIDE_BOTTOM) { - d = cairo_image_surface_get_width (surface); + gint w = cairo_image_surface_get_width (surface); cairo_translate (cr, x, y); - cairo_scale (cr, width / d, 1.0); - cairo_set_source_surface (cr, surface, 0.0, 0.0); - cairo_paint (cr); + cairo_scale (cr, width / w, 1.0); } else { - d = cairo_image_surface_get_height (surface); + gint h = cairo_image_surface_get_height (surface); cairo_translate (cr, x, y); - cairo_scale (cr, 1.0, height / d); - cairo_set_source_surface (cr, surface, 0.0, 0.0); - cairo_paint (cr); + cairo_scale (cr, 1.0, height / h); } + + cairo_set_source (cr, pattern); + cairo_rectangle (cr, x, y, width, height); + cairo_paint (cr); } cairo_restore (cr); + + cairo_pattern_destroy (pattern); } static void