Skip to content

Commit 61003f1

Browse files
committed
[Label] Add MSDF pixel range/outline configuration warning.
1 parent d705613 commit 61003f1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

scene/gui/label.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,43 @@ PackedStringArray Label::get_configuration_warnings() const {
657657
}
658658
}
659659

660+
Ref<FontFile> ff = font;
661+
if (ff.is_valid() && ff->is_multichannel_signed_distance_field()) {
662+
bool has_settings = settings.is_valid();
663+
int font_size = settings.is_valid() ? settings->get_font_size() : theme_cache.font_size;
664+
int outline_size = has_settings ? settings->get_outline_size() : theme_cache.font_outline_size;
665+
Vector<LabelSettings::StackedOutlineData> stacked_outline_datas = has_settings ? settings->get_stacked_outline_data() : Vector<LabelSettings::StackedOutlineData>();
666+
Vector<LabelSettings::StackedShadowData> stacked_shadow_datas = has_settings ? settings->get_stacked_shadow_data() : Vector<LabelSettings::StackedShadowData>();
667+
int max_outline_draw_size = outline_size;
668+
if (stacked_outline_datas.size() != 0) {
669+
int draw_iterations = stacked_outline_datas.size();
670+
for (int j = 0; j < draw_iterations; j++) {
671+
int stacked_outline_size = stacked_outline_datas[j].size;
672+
if (stacked_outline_size <= 0) {
673+
continue;
674+
}
675+
max_outline_draw_size += stacked_outline_size;
676+
}
677+
}
678+
if (stacked_shadow_datas.size() != 0) {
679+
int draw_iterations = stacked_shadow_datas.size();
680+
for (int j = 0; j < draw_iterations; j++) {
681+
LabelSettings::StackedShadowData stacked_shadow_data = stacked_shadow_datas[j];
682+
if (stacked_shadow_data.outline_size > 0) {
683+
max_outline_draw_size = MAX(max_outline_draw_size, stacked_shadow_data.outline_size);
684+
}
685+
}
686+
}
687+
float scale = (float)font_size / (float)ff->get_msdf_size();
688+
float ol = (float)max_outline_draw_size / scale / 4.0;
689+
float pxr = (float)ff->get_msdf_pixel_range() / 2.0 - 1.0;
690+
float r_pxr = (ol + 1.0) * 2.0;
691+
692+
if (ol > pxr) {
693+
warnings.push_back(vformat(RTR("MSDF font pixel range is too small, some outlines/shadows will not render. Set MSDF pixel range to be at least %d to render all outlines/shadows."), Math::ceil(r_pxr)));
694+
}
695+
}
696+
660697
return warnings;
661698
}
662699

@@ -857,6 +894,7 @@ void Label::_notification(int p_what) {
857894
case NOTIFICATION_THEME_CHANGED: {
858895
font_dirty = true;
859896
queue_redraw();
897+
update_configuration_warnings();
860898
} break;
861899

862900
case NOTIFICATION_RESIZED: {
@@ -1070,6 +1108,7 @@ void Label::set_text(const String &p_string) {
10701108
void Label::_invalidate() {
10711109
font_dirty = true;
10721110
queue_redraw();
1111+
update_configuration_warnings();
10731112
}
10741113

10751114
void Label::set_label_settings(const Ref<LabelSettings> &p_settings) {
@@ -1082,6 +1121,7 @@ void Label::set_label_settings(const Ref<LabelSettings> &p_settings) {
10821121
settings->connect_changed(callable_mp(this, &Label::_invalidate), CONNECT_REFERENCE_COUNTED);
10831122
}
10841123
_invalidate();
1124+
update_configuration_warnings();
10851125
}
10861126
}
10871127

0 commit comments

Comments
 (0)