Facepunch / garrysmod-requests

Feature requests for Garry's Mod
86 stars 24 forks source link

Fallback font list for `surface.CreateFont` #2493

Open Denneisk opened 1 month ago

Denneisk commented 1 month ago

I think having a feature to specify a fallback font(s), in the case that a certain desired font can't be loaded, would be helpful. My ideal implementation would be to allow a list of font names instead of a single font name string for the font field.

surface.CreateFont( "MyCoolFont", {
    font = { "my cool ttf", "comic sans ms", "coolvetica" }
}) -- Will try to load 3 fonts before using the default fallback

The error Couldn't find/load font 'my cool ttf', falling back to 'Tahoma'.. should not occur, and instead an error would only appear if the last case "coolvetica" fails to load. Any failures before the last case should be silent.

My intention for this is for developers who would like to leverage OS-installed fonts without having to require the user to download any additional fonts from an addon/server. Similar to their use in web design, fallback fonts allow for a more consistent visual style in the case that a certain desired font cannot load for any reason.

garryspins commented 1 month ago

This or surface.IsFontValid so we could implement it ourselves, would much prefer that.

Denneisk commented 1 month ago

The idea did cross my mind, but I feel like the convenience of not having to write your own parser for a list of desired fonts would be helpful, too. If anything, with such a function, it could be implemented entirely in Lua.