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

Skip to content

Commit 09755b4

Browse files
aitikguptatacaswell
authored andcommitted
Fix memory leak and render tofu
1 parent 8181be3 commit 09755b4

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/ft2font.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ FT2Font::~FT2Font()
384384
if (face) {
385385
FT_Done_Face(face);
386386
}
387+
388+
for (size_t i = 0; i < fallbacks.size(); i++) {
389+
Py_DECREF(fallbacks[i]->get_pyfont());
390+
}
387391
}
388392

389393
void FT2Font::clear()
@@ -515,15 +519,20 @@ void FT2Font::set_text(
515519
FT_BBox glyph_bbox;
516520
FT_Pos last_advance;
517521

518-
FT_UInt final_glyph_index;
522+
FT_UInt final_glyph_index = 0;
519523
FT_Error charcode_error, glyph_error;
520524
FT2Font *ft_object_with_glyph = this;
521525
bool was_found = load_char_with_fallback(ft_object_with_glyph, final_glyph_index, glyphs,
522526
char_to_font, glyph_to_font, codepoints[n], flags,
523527
charcode_error, glyph_error, false);
524528
if (!was_found) {
525529
ft_glyph_warn((FT_ULong)codepoints[n]);
526-
continue;
530+
531+
// render tofu
532+
// ft_object_with_glyph == this
533+
char_to_font[codepoints[n]] = ft_object_with_glyph;
534+
glyph_to_font[final_glyph_index] = ft_object_with_glyph;
535+
ft_object_with_glyph->load_glyph(final_glyph_index, flags, ft_object_with_glyph, false);
527536
}
528537

529538
glyph_index = final_glyph_index;

0 commit comments

Comments
 (0)