Skip to content

Commit 04d9761

Browse files
committed
Changed "font" to class variable
1 parent 1b5abea commit 04d9761

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Tests/test_imagedraw.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,23 @@ def test_stroke_multiline():
13141314
assert_image_similar_tofile(im, "Tests/images/imagedraw_stroke_multiline.png", 3.3)
13151315

13161316

1317+
def test_setting_default_font():
1318+
# Arrange
1319+
im = Image.new("RGB", (100, 250))
1320+
draw = ImageDraw.Draw(im)
1321+
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 120)
1322+
1323+
# Act
1324+
ImageDraw.ImageDraw.font = font
1325+
1326+
# Assert
1327+
try:
1328+
assert draw.getfont() == font
1329+
finally:
1330+
ImageDraw.ImageDraw.font = None
1331+
assert isinstance(draw.getfont(), ImageFont.ImageFont)
1332+
1333+
13171334
def test_same_color_outline():
13181335
# Prepare shape
13191336
x0, y0 = 5, 5

src/PIL/ImageDraw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747

4848
class ImageDraw:
49+
font = None
50+
4951
def __init__(self, im, mode=None):
5052
"""
5153
Create a drawing instance.
@@ -86,7 +88,6 @@ def __init__(self, im, mode=None):
8688
else:
8789
self.fontmode = "L" # aliasing is okay for other modes
8890
self.fill = 0
89-
self.font = None
9091

9192
def getfont(self):
9293
"""

0 commit comments

Comments
 (0)