Skip to content

Commit

Permalink
Merge pull request #94606 from bruvzg/rtl_msdf_r
Browse files Browse the repository at this point in the history
[RTL] Fix text size rounding with MSDF fonts.
  • Loading branch information
akien-mga committed Jul 22, 2024
2 parents 7bcb447 + 93ccf8e commit 6694f55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit 6694f55

Please sign in to comment.