memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.06k stars 767 forks source link

FONS_GLYPH_BITMAP_OPTIONAL doesn't inhibit FT_LOAD in fons__tt_buildGlyphBitmap #643

Open mulle-nat opened 1 year ago

mulle-nat commented 1 year ago

nanovg uses the FONS_GLYPH_BITMAP_OPTIONAL flag in various places to avoid the creation of superflous font atlas entries for glyphs. The actual glyph information is queried by fons__tt_buildGlyphBitmap , which always uses FT_LOAD_RENDER to render a (then unneeded) bitmap though. This is probably expensive and could be avoided, by passing an extra parameter to fons__tt_buildGlyphBitmap, telling FreeType not to.

fontstash.h:

    ftError = FT_Load_Glyph(font->font, glyph, FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT);
    if (ftError) return 0;

The same should be done for stb_truetype (or could be harmlessly ignored, if not supported there).