Getting and using installed system font family members
After a little more research it seems this is not currently possible to do in Godot. So I’ve added a proposal for an addition to SystemFont to support specifying font style names and getting a list of available such styles per font family.
You can support the proposal or contribute to the discussion here:
github.com/godotengine/godot-proposals
#### Add style_name support to SystemFont to allow using specific members of font families
opened 06:38PM - 06 Feb 25 UTC
lostminds
### Describe the project you are working on A non-game application where the us…er can select fonts from the system to use in the application ### Describe the problem or limitation you are having in your project With the addition of https://github.com/godotengine/godot/pull/62973 we now have support for accessing fonts installed on the system via the SystemFont class. And we can get a list of the names of the installed fonts via OS.get_system_fonts(). However, a limitation to this is that the list only provides the font family names of the installed fonts (such as "Roboto" or "Arial") but there is no way to get the names of the members of the font family, for example Thin, Italic, Semi-Bold, Bold-Italic etc. Below is an example of the font family Roboto as seen in the macOS font manager. !Image When loading a font from file, this name is accessible via get_style_name() so to keep with this convention I'll call this name `style_name` from now on. However, there is no way to specify this `style_name` in SystemFont to access a specific font version. Instead, what you can do is specify `font_weight` or `font_italic` to try and find bold or italic style versions. There is also no way to get what style_name members a font family has (could be just one or twelve, with various names), which makes it impossible to present a selector interface to select available system fonts where you can also show and pick the different variations of each font. ### Describe the feature / enhancement and how it helps to overcome the problem or limitation First complement the existing `OS.get_system_fonts()` with a new `OS.get_system_font_style_names(font_family_name)` which would return an array containing the style names of all members of the installed font identified with the font family name (if any). Second, extend the SystemFont class with a `font_style_names` property. This would work together with the font_names property to pick which font family member is selected and used by SystemFont. If `font_style_names` is set this should be used first and the `font_weight`, `font_italic` etc properties are disregarded if a match is found in the `font_style_names` array. However, in the spirit of the current implementation they could still be used as fallbacks. So for example if you specify a `style_names` "Thin" and `font_weight` 100 this could fall back to some other light style with low weight if no style named "Thin" is found. ### Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams To get and populate a font selector list you could do something like: ``` var font_family_names:PackedStringArray = OS.get_system_fonts() var font_style_names:PackedStringArray for font_family_name:String in font_family_names: font_style_names = OS.get_system_font_style_names(font_family_name) # add selector items / sub-items based on font_family_name and font_style_names ``` To use a specific font style, for example Roboto Thin Italic you would then use: ``` var robotoFont:SystemFont = SystemFont.new() robotoFont.font_names = ["Roboto"] robotoFont.font_style_names = ["Thin Italic"] ``` or some user-selected font version using ``` var userFont:SystemFont = SystemFont.new() userFont.font_names = [selected_font_family_name] userFont.font_style_names = [selected_font_style_name] ``` ### If this enhancement will not be used often, can it be worked around with a few lines of script? No, it's currently not possible to get a list of installed font family members, at least not via the Godot font system. Possibly you could try getting paths to the system font files and try to list the files in these directories and try guess based on the filenames. But this seems inefficient and prone to errors. It is also not possible to select a specific known font style member of an installed system font. In simple cases (like if there's a "Bold" style) it could be selected by setting the font family name as SystemFont `font_names` and setting `font_weight` to a guessed value of what the "Bold" style would have. But this will be increasingly difficult with style names like "Semi-Bold", "Book", "Roman", "Caption", "Display" etc that may not just refer to weight (and you don't know if they exist for this font). ### Is there a reason why this should be core and not an add-on in the asset library? Both SystemFont and the OS.get_system_fonts() function are core components, and the proposed support for getting and specifying font_style_names I think would allow them to be used as I think the original intention with the features was.