Skip to content

Commit 7cf03b8

Browse files
committed
add test for {1bpp, 2bpp, 4bpp, 8bpp} bitmap fonts
1 parent 28d3133 commit 7cf03b8

File tree

10 files changed

+22
-1
lines changed

10 files changed

+22
-1
lines changed

Tests/fonts/DejaVuSans-24-1.ttf

941 KB
Binary file not shown.

Tests/fonts/DejaVuSans-24-2.ttf

1.12 MB
Binary file not shown.

Tests/fonts/DejaVuSans-24-4.ttf

1.51 MB
Binary file not shown.

Tests/fonts/DejaVuSans-24-8.ttf

2.2 MB
Binary file not shown.

Tests/fonts/LICENSE.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ BungeeColor-Regular_colr_Windows.ttf, from https://github.com/djrrb/bungee
1212
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.
1313

1414

15+
DejaVuSans-24-{1,2,4,8}.ttf are based on DejaVuSans.ttf converted using FontForge.
16+
17+
1518
10x20-ISO8859-1.pcf, from https://packages.ubuntu.com/xenial/xfonts-base
1619

1720
"Public domain font. Share and enjoy."

Tests/images/bitmap_font_1.png

481 Bytes
Loading

Tests/images/bitmap_font_2.png

661 Bytes
Loading

Tests/images/bitmap_font_4.png

1.12 KB
Loading

Tests/images/bitmap_font_8.png

1.95 KB
Loading

Tests/test_imagefont_bitmap.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from PIL import Image, ImageDraw, ImageFont
44

5-
from .helper import assert_image_similar
5+
from .helper import assert_image_equal_tofile, assert_image_similar, skip_unless_feature
66

77
image_font_installed = True
88
try:
@@ -41,3 +41,21 @@ def test_similar():
4141
font=font_outline,
4242
)
4343
assert_image_similar(im_bitmap, im_outline, 4)
44+
45+
46+
@skip_unless_feature("freetype2")
47+
@pytest.mark.parametrize("bpp", (1, 2, 4, 8))
48+
def test_bitmap_font(bpp):
49+
text = "Bitmap Font"
50+
target = f"Tests/images/bitmap_font_{bpp}.png"
51+
font = ImageFont.truetype(
52+
f"Tests/fonts/DejaVuSans-24-{bpp}.ttf",
53+
24,
54+
layout_engine=ImageFont.LAYOUT_BASIC,
55+
)
56+
57+
im = Image.new("RGB", (160, 35), "white")
58+
draw = ImageDraw.Draw(im)
59+
draw.text((2, 2), text, "black", font)
60+
61+
assert_image_equal_tofile(im, target)

0 commit comments

Comments
 (0)