Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .ttc and .otc extensions to font file selection dialogs #91782

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timothyqiu
Copy link
Member

When trying to change the editor's main font, .ttc and .otc fonts were not listed in the dialog. Changing the filter to "All Files" and selecting such fonts works.

@timothyqiu timothyqiu added this to the 4.3 milestone May 10, 2024
@timothyqiu timothyqiu requested a review from a team as a code owner May 10, 2024 02:02
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TTC and OTC files contain multiple subfonts, so if using it is allowed for editor, it would make sense to also expose face_index to actually select which of subfonts to use. Something like:

diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index c019d46034..0a8b5a1f37 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -446,6 +446,11 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
 	EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
 	EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font_bold", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
 	EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/code_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
+
+	EDITOR_SETTING(Variant::INT, PROPERTY_HINT_NONE, "main_font_face_index", 0, "");
+	EDITOR_SETTING(Variant::INT, PROPERTY_HINT_NONE, "main_font_bold_face_index", 0, "");
+	EDITOR_SETTING(Variant::INT, PROPERTY_HINT_NONE, "code_font_face_index", 0, "");
+
 	_initial_set("interface/editor/separate_distraction_mode", false);
 	_initial_set("interface/editor/automatically_open_screenshots", true);
 	EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
diff --git a/editor/themes/editor_fonts.cpp b/editor/themes/editor_fonts.cpp
index c13ee6e6b0..fe47a64e2f 100644
--- a/editor/themes/editor_fonts.cpp
+++ b/editor/themes/editor_fonts.cpp
@@ -206,8 +206,13 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
 
 	// Init base font configs and load custom fonts.
 	String custom_font_path = EDITOR_GET("interface/editor/main_font");
+	int custom_font_face_index = EDITOR_GET("interface/editor/main_font_face_index");
+
 	String custom_font_path_bold = EDITOR_GET("interface/editor/main_font_bold");
+	int custom_font_bold_face_index = EDITOR_GET("interface/editor/main_font_bold_face_index");
+
 	String custom_font_path_source = EDITOR_GET("interface/editor/code_font");
+	int custom_font_source_face_index = EDITOR_GET("interface/editor/code_font_face_index");
 
 	Ref<FontVariation> default_fc;
 	default_fc.instantiate();
@@ -219,6 +224,7 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
 			custom_font->set_fallbacks(fallback_custom);
 		}
 		default_fc->set_base_font(custom_font);
+		default_fc->set_variation_face_index(custom_font_face_index);
 	} else {
 		EditorSettings::get_singleton()->set_manually("interface/editor/main_font", "");
 		default_fc->set_base_font(default_font);
@@ -236,6 +242,7 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
 			custom_font->set_fallbacks(fallback_custom);
 		}
 		default_fc_msdf->set_base_font(custom_font);
+		default_fc_msdf->set_variation_face_index(custom_font_face_index);
 	} else {
 		EditorSettings::get_singleton()->set_manually("interface/editor/main_font", "");
 		default_fc_msdf->set_base_font(default_font_msdf);
@@ -253,6 +260,7 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
 			custom_font->set_fallbacks(fallback_custom);
 		}
 		bold_fc->set_base_font(custom_font);
+		bold_fc->set_variation_face_index(custom_font_bold_face_index);
 	} else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
 		Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning);
 		{
@@ -279,6 +287,7 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
 			custom_font->set_fallbacks(fallback_custom);
 		}
 		bold_fc_msdf->set_base_font(custom_font);
+		bold_fc_msdf->set_variation_face_index(custom_font_bold_face_index);
 	} else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
 		Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning);
 		{
@@ -305,6 +314,7 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
 			custom_font->set_fallbacks(fallback_custom);
 		}
 		mono_fc->set_base_font(custom_font);
+		mono_fc->set_variation_face_index(custom_font_source_face_index);
 	} else {
 		EditorSettings::get_singleton()->set_manually("interface/editor/code_font", "");
 		mono_fc->set_base_font(default_font_mono);

@timothyqiu timothyqiu marked this pull request as draft May 10, 2024 06:25
@timothyqiu
Copy link
Member Author

I think it'll be hard for users to determine which index they want to use without seeing the actual name.

Seems have to add a related property hint / editor first.

@bruvzg
Copy link
Member

bruvzg commented May 10, 2024

Seems have to add a related property hint / editor first.

Adding some sort of UI would be nice, then we can also expose the rest of variation properties for the editor fonts as well.

@timothyqiu timothyqiu removed this from the 4.3 milestone May 10, 2024
@AThousandShips AThousandShips added this to the 4.x milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants