Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Require font parameter in FreeTypeFont and truetype()

Open radarhere opened this issue 1 year ago • 0 comments

Currently, font is an optional parameter for FreeTypeFont and truetype().

https://github.com/python-pillow/Pillow/blob/6dd4b3c826512b6e50f7343951bcb3650087119b/src/PIL/ImageFont.py#L198-L211

https://github.com/python-pillow/Pillow/blob/6dd4b3c826512b6e50f7343951bcb3650087119b/src/PIL/ImageFont.py#L758-L764

However, if it is None, then an error is raised.

>>> from PIL import ImageFont
>>> ImageFont.FreeTypeFont()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/ImageFont.py", line 261, in __init__
    load_from_bytes(font)
  File "PIL/ImageFont.py", line 240, in load_from_bytes
    self.font_bytes = f.read()
AttributeError: 'NoneType' object has no attribute 'read'
>>> from PIL import ImageFont
>>> ImageFont.truetype()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/ImageFont.py", line 834, in truetype
    return freetype(font)
  File "PIL/ImageFont.py", line 831, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "PIL/ImageFont.py", line 261, in __init__
    load_from_bytes(font)
  File "PIL/ImageFont.py", line 240, in load_from_bytes
    self.font_bytes = f.read()
AttributeError: 'NoneType' object has no attribute 'read'

This PR removes the defaults to make it required instead.

radarhere avatar Jul 25 '24 08:07 radarhere