add tests for opaque COLR and CBDT fonts

This commit is contained in:
nulano 2020-03-29 15:57:10 +02:00
parent 9151da162c
commit 55db572467
10 changed files with 99 additions and 1 deletions

Binary file not shown.

View File

@ -2,10 +2,12 @@
NotoNastaliqUrdu-Regular.ttf and NotoSansSymbols-Regular.ttf, from https://github.com/googlei18n/noto-fonts
NotoSans-Regular.ttf, from https://www.google.com/get/noto/
NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/
NotoColorEmoji.ttf, from https://github.com/googlefonts/noto-emoji
AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype
TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny
ArefRuqaa-Regular.ttf, from https://github.com/google/fonts/tree/master/ofl/arefruqaa
ter-x20b.pcf, from http://terminus-font.sourceforge.net/
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.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -840,6 +840,102 @@ class TestImageFont:
ValueError, lambda: d.multiline_text((0, 0), "foo\nbar", anchor=anchor)
)
def test_standard_embedded_color(self):
txt = "Hello World!"
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE)
ttf.getsize(txt)
img = Image.new("RGB", (300, 64), "white")
d = ImageDraw.Draw(img)
d.text((10, 10), txt, font=ttf, fill="#fa6", embedded_color=True)
with Image.open("Tests/images/standard_embedded.png") as expected:
assert_image_similar(img, expected, max(self.metrics["multiline"], 3))
@pytest.mark.skipif(
parse_version(features.version_module("freetype2")) < parse_version("2.5.0"),
reason="Freetype 2.5.0 or newer required",
)
def test_cbdt(self):
try:
font = ImageFont.truetype(
"Tests/fonts/NotoColorEmoji.ttf",
size=109,
layout_engine=self.LAYOUT_ENGINE,
)
im = Image.new("RGB", (150, 150), "white")
d = ImageDraw.Draw(im)
d.text((10, 10), "\u263A", embedded_color=True, font=font)
with Image.open("Tests/images/cbdt_notocoloremoji.png") as expected:
assert_image_similar(im, expected, self.metrics["multiline"])
except IOError as ex:
assert str(ex) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or unsupported")
@pytest.mark.skipif(
parse_version(features.version_module("freetype2")) < parse_version("2.5.0"),
reason="Freetype 2.5.0 or newer required",
)
def test_cbdt_mask(self):
try:
font = ImageFont.truetype(
"Tests/fonts/NotoColorEmoji.ttf",
size=109,
layout_engine=self.LAYOUT_ENGINE,
)
im = Image.new("RGB", (150, 150), "white")
d = ImageDraw.Draw(im)
d.text((10, 10), "\u263A", "black", font=font)
with Image.open("Tests/images/cbdt_notocoloremoji_mask.png") as expected:
assert_image_similar(im, expected, self.metrics["multiline"])
except IOError as ex:
assert str(ex) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or unsupported")
@pytest.mark.skipif(
parse_version(features.version_module("freetype2")) < parse_version("2.10.0"),
reason="Freetype 2.10.0 or newer required",
)
def test_colr(self):
font = ImageFont.truetype(
"Tests/fonts/BungeeColor-Regular_colr_Windows.ttf",
size=64,
layout_engine=self.LAYOUT_ENGINE,
)
im = Image.new("RGB", (300, 75), "white")
d = ImageDraw.Draw(im)
d.text((15, 5), "Bungee", embedded_color=True, font=font)
with Image.open("Tests/images/colr_bungee.png") as expected:
assert_image_similar(im, expected, 21)
@pytest.mark.skipif(
parse_version(features.version_module("freetype2")) < parse_version("2.10.0"),
reason="Freetype 2.10.0 or newer required",
)
def test_colr_mask(self):
font = ImageFont.truetype(
"Tests/fonts/BungeeColor-Regular_colr_Windows.ttf",
size=64,
layout_engine=self.LAYOUT_ENGINE,
)
im = Image.new("RGB", (300, 75), "white")
d = ImageDraw.Draw(im)
d.text((15, 5), "Bungee", "black", font=font)
with Image.open("Tests/images/colr_bungee_mask.png") as expected:
assert_image_similar(im, expected, 22)
@skip_unless_feature("raqm")
class TestImageFont_RaqmLayout(TestImageFont):

View File

@ -40,4 +40,4 @@ def test_similar():
fill=(0, 0, 0),
font=font_outline,
)
assert_image_similar(im_bitmap, im_outline, 20)
assert_image_similar(im_bitmap, im_outline, 44)