Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37c51b1

Browse files
committed
Fix memory leak and render tofu
1 parent 127d7f3 commit 37c51b1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ft2font.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ FT2Font::~FT2Font()
377377
if (face) {
378378
FT_Done_Face(face);
379379
}
380+
381+
for (size_t i = 0; i < fallbacks.size(); i++) {
382+
Py_DECREF(fallbacks[i]->get_pyfont());
383+
}
380384
}
381385

382386
void FT2Font::clear()
@@ -508,15 +512,20 @@ void FT2Font::set_text(
508512
FT_BBox glyph_bbox;
509513
FT_Pos last_advance;
510514

511-
FT_UInt final_glyph_index;
515+
FT_UInt final_glyph_index = 0;
512516
FT_Error charcode_error, glyph_error;
513517
FT2Font *ft_object_with_glyph = this;
514518
bool was_found = load_char_with_fallback(ft_object_with_glyph, final_glyph_index, glyphs,
515519
char_to_font, glyph_to_font, codepoints[n], flags,
516520
charcode_error, glyph_error, false);
517521
if (!was_found) {
518522
ft_glyph_warn((FT_ULong)codepoints[n]);
519-
continue;
523+
524+
// render tofu
525+
// ft_object_with_glyph == this
526+
char_to_font[codepoints[n]] = ft_object_with_glyph;
527+
glyph_to_font[final_glyph_index] = ft_object_with_glyph;
528+
ft_object_with_glyph->load_glyph(final_glyph_index, flags, ft_object_with_glyph, false);
520529
}
521530

522531
glyph_index = final_glyph_index;

0 commit comments

Comments
 (0)