Factor out a get_char_pixels method for clarity.

https://bugzilla.gnome.org/show_bug.cgi?id=647284
This commit is contained in:
Paolo Borelli 2011-04-09 22:19:51 +02:00
parent 76a571b61e
commit af7650ce1f

View File

@ -3660,6 +3660,23 @@ get_size_for_allocation (GtkLabel *label,
g_object_unref (layout);
}
static gint
get_char_pixels (GtkWidget *label,
PangoLayout *layout)
{
PangoContext *context;
PangoFontMetrics *metrics;
gint char_width, digit_width;
context = pango_layout_get_context (layout);
metrics = get_font_metrics (context, GTK_WIDGET (label));
char_width = pango_font_metrics_get_approximate_char_width (metrics);
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
pango_font_metrics_unref (metrics);
return MAX (char_width, digit_width);;
}
static void
gtk_label_get_preferred_layout_size (GtkLabel *label,
PangoRectangle *required,
@ -3728,16 +3745,9 @@ gtk_label_get_preferred_layout_size (GtkLabel *label,
if (priv->ellipsize || priv->wrap)
{
PangoContext *context;
PangoFontMetrics *metrics;
gint char_width, digit_width, char_pixels;
gint char_pixels;
context = pango_layout_get_context (layout);
metrics = get_font_metrics (context, GTK_WIDGET (label));
char_width = pango_font_metrics_get_approximate_char_width (metrics);
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
char_pixels = MAX (char_width, digit_width);
pango_font_metrics_unref (metrics);
char_pixels = get_char_pixels (GTK_WIDGET (label), layout);
required->width = char_pixels * MAX (priv->width_chars, ellipsize_chars);