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
Render text using kerning pairs information #6175
Comments
Do you use basic or Raqm layout? The default is Raqm, but it might not be available for you, you can check by running Edit: Kerning should work correctly in Raqm layout, but has been broken in basic layout since #2576 (about 6 years) because the kerning offset is scaled twice. |
I am checking now. |
*** RAQM (Bidirectional Text) support not installed Per instructions at https://github.com/HOST-Oman/libraqm |
How did you install Pillow? Depending on the answer, there are different ways to enable Raqm support. |
It was a while back but I think via pip3 in MacOS terminal.app. |
I don't have macOS, but I fixed a bug two days ago for Alpine that made it into yesterday's release: #6165 Edit:
|
Raqm is available on Homebrew, so it can be installed by |
@chrisnoessel did you have any luck? If none of the previous suggestions helped, I would suggest installing from Pillow main, to see if #6182 fixes the problem. If you're having trouble installing from source, let us know whether you are M1 or Intel, and your Python version, and we can put together a wheel for you. |
#6182 will not affect source builds, the fribidi shim is not used in that case, so there is no need to install from main. I think the wheels from https://github.com/radarhere/pillow-wheels/actions/runs/2093139164 (linked from #6182) should show whether #6182 fixes the problem. (perhaps it might be worth reverting the symlink part of python-pillow/pillow-wheels#281 to make sure the fix is tested on CI) |
Removing the symlink part of python-pillow/pillow-wheels#281 leads to https://github.com/radarhere/pillow-wheels/actions/runs/2117770741, where latest Pillow passes with #6182 and Pillow 9.1.0 fails without, as expected. I haven't created that PR yet just to avoid marking pillow-wheels as failing in GitHub Actions from now until the next release. If you think it should go in now though, happy for that. |
I would probably open the PR and make it a draft until the next release (to make sure it isn't forgotten about), but I don't have a strong preference either way. |
I've now opened it. python-pillow/pillow-wheels#285 |
Running the following code on my machine, from PIL import Image, ImageDraw, ImageFont
im = Image.new("RGB", (100, 100))
d = ImageDraw.Draw(im)
font = ImageFont.truetype("/System/Library/Fonts/Supplemental/Times New Roman.ttf", size=48, layout_engine=ImageFont.Layout.BASIC)
d.text((10, 0), "VA", font=font, fill="#f00")
font = ImageFont.truetype("/System/Library/Fonts/Supplemental/Times New Roman.ttf", size=48, layout_engine=ImageFont.Layout.RAQM)
d.text((10, 45), "VA", font=font, fill="#f00")
im.save("out.png") So with RAQM, VA is not just V and then A. Regarding the problem you're having detecting RAQM in your Pillow installation, #6182 should improve this situation when installing from wheels in the next Pillow release. Unless you would like further help, there doesn't seem to be anything more to be done here. |
Font files contain information about how to ideally separate pairs of letters called kerning tables. (This is different than letterspacing, which is the distance each letter has between any other letter.) Kerning tables are what make VA look correct rather than V A. Whenever I set text using Pillow, it disregards the kerning tables and creates very awkward letterspacing of some letter pairs that I can’t fix without opening the font, exporting the existing tables, and manually recreating the draw feature; which it not really a scalable option. Can the Image.text function be updated to register kerning tables?
(This is my first request, please forgive if I’m doing it wrong.)
The text was updated successfully, but these errors were encountered: