Page MenuHome

VFont: Refactor of check_freetypefont()
ClosedPublic

Authored by Harley Acheson (harley) on Jul 28 2021, 10:04 PM.

Details

Summary

Refactor of our Vfont check for font validity.


No functional changes here, just a correction of function that is confusing.

When about to load a vfont (used for 3D text objects) we check that the font is valid. But this function does not work as it appears. It currently does this:

glyph_index = FT_Get_Char_Index(face, 'A');
err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);

So it tries to obtain the glpyh index for the uppercase letter "A", if it can do so it loads that glyph and does further tests, if not errors out.

First, we should not deem a font invalid because it does not include latin letters. There are many valid and useful fonts without the letter "A" and everything in blender works fine with such fonts.

But more importantly this check doesn't work as it seems. The return of FT_Get_Char_Index for a font that does not include 'A' is zero. And that is a valid glyph index (as long as there is at least one). So this doesn't return an error if the font does not contain 'A'.

A better way to do this is to instead call FT_Get_First_Char() which always just gives you first glyph.

The current function also does not call FT_Done_Face() which should occur after opening a face with FT_New_Memory_Face.

This also reorganizes the function to be a bit shorter and easier to read.

Diff Detail

Repository
rB Blender

Event Timeline

Harley Acheson (harley) requested review of this revision.Jul 28 2021, 10:04 PM
Harley Acheson (harley) created this revision.
This revision is now accepted and ready to land.Sep 10 2021, 7:19 AM
Harley Acheson (harley) retitled this revision from Refactor of check_freetypefont() to VFont: Refactor of check_freetypefont().
Harley Acheson (harley) edited the summary of this revision. (Show Details)

Updating to current state of master.

This revision was automatically updated to reflect the committed changes.