Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

notmarek
Copy link

@notmarek notmarek commented Jan 17, 2025

This change is Reviewable

fbink.c Outdated Show resolved Hide resolved
fbink.c Outdated Show resolved Hide resolved
fbink.c Outdated Show resolved Hide resolved
notmarek and others added 3 commits January 17, 2025 20:43
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);
Copy link
Owner

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);
Copy link
Owner

@NiLuJe NiLuJe Jan 17, 2025

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".

Copy link
Owner

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);
Copy link
Owner

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants