Merge pull request #5761 from nulano/stroke

This commit is contained in:
Hugo van Kemenade 2021-10-14 21:33:07 +03:00 committed by GitHub
commit 1b5e662ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -867,6 +867,22 @@ class TestImageFont:
assert_image_equal_tofile(im, target) 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): def test_standard_embedded_color(self):
txt = "Hello World!" txt = "Hello World!"
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE) ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE)

View File

@ -833,7 +833,7 @@ font_render(FontObject *self, PyObject *args) {
} }
im = (Imaging)id; im = (Imaging)id;
load_flags = FT_LOAD_DEFAULT; load_flags = stroke_width ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT;
if (mask) { if (mask) {
load_flags |= FT_LOAD_TARGET_MONO; load_flags |= FT_LOAD_TARGET_MONO;
} }