-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
The problems with Fonts as Assets
-
When a
Font’s asset handles are dropped, the font data isn’t deleted because Cosmic Text clones theArcholding the font data and stores it in itsFontDb. Once a font is added to the database, it can’t be removed. The only way to remove fonts is to create a newFontDbinstance without the font you want to remove. Creating a new database changes all fontIDs, which requires regenerating all font atlases, text data, and layouts. This is all very expensive and probably not something that should happen automatically. -
If a font handle is dropped and its font asset is unloaded, its old
FontDbentry isn't overwritten. Instead, if you reload the same font again later, a new entry for the font data is added to cosmic text'sFontDb, alongside the old one. -
Font's are normally static data, there isn't a lot of need for applications to load and unload them dynamically.
-
Fontassets can contain multiple faces, but the handle can only be used to reference one of them. -
Font texture atlases are created per font instance and aren't disposed of automatically. Naively animating the
FontSizefor aTextentity can create easily create hundreds of texture atlases that persist and accumulate.
Some naive suggestions
-
Load fonts once during
Appcreation. -
Remove (the non-working) support for unloading fonts.
-
Load fonts using
Assets but hide the handle. Add an extension method onCommandslike:commands.load_font("fonts/FiraSans-Bold.ttf");Internally load the font data using an asset loader. Once the font data is loaded, automatically add it to Cosmic Text's database and then drop the handle.
-
Manage and dispose of font atlases using an LRU buffer.
-
Only allow fonts to be referenced by name string or by a generic font family enum.
-
Add a helper function/system that constructs a new a
FontDbinstance from a filtered set of fonts, replaces the existing database, and regenerates all the associated text data.