From facdd8eea63450ce585037b2632682e372a9180e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Wed, 3 Jun 2026 08:54:54 +0300 Subject: [PATCH] [RTL] Fix last line height with some fallback fonts. --- scene/gui/rich_text_label.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index b5acb731a0..f5f8c7f218 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -715,8 +715,10 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref String txt; String txt_sub; Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr; + Item *it_prev = l.from ? l.from : current; int remaining_characters = visible_characters - l.char_offset; for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) { + it_prev = it; switch (it->type) { case ITEM_DROPCAP: { // Add dropcap. @@ -748,6 +750,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref txt += "\n"; l.char_count++; remaining_characters--; + it_prev = nullptr; } break; case ITEM_TEXT: { ItemText *t = static_cast(it); @@ -875,6 +878,28 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref } } + // Add zero-width space to the end if line did not end with /n to ensure uniform height. + if (it_prev) { + Ref font = p_base_font; + int font_size = p_base_font_size; + + ItemFont *font_it = _find_font(it_prev); + if (font_it) { + if (font_it->font.is_valid()) { + font = font_it->font; + } + if (font_it->font_size > 0) { + font_size = font_it->font_size; + } + } + ItemFontSize *font_size_it = _find_font_size(it_prev); + if (font_size_it && font_size_it->font_size > 0) { + font_size = font_size_it->font_size; + } + l.text_buf->add_string(String::chr(0x200B), font, font_size, String(), it_prev->rid); + txt += "\n"; + } + // Apply BiDi override. TextServer::StructuredTextParser stt = _find_stt(l.from); l.text_buf->set_bidi_override(structured_text_parser(stt, st_args, txt));