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

Clipping when rendering Khmer text using Pillow and libraqm #87

Closed
bluman88 opened this issue Jul 5, 2018 · 4 comments
Closed

Clipping when rendering Khmer text using Pillow and libraqm #87

bluman88 opened this issue Jul 5, 2018 · 4 comments
Labels

Comments

@bluman88
Copy link

bluman88 commented Jul 5, 2018

I am using the Python library Pillow (5.3.0) to draw Khmer text onto an image using libraqm (0.5.0) for complex layout support (layout_engine=ImageFont.LAYOUT_RAQM).

While the glyph shapes are correct when rendered, some text is shifted right and consequently clipped by the bounding box. Compare the first rendering below (using Pillow) with the second (in MS Word). I have shown the bounding box in red.

Khmer rendered by Pillow

Khmer rendered by MS Word

Code to reproduce clipping effect:

#!/usr/bin/python3                                                              
# -*- coding: utf-8 -*-                                                         
from PIL import Image                                                           
from PIL import ImageFont                                                       
from PIL import ImageDraw                                                       
                                                                                
img = Image.new("RGB", (512, 512), "white")                                     
draw = ImageDraw.Draw(img)                                                      
font = ImageFont.truetype("Battambang-Regular.ttf", 60, layout_engine=ImageFont.LAYOUT_RAQM)                  
text = "លោកុប្បត្តិ"                                                                 
draw.text((0, 0), text, (0, 0, 0), font=font)                                   
img.save('out.png')

I am using the following versions on Ubuntu 18.04:

Any help would be greatly appreciated. I am not sure whether this issue stems from libraqm or one of the other libraries.

@khaledhosny
Copy link
Collaborator

Raqm does not do the rendering, just the layout. This clipping is likely a Pillow bug and should be reported and fixed there.

@bluman88
Copy link
Author

bluman88 commented Jul 5, 2018

Thanks, Khaled. I did wonder whether that might be the case, but I wanted to check whether the offset of the first glyph is given to Pillow by raqm (or FreeType, or something else) as part of the layout.

@hugovk
Copy link
Contributor

hugovk commented Sep 18, 2018

Here's the Pillow issue: python-pillow/Pillow#3235

@Fahad-Alsaidi
Copy link
Contributor

There is a pull request on python-pillow to fix this bug. I think we could now close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants