Changed "font" to class variable

This commit is contained in:
Andrew Murray 2022-08-06 17:29:44 +10:00
parent 1b5abea043
commit 04d9761316
2 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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):
"""