Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default ImageDraw font to be set #6484

Merged
merged 3 commits into from Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions Tests/test_imagedraw.py
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
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