From 7f7809f523de11c2f215651fd65e74045d9a8e02 Mon Sep 17 00:00:00 2001 From: Benjamin Otte <otte@redhat.com> Date: Thu, 11 Nov 2021 05:21:43 +0100 Subject: [PATCH] label: Don't do more work than necessary We only want to determine the size pixel-exact, not pango-unit-exact, so don't spend lots of time wondering if text is half a pixel or a quarter pixel wider. --- gtk/gtklabel.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 4d84d6fc8d..8f94d8ab36 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -1191,11 +1191,14 @@ get_width_for_height (GtkLabel *self, layout = gtk_label_get_measuring_layout (self, NULL, -1); pango_layout_get_size (layout, &max, NULL); + min = PANGO_PIXELS_CEIL (min); + max = PANGO_PIXELS_CEIL (max); while (min < max) { mid = (min + max) / 2; - layout = gtk_label_get_measuring_layout (self, layout, mid); + layout = gtk_label_get_measuring_layout (self, layout, mid * PANGO_SCALE); pango_layout_get_size (layout, &text_width, &text_height); + text_width = PANGO_PIXELS_CEIL (text_width); if (text_width > mid) min = mid = text_width; if (text_height > height) @@ -1204,8 +1207,8 @@ get_width_for_height (GtkLabel *self, max = mid; } - *minimum_width = min; - *natural_width = min; + *minimum_width = min * PANGO_SCALE; + *natural_width = min * PANGO_SCALE; } g_object_unref (layout);