[gtk+] label: Add optimization for a common special case
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] label: Add optimization for a common special case
- Date: Tue, 29 Mar 2011 15:48:56 +0000 (UTC)
commit 6ba3ef5d823d7ffbee86923782d65b4eb1b60668
Author: Benjamin Otte <otte redhat com>
Date: Tue Mar 29 03:16:34 2011 +0200
label: Add optimization for a common special case
Oftentimes we want to measure a layout that is as wide or wider than the
current layout's maximal width. In that case we can safely reuse the
current layout.
gtk/gtklabel.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index e9601ec..d17f4d7 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3044,6 +3044,7 @@ gtk_label_get_measuring_layout (GtkLabel * label,
int width)
{
GtkLabelPrivate *priv = label->priv;
+ PangoRectangle rect;
PangoLayout *copy;
if (existing_layout != NULL)
@@ -3065,6 +3066,18 @@ gtk_label_get_measuring_layout (GtkLabel * label,
return priv->layout;
}
+ /* oftentimes we want to measure a width that is far wider than the current width,
+ * even though the layout is not wrapped. In that case, we can just return the
+ * current layout, because for measuring purposes, it will be identical.
+ */
+ pango_layout_get_extents (priv->layout, NULL, &rect);
+ if ((width == -1 || rect.width <= width) &&
+ !pango_layout_is_wrapped (priv->layout))
+ {
+ g_object_ref (priv->layout);
+ return priv->layout;
+ }
+
copy = pango_layout_copy (priv->layout);
pango_layout_set_width (copy, width);
return copy;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]