From a26fca0117f72a01e02fbcad5765aead0f053097 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Thu, 22 Feb 2024 13:13:26 +0100 Subject: [PATCH] clutter/text: Use the PangoLayout y offset for min height calculation The min height reported by ClutterText when ellipsize and line-wrapping are enabled was too small to fit the text. The coordinates from `pango_layout_get_line_extents()` are baseline relative, so the `y` coordinate means that the highest ascent would be `-y` above the baseline and height gives the span between the ascent above the baseline and the descent below it, so `logical_line_rect.y + logical_line_rect.height` gives us the size of the descent. This is the wrong height to use for the height of the actor. The coordinates of the layout extents don't seems to be related to the baseline and are just for offsets when rendering, that's probably how this bug got initially introduced. Therefore, the `y` coordinate from the layout is the correct offset to use, even though, when looking at `pango_layout_get_extends_internal()`, it appears that `y` is always set to 0. Part-of: --- clutter/clutter/clutter-text.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index 9fa9cdf54..102220c74 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -2988,12 +2988,13 @@ clutter_text_get_preferred_height (ClutterActor *self, if ((priv->ellipsize && priv->wrap) && !priv->single_line_mode) { PangoLayoutLine *line; + PangoRectangle logical_line_rect = { 0, }; gfloat line_height; line = pango_layout_get_line_readonly (layout, 0); - pango_layout_line_get_extents (line, NULL, &logical_rect); + pango_layout_line_get_extents (line, NULL, &logical_line_rect); - logical_height = logical_rect.y + logical_rect.height; + logical_height = logical_rect.y + logical_line_rect.height; line_height = pango_to_logical_pixels (logical_height, resource_scale);