From cbd1e1cfe90c2e33139cdef9e20a050cabfbfadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Tue, 10 Jun 2025 20:44:28 +0300 Subject: [PATCH] Partially revert 107110, process all lines in VC_CHARS_BEFORE_SHAPING mode to return correct line count. --- doc/classes/RichTextLabel.xml | 3 --- scene/gui/rich_text_label.cpp | 32 +++++++++----------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml index a4e646b7e2a..5a9723d89c1 100644 --- a/doc/classes/RichTextLabel.xml +++ b/doc/classes/RichTextLabel.xml @@ -102,7 +102,6 @@ Returns the total number of lines in the text. Wrapped text is counted as multiple lines. - [b]Note:[/b] Lines hidden by [member visible_characters] are not counted. [b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_finished] or [signal finished] to determine whether document is fully loaded. @@ -189,8 +188,6 @@ Returns the total number of paragraphs (newlines or [code]p[/code] tags in the tag stack's text tags). Considers wrapped text as one paragraph. - [b]Note:[/b] Paragraphs hidden by [member visible_characters] are not counted. - [b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_finished] or [signal finished] to determine whether document is fully loaded. diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 19e18fd9111..119a7894afe 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -524,9 +524,6 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr; int remaining_characters = visible_characters - l.char_offset; for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) { - if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters <= 0) { - break; - } switch (it->type) { case ITEM_DROPCAP: { // Add dropcap. @@ -579,8 +576,11 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref } String lang = _find_language(it); String tx = t->text; - if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0) { - tx = tx.substr(0, remaining_characters); + if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0 && tx.length() > remaining_characters) { + String first = tx.substr(0, remaining_characters); + String second = tx.substr(remaining_characters, -1); + l.text_buf->add_string(first, font, font_size, lang, it->rid); + l.text_buf->add_string(second, font, font_size, lang, it->rid); } remaining_characters -= tx.length(); @@ -835,7 +835,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o bool rtl = (l.text_buf->get_direction() == TextServer::DIRECTION_RTL); bool lrtl = is_layout_rtl(); - bool trim_chars = (visible_characters >= 0) && (visible_chars_behavior == TextServer::VC_CHARS_AFTER_SHAPING); + bool trim_chars = (visible_characters >= 0) && (visible_chars_behavior == TextServer::VC_CHARS_AFTER_SHAPING || visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING); bool trim_glyphs_ltr = (visible_characters >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_LTR) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && !lrtl)); bool trim_glyphs_rtl = (visible_characters >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_RTL) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && lrtl)); int total_glyphs = (trim_glyphs_ltr || trim_glyphs_rtl) ? get_total_glyph_count() : 0; @@ -907,7 +907,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o } break; } - bool skip_prefix = (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && l.char_offset == visible_characters) || (trim_chars && l.char_offset > visible_characters) || (trim_glyphs_ltr && (r_processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (r_processed_glyphs < total_glyphs - visible_glyphs)); + bool skip_prefix = (trim_chars && l.char_offset > visible_characters) || (trim_glyphs_ltr && (r_processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (r_processed_glyphs < total_glyphs - visible_glyphs)); if (l.text_prefix.is_valid() && line == 0 && !skip_prefix) { Color font_color = _find_color(l.from, p_base_color); int outline_size = _find_outline_size(l.from, p_outline_size); @@ -6252,15 +6252,7 @@ void RichTextLabel::scroll_to_paragraph(int p_paragraph) { } int RichTextLabel::get_paragraph_count() const { - int para_count = 0; - int to_line = main->first_invalid_line.load(); - for (int i = 0; i < to_line; i++) { - if ((visible_characters >= 0) && main->lines[i].char_offset >= visible_characters) { - break; - } - para_count++; - } - return para_count; + return main->lines.size(); } int RichTextLabel::get_visible_paragraph_count() const { @@ -6335,13 +6327,7 @@ int RichTextLabel::get_line_count() const { int to_line = main->first_invalid_line.load(); for (int i = 0; i < to_line; i++) { MutexLock lock(main->lines[i].text_buf->get_mutex()); - for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) { - RID rid = main->lines[i].text_buf->get_line_rid(j); - if ((visible_characters >= 0) && main->lines[i].char_offset + TS->shaped_text_get_range(rid).x >= visible_characters) { - break; - } - line_count++; - } + line_count += main->lines[i].text_buf->get_line_count(); } return line_count; }