diff options
Diffstat (limited to 'scene/gui/label.cpp')
-rw-r--r-- | scene/gui/label.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index e83c062e8a..566d77e3fd 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -64,16 +64,17 @@ bool Label::is_uppercase() const { } int Label::get_line_height(int p_line) const { + Ref<Font> font = get_theme_font("font"); if (p_line >= 0 && p_line < lines_rid.size()) { - return TS->shaped_text_get_size(lines_rid[p_line]).y; + return TS->shaped_text_get_size(lines_rid[p_line]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM); } else if (lines_rid.size() > 0) { int h = 0; for (int i = 0; i < lines_rid.size(); i++) { - h = MAX(h, TS->shaped_text_get_size(lines_rid[i]).y); + h = MAX(h, TS->shaped_text_get_size(lines_rid[i]).y) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM); } return h; } else { - return get_theme_font("font")->get_height(get_theme_font_size("font_size")); + return font->get_height(get_theme_font_size("font_size")); } } @@ -138,6 +139,7 @@ void Label::_shape() { void Label::_update_visible() { int line_spacing = get_theme_constant("line_spacing", "Label"); Ref<StyleBox> style = get_theme_stylebox("normal", "Label"); + Ref<Font> font = get_theme_font("font"); int lines_visible = lines_rid.size(); if (max_lines_visible >= 0 && lines_visible > max_lines_visible) { @@ -147,7 +149,7 @@ void Label::_update_visible() { minsize.height = 0; int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped); for (int64_t i = lines_skipped; i < last_line; i++) { - minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; if (minsize.height > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } @@ -197,7 +199,7 @@ void Label::_notification(int p_what) { // Get number of lines to fit to the height. for (int64_t i = lines_skipped; i < lines_rid.size(); i++) { - total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } @@ -213,7 +215,7 @@ void Label::_notification(int p_what) { // Get real total height. total_h = 0; for (int64_t i = lines_skipped; i < last_line; i++) { - total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; } int vbegin = 0, vsep = 0; @@ -249,8 +251,10 @@ void Label::_notification(int p_what) { if (percent_visible < 1) { int total_glyphs = 0; for (int i = lines_skipped; i < last_line; i++) { - const Vector<TextServer::Glyph> glyphs = TS->shaped_text_get_glyphs(lines_rid[i]); - for (int j = 0; j < glyphs.size(); j++) { + const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(lines_rid[i]); + const TextServer::Glyph *glyphs = visual.ptr(); + int gl_size = visual.size(); + for (int j = 0; j < gl_size; j++) { if ((glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { total_glyphs++; } @@ -263,7 +267,7 @@ void Label::_notification(int p_what) { ofs.y = style->get_offset().y + vbegin; for (int i = lines_skipped; i < last_line; i++) { ofs.x = 0; - ofs.y += TS->shaped_text_get_ascent(lines_rid[i]); + ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(Font::SPACING_TOP); switch (align) { case ALIGN_FILL: case ALIGN_LEFT: { @@ -285,11 +289,13 @@ void Label::_notification(int p_what) { } break; } - const Vector<TextServer::Glyph> glyphs = TS->shaped_text_get_glyphs(lines_rid[i]); + const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(lines_rid[i]); + const TextServer::Glyph *glyphs = visual.ptr(); + int gl_size = visual.size(); float x = ofs.x; int outlines_drawn = glyhps_drawn; - for (int j = 0; j < glyphs.size(); j++) { + for (int j = 0; j < gl_size; j++) { for (int k = 0; k < glyphs[j].repeat; k++) { if (glyphs[j].font_rid != RID()) { if (font_color_shadow.a > 0) { @@ -318,7 +324,7 @@ void Label::_notification(int p_what) { } ofs.x = x; - for (int j = 0; j < glyphs.size(); j++) { + for (int j = 0; j < gl_size; j++) { for (int k = 0; k < glyphs[j].repeat; k++) { if (glyphs[j].font_rid != RID()) { TS->font_draw_glyph(glyphs[j].font_rid, ci, glyphs[j].font_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off), glyphs[j].index, font_color); @@ -337,7 +343,7 @@ void Label::_notification(int p_what) { } } - ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing; + ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(Font::SPACING_BOTTOM); } } @@ -381,12 +387,13 @@ int Label::get_line_count() const { } int Label::get_visible_line_count() const { + Ref<Font> font = get_theme_font("font"); Ref<StyleBox> style = get_theme_stylebox("normal"); int line_spacing = get_theme_constant("line_spacing"); int lines_visible = 0; float total_h = 0; for (int64_t i = lines_skipped; i < lines_rid.size(); i++) { - total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } |