Skip to content

Commit facdd8e

Browse files
committed
[RTL] Fix last line height with some fallback fonts.
1 parent d569fcf commit facdd8e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

scene/gui/rich_text_label.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,10 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
715715
String txt;
716716
String txt_sub;
717717
Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
718+
Item *it_prev = l.from ? l.from : current;
718719
int remaining_characters = visible_characters - l.char_offset;
719720
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
721+
it_prev = it;
720722
switch (it->type) {
721723
case ITEM_DROPCAP: {
722724
// Add dropcap.
@@ -748,6 +750,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
748750
txt += "\n";
749751
l.char_count++;
750752
remaining_characters--;
753+
it_prev = nullptr;
751754
} break;
752755
case ITEM_TEXT: {
753756
ItemText *t = static_cast<ItemText *>(it);
@@ -875,6 +878,28 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
875878
}
876879
}
877880

881+
// Add zero-width space to the end if line did not end with /n to ensure uniform height.
882+
if (it_prev) {
883+
Ref<Font> font = p_base_font;
884+
int font_size = p_base_font_size;
885+
886+
ItemFont *font_it = _find_font(it_prev);
887+
if (font_it) {
888+
if (font_it->font.is_valid()) {
889+
font = font_it->font;
890+
}
891+
if (font_it->font_size > 0) {
892+
font_size = font_it->font_size;
893+
}
894+
}
895+
ItemFontSize *font_size_it = _find_font_size(it_prev);
896+
if (font_size_it && font_size_it->font_size > 0) {
897+
font_size = font_size_it->font_size;
898+
}
899+
l.text_buf->add_string(String::chr(0x200B), font, font_size, String(), it_prev->rid);
900+
txt += "\n";
901+
}
902+
878903
// Apply BiDi override.
879904
TextServer::StructuredTextParser stt = _find_stt(l.from);
880905
l.text_buf->set_bidi_override(structured_text_parser(stt, st_args, txt));

0 commit comments

Comments
 (0)