Skip to content

Commit

Permalink
Do not crop again if glyph is the same as the previous one
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 30, 2023
1 parent a9bbaf6 commit 49a0b8e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -2761,10 +2761,15 @@ _font_getmask(ImagingFontObject *self, PyObject *args) {
b = self->baseline;
for (x = 0; text[i]; i++) {
glyph = &self->glyphs[text[i]];
bitmap =
ImagingCrop(self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
if (!bitmap) {
goto failed;
if (i == 0 || text[i] != text[i - 1]) {
if (i != 0) {
ImagingDelete(bitmap);
}
bitmap =
ImagingCrop(self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
if (!bitmap) {
goto failed;
}
}
status = ImagingPaste(
im,
Expand All @@ -2774,13 +2779,15 @@ _font_getmask(ImagingFontObject *self, PyObject *args) {
glyph->dy0 + b,
glyph->dx1 + x,
glyph->dy1 + b);
ImagingDelete(bitmap);
if (status < 0) {
goto failed;
}
x = x + glyph->dx;
b = b + glyph->dy;
}
if (i != 0) {
ImagingDelete(bitmap);
}
free(text);
return PyImagingNew(im);

Expand Down

0 comments on commit 49a0b8e

Please sign in to comment.