Skip to content

Commit

Permalink
Changed "font" to class variable
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Aug 6, 2022
1 parent 1b5abea commit 04d9761
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@


class ImageDraw:
font = None

def __init__(self, im, mode=None):
"""
Create a drawing instance.
Expand Down Expand Up @@ -86,7 +88,6 @@ def __init__(self, im, mode=None):
else:
self.fontmode = "L" # aliasing is okay for other modes
self.fill = 0
self.font = None

def getfont(self):
"""
Expand Down

0 comments on commit 04d9761

Please sign in to comment.