Godot Version
4.3
Question
I’m trying to build a font selector where the user can use pick between installed systems fonts to use.
Using OS.get_system_fonts() I can get a list of all installed font family names on the system. However, the issue I’m running into is that this is just the first step to picking a font. Each such font family usually has a number of style variations (from 1 up to 12), like Bold, Italic, This, Regular, Roman, Semi-Bold etc. And to identify and select a specific font you need to know both the font family name and the style name. For example “Roboto Light Italic”. However, I’ve found no way of finding what style members each font family has.
Given a font family name from the OS.get_system_fonts() list (like “Roboto”), is there a way to get what style variations are available for this font family?
The way to use a system font is then via the SystemFont class, which works sort of like a query where you can assign a number of font_names
(family names) and traits (like font_italic
and font_weight
values). But it works with fallbacks, so if no match is found you get the closest fallback instead of nothing. And there seems to be no way of getting them by their style name (like “Thin”, “Roman” or “Semi-bold”)? So if you were able to get the names of the style members of a font family, how would you get that specific system font?
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:
opened 06:38PM - 06 Feb 25 UTC
### 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](https://docs.godotengine.org/en/stable/classes/class_systemfont.html) class. And we can get a list of the names of the installed fonts via [OS.get_system_fonts()](https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-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.

When loading a font from file, this name is accessible via [get_style_name()](https://docs.godotengine.org/en/stable/classes/class_font.html#class-font-method-get-font-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](https://docs.godotengine.org/en/stable/classes/class_systemfont.html#class-systemfont-property-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.