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

Added byte support to FreeTypeFont #8141

Merged
merged 2 commits into from
Jun 25, 2024

Conversation

radarhere
Copy link
Member

Currently, FreeTypeFont doesn't support bytes, while the less-used ImageFont does.

>>> from PIL import ImageFont
>>> font = ImageFont.load_default()
>>> font
<PIL.ImageFont.FreeTypeFont object at 0x102bbac10>
>>> font.getlength("test")
16.0
>>> font.getlength(b"test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/ImageFont.py", line 353, in getlength
    return self.font.getlength(text, mode, direction, features, language) / 64
TypeError: expected string
>>> from PIL import _util
>>> ImageFont.core = _util.DeferredError(ImportError)
>>> font = ImageFont.load_default()
>>> font
<PIL.ImageFont.ImageFont object at 0x102d23910>
>>> font.getlength("test")
24
>>> font.getlength(b"test")
24

This adds byte support to FreeTypeFont.

@hugovk hugovk merged commit 563f45c into python-pillow:main Jun 25, 2024
56 of 57 checks passed
@radarhere radarhere deleted the freetypefont_bytes branch June 25, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants