Page MenuHome

BLF: Fonts with FT_Face Optional
ClosedPublic

Authored by Harley Acheson (harley) on Jun 21 2022, 10:02 PM.

Details

Summary

Allow FontBLFs to exist with NULL FT_Face, added when actually needed.


With this patch installed, the fallback fonts do not load with FT_Face, and one is only created when the font is actually required. This not only speeds up startup, but unused language fonts will never be loaded.

Diff Detail

Repository
rB Blender

Event Timeline

Harley Acheson (harley) requested review of this revision.Jun 21 2022, 10:02 PM
Harley Acheson (harley) created this revision.
Harley Acheson (harley) edited the summary of this revision. (Show Details)Jun 22 2022, 3:24 AM
Harley Acheson (harley) edited the summary of this revision. (Show Details)

Only drop the faces of the fallback members, not the main fonts.

Harley Acheson (harley) retitled this revision from BLF Experiment: Fonts with FT_Face Optional to BLF WIP: Fonts with FT_Face Optional.

Now have coverage details for the suggested fonts in source, so we can have those without loading the faces. Startup is faster without loading the faces for all fonts. And unused fonts are never loaded.

Currently seems a bit ugly. I think I need to find a way to make it prettier and more obvious, otherwise might seems confusing and complex. Might just need better naming and good comments.

Much simpler. If the font is in the static list of details, don't load the face, otherwise do.

Ensuring that kerning cache table gets created. No need for flags in eFaceDetails, just use same last_resort detection.

Harley Acheson (harley) retitled this revision from BLF WIP: Fonts with FT_Face Optional to BLF: Fonts with FT_Face Optional.

Improved comments.

Harley Acheson (harley) edited the summary of this revision. (Show Details)Jun 26 2022, 9:06 PM
Brecht Van Lommel (brecht) requested changes to this revision.Jun 27 2022, 4:26 PM

Approach looks fine, but some issues regarding error handling.

source/blender/blenfont/intern/blf_font.c
1162

This assumes blf_ensure_face can't fail, but it can leave font->face NULL currently.

1274

There should be some mechanism that prevents it from repeatedly trying to reload the same file on failure. Either with some boolean that indicates there was an error before or creating a dummy empty font face.

1286

This will end up calling FT_Done_Face a second time on the same font->face on blf_font_free, in some cases.

1378

Replace MEM_freeN with a call to blf_font_free. And then remove the call from FT_Done_Face from blf_ensure_face, leaving blf_font_free to clean up everything. That also prevent leaking font->filepath.

1442

Should this check if if(font->face), it's not clear this function accepts NULL.

This revision now requires changes to proceed.Jun 27 2022, 4:26 PM
Harley Acheson (harley) marked 5 inline comments as done.Jun 28 2022, 3:00 AM

completing current review items.

@Brecht Van Lommel (brecht) - There should be some mechanism that prevents it from repeatedly trying to reload the same file on failure...

Doing this with (another) font flag keeps this entirely within blf_ensure_face. Seems to make sense.

This revision is now accepted and ready to land.Jun 28 2022, 3:22 PM

Updated to the current state of master.

Harley Acheson (harley) planned changes to this revision.Jul 7 2022, 11:34 PM

Harley: careful update to master required after Variable font commit

Updated to the current state of master. Also moved a few more things into blf_ensure_face that can be avoided until a face is needed.

This revision is now accepted and ready to land.Jul 8 2022, 3:58 AM
This revision was automatically updated to reflect the committed changes.