Getting and using installed system font family members

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:

Hello! Sorry to necro an old topic - I am in the same boat as you, trying to make an application in Godot that would benefit from a system font picker. I read over the GitHub discussion and it seems there aren’t any great options at the moment.

I just wanted to ask if you’ve found a solution to your font picker problems. There seem to be precious few resources on the topic, so I’m curious if you’ve found a workaround or managed to build something that works well enough.

No, unfortunately not. My initial research about it basically ended in realizing this was a limitation in Godot that was hard to get around, and me writing that proposal to get a discussion started. I’d still like this functionality, but I’ve since then just put it on the backlog and concentrated on other features.

If you’re going to make a try for it I did think of a couple of different approaches that I might try if I get back to this, maybe you could get some inspiration from these. In all these cases I’m thinking of periodically (like at startup) somehow building up my own database of installed system fonts with font variants.
To do this some possible options could be:

  • Use the Godot supplied list of font family names OS.get_system_fonts(), and then iterate over different common style names with SystemFont to see if any of them return a different font (meaning these fonts styles exist). The drawbacks are kind of obvious, and it’s probably both very slow and resource wasteful, but it’s quite easy to build and should get most installed font versions if you test enough common style names.
  • Use the Godot system font access to get access to the system font paths, then use file system access to try and find all font files in this location and from there try to get the installed different fonts. Not sure how/if this would work, but it’s a different approach at least.
  • Try to build a custom C# font manager that uses either built in .net system font access (if that exists) or some cross-platform system font C# library or .net module, and get access to the system font list with style variants that way bypassing the Godot font system.
  • And a forth approach I just thought of now: You might be able to get the installed fonts via command line tools. On linux there’s apparently a command fc-list, and on macOS there’s atsutil fonts -list if there’s one on windows as well that could be used to get the available fonts. Found Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' might work on windows, but haven’t tested it (yet).

Let me know if you try any of these or if you figure out some other way.