diff --git a/Tests/images/imagedraw_stroke_descender.png b/Tests/images/imagedraw_stroke_descender.png new file mode 100644 index 00000000000..93462334ae4 Binary files /dev/null and b/Tests/images/imagedraw_stroke_descender.png differ diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 4535a4838e2..67936e0c52d 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -850,6 +850,21 @@ def test_stroke(self): im, Image.open("Tests/images/imagedraw_stroke_" + suffix + ".png"), 3.1 ) + @unittest.skipUnless(HAS_FREETYPE, "ImageFont not available") + def test_stroke_descender(self): + # Arrange + im = Image.new("RGB", (120, 130)) + draw = ImageDraw.Draw(im) + font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 120) + + # Act + draw.text((10, 0), "y", "#f00", font, stroke_width=2, stroke_fill="#0f0") + + # Assert + self.assert_image_similar( + im, Image.open("Tests/images/imagedraw_stroke_descender.png"), 6.76 + ) + @unittest.skipUnless(HAS_FREETYPE, "ImageFont not available") def test_stroke_multiline(self): # Arrange diff --git a/src/_imagingft.c b/src/_imagingft.c index 62a4c283e71..c9d489e8ee1 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -782,9 +782,6 @@ font_render(FontObject* self, PyObject* args) im = (Imaging) id; /* Note: bitmap fonts within ttf fonts do not work, see #891/pr#960 */ load_flags = FT_LOAD_NO_BITMAP; - if (stroker == NULL) { - load_flags |= FT_LOAD_RENDER; - } if (mask) { load_flags |= FT_LOAD_TARGET_MONO; } @@ -792,7 +789,7 @@ font_render(FontObject* self, PyObject* args) ascender = 0; for (i = 0; i < count; i++) { index = glyph_info[i].index; - error = FT_Load_Glyph(self->face, index, load_flags); + error = FT_Load_Glyph(self->face, index, load_flags | FT_LOAD_RENDER); if (error) { return geterror(error); } @@ -806,6 +803,10 @@ font_render(FontObject* self, PyObject* args) ascender = temp; } + if (stroker == NULL) { + load_flags |= FT_LOAD_RENDER; + } + x = y = 0; horizontal_dir = dir && strcmp(dir, "ttb") == 0 ? 0 : 1; for (i = 0; i < count; i++) {