mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #784 from tk0miya/master
Fix return value of FreeTypeFont.textsize() does not include font offsets
This commit is contained in:
commit
962f1b46af
|
@ -140,7 +140,8 @@ class FreeTypeFont:
|
|||
return self.font.ascent, self.font.descent
|
||||
|
||||
def getsize(self, text):
|
||||
return self.font.getsize(text)[0]
|
||||
size, offset = self.font.getsize(text)
|
||||
return (size[0] + offset[0], size[1] + offset[1])
|
||||
|
||||
def getoffset(self, text):
|
||||
return self.font.getsize(text)[1]
|
||||
|
|
BIN
Tests/images/rectangle_surrounding_text.png
Normal file
BIN
Tests/images/rectangle_surrounding_text.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -71,11 +71,25 @@ try:
|
|||
self.assert_image_equal(img_path, img_filelike)
|
||||
self._clean()
|
||||
|
||||
def test_textsize_equal(self):
|
||||
im = Image.new(mode='RGB', size=(300, 100))
|
||||
draw = ImageDraw.Draw(im)
|
||||
ttf = ImageFont.truetype(font_path, font_size)
|
||||
|
||||
txt = "Hello World!"
|
||||
size = draw.textsize(txt, ttf)
|
||||
draw.text((10, 10), txt, font=ttf)
|
||||
draw.rectangle((10, 10, 10 + size[0], 10 + size[1]))
|
||||
|
||||
target = 'Tests/images/rectangle_surrounding_text.png'
|
||||
target_img = Image.open(target)
|
||||
self.assert_image_equal(im, target_img)
|
||||
|
||||
def test_render_multiline(self):
|
||||
im = Image.new(mode='RGB', size=(300, 100))
|
||||
draw = ImageDraw.Draw(im)
|
||||
ttf = ImageFont.truetype(font_path, font_size)
|
||||
line_spacing = draw.textsize('A', font=ttf)[1] + 8
|
||||
line_spacing = draw.textsize('A', font=ttf)[1] + 4
|
||||
lines = ['hey you', 'you are awesome', 'this looks awkward']
|
||||
y = 0
|
||||
for line in lines:
|
||||
|
|
Loading…
Reference in New Issue
Block a user