1
0
Fork 0

Merge pull request #94606 from bruvzg/rtl_msdf_r

[RTL] Fix text size rounding with MSDF fonts.
This commit is contained in:
Rémi Verschelde 2024-07-22 14:13:17 +02:00
commit 6694f55f40
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 8 additions and 8 deletions

View File

@ -175,7 +175,7 @@
<return type="Vector2" /> <return type="Vector2" />
<param index="0" name="line" type="int" /> <param index="0" name="line" type="int" />
<description> <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> </description>
</method> </method>
<method name="get_line_underline_position" qualifiers="const"> <method name="get_line_underline_position" qualifiers="const">

View File

@ -828,14 +828,14 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
break; break;
} }
const Size2 line_size = l.text_buf->get_line_size(line); double l_height = l.text_buf->get_line_ascent(line) + l.text_buf->get_line_descent(line);
if (p_ofs.y + off.y + line_size.y <= 0) { if (p_ofs.y + off.y + l_height <= 0) {
off.y += line_size.y; off.y += l_height;
continue; continue;
} }
float width = l.text_buf->get_width(); float width = l.text_buf->get_width();
float length = line_size.x; float length = l.text_buf->get_line_size(line).x;
// Draw line. // Draw line.
line_count++; line_count++;
@ -5139,7 +5139,7 @@ void RichTextLabel::scroll_to_selection() {
if (range.x <= selection.from_char && range.y >= selection.from_char) { if (range.x <= selection.from_char && range.y >= selection.from_char) {
break; 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. // 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)) { if ((line_count <= p_line) && (line_count + main->lines[i].text_buf->get_line_count() >= p_line)) {
float line_offset = 0.f; float line_offset = 0.f;
for (int j = 0; j < p_line - line_count; j++) { 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); vscroll->set_value(main->lines[i].offset.y + line_offset);
return; 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())) { if ((line_count <= p_line) && (p_line <= line_count + main->lines[i].text_buf->get_line_count())) {
float line_offset = 0.f; float line_offset = 0.f;
for (int j = 0; j < p_line - line_count; j++) { 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; return main->lines[i].offset.y + line_offset;
} }