[gtk+] label: Move ellipsized layout width computation
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] label: Move ellipsized layout width computation
- Date: Tue, 29 Mar 2011 15:49:21 +0000 (UTC)
commit c94dca36cafc1c0538de2517d39b172bcafa9638
Author: Benjamin Otte <otte redhat com>
Date: Tue Mar 29 13:21:48 2011 +0200
label: Move ellipsized layout width computation
... from size_allocate() to update_layout_width().
gtk/gtklabel.c | 150 +++++++++++++++++++++++++++-----------------------------
1 files changed, 72 insertions(+), 78 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 5a70a74..7431b0f 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3214,7 +3214,78 @@ gtk_label_update_layout_width (GtkLabel *label)
gtk_widget_get_allocation (widget, &allocation);
if (priv->ellipsize)
- pango_layout_set_width (priv->layout, allocation.width * PANGO_SCALE);
+ {
+ PangoRectangle logical;
+ PangoRectangle bounds;
+ gint xpad, ypad;
+
+ gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
+
+ bounds.x = bounds.y = 0;
+ bounds.width = allocation.width - xpad * 2;
+ bounds.height = allocation.height - ypad * 2;
+
+ pango_layout_set_width (priv->layout, -1);
+ pango_layout_get_pixel_extents (priv->layout, NULL, &logical);
+
+ if (priv->have_transform)
+ {
+ PangoContext *context = gtk_widget_get_pango_context (widget);
+ const PangoMatrix *matrix = pango_context_get_matrix (context);
+
+ const gdouble dx = matrix->xx; /* cos (M_PI * angle / 180) */
+ const gdouble dy = matrix->xy; /* sin (M_PI * angle / 180) */
+ if (fabs (dy) < 0.01)
+ {
+ if (logical.width > bounds.width)
+ pango_layout_set_width (priv->layout, bounds.width * PANGO_SCALE);
+ }
+ else if (fabs (dx) < 0.01)
+ {
+ if (logical.width > bounds.height)
+ pango_layout_set_width (priv->layout, bounds.height * PANGO_SCALE);
+ }
+ else
+ {
+ gdouble x0, y0, x1, y1, length;
+ gboolean vertical;
+ gint cy;
+
+ x0 = bounds.width / 2;
+ y0 = dx ? x0 * dy / dx : G_MAXDOUBLE;
+ vertical = fabs (y0) > bounds.height / 2;
+
+ if (vertical)
+ {
+ y0 = bounds.height/2;
+ x0 = dy ? y0 * dx / dy : G_MAXDOUBLE;
+ }
+
+ length = 2 * sqrt (x0 * x0 + y0 * y0);
+ pango_layout_set_width (priv->layout, rint (length * PANGO_SCALE));
+ pango_layout_get_pixel_size (priv->layout, NULL, &cy);
+
+ x1 = +dy * cy/2;
+ y1 = -dx * cy/2;
+
+ if (vertical)
+ {
+ y0 = bounds.height/2 + y1 - y0;
+ x0 = -y0 * dx/dy;
+ }
+ else
+ {
+ x0 = bounds.width/2 + x1 - x0;
+ y0 = -x0 * dy/dx;
+ }
+
+ length = length - sqrt (x0 * x0 + y0 * y0) * 2;
+ pango_layout_set_width (priv->layout, rint (length * PANGO_SCALE));
+ }
+ }
+ else if (logical.width > bounds.width)
+ pango_layout_set_width (priv->layout, bounds.width * PANGO_SCALE);
+ }
else if (priv->wrap)
{
GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
@@ -3740,83 +3811,6 @@ gtk_label_size_allocate (GtkWidget *widget,
gtk_label_ensure_layout (label);
- if (priv->ellipsize)
- {
- if (priv->layout)
- {
- PangoRectangle logical;
- PangoRectangle bounds;
- gint xpad, ypad;
-
- gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
-
- bounds.x = bounds.y = 0;
- bounds.width = allocation->width - xpad * 2;
- bounds.height = allocation->height - ypad * 2;
-
- pango_layout_set_width (priv->layout, -1);
- pango_layout_get_pixel_extents (priv->layout, NULL, &logical);
-
- if (priv->have_transform)
- {
- PangoContext *context = gtk_widget_get_pango_context (widget);
- const PangoMatrix *matrix = pango_context_get_matrix (context);
-
- const gdouble dx = matrix->xx; /* cos (M_PI * angle / 180) */
- const gdouble dy = matrix->xy; /* sin (M_PI * angle / 180) */
- if (fabs (dy) < 0.01)
- {
- if (logical.width > bounds.width)
- pango_layout_set_width (priv->layout, bounds.width * PANGO_SCALE);
- }
- else if (fabs (dx) < 0.01)
- {
- if (logical.width > bounds.height)
- pango_layout_set_width (priv->layout, bounds.height * PANGO_SCALE);
- }
- else
- {
- gdouble x0, y0, x1, y1, length;
- gboolean vertical;
- gint cy;
-
- x0 = bounds.width / 2;
- y0 = dx ? x0 * dy / dx : G_MAXDOUBLE;
- vertical = fabs (y0) > bounds.height / 2;
-
- if (vertical)
- {
- y0 = bounds.height/2;
- x0 = dy ? y0 * dx / dy : G_MAXDOUBLE;
- }
-
- length = 2 * sqrt (x0 * x0 + y0 * y0);
- pango_layout_set_width (priv->layout, rint (length * PANGO_SCALE));
- pango_layout_get_pixel_size (priv->layout, NULL, &cy);
-
- x1 = +dy * cy/2;
- y1 = -dx * cy/2;
-
- if (vertical)
- {
- y0 = bounds.height/2 + y1 - y0;
- x0 = -y0 * dx/dy;
- }
- else
- {
- x0 = bounds.width/2 + x1 - x0;
- y0 = -x0 * dy/dx;
- }
-
- length = length - sqrt (x0 * x0 + y0 * y0) * 2;
- pango_layout_set_width (priv->layout, rint (length * PANGO_SCALE));
- }
- }
- else if (logical.width > bounds.width)
- pango_layout_set_width (priv->layout, bounds.width * PANGO_SCALE);
- }
- }
-
if (priv->select_info && priv->select_info->window)
{
gdk_window_move_resize (priv->select_info->window,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]