From cf0567d8a588797e3df267f53f807749c986f503 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Wed, 12 Feb 2020 14:20:36 +0000 Subject: [PATCH] subset_test: test subsetting font to empty glyf table --- Tests/subset/subset_test.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index 2ffc55501..14ca3137b 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -12,6 +12,8 @@ import shutil import sys import tempfile import unittest +import pathlib +import pytest class SubsetTest(unittest.TestCase): @@ -835,5 +837,40 @@ def test_subset_single_pos_format(): ] +@pytest.fixture +def ttf_path(tmp_path): + # $(dirname $0)/../ttLib/data + ttLib_data = pathlib.Path(__file__).parent.parent / "ttLib" / "data" + font = TTFont() + font.importXML(ttLib_data / "TestTTF-Regular.ttx") + font_path = tmp_path / "TestTTF-Regular.ttf" + font.save(font_path) + return font_path + + +def test_subset_empty_glyf(tmp_path, ttf_path): + subset_path = tmp_path / (ttf_path.name + ".subset") + # only keep empty .notdef and space glyph, resulting in an empty glyf table + subset.main( + [ + str(ttf_path), + "--no-notdef-outline", + "--glyph-names", + f"--output-file={subset_path}", + "--glyphs=.notdef space", + ] + ) + subset_font = TTFont(subset_path) + + assert subset_font.getGlyphOrder() == [".notdef", "space"] + assert subset_font.reader['glyf'] == b"\x00" + + glyf = subset_font["glyf"] + assert all(glyf[g].numberOfContours == 0 for g in subset_font.getGlyphOrder()) + + loca = subset_font["loca"] + assert all(loc == 0 for loc in loca) + + if __name__ == "__main__": sys.exit(unittest.main())