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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3610>
This commit is contained in:
Julian Sparber 2024-02-22 13:13:26 +01:00
parent 100dc6d2b1
commit a26fca0117

View File

@ -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);