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

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

Closed
masushin opened this issue Aug 6, 2017 · 12 comments
Closed
Labels
Bug Any unexpected behavior, until confirmed feature. Font Rendering
Projects

Comments

@masushin
Copy link

masushin commented Aug 6, 2017

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
Copy link
Member

wiredfool commented Aug 6, 2017

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
Copy link
Author

masushin commented Aug 6, 2017

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
Copy link
Author

masushin commented Oct 3, 2017

Similarly, This phenomenon appear in pillow 4.3.0.

@wiredfool
Copy link
Member

wiredfool commented Oct 4, 2017

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
Copy link

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
Copy link
Author

masushin commented Nov 4, 2017

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 aclark4life added the Bug Any unexpected behavior, until confirmed feature. label Mar 17, 2018
@aclark4life
Copy link
Member

@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".

@radarhere radarhere changed the title Japanese font glyph with direction "ttb" is drawn to incorrect position. Japanese font glyph with direction "ttb" is drawn to incorrect position Jul 7, 2018
@HinTak
Copy link
Contributor

HinTak commented Oct 26, 2018

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

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

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

@radarhere
Copy link
Member

@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
Copy link
Author

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

@masushin
Copy link
Author

masushin commented Jun 23, 2019

I got a image as I expected.

tmpto88ub18

I think this issue is resolved.
thank you !

Pillow automation moved this from Icebox to Closed Jun 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. Font Rendering
Projects
Pillow
  
Closed
Development

No branches or pull requests

6 participants