-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds basic support for working with system fonts #16365
base: main
Are you sure you want to change the base?
Conversation
Awesome! I swapped to this branch locally with my playground example and every locale now displays without the need to load any external font files 🎊 I suppose this does increase the need for users to have the ability to control |
If it's enabled by default, add an example that shows how to disable this feature. Reasoning is simple: if an app is shipped with a font, why waste time loading all system fonts? IMO add something like: So user will have simple way, and control when to load. |
I've left it is a feature that's disabled by default. To enable system fonts, you enable the |
I've just noticed #14150, was that effort abandoned? |
I never saw that! Looks like it wasn't linked to the original issue. I'm happy to incorporate changes from that PR, or close this out in favour of that one, I'll leave that up to the reviewers. |
Most likely not a Bevy issue, but the example hangs on my macbook when it eventually tries to load edit: I think this reproduces in bare cosmic, but was fixed in an unreleased commit. I'll make an issue to beg for a release over there. |
Also added a mapping between `AssetId<Font>` and `fontdb::ID` to avoid creating new assets and handles when it's not required.
Objective
cosmic_text
font fallback causes inconsistent text rendering results #16354Solution
system_font
, which will instructcosmic_text
to begin loading system fonts on startup.FontLibrary
, which allows for convenient searching of all loaded fonts, returning aHandle<Font>
if you have found a suitable candidate.system_fonts
, which demonstrates searching for and using system fonts.Testing
system_fonts
exampleShowcase
Users now have access to the
FontLibrary
system parameter, which allows searching for available fonts. This helps with using the newsystem_fonts
feature, which will load system fonts at runtime.In the below snippets,
fonts
is of typeFontLibrary
Notes
Loading system fonts increases startup time by a few seconds. I suspect this is platform dependent, and is largely out of our control.The startup cost is now negligible (I cannot measure the difference, much less than a second), since moving system font loading onto a background task. I do believe it's worth keeping this behind a feature gate as it's already organised this way, and there may be a performance cost on some platforms. More options for the user is better IMO.system_fonts
feature is enabled on a platformcosmic_text
does not support, it is simply a no-op, making the feature safe to enable in all cases.FontLibrary
system param could use some more methods, such as an iterator. I have deliberately only exposed afind
method since we need to do some work with theAssets<Font>
to ensure it's available for theTextPipeline
.Font
type assumes every font will have binary data associated with it (thedata
field). For system fonts this is not the case. I'm simply inserting no data (empty slice) for these fonts. It might be prudent to updateFont
to be anenum
instead to make this more clear.