Skip to content

Commit

Permalink
don't use bitmap glyphs when drawing text with stroker
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano committed Oct 14, 2021
1 parent b34430b commit 19f4c6f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Binary file added Tests/images/bitmap_font_stroke_basic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/bitmap_font_stroke_raqm.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_imagefont.py
Expand Up @@ -867,6 +867,22 @@ def test_bitmap_font(self, bpp):

assert_image_equal_tofile(im, target)

def test_bitmap_font_stroke(self):
text = "Bitmap Font"
layout_name = ["basic", "raqm"][self.LAYOUT_ENGINE]
target = f"Tests/images/bitmap_font_stroke_{layout_name}.png"
font = ImageFont.truetype(
"Tests/fonts/DejaVuSans/DejaVuSans-24-8-stripped.ttf",
24,
layout_engine=self.LAYOUT_ENGINE,
)

im = Image.new("RGB", (160, 35), "white")
draw = ImageDraw.Draw(im)
draw.text((2, 2), text, "black", font, stroke_width=2, stroke_fill="red")

assert_image_similar_tofile(im, target, 0.03)

def test_standard_embedded_color(self):
txt = "Hello World!"
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE)
Expand Down
2 changes: 1 addition & 1 deletion src/_imagingft.c
Expand Up @@ -833,7 +833,7 @@ font_render(FontObject *self, PyObject *args) {
}

im = (Imaging)id;
load_flags = FT_LOAD_DEFAULT;
load_flags = stroke_width ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT;
if (mask) {
load_flags |= FT_LOAD_TARGET_MONO;
}
Expand Down

0 comments on commit 19f4c6f

Please sign in to comment.