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 #3235

Closed
bluman88 opened this issue Jul 5, 2018 · 6 comments · Fixed by #3787
Closed

Clipping when rendering Khmer text using Pillow and libraqm #3235

bluman88 opened this issue Jul 5, 2018 · 6 comments · Fixed by #3787
Labels

Comments

@bluman88
Copy link

bluman88 commented Jul 5, 2018

What did you do?

I used 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).

What did you expect to happen?

I expected the word "លោកុប្បត្តិ" to be rendered like this (output from MS Word):
khmer-word

What actually happened?

The left offset of the text was too large and resulted in clipping on the right-hand side of the bounding box (shown in red):
khmer-pillow

Depending on how many glyphs of the word I chose to render, the offset became larger.

What versions of Pillow and Python are you using?

I am using the following versions on Ubuntu 18.04:

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')
@hugovk
Copy link
Member

hugovk commented Sep 18, 2018

From the raqm issue:

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

HOST-Oman/libraqm#87 (comment)

@bluman88
Copy link
Author

Thanks for linking the raqm issue, Hugo. This is still a problem. Does anyone know what is causing the issue?

@bluman88
Copy link
Author

bluman88 commented Jan 3, 2019

Confirmed that this is still a problem with Pillow 5.5.0 and libraqm 0.5.0.

Does anyone know where to start looking?

@radarhere
Copy link
Member

From #597, I find that the widths are different if Unicode numbers are used instead of characters. Neither is correct though.

from PIL import Image, ImageDraw, ImageFont
img = Image.new('L', (300, 130))
d = ImageDraw.Draw(img)
font = ImageFont.truetype("KhmerOS.ttf", 30)
d.text((50, 30), u'\u179f\u17d2\u1793\u17b6', fill=(255), font=font)
d.text((150, 30), u'ស្នាក់', fill=(255), font=font)
img.save('test.tif')

@radarhere
Copy link
Member

I've created PR #3787 to resolve this.

@bluman88
Copy link
Author

bluman88 commented Apr 11, 2019

Perfect. Thank you. PR #3787 fixes the issue I have been having. Here is the original text with correct layout using the new code:

sample-out

@bluman88 bluman88 closed this as completed May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants