diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 23bc756bb..961b4d081 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -1314,6 +1314,23 @@ def test_stroke_multiline(): assert_image_similar_tofile(im, "Tests/images/imagedraw_stroke_multiline.png", 3.3) +def test_setting_default_font(): + # Arrange + im = Image.new("RGB", (100, 250)) + draw = ImageDraw.Draw(im) + font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 120) + + # Act + ImageDraw.ImageDraw.font = font + + # Assert + try: + assert draw.getfont() == font + finally: + ImageDraw.ImageDraw.font = None + assert isinstance(draw.getfont(), ImageFont.ImageFont) + + def test_same_color_outline(): # Prepare shape x0, y0 = 5, 5 diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 8970471d3..712ec6e09 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -46,6 +46,8 @@ directly. class ImageDraw: + font = None + def __init__(self, im, mode=None): """ Create a drawing instance. @@ -86,7 +88,6 @@ class ImageDraw: else: self.fontmode = "L" # aliasing is okay for other modes self.fill = 0 - self.font = None def getfont(self): """