From 863dd9aa46aff502f7425ea6045de93bf09b76a3 Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Mon, 19 Mar 2018 20:48:43 +0700 Subject: [PATCH] Always emit dynamic font change in update_oversampling Fixes #15787. The issue occurred when two (or more) separate DynamicFont instances used the same DynamicFontAtSize instance due to having equal properties. The first instance updated its data_at_size and emitted "changed" signal, but the second did not because it considered the data_at_size to be up to date, even though it has just been updated. --- scene/gui/label.cpp | 4 ++-- scene/resources/default_theme/default_theme.cpp | 2 +- scene/resources/dynamic_font.cpp | 15 ++++++--------- scene/resources/dynamic_font.h | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index f74c2372c9e..f1b0d36f325 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -93,7 +93,7 @@ void Label::_notification(int p_what) { bool use_outline = get_constant("shadow_as_outline"); Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); int line_spacing = get_constant("line_spacing"); - Color font_outline_modulator = get_color("font_outline_modulator"); + Color font_outline_modulate = get_color("font_outline_modulate"); style->draw(ci, Rect2(Point2(0, 0), get_size())); @@ -151,7 +151,7 @@ void Label::_notification(int p_what) { int line = 0; int line_to = lines_skipped + (lines_visible > 0 ? lines_visible : 1); - FontDrawer drawer(font, font_outline_modulator); + FontDrawer drawer(font, font_outline_modulate); while (wc) { /* handle lines not meant to be drawn quickly */ if (line >= line_to) diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 5b9ebbd4e96..5ac9344f313 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -415,7 +415,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_color("font_color", "Label", Color(1, 1, 1)); theme->set_color("font_color_shadow", "Label", Color(0, 0, 0, 0)); - theme->set_color("font_outline_modulator", "Label", Color(1, 1, 1)); + theme->set_color("font_outline_modulate", "Label", Color(1, 1, 1)); theme->set_constant("shadow_offset_x", "Label", 1 * scale); theme->set_constant("shadow_offset_y", "Label", 1 * scale); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 0f8db44596a..f41a26a680e 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -444,7 +444,7 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp ret.x = 0; ret.y = 0; - int texsize = MAX(id.size * 8, 256); + int texsize = MAX(id.size * oversampling * 8, 256); if (mw > texsize) texsize = mw; //special case, adapt to it? if (mh > texsize) @@ -644,11 +644,9 @@ void DynamicFontAtSize::_update_char(CharType p_char) { char_map[p_char] = character; } -bool DynamicFontAtSize::update_oversampling() { - if (oversampling == font_oversampling) - return false; - if (!valid) - return false; +void DynamicFontAtSize::update_oversampling() { + if (oversampling == font_oversampling || !valid) + return; FT_Done_FreeType(library); textures.clear(); @@ -656,8 +654,6 @@ bool DynamicFontAtSize::update_oversampling() { oversampling = font_oversampling; valid = false; _load(); - - return true; } DynamicFontAtSize::DynamicFontAtSize() { @@ -1082,7 +1078,8 @@ void DynamicFont::update_oversampling() { SelfList *E = dynamic_fonts.first(); while (E) { - if (E->self()->data_at_size.is_valid() && E->self()->data_at_size->update_oversampling()) { + if (E->self()->data_at_size.is_valid()) { + E->self()->data_at_size->update_oversampling(); changed.push_back(Ref(E->self())); } E = E->next(); diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index f024465ccde..f460bca2d49 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -192,7 +192,7 @@ public: 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; void set_texture_flags(uint32_t p_flags); - bool update_oversampling(); + void update_oversampling(); DynamicFontAtSize(); ~DynamicFontAtSize();