Skip to content
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

Fonts: lazy loading #615

Merged
merged 2 commits into from Nov 26, 2022
Merged

Fonts: lazy loading #615

merged 2 commits into from Nov 26, 2022

Conversation

DevCharly
Copy link
Collaborator

This PR introduced lazy loading of font files.
This avoids loading of unused fonts and reduces startup time.
Loading first font file takes about 150-200 milliseconds, subsequent font files 5-10 ms.

To use lazy loading, install the font with installLazy() instead of install(). E.g.

FlatRobotoFont.installLazy();

When FlatLaf uses the font, it automatically loads the font files.

When using new Font(...), you need to first invoke FontUtils.loadFontFamily(family) to ensure that the font family is loaded. E.g.:

FontUtils.loadFontFamily( FlatRobotoFont.FAMILY );
Font font = new Font( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );

Or use following:

Font font = FontUtils.getCompositeFont( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );

@DevCharly DevCharly added this to the 3.0 milestone Nov 21, 2022
@DevCharly DevCharly merged commit 95b4366 into main Nov 26, 2022
@DevCharly DevCharly deleted the fonts-lazy-loading branch November 28, 2022 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant