Re: [PATCH] limit the number of extended layout features supported by GtkLabel at the same time



> However, I'm actually thinking of disabling completely
> height_for_width/width_for_height for non-wrapping labels (right now
> it's accepted for elliipsizing labels), as well as disabling
> get_natural_size for wrapping labels.  In the meanwhile, this patch
> makes things work properly.

Here is the patch to do that, on top of the other patch I sent (the
changes to gtk_label_style_set and
gtk_label_extended_layout_get_size_for_allocation are needed even with
this patch).

The results of testextendedlayout are okay (except that baseline
alignment does not work with or without my patch), and I also fixed
autotestextendedlayout because it failed in the current tip of the
branch, independent of my previous patch.

Paolo
2008-09-03  Paolo Bonzini  <bonzini gnu org>
    
    	* gtk/gtklabel.c: Disable natural size layout for wrapping
    	labels (undoing part of the previous patch), and disable
    	height-for-width/width-for-height layout for non-wrapping,
    	ellipsizing labels.
    
    	* tests/autotestextendedlayout.c: Update to match the above.

diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index fac4b7f..9adbc68 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -4367,11 +4367,12 @@ gtk_label_extended_layout_get_features (GtkExtendedLayout *layout)
   GtkLabelPrivate *priv = GTK_LABEL_GET_PRIVATE (label);
   GtkExtendedLayoutFeatures features;
 
-  features =
-    GTK_EXTENDED_LAYOUT_NATURAL_SIZE |
-    GTK_EXTENDED_LAYOUT_BASELINES;
+  features = GTK_EXTENDED_LAYOUT_BASELINES;
 
-  if (label->ellipsize || (label->wrap && priv->full_size))
+  if (!label->wrap)
+    features |= GTK_EXTENDED_LAYOUT_NATURAL_SIZE;
+
+  else if (priv->full_size)
     {
       gdouble angle = gtk_label_get_angle (label);
 
@@ -4416,40 +4417,24 @@ gtk_label_extended_layout_get_natural_size (GtkExtendedLayout *layout,
                                             GtkRequisition    *requisition)
 {
   GtkLabel *label;
-  GtkLabelPrivate *priv;
   gboolean ellipsize;
-  gint wrap_width;
   PangoLayout *tmp;
 
   label = GTK_LABEL (layout);
-  priv = GTK_LABEL_GET_PRIVATE (label);
+  g_assert (!label->wrap);
   gtk_label_ensure_layout (label);
 
   ellipsize = label->ellipsize;
   label->ellipsize = PANGO_ELLIPSIZE_NONE;
 
-  wrap_width = priv->wrap_width;
   tmp = label->layout;
-
-  /* See comment in gtk_label_size_request.  */
-
-  if (label->wrap)
-    {
-      g_object_ref (label->layout);
-      gtk_label_clear_layout (label);
-    }
-  else
-    {
-      label->layout = pango_layout_copy (tmp);
-      pango_layout_set_width (label->layout, -1);
-    }
-
+  label->layout = pango_layout_copy (tmp);
+  pango_layout_set_width (label->layout, -1);
   gtk_label_size_request (GTK_WIDGET (label), requisition);
 
   g_object_unref (label->layout);
   label->ellipsize = ellipsize;
   label->layout = tmp;
-  priv->wrap_width = wrap_width;
 }
 
 static gint
diff --git a/tests/autotestextendedlayout.c b/tests/autotestextendedlayout.c
index 6b47477..cf731fd 100644
--- a/tests/autotestextendedlayout.c
+++ b/tests/autotestextendedlayout.c
@@ -264,8 +264,6 @@ gtk_label_test_natural_size (void)
       const GEnumValue *const wrap = (i >= 0 ? &wrap_class->values[i] : NULL);
       const gchar *wrap_mode = (wrap ? wrap->value_nick : "none");
 
-      gtk_label_set_line_wrap (label, NULL != wrap);
-
       if (wrap)
         gtk_label_set_line_wrap_mode (label, wrap->value);
 
@@ -311,7 +309,7 @@ gtk_label_test_extended_layout (void)
 
   log_test (NULL != iface->get_features);
   log_test (NULL != iface->get_height_for_width);
-  log_test (NULL == iface->get_width_for_height);
+  log_test (NULL != iface->get_width_for_height);
   log_test (NULL != iface->get_natural_size);
   log_test (NULL != iface->get_baselines);
 
@@ -324,19 +322,22 @@ gtk_label_test_extended_layout (void)
   log_test (0 != (features & GTK_EXTENDED_LAYOUT_NATURAL_SIZE));
   log_test (0 != (features & GTK_EXTENDED_LAYOUT_BASELINES));
 
+  gtk_label_test_baselines ();
+  gtk_label_test_natural_size ();
+
   gtk_label_set_line_wrap (label, TRUE);
+  gtk_label_set_full_size (label, TRUE);
   features = gtk_extended_layout_get_features (layout);
 
   log_test (0 != (features & GTK_EXTENDED_LAYOUT_HEIGHT_FOR_WIDTH));
   log_test (0 == (features & GTK_EXTENDED_LAYOUT_WIDTH_FOR_HEIGHT));
-  log_test (0 != (features & GTK_EXTENDED_LAYOUT_NATURAL_SIZE));
+  log_test (0 == (features & GTK_EXTENDED_LAYOUT_NATURAL_SIZE));
   log_test (0 != (features & GTK_EXTENDED_LAYOUT_BASELINES));
 
   g_object_unref (widget);
 
   gtk_label_test_baselines ();
   gtk_label_test_height_for_width ();
-  gtk_label_test_natural_size ();
 }
 
 static void
@@ -397,11 +398,12 @@ gtk_bin_test_extended_layout (void)
       log_test (0 != (features & GTK_EXTENDED_LAYOUT_BASELINES));
 
       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+      gtk_label_set_full_size (GTK_LABEL (label), TRUE);
       features = gtk_extended_layout_get_features (layout);
 
       log_test (0 != (features & GTK_EXTENDED_LAYOUT_HEIGHT_FOR_WIDTH));
       log_test (0 == (features & GTK_EXTENDED_LAYOUT_WIDTH_FOR_HEIGHT));
-      log_test (0 != (features & GTK_EXTENDED_LAYOUT_NATURAL_SIZE));
+      log_test (0 == (features & GTK_EXTENDED_LAYOUT_NATURAL_SIZE));
       log_test (0 != (features & GTK_EXTENDED_LAYOUT_BASELINES));
 
       /* verify baseline propagation */


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