Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle input UFO with bad glyph names? #271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/featureWriters/kernFeatureWriter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from ufo2ft.featureCompiler import parseLayoutFeatures
from ufo2ft.featureWriters import KernFeatureWriter, ast
from ufo2ft.errors import InvalidFontData

import pytest
from . import FeatureWriterTest
Expand Down Expand Up @@ -722,6 +723,15 @@ def test_kern_RTL_and_DFLT_numbers(self, FontClass):
"""
)

def test_error_on_bad_glyph_name(self, FontClass):
# One glyph has an invalid glyph name (in fea syntax): "V,"
glyphs = {"A": ord('A'), "V,": ord("V")}
kerning = {("A", "V,"): -40}
features = "languagesystem latn dflt;"
ufo = makeUFO(FontClass, glyphs, kerning=kerning, features=features)
with pytest.raises(InvalidFontData):
generated = self.writeFeatures(ufo)


if __name__ == "__main__":
import sys
Expand Down
9 changes: 9 additions & 0 deletions tests/featureWriters/markFeatureWriter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
parseAnchorName,
)
from ufo2ft.featureCompiler import parseLayoutFeatures
from ufo2ft.errors import InvalidFontData

import pytest
from . import FeatureWriterTest
Expand Down Expand Up @@ -579,6 +580,14 @@ def test_all_features(self, testufo):
"""
)

def test_error_on_bad_glyph_name(self, testufo):
# Add a glyph with an invalid name to the test UFO: "f_i,"
testufo.newGlyph("a,").appendAnchor({"name": "top", "x": 100, "y": 200})
writer = MarkFeatureWriter()
feaFile = ast.FeatureFile()
with pytest.raises(InvalidFontData):
writer.write(testufo, feaFile)


if __name__ == "__main__":
import sys
Expand Down