[feat] Add support for loading OpenType fonts from memory.#82
Open
notmarek wants to merge 5 commits intoNiLuJe:masterfrom
Open
[feat] Add support for loading OpenType fonts from memory.#82notmarek wants to merge 5 commits intoNiLuJe:masterfrom
notmarek wants to merge 5 commits intoNiLuJe:masterfrom
Conversation
NiLuJe
reviewed
Jan 17, 2025
NiLuJe
reviewed
Jan 17, 2025
NiLuJe
reviewed
Jan 17, 2025
NiLuJe
reviewed
Jan 17, 2025
| fclose(f); | ||
| } | ||
| int result = add_ot_font_data(data, style, ot_fonts); | ||
| free(data); |
Owner
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).
NiLuJe
reviewed
Jan 17, 2025
| // Then, get the offset to the first font | ||
| const int fontoffset = stbtt_GetFontOffsetForIndex(data, 0); | ||
| if (fontoffset == -1) { | ||
| free(data); |
Owner
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".
Owner
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.
NiLuJe
reviewed
Jan 17, 2025
| // 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); |
NiLuJe
reviewed
Jan 17, 2025
| stbtt_fontinfo* font_info = calloc(1U, sizeof(stbtt_fontinfo)); | ||
| if (!font_info) { | ||
| PFWARN("Error allocating stbtt_fontinfo struct: %m"); | ||
| free(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change is