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 Jan 1, 2024
1 parent ecd3948 commit 6cad0d6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,7 @@ _font_text_asBytes(PyObject *encoded_string, unsigned char **text) {
static PyObject *
_font_getmask(ImagingFontObject *self, PyObject *args) {
Imaging im;
Imaging bitmap;
Imaging bitmap = NULL;
int x, b;
int i = 0;
int status;
Expand Down Expand Up @@ -2765,10 +2765,13 @@ _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]) {
ImagingDelete(bitmap);
bitmap =
ImagingCrop(self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
if (!bitmap) {
goto failed;
}
}
status = ImagingPaste(
im,
Expand All @@ -2778,17 +2781,18 @@ _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;
}
ImagingDelete(bitmap);
free(text);
return PyImagingNew(im);

failed:
ImagingDelete(bitmap);
free(text);
ImagingDelete(im);
Py_RETURN_NONE;
Expand Down

0 comments on commit 6cad0d6

Please sign in to comment.