Skip to content

Commit c89fc36

Browse files
committed
Fixed stroke on FreeType < 2.9
1 parent a89156a commit c89fc36

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed
2.14 KB
Loading

Tests/test_imagedraw.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,22 @@ def test_stroke():
941941
)
942942

943943

944+
@pytest.mark.skipif(not HAS_FREETYPE, reason="ImageFont not available")
945+
def test_stroke_descender():
946+
# Arrange
947+
im = Image.new("RGB", (120, 130))
948+
draw = ImageDraw.Draw(im)
949+
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 120)
950+
951+
# Act
952+
draw.text((10, 0), "y", "#f00", font, stroke_width=2, stroke_fill="#0f0")
953+
954+
# Assert
955+
assert_image_similar(
956+
im, Image.open("Tests/images/imagedraw_stroke_descender.png"), 6.76
957+
)
958+
959+
944960
@pytest.mark.skipif(not HAS_FREETYPE, reason="ImageFont not available")
945961
def test_stroke_multiline():
946962
# Arrange

src/_imagingft.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,17 +782,14 @@ font_render(FontObject* self, PyObject* args)
782782
im = (Imaging) id;
783783
/* Note: bitmap fonts within ttf fonts do not work, see #891/pr#960 */
784784
load_flags = FT_LOAD_NO_BITMAP;
785-
if (stroker == NULL) {
786-
load_flags |= FT_LOAD_RENDER;
787-
}
788785
if (mask) {
789786
load_flags |= FT_LOAD_TARGET_MONO;
790787
}
791788

792789
ascender = 0;
793790
for (i = 0; i < count; i++) {
794791
index = glyph_info[i].index;
795-
error = FT_Load_Glyph(self->face, index, load_flags);
792+
error = FT_Load_Glyph(self->face, index, load_flags | FT_LOAD_RENDER);
796793
if (error) {
797794
return geterror(error);
798795
}
@@ -806,6 +803,10 @@ font_render(FontObject* self, PyObject* args)
806803
ascender = temp;
807804
}
808805

806+
if (stroker == NULL) {
807+
load_flags |= FT_LOAD_RENDER;
808+
}
809+
809810
x = y = 0;
810811
horizontal_dir = dir && strcmp(dir, "ttb") == 0 ? 0 : 1;
811812
for (i = 0; i < count; i++) {

0 commit comments

Comments
 (0)