add test for {1bpp, 2bpp, 4bpp, 8bpp} bitmap fonts

This commit is contained in:
nulano 2020-10-07 04:36:12 +01:00
parent 28d313305a
commit 24f3d85a3e
10 changed files with 22 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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}-stripped.ttf are based on DejaVuSans.ttf converted using FontForge to add bitmap strikes and keep only the ASCII range.
10x20-ISO8859-1.pcf, from https://packages.ubuntu.com/xenial/xfonts-base
"Public domain font. Share and enjoy."

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -2,7 +2,7 @@ import pytest
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:
@ -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}-stripped.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)