python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.18k stars 2.22k forks source link

Japanese font glyph with direction "ttb" is drawn to incorrect position #2656

Closed masushin closed 5 years ago

masushin commented 7 years ago

What did you do?

I tried to draw Japanese font glyph by following test code.

from PIL import Image, ImageDraw, ImageFont

txt = Image.new('RGBA', (200,200), (255,255,255,255))
fnt = ImageFont.truetype("GenEiAntiqueN-Medium.otf", 80)
d = ImageDraw.Draw(txt)
d.text((60,20), "あい", font=fnt, fill=(0,0,0,255), direction="ttb")
txt.show()

What did you expect to happen?

I expected to get the following image.

ai

What actually happened?

I got the following image.

ai2

Glyphs are drawn to deviate to the lower left.

Also, it seems that these glyphs are drawn overlapping. (It may be better to deal with this after the first problem has been solved..)

The font file using in my code can be got from the following link. http://okoneya.jp/font/GenEiAntique-3.0.zip

Incidentally, I tried it using other font "ヒラギノ 明朝". It included in Japanese mac OS. And same problem appear. So, I think it is not problem with a specific font file.

Please let me know if there are mistake in my code.

What versions of Pillow and Python are you using?

Python 3.6.0 Pillow 4.2.1

wiredfool commented 7 years ago

Do you have the raqm feature compiled in? ( you would have had to build from source, as it's not in the binary builds)

(for reference:)

from PIL import features
print (features.check('raqm'))
masushin commented 7 years ago

I installed libraqm using depends/install_raqm_cmake.sh. It seemed that it is compiled from source. So, I think yes.

>>> from PIL import features
>>> print ("raqm:",features.check('raqm'))
raqm: True
masushin commented 7 years ago

Similarly, This phenomenon appear in pillow 4.3.0.

wiredfool commented 7 years ago

It looks like the layout we're getting is straight from what raqm is getting from harfbuzz. It's either a bug in harfbuzz, or raqm is driving it incorrectly for this font/script.

I've looked at this against harfbuzz 1.01 (default ubuntu 16.04) and the latest 1.5.1, and raqm@MASTER

@khaledhosny Can you take a look at this?

khaledhosny commented 7 years ago

Raqm only passes the direction to HarfBuzz, the code that does the rendering needs to handle vertical direction specially by using y_advance instead of x_advance.

masushin commented 6 years ago

Sorry, I couldn't understand above exactly. Let me confirm about this issue. Is it mean that cause of this issue is raqm or HarfBuzz, not pillow? (Is it better that I contact to raqm or HarfBuzz official ?)

aclark4life commented 6 years ago

@masushin FWIW I read it as potentially something Pillow could do (e.g. "by using y_advance instead of x_advance"), assuming Pillow is "the code that does the rendering".

HinTak commented 5 years ago

Have a look at the vertical layout example https://github.com/HinTak/harfbuzz-python-demos

radarhere commented 5 years ago

I wasn't able to reproduce the shift to the left, but I've created PR #3856 to fix the vertical positioning issues.

radarhere commented 5 years ago

@masushin #3856 has been merged. Are you able to install raqm 0.7, retest this with Pillow master, and let us know if this issue is resolved?

masushin commented 5 years ago

ok, I'll try it and report a result.

masushin commented 5 years ago

I got a image as I expected.

tmpto88ub18

I think this issue is resolved. thank you !