Skip to content

Commit

Permalink
add test for {1bpp, 2bpp, 4bpp, 8bpp} bitmap fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano committed Oct 7, 2020
1 parent 0bd2930 commit d5c1b8c
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 1 deletion.
Binary file added Tests/fonts/DejaVuSans-24-1.ttf
Binary file not shown.
Binary file added Tests/fonts/DejaVuSans-24-2.ttf
Binary file not shown.
Binary file added Tests/fonts/DejaVuSans-24-4.ttf
Binary file not shown.
Binary file added Tests/fonts/DejaVuSans-24-8.ttf
Binary file not shown.
3 changes: 3 additions & 0 deletions Tests/fonts/LICENSE.txt
Expand Up @@ -12,6 +12,9 @@ BungeeColor-Regular_colr_Windows.ttf, from https://github.com/djrrb/bungee
All of the above fonts are published under the SIL Open Font License (OFL) v1.1 (http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL), which allows you to copy, modify, and redistribute them if you need to.


DejaVuSans-24-{1,2,4,8}.ttf are based on DejaVuSans.ttf converted using FontForge.


10x20-ISO8859-1.pcf, from https://packages.ubuntu.com/xenial/xfonts-base

"Public domain font. Share and enjoy."
Binary file added Tests/images/bitmap_font_1.png
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/bitmap_font_2.png
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/bitmap_font_4.png
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/bitmap_font_8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion Tests/test_imagefont_bitmap.py
Expand Up @@ -2,7 +2,7 @@

from PIL import Image, ImageDraw, ImageFont

from .helper import assert_image_similar
from .helper import assert_image_equal_tofile, assert_image_similar, skip_unless_feature

image_font_installed = True
try:
Expand Down Expand Up @@ -41,3 +41,21 @@ def test_similar():
font=font_outline,
)
assert_image_similar(im_bitmap, im_outline, 4)


@skip_unless_feature("freetype2")
@pytest.mark.parametrize("bpp", (1, 2, 4, 8))
def test_bitmap_font(bpp):
text = "Bitmap Font"
target = f"Tests/images/bitmap_font_{bpp}.png"
font = ImageFont.truetype(
f"Tests/fonts/DejaVuSans-24-{bpp}.ttf",
24,
layout_engine=ImageFont.LAYOUT_BASIC,
)

im = Image.new("RGB", (160, 35), "white")
draw = ImageDraw.Draw(im)
draw.text((2, 2), text, "black", font)

assert_image_equal_tofile(im, target)

0 comments on commit d5c1b8c

Please sign in to comment.