diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-07-22 07:48:09 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-07-22 07:48:29 +0300 |
commit | 93ccf8e9e4b76e64fd5a09e31f0455cdf9bd2ff1 (patch) | |
tree | 39f1ae860507be1de58b3bebd278612802a9933b | |
parent | e25f3c0d38d457b15a63720240736f564ce0501b (diff) | |
download | redot-engine-93ccf8e9e4b76e64fd5a09e31f0455cdf9bd2ff1.tar.gz |
[RTL] Fix text size rounding with MSDF fonts.
-rw-r--r-- | doc/classes/TextParagraph.xml | 2 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 14 |
2 files changed, 8 insertions, 8 deletions
diff --git a/doc/classes/TextParagraph.xml b/doc/classes/TextParagraph.xml index 541078ed22..c6511a2b8e 100644 --- a/doc/classes/TextParagraph.xml +++ b/doc/classes/TextParagraph.xml @@ -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"> diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 5ef02bf19d..1da3668ebe 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -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++; @@ -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. @@ -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; @@ -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; } |