Merge pull request #62860 from Calinou/editor-log-bold-italic-mono-fonts

Define bold, italics and mono fonts in editor log for `print_rich()`
This commit is contained in:
Rémi Verschelde 2022-10-04 10:30:22 +02:00
commit 3a5eac7ca3
2 changed files with 42 additions and 5 deletions

View File

@ -317,6 +317,24 @@ void editor_register_fonts(Ref<Theme> p_theme) {
mono_other_fc->set_opentype_features(ftrs); mono_other_fc->set_opentype_features(ftrs);
} }
// Use fake bold/italics to style the editor log's `print_rich()` output.
// Use stronger embolden strength to make bold easier to distinguish from regular text.
Ref<FontVariation> mono_other_fc_bold = mono_other_fc->duplicate();
mono_other_fc_bold->set_variation_embolden(0.8);
Ref<FontVariation> mono_other_fc_italic = mono_other_fc->duplicate();
mono_other_fc_italic->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
Ref<FontVariation> mono_other_fc_bold_italic = mono_other_fc->duplicate();
mono_other_fc_bold_italic->set_variation_embolden(0.8);
mono_other_fc_bold_italic->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
Ref<FontVariation> mono_other_fc_mono = mono_other_fc->duplicate();
// Use a different font style to distinguish `[code]` in rich prints.
// This emulates the "faint" styling used in ANSI escape codes by using a slightly thinner font.
mono_other_fc_mono->set_variation_embolden(-0.25);
mono_other_fc_mono->set_variation_transform(Transform2D(1.0, 0.1, 0.0, 1.0, 0.0, 0.0));
Ref<FontVariation> italic_fc = default_fc->duplicate(); Ref<FontVariation> italic_fc = default_fc->duplicate();
italic_fc->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0)); italic_fc->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
@ -386,6 +404,10 @@ void editor_register_fonts(Ref<Theme> p_theme) {
p_theme->set_font_size("output_source_size", "EditorFonts", int(EDITOR_GET("run/output/font_size")) * EDSCALE); p_theme->set_font_size("output_source_size", "EditorFonts", int(EDITOR_GET("run/output/font_size")) * EDSCALE);
p_theme->set_font("output_source", "EditorFonts", mono_other_fc); p_theme->set_font("output_source", "EditorFonts", mono_other_fc);
p_theme->set_font("output_source_bold", "EditorFonts", mono_other_fc_bold);
p_theme->set_font("output_source_italic", "EditorFonts", mono_other_fc_italic);
p_theme->set_font("output_source_bold_italic", "EditorFonts", mono_other_fc_bold_italic);
p_theme->set_font("output_source_mono", "EditorFonts", mono_other_fc_mono);
p_theme->set_font_size("status_source_size", "EditorFonts", default_font_size); p_theme->set_font_size("status_source_size", "EditorFonts", default_font_size);
p_theme->set_font("status_source", "EditorFonts", mono_other_fc); p_theme->set_font("status_source", "EditorFonts", mono_other_fc);

View File

@ -65,19 +65,34 @@ void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_f
} }
void EditorLog::_update_theme() { void EditorLog::_update_theme() {
Ref<Font> normal_font = get_theme_font(SNAME("output_source"), SNAME("EditorFonts")); const Ref<Font> normal_font = get_theme_font(SNAME("output_source"), SNAME("EditorFonts"));
if (normal_font.is_valid()) { if (normal_font.is_valid()) {
log->add_theme_font_override("normal_font", normal_font); log->add_theme_font_override("normal_font", normal_font);
} }
log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts"))); const Ref<Font> bold_font = get_theme_font(SNAME("output_source_bold"), SNAME("EditorFonts"));
log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4));
Ref<Font> bold_font = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
if (bold_font.is_valid()) { if (bold_font.is_valid()) {
log->add_theme_font_override("bold_font", bold_font); log->add_theme_font_override("bold_font", bold_font);
} }
const Ref<Font> italics_font = get_theme_font(SNAME("output_source_italic"), SNAME("EditorFonts"));
if (italics_font.is_valid()) {
log->add_theme_font_override("italics_font", italics_font);
}
const Ref<Font> bold_italics_font = get_theme_font(SNAME("output_source_bold_italic"), SNAME("EditorFonts"));
if (bold_italics_font.is_valid()) {
log->add_theme_font_override("bold_italics_font", bold_italics_font);
}
const Ref<Font> mono_font = get_theme_font(SNAME("output_source_mono"), SNAME("EditorFonts"));
if (mono_font.is_valid()) {
log->add_theme_font_override("mono_font", mono_font);
}
log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts")));
log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4));
type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_theme_icon(SNAME("Popup"), SNAME("EditorIcons"))); type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_theme_icon(SNAME("Popup"), SNAME("EditorIcons")));
type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons")));
type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_icon(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons"))); type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_icon(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));