-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
updated version of Add complex text support #1682 #2284
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
Changes from all commits
592725b
ff5c2ca
f013dd1
8b3ed96
228af63
25b2a64
95a2ac1
c6d5de6
3130bce
1b7401a
af0df0c
f2ba268
37e2588
ebdc297
629522a
22d2a5e
b18ead3
5833779
4b8d884
5891d23
8739e53
8144eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from helper import unittest, PillowTestCase | ||
| from PIL import Image | ||
| from PIL import ImageDraw, ImageFont | ||
|
|
||
| #check if raqm installed | ||
| have_raqm = ImageFont.core.have_raqm | ||
|
|
||
| FONT_SIZE = 20 | ||
| FONT_PATH = "Tests/fonts/DejaVuSans.ttf" | ||
|
|
||
| try: | ||
| from PIL import ImageFont | ||
|
|
||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a way to check if raqm is installed. As it stands, if there is an error that triggers an import error on ImageFont, then this whole set of tests are going to get skipped. There are version flags for several of the libraries, that would be something to add to _imagingft.c, potentially for all three libraries, but at least raqm. |
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr') | ||
| @unittest.skipIf(not have_raqm, "Raqm Library is not installed !") | ||
| class TestImagecomplextext(PillowTestCase): | ||
| def test_complex_text(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'اهلا عمان', font=ttf, fill=500) | ||
|
|
||
| target = 'Tests/images/test_text.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_y_offset(self): | ||
| ttf = ImageFont.truetype("Tests/fonts/NotoNastaliqUrdu-Regular.ttf", FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'العالم العربي', font=ttf, fill=500) | ||
|
|
||
| target = 'Tests/images/test_y_offset.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_complex_unicode_text(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), u'السلام عليكم', font=ttf, fill=500) | ||
|
|
||
| target = 'Tests/images/test_complex_unicode_text.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_text_direction_rtl(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'English عربي', font=ttf, fill=500, direction='rtl') | ||
|
|
||
| target = 'Tests/images/test_direction_rtl.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_text_direction_ltr(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'سلطنة عمان Oman', font=ttf, fill=500, direction='ltr') | ||
|
|
||
| target = 'Tests/images/test_direction_ltr.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_text_direction_rtl2(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'Oman سلطنة عمان', font=ttf, fill=500, direction='rtl') | ||
|
|
||
| target = 'Tests/images/test_direction_ltr.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_ligature_features(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'filling', font=ttf, fill=500, features=['-liga']) | ||
|
|
||
| target = 'Tests/images/test_ligature_features.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_kerning_features(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'TeToAV', font=ttf, fill=500, features=['-kern']) | ||
|
|
||
| target = 'Tests/images/test_kerning_features.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| def test_arabictext_features(self): | ||
| ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| im = Image.new(mode='RGB', size=(300, 100)) | ||
| draw = ImageDraw.Draw(im) | ||
| draw.text((0, 0), 'اللغة العربية', font=ttf, fill=500, features=['-fina','-init','-medi']) | ||
|
|
||
| target = 'Tests/images/test_arabictext_features.png' | ||
| target_img = Image.open(target) | ||
|
|
||
| self.assert_image_similar(im, target_img, .5) | ||
|
|
||
| except ImportError: | ||
| class TestImagecomplextext(PillowTestCase): | ||
| def test_skip(self): | ||
| self.skipTest("ImportError") | ||
| except KeyError: | ||
| class TestImagecomplextext(PillowTestCase): | ||
| def test_skip(self): | ||
| self.skipTest("KeyError") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have a more descriptive skip message (because it could be |
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
|
|
||
| # End of file | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to trigger on raqm being available when it's not compiled in but freetype is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I delete it, all builds fails the error is