Partially revert 107110, process all lines in VC_CHARS_BEFORE_SHAPING mode to return correct line count.

This commit is contained in:
Pāvels Nadtočajevs
2025-06-10 20:44:28 +03:00
parent db57f282fa
commit cbd1e1cfe9
2 changed files with 9 additions and 26 deletions

View File

@ -102,7 +102,6 @@
<return type="int" /> <return type="int" />
<description> <description>
Returns the total number of lines in the text. Wrapped text is counted as multiple lines. 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. [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.
</description> </description>
</method> </method>
@ -189,8 +188,6 @@
<return type="int" /> <return type="int" />
<description> <description>
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. 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.
</description> </description>
</method> </method>
<method name="get_paragraph_offset"> <method name="get_paragraph_offset">

View File

@ -524,9 +524,6 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr; 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; int remaining_characters = visible_characters - l.char_offset;
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) { 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) { switch (it->type) {
case ITEM_DROPCAP: { case ITEM_DROPCAP: {
// Add dropcap. // Add dropcap.
@ -579,8 +576,11 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
} }
String lang = _find_language(it); String lang = _find_language(it);
String tx = t->text; String tx = t->text;
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0) { if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0 && tx.length() > remaining_characters) {
tx = tx.substr(0, 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(); 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 rtl = (l.text_buf->get_direction() == TextServer::DIRECTION_RTL);
bool lrtl = is_layout_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_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)); 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; 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; } 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) { if (l.text_prefix.is_valid() && line == 0 && !skip_prefix) {
Color font_color = _find_color(l.from, p_base_color); Color font_color = _find_color(l.from, p_base_color);
int outline_size = _find_outline_size(l.from, p_outline_size); 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 RichTextLabel::get_paragraph_count() const {
int para_count = 0; return main->lines.size();
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;
} }
int RichTextLabel::get_visible_paragraph_count() const { 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(); int to_line = main->first_invalid_line.load();
for (int i = 0; i < to_line; i++) { for (int i = 0; i < to_line; i++) {
MutexLock lock(main->lines[i].text_buf->get_mutex()); MutexLock lock(main->lines[i].text_buf->get_mutex());
for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) { line_count += main->lines[i].text_buf->get_line_count();
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++;
}
} }
return line_count; return line_count;
} }