Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ python:
- 3.4
- nightly

sudo: required # needed for trusty beta
dist: trusty # needed for HarfBuzz

install:
- "travis_retry sudo add-apt-repository -y ppa:as-bahanta/raqm"
- "travis_retry sudo apt-get update"
- "travis_retry sudo apt-get -qq install libfreetype6-dev liblcms2-dev python-qt4 ghostscript libffi-dev libjpeg-turbo-progs cmake imagemagick"
- "travis_retry sudo apt-get -qq install libfreetype6-dev libharfbuzz-dev libfribidi-dev libraqm-dev liblcms2-dev python-qt4 ghostscript libffi-dev libjpeg-turbo-progs cmake imagemagick"
- "travis_retry pip install cffi"
- "travis_retry pip install nose"
- "travis_retry pip install check-manifest"
Expand Down
8 changes: 4 additions & 4 deletions PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,17 @@ def text(self, xy, text, fill=None, font=None, anchor=None, *args, **kwargs):
ink = fill
if ink is not None:
try:
mask, offset = font.getmask2(text, self.fontmode)
mask, offset = font.getmask2(text, self.fontmode, *args, **kwargs)
xy = xy[0] + offset[0], xy[1] + offset[1]
except AttributeError:
try:
mask = font.getmask(text, self.fontmode)
mask = font.getmask(text, self.fontmode, *args, **kwargs)
except TypeError:
mask = font.getmask(text)
self.draw.draw_bitmap(xy, mask, ink)

def multiline_text(self, xy, text, fill=None, font=None, anchor=None,
spacing=4, align="left"):
spacing=4, align="left", direction=None, features=None):
widths = []
max_width = 0
lines = self._multiline_split(text)
Expand All @@ -281,7 +281,7 @@ def multiline_text(self, xy, text, fill=None, font=None, anchor=None,
left += (max_width - widths[idx])
else:
assert False, 'align must be "left", "center" or "right"'
self.text((left, top), line, fill, font, anchor)
self.text((left, top), line, fill, font, anchor, direction=direction, features=features)
top += line_spacing
left = xy[0]

Expand Down
14 changes: 7 additions & 7 deletions PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ def getname(self):
def getmetrics(self):
return self.font.ascent, self.font.descent

def getsize(self, text):
size, offset = self.font.getsize(text)
def getsize(self, text, direction=None, features=None):
size, offset = self.font.getsize(text, direction, features)
return (size[0] + offset[0], size[1] + offset[1])

def getoffset(self, text):
return self.font.getsize(text)[1]

def getmask(self, text, mode=""):
return self.getmask2(text, mode)[0]
def getmask(self, text, mode="", direction=None, features=None):
return self.getmask2(text, mode, direction=direction, features=features)[0]

def getmask2(self, text, mode="", fill=Image.core.fill):
size, offset = self.font.getsize(text)
def getmask2(self, text, mode="", fill=Image.core.fill, direction=None, features=None):
size, offset = self.font.getsize(text, direction, features)
im = fill("L", size, 0)
self.font.render(text, im.id, mode == "1")
self.font.render(text, im.id, mode == "1", direction, features)
return im, offset

def font_variant(self, font=None, size=None, index=None, encoding=None):
Expand Down
1 change: 1 addition & 0 deletions PIL/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"tkinter": "PIL._imagingtk",
"freetype2": "PIL._imagingft",
"littlecms2": "PIL._imagingcms",
"raqm": "PIL._imagingft",
"webp": "PIL._webp",
"transp_webp": ("WEBP", "WebPDecoderBuggyAlpha")
}
Expand Down
Binary file added Tests/fonts/NotoNastaliqUrdu-Regular.ttf
Binary file not shown.
Binary file added Tests/images/test_Nastalifont_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_arabictext_features.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_complex_unicode_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_direction_ltr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_direction_rtl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_kerning_features.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_ligature_features.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/test_y_offset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 136 additions & 0 deletions Tests/test_imagefontctl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# -*- coding: utf-8 -*-
from helper import unittest, PillowTestCase
from PIL import Image
from PIL import ImageDraw

FONT_SIZE = 20
FONT_PATH = "Tests/fonts/DejaVuSans.ttf"

try:
from PIL import ImageFont

# check if raqm is available
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
im = Image.new(mode='RGB', size=(300, 100))
draw = ImageDraw.Draw(im)
draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr')

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 (KeyError, ImportError):
class TestImagecomplextext(PillowTestCase):
def test_skip(self):
self.skipTest("KeyError")

if __name__ == '__main__':
unittest.main()

# End of file
Loading