-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Truetype fonts not being rendered correctly with the TEXT method #4177
Comments
Have now discovered that:
|
I can replicate this error on macOS with updated libs. I've seen issues similar to this using Pillow to render text for little 1-bit OLED displays. |
Apologies for the delay.
I had to go live with the quirks (padded the text with spaces) and not had another machine I can test on. I've got a Pi Zero now but no screen (and no money to buy one) but will try in the next week to get it set up as per the live box (I do still have the build document :-)) and test it.
I have a hospital appointment on Monday - not sue if they will be keeping me in or not so I may not get back to you for a week or so.
Andrew
|
@BeauSlim I'm not able to replicate this on my macOS machine. Are you still able to? |
Yes. ADBeasley's posted code produces exactly the same image as above on my macOS Catalina machine with Pillow 7.1.2 under brew's Python 3.7.7. I played with it a bit. If you manually set screen_image.fontmode='P' the text isn't clipped, so maybe it comes down to the old fontmode '1' problem? And it appears that #2293 is not related to an outdated FreeType library since ImageFont.core.freetype2_version gives me 2.10.1 and I am still getting problems with vertical alignment with mode '1' TTF text: I ended up converting the fonts I wanted into .bdf format to solve this, so no big deal, but it definitely points to a bug somewhere. |
I can actually reproduce #2293 with 7.1.1 from PyPI on Windows 10 using My WIP branch (#4553) doesn't have these issues, although I'm not sure it is perfect either. from PIL import Image, ImageDraw, ImageFont
im = Image.new("RGB", (400, 100), "white")
d = ImageDraw.Draw(im)
def line(y, engine, mode):
f = ImageFont.truetype("verdanab.ttf", 13, layout_engine=engine)
d.fontmode = mode
d.text((10, y), "engine: {}, mode: {}".format(engine, mode), "black", f)
d.text((170, y), "01234567890123456789", "black", f)
line(10, 0, '1') # 0 is basic layout
line(30, 0, 'L')
line(50, 1, '1') # 1 is raqm layout
line(70, 1, 'L') Edit: Corrected images. |
I just realized that I forgot to actually test this bug specifically; I can reproduce this issue with both 7.1.1 and my WIP branch, getting practically the same images as OP. Note that it only happens with Basic layout. |
I solved this one. The problems is that
|
What did you do?
Created an image suitable for the Pimoroni InkyHat display
Added italic text onto the image object at different places
What did you expect to happen?
The whole of the last character of the text to be displayed as it did to render correctly on Stretch on the Pi Zero
Looking at the font from a Mac (Mojave), the characters look fine.
What actually happened?
Depending on the length of the text, some or all of the last character is missing when using some italic fonts. If the text length is around 105 - 110 pixels then you can lose some / all of the very last character.
Padding out the text string with spaces so it is longer than 110 pixels fixes the issue
What are your OS, Python and Pillow versions?
The fonts used are available from Font Squirrel - the two are:
Open Sans here
Ubuntu here
The text was updated successfully, but these errors were encountered: