[gtk+] label: Fix ellipsize and wrap being set



commit f55fe7e20b25de842ae61987049bdf57f10702f3
Author: Benjamin Otte <otte redhat com>
Date:   Fri Nov 2 21:49:32 2012 +0100

    label: Fix ellipsize and wrap being set
    
    The label code assumed that Pango treats this as "wrap to as much space
    as possible and then ellipsize all the lines", but for Pango, ellipsize
    takes precedence over wrap. So do the same thing in GtkLabel.
    
    Also updated is the reftest that checked this behavior.

 gtk/gtklabel.c                     |   31 ++++----------------
 tests/reftests/label-sizing.ref.ui |   54 ++++++++++++------------------------
 2 files changed, 24 insertions(+), 61 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index bb3ca4f..113ce57 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3158,7 +3158,6 @@ get_font_metrics (PangoContext *context, GtkWidget *widget)
  * @label: the label
  * @existing_layout: %NULL or an existing layout already in use.
  * @width: the width to measure with in pango units, or -1 for infinite
- * @height: the height to measure with in pango units, or -1 for infinite
  *
  * Gets a layout that can be used for measuring sizes. The returned
  * layout will be identical to the label's layout except for the
@@ -3170,8 +3169,7 @@ get_font_metrics (PangoContext *context, GtkWidget *widget)
 static PangoLayout *
 gtk_label_get_measuring_layout (GtkLabel *   label,
                                 PangoLayout *existing_layout,
-                                int          width,
-                                int          height)
+                                int          width)
 {
   GtkLabelPrivate *priv = label->priv;
   PangoRectangle rect;
@@ -3182,7 +3180,6 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
       if (existing_layout != priv->layout)
         {
           pango_layout_set_width (existing_layout, width);
-          pango_layout_set_height (existing_layout, height);
           return existing_layout;
         }
 
@@ -3191,8 +3188,7 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
 
   gtk_label_ensure_layout (label);
 
-  if (pango_layout_get_width (priv->layout) == width &&
-      pango_layout_get_height (priv->layout) == height)
+  if (pango_layout_get_width (priv->layout) == width)
     {
       g_object_ref (priv->layout);
       return priv->layout;
@@ -3206,7 +3202,6 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
     {
       g_object_ref (priv->layout);
       pango_layout_set_width (priv->layout, width);
-      pango_layout_set_height (priv->layout, height);
       return priv->layout;
     }
 
@@ -3217,7 +3212,6 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
    */
   pango_layout_get_extents (priv->layout, NULL, &rect);
   if ((width == -1 || rect.width <= width) &&
-      (height == -1 || rect.height <= height) &&
       !pango_layout_is_wrapped (priv->layout) &&
       !pango_layout_is_ellipsized (priv->layout))
     {
@@ -3227,7 +3221,6 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
 
   copy = pango_layout_copy (priv->layout);
   pango_layout_set_width (copy, width);
-  pango_layout_set_height (copy, height);
   return copy;
 }
 
@@ -3258,7 +3251,6 @@ gtk_label_update_layout_width (GtkLabel *label)
           const gdouble dy = matrix->xy; /* sin (M_PI * angle / 180) */
 
           pango_layout_set_width (priv->layout, -1);
-          pango_layout_set_height (priv->layout, -1);
           pango_layout_get_pixel_extents (priv->layout, NULL, &logical);
 
           if (fabs (dy) < 0.01)
@@ -3312,13 +3304,11 @@ gtk_label_update_layout_width (GtkLabel *label)
       else
         {
           pango_layout_set_width (priv->layout, width * PANGO_SCALE);
-          pango_layout_set_height (priv->layout, priv->ellipsize ? height * PANGO_SCALE : -1);
         }
     }
   else
     {
       pango_layout_set_width (priv->layout, -1);
-      pango_layout_set_height (priv->layout, -1);
     }
 }
 
@@ -3487,11 +3477,10 @@ get_size_for_allocation (GtkLabel        *label,
                          gint            *minimum_size,
                          gint            *natural_size)
 {
-  GtkLabelPrivate *priv = label->priv;
   PangoLayout *layout;
   gint text_height;
 
-  layout = gtk_label_get_measuring_layout (label, NULL, allocation * PANGO_SCALE, -1);
+  layout = gtk_label_get_measuring_layout (label, NULL, allocation * PANGO_SCALE);
 
   pango_layout_get_pixel_size (layout, NULL, &text_height);
 
@@ -3499,15 +3488,7 @@ get_size_for_allocation (GtkLabel        *label,
     *minimum_size = text_height;
 
   if (natural_size)
-    {
-      if (priv->ellipsize && priv->wrap)
-        {
-          layout = gtk_label_get_measuring_layout (label, layout, allocation * PANGO_SCALE, G_MAXINT);
-          pango_layout_get_pixel_size (layout, NULL, &text_height);
-        }
-
-      *natural_size = text_height;
-    }
+    *natural_size = text_height;
 
   g_object_unref (layout);
 }
@@ -3554,7 +3535,7 @@ gtk_label_get_preferred_layout_size (GtkLabel *label,
    */
 
   /* Start off with the pixel extents of an as-wide-as-possible layout */
-  layout = gtk_label_get_measuring_layout (label, NULL, -1, -1);
+  layout = gtk_label_get_measuring_layout (label, NULL, -1);
 
   pango_layout_get_extents (layout, NULL, natural);
   natural->x = natural->y = 0;
@@ -3565,7 +3546,7 @@ gtk_label_get_preferred_layout_size (GtkLabel *label,
   if (priv->ellipsize || priv->wrap)
     {
       /* a layout with width 0 will be as small as humanly possible */
-      layout = gtk_label_get_measuring_layout (label, layout, 0, -1);
+      layout = gtk_label_get_measuring_layout (label, layout, 0);
 
       pango_layout_get_extents (layout, NULL, required);
 
diff --git a/tests/reftests/label-sizing.ref.ui b/tests/reftests/label-sizing.ref.ui
index e615948..b33923d 100644
--- a/tests/reftests/label-sizing.ref.ui
+++ b/tests/reftests/label-sizing.ref.ui
@@ -625,8 +625,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">A
-&#x2026;</property>
+                    <property name="label" translatable="yes">&#x2026;</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
                     </attributes>
@@ -1257,8 +1256,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCD
-ABCD</property>
+                    <property name="label" translatable="yes">ABC&#x2026;</property>
                     <property name="width_chars">4</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
@@ -1892,8 +1890,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="width_chars">8</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
@@ -3161,8 +3158,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">A
-&#x2026;</property>
+                    <property name="label" translatable="yes">&#x2026;</property>
                     <property name="max_width_chars">4</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
@@ -3209,8 +3205,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCD
-ABCD</property>
+                    <property name="label" translatable="yes">ABC&#x2026;</property>
                     <property name="max_width_chars">4</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
@@ -3812,8 +3807,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCD
-ABCD</property>
+                    <property name="label" translatable="yes">ABC&#x2026;</property>
                     <property name="width_chars">4</property>
                     <property name="max_width_chars">4</property>
                     <attributes>
@@ -3862,8 +3856,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCD
-ABCD</property>
+                    <property name="label" translatable="yes">ABC&#x2026;</property>
                     <property name="width_chars">4</property>
                     <property name="max_width_chars">4</property>
                     <attributes>
@@ -4466,8 +4459,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="width_chars">8</property>
                     <property name="max_width_chars">4</property>
                     <attributes>
@@ -4516,8 +4508,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="width_chars">8</property>
                     <property name="max_width_chars">4</property>
                     <attributes>
@@ -5755,8 +5746,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">A
-&#x2026;</property>
+                    <property name="label" translatable="yes">&#x2026;</property>
                     <property name="max_width_chars">8</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
@@ -5803,8 +5793,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="max_width_chars">8</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
@@ -6406,8 +6395,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCD
-ABCD</property>
+                    <property name="label" translatable="yes">ABC&#x2026;</property>
                     <property name="width_chars">4</property>
                     <property name="max_width_chars">8</property>
                     <attributes>
@@ -6456,8 +6444,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="width_chars">4</property>
                     <property name="max_width_chars">8</property>
                     <attributes>
@@ -7060,8 +7047,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="width_chars">8</property>
                     <property name="max_width_chars">8</property>
                     <attributes>
@@ -7110,8 +7096,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="width_chars">8</property>
                     <property name="max_width_chars">8</property>
                     <attributes>
@@ -8347,8 +8332,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">A
-&#x2026;</property>
+                    <property name="label" translatable="yes">&#x2026;</property>
                     <property name="max_width_chars">12</property>
                     <attributes>
                       <attribute name="font-desc" value="Monospace"/>
@@ -8995,8 +8979,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCD
-ABCD</property>
+                    <property name="label" translatable="yes">ABC&#x2026;</property>
                     <property name="width_chars">4</property>
                     <property name="max_width_chars">12</property>
                     <attributes>
@@ -9646,8 +9629,7 @@ ABCD</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">ABCDE   
-ABCD</property>
+                    <property name="label" translatable="yes">ABCDE A&#x2026;</property>
                     <property name="width_chars">8</property>
                     <property name="max_width_chars">12</property>
                     <attributes>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]