mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-28 21:13:41 +03:00
Merge pull request #383 from hugovk/master
Fix for issue #382: TypeError with TransposedFont's getsize()
This commit is contained in:
commit
a803528c8a
|
@ -171,7 +171,7 @@ class TransposedFont:
|
||||||
self.orientation = orientation # any 'transpose' argument, or None
|
self.orientation = orientation # any 'transpose' argument, or None
|
||||||
|
|
||||||
def getsize(self, text):
|
def getsize(self, text):
|
||||||
w, h = self.font.getsize(text)[0]
|
w, h = self.font.getsize(text)
|
||||||
if self.orientation in (Image.ROTATE_90, Image.ROTATE_270):
|
if self.orientation in (Image.ROTATE_90, Image.ROTATE_270):
|
||||||
return h, w
|
return h, w
|
||||||
return w, h
|
return w, h
|
||||||
|
|
|
@ -90,3 +90,46 @@ def test_render_multiline():
|
||||||
assert_image_similar(im, target_img,.5)
|
assert_image_similar(im, target_img,.5)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rotated_transposed_font():
|
||||||
|
img_grey = Image.new("L", (100, 100))
|
||||||
|
draw = ImageDraw.Draw(img_grey)
|
||||||
|
word = "testing"
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
|
orientation = Image.ROTATE_90
|
||||||
|
transposed_font = ImageFont.TransposedFont(font, orientation=orientation)
|
||||||
|
|
||||||
|
# Original font
|
||||||
|
draw.setfont(font)
|
||||||
|
box_size_a = draw.textsize(word)
|
||||||
|
|
||||||
|
# Rotated font
|
||||||
|
draw.setfont(transposed_font)
|
||||||
|
box_size_b = draw.textsize(word)
|
||||||
|
|
||||||
|
# Check (w,h) of box a is (h,w) of box b
|
||||||
|
assert_equal(box_size_a[0], box_size_b[1])
|
||||||
|
assert_equal(box_size_a[1], box_size_b[0])
|
||||||
|
|
||||||
|
|
||||||
|
def test_unrotated_transposed_font():
|
||||||
|
img_grey = Image.new("L", (100, 100))
|
||||||
|
draw = ImageDraw.Draw(img_grey)
|
||||||
|
word = "testing"
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
|
orientation = None
|
||||||
|
transposed_font = ImageFont.TransposedFont(font, orientation=orientation)
|
||||||
|
|
||||||
|
# Original font
|
||||||
|
draw.setfont(font)
|
||||||
|
box_size_a = draw.textsize(word)
|
||||||
|
|
||||||
|
# Rotated font
|
||||||
|
draw.setfont(transposed_font)
|
||||||
|
box_size_b = draw.textsize(word)
|
||||||
|
|
||||||
|
# Check boxes a and b are same size
|
||||||
|
assert_equal(box_size_a, box_size_b)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user