Skip to content

Commit

Permalink
Hold on to data used for FT_New_Memory_Face until after FT_Done_Face …
Browse files Browse the repository at this point in the history
…is called. (#19)
  • Loading branch information
ChrisLoer authored Feb 16, 2023
1 parent bf5bed5 commit 2584db2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ string do_range(std::vector<FT_Face> &faces, std::string name, unsigned start, u
struct fontstack {
FT_Library library;
std::vector<FT_Face> *faces;
std::vector<char *> *data;
std::set<std::string> *seen_face_names;
std::string *name;
};
Expand All @@ -99,6 +100,7 @@ extern "C" {
fontstack *create_fontstack() {
fontstack *f = (fontstack *)malloc(sizeof(fontstack));
f->faces = new std::vector<FT_Face>;
f->data = new std::vector<char *>;
f->name = new std::string;
f->seen_face_names = new std::set<std::string>;

Expand Down Expand Up @@ -144,6 +146,9 @@ extern "C" {
for (auto fc : *f->faces) {
FT_Done_Face(fc);
}
for (auto d : *f->data) {
free(d);
}
FT_Done_FreeType(f->library);
delete f->faces;
delete f->name;
Expand Down Expand Up @@ -213,9 +218,10 @@ int main(int argc, char *argv[])
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);

std::vector<char> buffer(size);
file.read(buffer.data(), size);
fontstack_add_face(f,(FT_Byte *)buffer.data(),size);
char * buffer = (char *)malloc(size);
f->data->push_back(buffer);
file.read(buffer, size);
fontstack_add_face(f,(FT_Byte *)buffer,size);
}

std::string fname{fontstack_name(f)};
Expand All @@ -242,4 +248,4 @@ int main(int argc, char *argv[])

return 0;
}
#endif
#endif

0 comments on commit 2584db2

Please sign in to comment.