Merge pull request #62818 from bruvzg/font_reg_fixes
This commit is contained in:
commit
284a322277
4 changed files with 95 additions and 82 deletions
|
@ -1638,37 +1638,34 @@ void CodeTextEditor::_apply_settings_change() {
|
|||
font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size");
|
||||
int ot_mode = EditorSettings::get_singleton()->get("interface/editor/code_font_contextual_ligatures");
|
||||
|
||||
Ref<Font> fb = text_editor->get_theme_font(SNAME("font"));
|
||||
Ref<FontVariation> fc = fb;
|
||||
if (fc.is_null()) {
|
||||
fc.instantiate();
|
||||
fc->set_base_font(fb);
|
||||
}
|
||||
|
||||
switch (ot_mode) {
|
||||
case 1: { // Disable ligatures.
|
||||
fc->set_opentype_features(Dictionary());
|
||||
} 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;
|
||||
Ref<FontVariation> fc = text_editor->get_theme_font(SNAME("font"));
|
||||
if (fc.is_valid()) {
|
||||
switch (ot_mode) {
|
||||
case 1: { // Disable ligatures.
|
||||
Dictionary ftrs;
|
||||
ftrs[TS->name_to_tag("calt")] = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
default: { // Default.
|
||||
Dictionary ftrs;
|
||||
ftrs[TS->name_to_tag("calt")] = 1;
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
default: { // Default.
|
||||
Dictionary ftrs;
|
||||
ftrs[TS->name_to_tag("calt")] = 1;
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
text_editor->add_theme_font_override("font", fc);
|
||||
|
||||
text_editor->set_code_hint_draw_below(EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line"));
|
||||
|
||||
|
@ -1870,34 +1867,33 @@ CodeTextEditor::CodeTextEditor() {
|
|||
text_editor->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
int ot_mode = EditorSettings::get_singleton()->get("interface/editor/code_font_contextual_ligatures");
|
||||
Ref<Font> fb = text_editor->get_theme_font(SNAME("font"));
|
||||
Ref<FontVariation> fc = fb;
|
||||
if (fc.is_null()) {
|
||||
fc.instantiate();
|
||||
fc->set_base_font(fb);
|
||||
}
|
||||
switch (ot_mode) {
|
||||
case 1: { // Disable ligatures.
|
||||
fc->set_opentype_features(Dictionary());
|
||||
} 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;
|
||||
Ref<FontVariation> fc = text_editor->get_theme_font(SNAME("font"));
|
||||
if (fc.is_valid()) {
|
||||
switch (ot_mode) {
|
||||
case 1: { // Disable ligatures.
|
||||
Dictionary ftrs;
|
||||
ftrs[TS->name_to_tag("calt")] = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
default: { // Default.
|
||||
Dictionary ftrs;
|
||||
ftrs[TS->name_to_tag("calt")] = 1;
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
default: { // Default.
|
||||
Dictionary ftrs;
|
||||
ftrs[TS->name_to_tag("calt")] = 1;
|
||||
fc->set_opentype_features(ftrs);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
text_editor->add_theme_font_override("font", fc);
|
||||
|
||||
|
|
|
@ -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,24 +271,46 @@ 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
mono_fc->set_variation_opentype(variations_mono);
|
||||
}
|
||||
mono_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
|
||||
mono_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
|
||||
|
||||
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_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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -3697,7 +3697,7 @@ void CanvasItemEditor::_draw_transform_message() {
|
|||
return;
|
||||
}
|
||||
|
||||
Ref<FontFile> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
Point2 msgpos = Point2(RULER_WIDTH + 5 * EDSCALE, viewport->get_size().y - 20 * EDSCALE);
|
||||
viewport->draw_string(font, msgpos + Point2(1, 1), transform_message, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8));
|
||||
|
|
|
@ -2081,7 +2081,7 @@ Ref<Font> RichTextLabel::_find_font(Item *p_item) {
|
|||
fontitem = fontitem->parent;
|
||||
}
|
||||
|
||||
return Ref<FontFile>();
|
||||
return Ref<Font>();
|
||||
}
|
||||
|
||||
int RichTextLabel::_find_font_size(Item *p_item) {
|
||||
|
@ -4002,7 +4002,7 @@ void RichTextLabel::append_text(const String &p_bbcode) {
|
|||
if (subtag_a.size() == 2) {
|
||||
if (subtag_a[0] == "name" || subtag_a[0] == "n") {
|
||||
String fnt = subtag_a[1];
|
||||
Ref<Font> font_data = ResourceLoader::load(fnt, "FontFile");
|
||||
Ref<Font> font_data = ResourceLoader::load(fnt, "Font");
|
||||
if (font_data.is_valid()) {
|
||||
fc->set_base_font(font_data);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue