gnome-disk-utility/gnome-disk-utility-3.16.2-fix-benchmark-dialog-font-rendering.patch

139 lines
4.5 KiB
Diff

From e7fa99bbd9ab3d854e11cfa43813c84f37a0c597 Mon Sep 17 00:00:00 2001
From: David King <dking@redhat.com>
Date: Tue, 2 Jun 2015 11:03:31 +0100
Subject: [PATCH] Fix font rendering in benchmark dialog
Use Pango to render text around the benchmark graph, rather than the toy
Cairo text API.
https://bugzilla.gnome.org/show_bug.cgi?id=656864
---
src/disks/gdubenchmarkdialog.c | 61 +++++++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 22 deletions(-)
diff --git a/src/disks/gdubenchmarkdialog.c b/src/disks/gdubenchmarkdialog.c
index 22fe98a..93f1987 100644
--- a/src/disks/gdubenchmarkdialog.c
+++ b/src/disks/gdubenchmarkdialog.c
@@ -248,6 +248,10 @@ on_drawing_area_draw (GtkWidget *widget,
gdouble access_time_max = 0.0;
gdouble prev_x;
gdouble prev_y;
+ GtkStyleContext *context;
+ PangoFontDescription *font_desc;
+ GdkRGBA fg;
+ PangoLayout *layout;
G_LOCK (bm_lock);
@@ -342,9 +346,6 @@ on_drawing_area_draw (GtkWidget *widget,
width = allocation.width;
height = allocation.height;
- cairo_select_font_face (cr, "sans",
- CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
- cairo_set_font_size (cr, 8.0);
cairo_set_line_width (cr, 1.0);
#if 0
@@ -409,23 +410,35 @@ on_drawing_area_draw (GtkWidget *widget,
gh -= needed;
}
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg);
+ gtk_style_context_get (context,
+ GTK_STATE_FLAG_NORMAL,
+ GTK_STYLE_PROPERTY_FONT,
+ &font_desc,
+ NULL);
+ pango_font_description_set_size (font_desc, 0.8 * 8 * PANGO_SCALE);
+ layout = pango_cairo_create_layout (cr);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_font_description_free (font_desc);
+
/* draw x markers ("%d%%") + vertical grid */
for (n = 0; n <= 10; n++)
{
- cairo_text_extents_t te;
+ PangoRectangle extents;
x = gx + ceil (n * gw / 10.0);
y = gy + gh + x_marker_height/2.0;
s = g_strdup_printf ("%u%%", n * 10);
- cairo_text_extents (cr, s, &te);
-
+ pango_layout_set_text (layout, s, -1);
+ pango_layout_get_extents (layout, NULL, &extents);
cairo_move_to (cr,
- x - te.x_bearing - te.width/2,
- y - te.y_bearing - te.height/2);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_show_text (cr, s);
+ x - extents.width/PANGO_SCALE/2,
+ y - extents.height/PANGO_SCALE/2);
+ gdk_cairo_set_source_rgba (cr, &fg);
+ pango_cairo_show_layout (cr, layout);
g_free (s);
}
@@ -433,37 +446,41 @@ on_drawing_area_draw (GtkWidget *widget,
/* draw left y markers ("%d MB/s") */
for (n = 0; n <= num_y_markers; n++)
{
- cairo_text_extents_t te;
+ PangoRectangle extents;
x = gx/2.0;
y = gy + gh - gh * n / num_y_markers;
s = y_left_markers[n];
- cairo_text_extents (cr, s, &te);
+ pango_layout_set_text (layout, s, -1);
+ pango_layout_get_extents (layout, NULL, &extents);
cairo_move_to (cr,
- x - te.x_bearing - te.width/2,
- y - te.y_bearing - te.height/2);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_show_text (cr, s);
+ x - extents.width/PANGO_SCALE/2,
+ y - extents.height/PANGO_SCALE/2);
+ gdk_cairo_set_source_rgba (cr, &fg);
+ pango_cairo_show_layout (cr, layout);
}
/* draw right y markers ("%d ms") */
for (n = 0; n <= num_y_markers; n++)
{
- cairo_text_extents_t te;
+ PangoRectangle extents;
x = gx + gw + (width - (gx + gw))/2.0;
y = gy + gh - gh * n / num_y_markers;
s = y_right_markers[n];
- cairo_text_extents (cr, s, &te);
+ pango_layout_set_text (layout, s, -1);
+ pango_layout_get_extents (layout, NULL, &extents);
cairo_move_to (cr,
- x - te.x_bearing - te.width/2,
- y - te.y_bearing - te.height/2);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_show_text (cr, s);
+ x - extents.width/PANGO_SCALE/2,
+ y - extents.height/PANGO_SCALE/2);
+ gdk_cairo_set_source_rgba (cr, &fg);
+ pango_cairo_show_layout (cr, layout);
}
+ g_object_unref (layout);
+
/* fill graph area */
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_rectangle (cr, gx + 0.5, gy + 0.5, gw, gh);
--
2.4.2