From 60cf7dc32103b6e7326ba45e3a7662066f2b472a Mon Sep 17 00:00:00 2001 From: Elia Sarti Date: Wed, 25 Dec 2019 10:23:45 +0100 Subject: [PATCH] Add ability to specify font scale for RichTextLabel Also fixes #5557. --- editor/editor_help.cpp | 6 +- scene/gui/rich_text_label.cpp | 112 +++++++++++++++++++++++-------- scene/gui/rich_text_label.h | 9 +++ scene/resources/dynamic_font.cpp | 16 ++--- scene/resources/dynamic_font.h | 7 +- scene/resources/font.cpp | 14 ++-- scene/resources/font.h | 18 +++-- 7 files changed, 130 insertions(+), 52 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index bbbb50297f73..f8238d088df2 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -508,6 +508,9 @@ void EditorHelp::_update_doc() { _add_text(cd.properties[i].name); + class_desc->pop(); + class_desc->pop(); + if (describe) { class_desc->pop(); property_descr = true; @@ -525,9 +528,6 @@ void EditorHelp::_update_doc() { class_desc->pop(); } - class_desc->pop(); - class_desc->pop(); - class_desc->pop(); } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index abca865ae025..4a5406121d29 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1,4 +1,4 @@ -/*************************************************************************/ +/*************************************************************************/ /* rich_text_label.cpp */ /*************************************************************************/ /* This file is part of: */ @@ -194,10 +194,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (cfont.is_null()) cfont = p_base_font; + real_t cfont_scale = _find_font_scale(it); //line height should be the font height for the first time, this ensures that an empty line will never have zero height and successive newlines are displayed - int line_height = cfont->get_height(); - int line_ascent = cfont->get_ascent(); - int line_descent = cfont->get_descent(); + int line_height = cfont->get_height() * cfont_scale; + int line_ascent = cfont->get_ascent() * cfont_scale; + int line_descent = cfont->get_descent() * cfont_scale; int nonblank_line_count = 0; //number of nonblank lines as counted during PROCESS_DRAW @@ -230,6 +231,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & l.ascent_caches.push_back(line_ascent); \ l.descent_caches.push_back(line_descent); \ l.space_caches.push_back(spaces); \ + wofs = begin; \ } \ line_wrapped = false; \ y += line_height + get_constant(SceneStringNames::get_singleton()->line_separation); \ @@ -238,7 +240,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & line_descent = 0; \ spaces = 0; \ spaces_size = 0; \ - wofs = begin; \ align_ofs = 0; \ if (p_mode != PROCESS_CACHE) { \ lh = line < l.height_caches.size() ? l.height_caches[line] : 1; \ @@ -322,7 +323,13 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (it != l.from) { ItemIndent *indent_it = static_cast(it); - int indent = indent_it->level * tab_size * cfont->get_char_size(' ').width; + Ref font = _find_font(it); + if (font.is_null()) + font = p_base_font; + + real_t font_scale = _find_font_scale(it); + + int indent = indent_it->level * tab_size * Math::round(cfont->get_char_size(' ').width * font_scale); margin += indent; begin += indent; wofs += indent; @@ -337,10 +344,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (font.is_null()) font = p_base_font; + real_t font_scale = _find_font_scale(it); const CharType *c = text->text.c_str(); const CharType *cf = c; - int ascent = font->get_ascent(); - int descent = font->get_descent(); + int ascent = Math::round(font->get_ascent() * font_scale); + int descent = Math::round(font->get_descent() * font_scale); Color color; Color font_color_shadow; @@ -391,9 +399,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } while (c[end] != 0 && !(end && c[end - 1] == ' ' && c[end] != ' ')) { - int cw = font->get_char_size(c[end], c[end + 1]).width; + int cw = Math::round(font->get_char_size(c[end], c[end + 1]).width * font_scale); if (c[end] == '\t') { - cw = tab_size * font->get_char_size(' ').width; + cw = Math::round(tab_size * font->get_char_size(' ').width * font_scale); } if (end > 0 && w + cw + begin > p_width) { @@ -414,7 +422,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (end && c[end - 1] == ' ') { if (p_mode == PROCESS_CACHE) { - spaces_size += font->get_char_size(' ').width; + spaces_size += Math::round(font->get_char_size(' ').width * font_scale); } else if (align == ALIGN_FILL) { int ln = MIN(l.offset_caches.size() - 1, line); if (l.space_caches[ln]) { @@ -434,10 +442,10 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (p_mode == PROCESS_POINTER && r_click_char && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) { //int o = (wofs+w)-p_click_pos.x; - int cw = font->get_char_size(c[i], c[i + 1]).x; + int cw = Math::round(font->get_char_size(c[i], c[i + 1]).x * font_scale); if (c[i] == '\t') { - cw = tab_size * font->get_char_size(' ').width; + cw = tab_size * Math::round(font->get_char_size(' ').width * font_scale); } if (p_click_pos.x - cw / 2 > p_ofs.x + align_ofs + pofs) { @@ -548,32 +556,32 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (visible) { if (selected) { - cw = font->get_char_size(fx_char, c[i + 1]).x; + cw = font->get_char_size(fx_char, c[i + 1]).x * font_scale; draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg); } if (p_font_color_shadow.a > 0) { float x_ofs_shadow = align_ofs + pofs; float y_ofs_shadow = y + lh - line_descent; - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + shadow_ofs + fx_offset, fx_char, c[i + 1], p_font_color_shadow); + font->draw_char_scaled(ci, Point2(x_ofs_shadow, y_ofs_shadow) + shadow_ofs + fx_offset, font_scale, fx_char, c[i + 1], p_font_color_shadow); if (p_shadow_as_outline) { - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, shadow_ofs.y) + fx_offset, fx_char, c[i + 1], p_font_color_shadow); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(shadow_ofs.x, -shadow_ofs.y) + fx_offset, fx_char, c[i + 1], p_font_color_shadow); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, -shadow_ofs.y) + fx_offset, fx_char, c[i + 1], p_font_color_shadow); + font->draw_char_scaled(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, shadow_ofs.y) + fx_offset, font_scale, fx_char, c[i + 1], p_font_color_shadow); + font->draw_char_scaled(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(shadow_ofs.x, -shadow_ofs.y) + fx_offset, font_scale, fx_char, c[i + 1], p_font_color_shadow); + font->draw_char_scaled(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, -shadow_ofs.y) + fx_offset, font_scale, fx_char, c[i + 1], p_font_color_shadow); } } if (selected) { - drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), fx_char, c[i + 1], override_selected_font_color ? selection_fg : fx_color); + drawer.draw_char_scaled(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), font_scale, fx_char, c[i + 1], override_selected_font_color ? selection_fg : fx_color); } else { - cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color); + cw = drawer.draw_char_scaled(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, font_scale, fx_char, c[i + 1], fx_color); } } p_char_count++; if (c[i] == '\t') { - cw = tab_size * font->get_char_size(' ').width; + cw = tab_size * Math::round(font->get_char_size(' ').width * font_scale); } ofs += cw; @@ -621,22 +629,25 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (font.is_null()) font = p_base_font; + real_t font_scale = _find_font_scale(it); + if (p_mode == PROCESS_POINTER && r_click_char) *r_click_char = 0; ENSURE_WIDTH(img->size.width); - bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->size.height, img->size.height)); + bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - Math::round(font->get_descent() * font_scale) - img->size.height, img->size.height)); + if (visible) line_is_blank = false; if (p_mode == PROCESS_DRAW && visible) { - img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size)); + img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - Math::round(font->get_descent() * font_scale) - img->size.height), img->size)); } p_char_count++; ADVANCE(img->size.width); - CHECK_HEIGHT((img->size.height + font->get_descent())); + CHECK_HEIGHT((img->size.height + Math::round(font->get_descent() * font_scale))); } break; case ITEM_NEWLINE: { @@ -1316,6 +1327,24 @@ Ref RichTextLabel::_find_font(Item *p_item) { return Ref(); } +real_t RichTextLabel::_find_font_scale(Item *p_item) { + + Item *sizeitem = p_item; + + while (sizeitem) { + + if (sizeitem->type == ITEM_FONT_SCALE) { + + ItemScaleFont *fi = static_cast(sizeitem); + return fi->scale; + } + + sizeitem = sizeitem->parent; + } + + return 0; +} + int RichTextLabel::_find_margin(Item *p_item, const Ref &p_base_font) { Item *item = p_item; @@ -1330,9 +1359,11 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref &p_base_font) { if (font.is_null()) font = p_base_font; + real_t font_scale = _find_font_scale(item); + ItemIndent *indent = static_cast(item); - margin += indent->level * tab_size * font->get_char_size(' ').width; + margin += indent->level * tab_size * Math::round(font->get_char_size(' ').width * font_scale); } else if (item->type == ITEM_LIST) { @@ -1467,7 +1498,7 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) { if (from && from != to) { - if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) + if (from->type != ITEM_FONT && from->type != ITEM_FONT_SCALE && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) return true; for (List::Element *E = from->subitems.front(); E; E = E->next()) { @@ -1724,6 +1755,16 @@ void RichTextLabel::push_font(const Ref &p_font) { _add_item(item, true); } +void RichTextLabel::push_font_scale(real_t scale) { + + ERR_FAIL_COND(current->type == ITEM_TABLE); + ERR_FAIL_COND(scale <= 0); + ItemScaleFont *item = memnew(ItemScaleFont); + + item->scale = scale; + _add_item(item, true); +} + void RichTextLabel::push_normal() { Ref normal_font = get_font("normal_font"); ERR_FAIL_COND(normal_font.is_null()); @@ -2281,6 +2322,16 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("font"); + } else if (tag.begins_with("font_scale=")) { + + float size = tag.substr(11, tag.length()).to_float(); + + if (size > 0) + push_font_scale(size); + + pos = brk_end + 1; + tag_stack.push_front("font_scale"); + } else if (tag.begins_with("fade")) { Vector tags = tag.split(" ", false); int startIndex = 0; @@ -2485,7 +2536,13 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p _validate_line_caches(main); - int fh = _find_font(t).is_valid() ? _find_font(t)->get_height() : get_font("normal_font")->get_height(); + Ref font = _find_font(t); + if (!font.is_valid()) + font = get_font("normal_font"); + + real_t font_scale = _find_font_scale(it); + + int fh = Math::round(font->get_height() * font_scale); float offset = 0; @@ -2780,6 +2837,7 @@ void RichTextLabel::_bind_methods() { BIND_ENUM_CONSTANT(ITEM_IMAGE); BIND_ENUM_CONSTANT(ITEM_NEWLINE); BIND_ENUM_CONSTANT(ITEM_FONT); + BIND_ENUM_CONSTANT(ITEM_FONT_SCALE); BIND_ENUM_CONSTANT(ITEM_COLOR); BIND_ENUM_CONSTANT(ITEM_UNDERLINE); BIND_ENUM_CONSTANT(ITEM_STRIKETHROUGH); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index b9837fdfcc66..9ebaa7519c3c 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -61,6 +61,7 @@ class RichTextLabel : public Control { ITEM_IMAGE, ITEM_NEWLINE, ITEM_FONT, + ITEM_FONT_SCALE, ITEM_COLOR, ITEM_UNDERLINE, ITEM_STRIKETHROUGH, @@ -157,6 +158,12 @@ class RichTextLabel : public Control { ItemFont() { type = ITEM_FONT; } }; + struct ItemScaleFont : public Item { + + real_t scale; + ItemScaleFont() { type = ITEM_FONT_SCALE; } + }; + struct ItemColor : public Item { Color color; ItemColor() { type = ITEM_COLOR; } @@ -372,6 +379,7 @@ class RichTextLabel : public Control { void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL); Ref _find_font(Item *p_item); + real_t _find_font_scale(Item *p_item); int _find_margin(Item *p_item, const Ref &p_base_font); Align _find_align(Item *p_item); Color _find_color(Item *p_item, const Color &p_default_color); @@ -416,6 +424,7 @@ class RichTextLabel : public Control { void push_bold_italics(); void push_italics(); void push_mono(); + void push_font_scale(real_t scale); void push_color(const Color &p_color); void push_underline(); void push_strikethrough(); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 75245719565b..1d232239f577 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -299,7 +299,7 @@ void DynamicFontAtSize::set_texture_flags(uint32_t p_flags) { } } -float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector > &p_fallbacks, bool p_advance_only) const { +float DynamicFontAtSize::draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next, const Color &p_modulate, const Vector > &p_fallbacks, bool p_advance_only) const { if (!valid) return 0; @@ -319,18 +319,18 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT if (!p_advance_only && ch->texture_idx != -1) { Point2 cpos = p_pos; - cpos.x += ch->h_align; - cpos.y -= font->get_ascent(); - cpos.y += ch->v_align; + cpos.x += ch->h_align * p_scale; + cpos.y -= font->get_ascent() * p_scale; + cpos.y += ch->v_align * p_scale; Color modulate = p_modulate; if (FT_HAS_COLOR(face)) { modulate.r = modulate.g = modulate.b = 1.0; } RID texture = font->textures[ch->texture_idx].texture->get_rid(); - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size), texture, ch->rect_uv, modulate, false, RID(), false); + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size * p_scale), texture, ch->rect_uv, modulate, false, RID(), false); } - advance = ch->advance; + advance = ch->advance * p_scale; } return advance; @@ -864,7 +864,7 @@ bool DynamicFont::has_outline() const { return outline_cache_id.outline_size > 0; } -float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { +float DynamicFont::draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { const Ref &font_at_size = p_outline && outline_cache_id.outline_size > 0 ? outline_data_at_size : data_at_size; if (!font_at_size.is_valid()) @@ -875,7 +875,7 @@ float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_ // If requested outline draw, but no outline is present, simply return advance without drawing anything bool advance_only = p_outline && outline_cache_id.outline_size == 0; - return font_at_size->draw_char(p_canvas_item, p_pos, p_char, p_next, color, fallbacks, advance_only) + spacing_char; + return font_at_size->draw_char_scaled(p_canvas_item, p_pos, p_scale, p_char, p_next, color, fallbacks, advance_only) + spacing_char; } void DynamicFont::set_fallback(int p_idx, const Ref &p_data) { diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index d0a709a2d35f..b0724c3d2569 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -192,7 +192,10 @@ class DynamicFontAtSize : public Reference { Size2 get_char_size(CharType p_char, CharType p_next, const Vector > &p_fallbacks) const; - float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector > &p_fallbacks, bool p_advance_only = false) const; + float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector > &p_fallbacks, bool p_advance_only = false) const { + return draw_char_scaled(p_canvas_item, p_pos, 1.0, p_char, p_next, p_modulate, p_fallbacks, p_advance_only); + } + float draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next, const Color &p_modulate, const Vector > &p_fallbacks, bool p_advance_only = false) const; void set_texture_flags(uint32_t p_flags); void update_oversampling(); @@ -283,7 +286,7 @@ class DynamicFont : public Font { virtual bool has_outline() const; - virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; + virtual float draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; SelfList font_list; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 124e4d37e67b..12f0adcdc914 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -540,26 +540,26 @@ Ref BitmapFont::get_fallback() const { return fallback; } -float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { +float BitmapFont::draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { const Character *c = char_map.getptr(p_char); if (!c) { if (fallback.is_valid()) - return fallback->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate, p_outline); + return fallback->draw_char_scaled(p_canvas_item, p_pos, p_scale, p_char, p_next, p_modulate, p_outline); return 0; } ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); if (!p_outline && c->texture_idx != -1) { Point2 cpos = p_pos; - cpos.x += c->h_align; - cpos.y -= ascent; - cpos.y += c->v_align; - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx]->get_rid(), c->rect, p_modulate, false, RID(), false); + cpos.x += c->h_align * p_scale; + cpos.y -= ascent * p_scale; + cpos.y += c->v_align * p_scale; + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size * p_scale), textures[c->texture_idx]->get_rid(), c->rect, p_modulate, false, RID(), false); } - return get_char_size(p_char, p_next).width; + return get_char_size(p_char, p_next).width * p_scale; } Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const { diff --git a/scene/resources/font.h b/scene/resources/font.h index 9b99b85d224f..f2822e093ef9 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -58,7 +58,10 @@ class Font : public Resource { void draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, float p_width, const String &p_text, const Color &p_modulate = Color(1, 1, 1), const Color &p_outline_modulate = Color(1, 1, 1)) const; virtual bool has_outline() const { return false; } - virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const = 0; + virtual float draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const = 0; + float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const { + return draw_char_scaled(p_canvas_item, p_pos, 1.0, p_char, p_next, p_modulate, p_outline); + } void update_changes(); Font(); @@ -73,6 +76,7 @@ class FontDrawer { struct PendingDraw { RID canvas_item; Point2 pos; + float scale; CharType chr; CharType next; Color modulate; @@ -88,17 +92,21 @@ class FontDrawer { } float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) { + return draw_char_scaled(p_canvas_item, p_pos, 1.0, p_char, p_next, p_modulate); + } + + float draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) { if (has_outline) { - PendingDraw draw = { p_canvas_item, p_pos, p_char, p_next, p_modulate }; + PendingDraw draw = { p_canvas_item, p_pos, p_scale, p_char, p_next, p_modulate }; pending_draws.push_back(draw); } - return font->draw_char(p_canvas_item, p_pos, p_char, p_next, has_outline ? outline_color : p_modulate, has_outline); + return font->draw_char_scaled(p_canvas_item, p_pos, p_scale, p_char, p_next, has_outline ? outline_color : p_modulate, has_outline); } ~FontDrawer() { for (int i = 0; i < pending_draws.size(); ++i) { const PendingDraw &draw = pending_draws[i]; - font->draw_char(draw.canvas_item, draw.pos, draw.chr, draw.next, draw.modulate, false); + font->draw_char_scaled(draw.canvas_item, draw.pos, draw.scale, draw.chr, draw.next, draw.modulate, false); } } }; @@ -192,7 +200,7 @@ class BitmapFont : public Font { void set_distance_field_hint(bool p_distance_field); bool is_distance_field_hint() const; - float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; + float draw_char_scaled(RID p_canvas_item, const Point2 &p_pos, float p_scale, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; BitmapFont(); ~BitmapFont();