Skip to content

Corrected ttb text positioning#3856

Merged
hugovk merged 3 commits intopython-pillow:masterfrom
radarhere:ttb
Jun 19, 2019
Merged

Corrected ttb text positioning#3856
hugovk merged 3 commits intopython-pillow:masterfrom
radarhere:ttb

Conversation

@radarhere
Copy link
Copy Markdown
Member

Helps #2656 and #3125

libraqm 0.4 and 0.5 throw an error for ttb - see HOST-Oman/libraqm@7088743. 0.3 works, but since there is no simple way to test for the difference between 0.3 and 0.4, for simplicity I'm saying that ttb requires libraqm 0.6 or later.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented May 17, 2019

Thanks!

Is there a way to get the libraqm version programatically? If not, shall we open an issue with libraqm to ask them to add some API? It may be useful in the future.

@radarhere
Copy link
Copy Markdown
Member Author

To be clear, this is testing to see if libraqm 0.6 is present, just not through a version string - I do it by testing for the existence of an unrelated function that was added in 0.6.

I've created HOST-Oman/libraqm#103 requesting a version identifier.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented May 18, 2019

Thanks! It could be that the unrelated feature is removed in 0.7 or some future version, and then breaking this fix.

src/_imagingft.c Outdated
if (p_raqm.version == 1){
for (i = 0; i < count; i++) {
for (i = 0; i < count; i++) {
if (p_raqm.version == 1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be faster to check the condition outside the loop.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I've updated the commit

src/_imagingft.c Outdated
if (p_raqm.version == 1){
for (i = 0; i < count; i++) {
for (i = 0; i < count; i++) {
if (p_raqm.version == 1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be faster to check the condition outside the loop.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a duplicate comment.

im = Image.new(mode='RGB', size=(100, 300))
draw = ImageDraw.Draw(im)
try:
draw.text((0, 0), 'English عربي', font=ttf, fill=500, direction='ttb')
Copy link
Copy Markdown

@khaledhosny khaledhosny May 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn’t it be better to actually test some CJK characters here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble finding a small CJK font that could be included within the Pillow license. Do you have any thoughts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I've found one that's not too large.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also subset any font with pyftsubset (from FontTools) to include just the few characters used in the test.

src/_imagingft.c Outdated
if (horizontal_dir) {
x += glyph_info[i].x_advance;
} else {
y -= glyph_info[i].y_advance;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the condition is not needed, you can assign x and y unconditionally. In horizontal direction y_advance will be zero and in vertical direction x_advance will be zero.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I've updated the commit.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented May 27, 2019

Now HOST-Oman/libraqm#104 is merged and released in https://github.com/HOST-Oman/libraqm/releases/tag/v0.7.0, can we replace the version inference with a direct check for 0.7.0+?

@radarhere
Copy link
Copy Markdown
Member Author

Okay, done.

@hugovk hugovk merged commit b271485 into python-pillow:master Jun 19, 2019
@radarhere radarhere deleted the ttb branch June 19, 2019 10:25
radarhere added a commit to radarhere/Pillow that referenced this pull request Jun 20, 2019
hugovk added a commit that referenced this pull request Jun 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants