[feat] Add support for loading OpenType fonts from memory. - #82
Conversation
| fclose(f); | ||
| } | ||
| int result = add_ot_font_data(data, style, ot_fonts); | ||
| free(data); |
There was a problem hiding this comment.
That's a problem ;).
(The data is still live, stbtt doesn't make a copy, it just keeps a reference to that same pointer).
| // Then, get the offset to the first font | ||
| const int fontoffset = stbtt_GetFontOffsetForIndex(data, 0); | ||
| if (fontoffset == -1) { | ||
| free(data); |
There was a problem hiding this comment.
In the same vein, this needs to be free(font_info->data);
Which implies that we take ownership of the pointer, which might be a problem for your usecase (e.g., pointer to static content), so this may need to be more complex to add a way to say "nope, this data is immutable, don't ever try to free it".
There was a problem hiding this comment.
Weeelll, except font_info->data only exists after stbtt_InitFont ;p.
The point about ownership still stands, though ;p.
| // First, check if we can actually find a recognizable font format in the data... | ||
| const int fontcount = stbtt_GetNumberOfFonts(data); | ||
| if (fontcount == 0) { | ||
| free(data); |
| stbtt_fontinfo* font_info = calloc(1U, sizeof(stbtt_fontinfo)); | ||
| if (!font_info) { | ||
| PFWARN("Error allocating stbtt_fontinfo struct: %m"); | ||
| free(data); |
|



This change is