Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed stroke on FreeType < 2.9 #4401

Merged
merged 1 commit into from Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Tests/images/imagedraw_stroke_descender.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions Tests/test_imagedraw.py
Expand Up @@ -944,6 +944,22 @@ def test_stroke():
)


@skip_unless_feature("freetype2")
def test_stroke_descender():
# 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
assert_image_similar(
im, Image.open("Tests/images/imagedraw_stroke_descender.png"), 6.76
)


@skip_unless_feature("freetype2")
def test_stroke_multiline():
# Arrange
Expand Down
9 changes: 5 additions & 4 deletions src/_imagingft.c
Expand Up @@ -782,17 +782,14 @@ 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;
}

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);
}
Expand All @@ -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++) {
Expand Down