Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTL] Fix text size rounding with MSDF fonts. #94606

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/classes/TextParagraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<return type="Vector2" />
<param index="0" name="line" type="int" />
<description>
Returns size of the bounding box of the line of text.
Returns size of the bounding box of the line of text. Returned size is rounded up.
</description>
</method>
<method name="get_line_underline_position" qualifiers="const">
Expand Down
14 changes: 7 additions & 7 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,14 +828,14 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
break;
}

const Size2 line_size = l.text_buf->get_line_size(line);
if (p_ofs.y + off.y + line_size.y <= 0) {
off.y += line_size.y;
double l_height = l.text_buf->get_line_ascent(line) + l.text_buf->get_line_descent(line);
if (p_ofs.y + off.y + l_height <= 0) {
off.y += l_height;
continue;
}

float width = l.text_buf->get_width();
float length = line_size.x;
float length = l.text_buf->get_line_size(line).x;

// Draw line.
line_count++;
Expand Down Expand Up @@ -5139,7 +5139,7 @@ void RichTextLabel::scroll_to_selection() {
if (range.x <= selection.from_char && range.y >= selection.from_char) {
break;
}
line_offset += selection.from_frame->lines[selection.from_line].text_buf->get_line_size(i).y + theme_cache.line_separation;
line_offset += selection.from_frame->lines[selection.from_line].text_buf->get_line_ascent(i) + selection.from_frame->lines[selection.from_line].text_buf->get_line_descent(i) + theme_cache.line_separation;
}

// Add nested frame (e.g. table cell) offset.
Expand Down Expand Up @@ -5191,7 +5191,7 @@ void RichTextLabel::scroll_to_line(int p_line) {
if ((line_count <= p_line) && (line_count + main->lines[i].text_buf->get_line_count() >= p_line)) {
float line_offset = 0.f;
for (int j = 0; j < p_line - line_count; j++) {
line_offset += main->lines[i].text_buf->get_line_size(j).y + theme_cache.line_separation;
line_offset += main->lines[i].text_buf->get_line_ascent(j) + main->lines[i].text_buf->get_line_descent(j) + theme_cache.line_separation;
}
vscroll->set_value(main->lines[i].offset.y + line_offset);
return;
Expand All @@ -5211,7 +5211,7 @@ float RichTextLabel::get_line_offset(int p_line) {
if ((line_count <= p_line) && (p_line <= line_count + main->lines[i].text_buf->get_line_count())) {
float line_offset = 0.f;
for (int j = 0; j < p_line - line_count; j++) {
line_offset += main->lines[i].text_buf->get_line_size(j).y + theme_cache.line_separation;
line_offset += main->lines[i].text_buf->get_line_ascent(j) + main->lines[i].text_buf->get_line_descent(j) + theme_cache.line_separation;
}
return main->lines[i].offset.y + line_offset;
}
Expand Down
Loading