Skip to content

Commit b7b0459

Browse files
committed
Merge pull request #107373 from bruvzg/rtl_line_count
Partially revert 107110, process all lines in `VC_CHARS_BEFORE_SHAPING` mode to return correct line count.
2 parents db57f28 + cbd1e1c commit b7b0459

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

doc/classes/RichTextLabel.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
<return type="int" />
103103
<description>
104104
Returns the total number of lines in the text. Wrapped text is counted as multiple lines.
105-
[b]Note:[/b] Lines hidden by [member visible_characters] are not counted.
106105
[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.
107106
</description>
108107
</method>
@@ -189,8 +188,6 @@
189188
<return type="int" />
190189
<description>
191190
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.
192-
[b]Note:[/b] Paragraphs hidden by [member visible_characters] are not counted.
193-
[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.
194191
</description>
195192
</method>
196193
<method name="get_paragraph_offset">

scene/gui/rich_text_label.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,6 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
524524
Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
525525
int remaining_characters = visible_characters - l.char_offset;
526526
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
527-
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters <= 0) {
528-
break;
529-
}
530527
switch (it->type) {
531528
case ITEM_DROPCAP: {
532529
// Add dropcap.
@@ -579,8 +576,11 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
579576
}
580577
String lang = _find_language(it);
581578
String tx = t->text;
582-
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0) {
583-
tx = tx.substr(0, remaining_characters);
579+
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0 && tx.length() > remaining_characters) {
580+
String first = tx.substr(0, remaining_characters);
581+
String second = tx.substr(remaining_characters, -1);
582+
l.text_buf->add_string(first, font, font_size, lang, it->rid);
583+
l.text_buf->add_string(second, font, font_size, lang, it->rid);
584584
}
585585
remaining_characters -= tx.length();
586586

@@ -835,7 +835,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
835835
bool rtl = (l.text_buf->get_direction() == TextServer::DIRECTION_RTL);
836836
bool lrtl = is_layout_rtl();
837837

838-
bool trim_chars = (visible_characters >= 0) && (visible_chars_behavior == TextServer::VC_CHARS_AFTER_SHAPING);
838+
bool trim_chars = (visible_characters >= 0) && (visible_chars_behavior == TextServer::VC_CHARS_AFTER_SHAPING || visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING);
839839
bool trim_glyphs_ltr = (visible_characters >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_LTR) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && !lrtl));
840840
bool trim_glyphs_rtl = (visible_characters >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_RTL) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && lrtl));
841841
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
907907
} break;
908908
}
909909

910-
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));
910+
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));
911911
if (l.text_prefix.is_valid() && line == 0 && !skip_prefix) {
912912
Color font_color = _find_color(l.from, p_base_color);
913913
int outline_size = _find_outline_size(l.from, p_outline_size);
@@ -6252,15 +6252,7 @@ void RichTextLabel::scroll_to_paragraph(int p_paragraph) {
62526252
}
62536253

62546254
int RichTextLabel::get_paragraph_count() const {
6255-
int para_count = 0;
6256-
int to_line = main->first_invalid_line.load();
6257-
for (int i = 0; i < to_line; i++) {
6258-
if ((visible_characters >= 0) && main->lines[i].char_offset >= visible_characters) {
6259-
break;
6260-
}
6261-
para_count++;
6262-
}
6263-
return para_count;
6255+
return main->lines.size();
62646256
}
62656257

62666258
int RichTextLabel::get_visible_paragraph_count() const {
@@ -6335,13 +6327,7 @@ int RichTextLabel::get_line_count() const {
63356327
int to_line = main->first_invalid_line.load();
63366328
for (int i = 0; i < to_line; i++) {
63376329
MutexLock lock(main->lines[i].text_buf->get_mutex());
6338-
for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) {
6339-
RID rid = main->lines[i].text_buf->get_line_rid(j);
6340-
if ((visible_characters >= 0) && main->lines[i].char_offset + TS->shaped_text_get_range(rid).x >= visible_characters) {
6341-
break;
6342-
}
6343-
line_count++;
6344-
}
6330+
line_count += main->lines[i].text_buf->get_line_count();
63456331
}
63466332
return line_count;
63476333
}

0 commit comments

Comments
 (0)