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

Ensure we write contents.plist, or we'll get an invalid ufo if no glyphs are ever added #1708

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
8 changes: 6 additions & 2 deletions src/fontra/backends/designspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ def _createUFO(self, sourceName: str) -> UFOLayer:
if value is not None:
setattr(info, infoAttr, value)
reader.writeInfo(info)
_ = reader.getGlyphSet() # this creates the default layer
glyphSet = reader.getGlyphSet() # this creates the default layer
glyphSet.writeContents()
reader.writeLayerContents()
ufoLayerName = reader.getDefaultLayerName()
assert os.path.isdir(ufoPath)
Expand Down Expand Up @@ -755,6 +756,8 @@ def _createUFOLayer(

if ufoLayerName not in existingLayerNames:
reader.writeLayerContents()
glyphSet = self.ufoManager.getGlyphSet(ufoPath, ufoLayerName)
glyphSet.writeContents()

ufoLayer = UFOLayer(
manager=self.ufoManager,
Expand Down Expand Up @@ -1370,7 +1373,8 @@ def createDSDocFromUFOPath(ufoPath, styleName):
info = UFOFontInfo()
_updateFontInfoFromDict(info, defaultUFOInfoAttrs)
writer.writeInfo(info)
_ = writer.getGlyphSet() # this creates the default layer
glyphSet = writer.getGlyphSet() # this creates the default layer
glyphSet.writeContents()
writer.writeLayerContents()
assert os.path.isdir(ufoPath)

Expand Down
15 changes: 15 additions & 0 deletions test-py/test_backends_designspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,21 @@ async def test_null_output(tmpdir, suffix):
await copyFont(inputBackend, outBackend)


@pytest.mark.parametrize("suffix", [".ufo", ".designspace"])
async def test_empty_layers_have_contents_plist(tmpdir, suffix, testFont):
tmpdir = pathlib.Path(tmpdir)
outPath = tmpdir / ("test" + suffix)

sources = await testFont.getSources()

outBackend = newFileSystemBackend(outPath)
await outBackend.putSources(sources)

for ufoPath in tmpdir.glob("*.ufo"):
for glyphsDir in ufoPath.glob("glyphs*"):
assert (glyphsDir / "contents.plist").exists()


def fileNamesFromDir(path):
return sorted(p.name for p in path.iterdir())

Expand Down