[gtk+] label: Only get font metrics if we have to
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] label: Only get font metrics if we have to
- Date: Tue, 29 Mar 2011 15:49:01 +0000 (UTC)
commit 0930de944697b76008863f87d2adce7f059e5a4a
Author: Benjamin Otte <otte redhat com>
Date: Tue Mar 29 03:31:09 2011 +0200
label: Only get font metrics if we have to
Getting these metrics is expensive, so avoid it if possible.
gtk/gtklabel.c | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index d17f4d7..e0c6c5b 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3091,20 +3091,12 @@ get_label_width (GtkLabel *label,
{
GtkLabelPrivate *priv;
PangoLayout *layout;
- PangoContext *context;
- PangoFontMetrics *metrics;
PangoRectangle rect;
- gint char_width, digit_width, char_pixels, text_width, ellipsize_chars, guess_width;
+ gint text_width, ellipsize_chars, guess_width;
priv = label->priv;
layout = gtk_label_get_measuring_layout (label, NULL, -1);
- 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);
/* Fetch the length of the complete unwrapped text */
pango_layout_get_extents (layout, NULL, &rect);
@@ -3141,6 +3133,17 @@ get_label_width (GtkLabel *label,
if (priv->ellipsize || priv->wrap)
{
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ gint char_width, digit_width, 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);
+
*minimum = char_pixels * MAX (priv->width_chars, ellipsize_chars);
/* Default to the minimum width regularly guessed by GTK+ if no minimum
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]