diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-07-07 15:27:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-07 15:27:11 +0200 |
commit | 284a322277067c0c185d2cd5ddfd83e9b5875b6d (patch) | |
tree | 6a27258a05f97d927ddd4ee778405064953d4ae9 /editor/editor_fonts.cpp | |
parent | 1b8711b56cb904f302a4b7e9ae33239ff47e6a9e (diff) | |
parent | a319e6e6232f3e6b9056bd26822f5aa3738b6cd6 (diff) |
Merge pull request #62818 from bruvzg/font_reg_fixes
Diffstat (limited to 'editor/editor_fonts.cpp')
-rw-r--r-- | editor/editor_fonts.cpp | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 8deee57dc9..d58dc98f07 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -164,11 +164,6 @@ void editor_register_fonts(Ref<Theme> p_theme) { default_font_bold_msdf->set_fallbacks(fallbacks_bold); Ref<FontFile> default_font_mono = load_internal_font(_font_JetBrainsMono_Regular, _font_JetBrainsMono_Regular_size, font_hinting, font_antialiased, true, font_subpixel_positioning); - { - Dictionary opentype_features_mono; - opentype_features_mono["calt"] = 0; - default_font_mono->set_opentype_feature_overrides(opentype_features_mono); // Disable contextual alternates (coding ligatures). - } default_font_mono->set_fallbacks(fallbacks); // Init base font configs and load custom fonts. @@ -276,23 +271,45 @@ void editor_register_fonts(Ref<Theme> p_theme) { EditorSettings::get_singleton()->set_manually("interface/editor/code_font", ""); mono_fc->set_base_font(default_font_mono); } + mono_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE); + mono_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE); - String code_font_custom_variations = EditorSettings::get_singleton()->get("interface/editor/code_font_custom_variations"); - Dictionary variations_mono; - if (!code_font_custom_variations.is_empty()) { - Vector<String> variation_tags = code_font_custom_variations.split(","); - for (int i = 0; i < variation_tags.size(); i++) { - Vector<String> subtag_a = variation_tags[i].split("="); - if (subtag_a.size() == 2) { - variations_mono[TS->name_to_tag(subtag_a[0])] = subtag_a[1].to_float(); - } else if (subtag_a.size() == 1) { - variations_mono[TS->name_to_tag(subtag_a[0])] = 1; + Ref<FontVariation> mono_other_fc = mono_fc->duplicate(); + + // Enable contextual alternates (coding ligatures) and custom features for the source editor font. + int ot_mode = EditorSettings::get_singleton()->get("interface/editor/code_font_contextual_ligatures"); + switch (ot_mode) { + case 1: { // Disable ligatures. + Dictionary ftrs; + ftrs[TS->name_to_tag("calt")] = 0; + mono_fc->set_opentype_features(ftrs); + } break; + case 2: { // Custom. + Vector<String> subtag = String(EditorSettings::get_singleton()->get("interface/editor/code_font_custom_opentype_features")).split(","); + Dictionary ftrs; + for (int i = 0; i < subtag.size(); i++) { + Vector<String> subtag_a = subtag[i].split("="); + if (subtag_a.size() == 2) { + ftrs[TS->name_to_tag(subtag_a[0])] = subtag_a[1].to_int(); + } else if (subtag_a.size() == 1) { + ftrs[TS->name_to_tag(subtag_a[0])] = 1; + } } - } - mono_fc->set_variation_opentype(variations_mono); + mono_fc->set_opentype_features(ftrs); + } break; + default: { // Default. + Dictionary ftrs; + ftrs[TS->name_to_tag("calt")] = 1; + mono_fc->set_opentype_features(ftrs); + } break; + } + + { + // Disable contextual alternates (coding ligatures). + Dictionary ftrs; + ftrs[TS->name_to_tag("calt")] = 0; + mono_other_fc->set_opentype_features(ftrs); } - mono_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE); - mono_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE); 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)); @@ -359,11 +376,11 @@ void editor_register_fonts(Ref<Theme> p_theme) { p_theme->set_font("source", "EditorFonts", mono_fc); p_theme->set_font_size("expression_size", "EditorFonts", (int(EDITOR_GET("interface/editor/code_font_size")) - 1) * EDSCALE); - p_theme->set_font("expression", "EditorFonts", mono_fc); + p_theme->set_font("expression", "EditorFonts", mono_other_fc); 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_fc); + p_theme->set_font("output_source", "EditorFonts", mono_other_fc); p_theme->set_font_size("status_source_size", "EditorFonts", default_font_size); - p_theme->set_font("status_source", "EditorFonts", mono_fc); + p_theme->set_font("status_source", "EditorFonts", mono_other_fc); } |