-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] Add support for loading OpenType fonts from memory. #82
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: NiLuJe <[email protected]>
Co-authored-by: NiLuJe <[email protected]>
Co-authored-by: NiLuJe <[email protected]>
fclose(f); | ||
} | ||
int result = add_ot_font_data(data, style, ot_fonts); | ||
free(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a problem ;).
(The data is still live, stbtt doesn't make a copy, it just keeps a reference to that same pointer).
fontcount); | ||
} | ||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weeelll, except font_info->data
only exists after stbtt_InitFont
;p.
The point about ownership still stands, though ;p.
return ERRCODE(EXIT_FAILURE); | ||
} | ||
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
if (!font_info) { | ||
PFWARN("Error allocating stbtt_fontinfo struct: %m"); | ||
free(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
This change is