[gtk/wip/otte/for-master] Revert "label: Never measure more than max-width-chars"




commit c2ce8cd31cbe0d9e9038d7e657d1e56e4007a6de
Author: Benjamin Otte <otte redhat com>
Date:   Thu Nov 4 13:28:45 2021 +0100

    Revert "label: Never measure more than max-width-chars"
    
    This reverts commit ba44e7a228534ff066694ad97d25eaa23ec5f3af.
    
    The change was meant to revert to old GTK3 behavior but it actually
    broke new GTK4 behavior that is in use where max-width-chars is used to
    determine an ideal size, but where we don't want to limit the width to
    that size.
    
    So what happens is the reintroduction of GTK3-style lots of whitepsace
    bugs, and we really don't want those.
    
    We also don't want to break backwards compat if we can avoid it.
    
    So let's revert this.
    
    Fixes #4399

 gtk/gtklabel.c | 49 ++++++++++++++++++-------------------------------
 1 file changed, 18 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 661902a275..e94615473d 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -1017,23 +1017,6 @@ gtk_label_get_measuring_layout (GtkLabel    *self,
   return copy;
 }
 
-static int
-get_char_pixels (GtkWidget   *self,
-                 PangoLayout *layout)
-{
-  PangoContext *context;
-  PangoFontMetrics *metrics;
-  int char_width, digit_width;
-
-  context = pango_layout_get_context (layout);
-  metrics = pango_context_get_metrics (context, NULL, NULL);
-  char_width = pango_font_metrics_get_approximate_char_width (metrics);
-  digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
-  pango_font_metrics_unref (metrics);
-
-  return MAX (char_width, digit_width);
-}
-
 static void
 get_height_for_width (GtkLabel *self,
                       int       width,
@@ -1045,20 +1028,7 @@ get_height_for_width (GtkLabel *self,
   PangoLayout *layout;
   int text_height, baseline;
 
-  width *= PANGO_SCALE;
-  if (self->max_width_chars > -1)
-    {
-      int char_pixels, width_chars;
-
-      layout = gtk_label_get_measuring_layout (self, NULL, -1);
-      char_pixels = get_char_pixels (GTK_WIDGET (self), layout);
-      if (self->width_chars > self->max_width_chars)
-        width_chars = self->width_chars;
-      else
-        width_chars = self->max_width_chars;
-      width = MIN (char_pixels * width_chars, width);
-    }
-  layout = gtk_label_get_measuring_layout (self, NULL, width);
+  layout = gtk_label_get_measuring_layout (self, NULL, width * PANGO_SCALE);
 
   pango_layout_get_pixel_size (layout, NULL, &text_height);
 
@@ -1072,6 +1042,23 @@ get_height_for_width (GtkLabel *self,
   g_object_unref (layout);
 }
 
+static int
+get_char_pixels (GtkWidget   *self,
+                 PangoLayout *layout)
+{
+  PangoContext *context;
+  PangoFontMetrics *metrics;
+  int char_width, digit_width;
+
+  context = pango_layout_get_context (layout);
+  metrics = pango_context_get_metrics (context, NULL, NULL);
+  char_width = pango_font_metrics_get_approximate_char_width (metrics);
+  digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
+  pango_font_metrics_unref (metrics);
+
+  return MAX (char_width, digit_width);
+}
+
 static void
 gtk_label_get_preferred_layout_size (GtkLabel *self,
                                      PangoRectangle *smallest,


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