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

Text clipping arabic fonts #3745

Closed
hsidky opened this issue Mar 24, 2019 · 1 comment · Fixed by #3864
Closed

Text clipping arabic fonts #3745

hsidky opened this issue Mar 24, 2019 · 1 comment · Fixed by #3864

Comments

@hsidky
Copy link

hsidky commented Mar 24, 2019

What did you do?

I used Pillow (5.4.1) to draw Arabic text onto a canvas using libraqm (0.5.0)

What did you expect to happen?

I expected the arabic text to be rendered without clipping.

What actually happened?

The text was clipped.

image

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 18.04
  • Python: 3.6.8
  • Pillow: 5.4.1

Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as plone, Django, or buildout, try to replicate the issue just using Pillow.

%matplotlib inline 
from PIL import Image, ImageDraw, ImageFont
import matplotlib.pyplot as plt

font = ImageFont.truetype('ArefRuqaa-Regular.ttf', 70)
canvas = Image.new('RGB', (128, 128), color='white')
draw = ImageDraw.Draw(canvas)
draw.text((0, 0), 'لح', 'black', font, layout_engine=ImageFont.LAYOUT_RAQM)
canvas.save('test.png', format='PNG')

plt.imshow(plt.imread('test.png'))

I am using the Aref-Ruqaa font. The exact version I am using is here:
https://github.com/alif-type/aref-ruqaa/blob/master/ArefRuqaa-Regular.ttf

Using font.getsize('لح') gives me (29, 121) but as you can see from the image above, while the text is 121 pixels high it is still clipped from the top. It is also clipped on the right side, even though there is an offset of (-2, 46).

So the dimensions are correct but the actual drawn text is clipped. I was informed that the font is cascading so font global metrics cannot be used reliably for clipping.

Is there any way to correct this clipping?

Thanks!

@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@radarhere
Copy link
Member

I've created PR #3864 to resolve this.

@radarhere radarhere moved this from In progress to Review/QA in Pillow May 23, 2019
Pillow automation moved this from Review/QA to Closed Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

2 participants