Fix T99872: Crash Loading Embedded Fonts - 3.3

Ensure kerning cache exists when loading embedded fonts

---

When loading embedded fonts from memory the font->kerning_cache is not
created and so we get a crash if the font does support kerning.
This was not caught because the loading of packed fonts was not
actually doing anything in VSE until {523bc981cfee}.

We have since consolidated `blf_font_new` and `blf_font_new_from_mem`
into a single function so that they cannot get out of sync like this
any more.  So this fix is specific to Blender 3.3.  But we can add this
as a candidate for corrective release 3.2.3

Reviewed By: brecht

Maniphest Tasks: T99872

Differential Revision: https://developer.blender.org/D15704
This commit is contained in:
Harley Acheson 2022-11-09 09:27:59 +01:00 committed by Sergey Sharybin
parent e86b5230ca
commit 19202736d5
Notes: blender-bot 2023-02-13 22:38:46 +01:00
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
Referenced by issue #99872, Regression: Crashes when using packed text font in VSE
1 changed files with 14 additions and 3 deletions

View File

@ -1356,13 +1356,24 @@ FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int m
return NULL;
}
font->name = BLI_strdup(name);
font->filepath = NULL;
blf_font_fill(font);
if (FT_HAS_MULTIPLE_MASTERS(font->face)) {
FT_Get_MM_Var(font->face, &(font->variations));
}
font->name = BLI_strdup(name);
font->filepath = NULL;
blf_font_fill(font);
if (FT_HAS_KERNING(font->face)) {
/* Create kerning cache table and fill with value indicating "unset". */
font->kerning_cache = MEM_mallocN(sizeof(KerningCacheBLF), __func__);
for (uint i = 0; i < KERNING_CACHE_TABLE_SIZE; i++) {
for (uint j = 0; j < KERNING_CACHE_TABLE_SIZE; j++) {
font->kerning_cache->ascii_table[i][j] = KERNING_ENTRY_UNSET;
}
}
}
return font;
}