-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from helper import unittest, PillowTestCase | ||
from PIL import Image, ImageFont, ImageDraw | ||
|
||
class TestImageFontBitmap(PillowTestCase): | ||
def test_similar(self): | ||
text = 'EmbeddedBitmap' | ||
font_outline = ImageFont.truetype(font='Tests/fonts/DejaVuSans.ttf', size=24) | ||
font_bitmap = ImageFont.truetype(font='Tests/fonts/DejaVuSans-bitmap.ttf', size=24) | ||
size_outline, size_bitmap = font_outline.getsize(text), font_bitmap.getsize(text) | ||
size_final = max(size_outline[0], size_bitmap[0]), max(size_outline[1], size_bitmap[1]) | ||
im_bitmap = Image.new('RGB', size_final, (255, 255, 255)) | ||
im_outline = im_bitmap.copy() | ||
draw_bitmap, draw_outline = ImageDraw.Draw(im_bitmap), ImageDraw.Draw(im_outline) | ||
|
||
# Metrics are different on the bitmap and ttf fonts, more so on some platforms | ||
# and versions of freetype than others. Mac has a 1px difference, linux doesn't. | ||
draw_bitmap.text((0, size_final[1] - size_bitmap[1]), | ||
text, fill=(0, 0, 0), font=font_bitmap) | ||
draw_outline.text((0, size_final[1] - size_outline[1]), | ||
text, fill=(0, 0, 0), font=font_outline) | ||
self.assert_image_similar(im_bitmap, im_outline, 20) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters