Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

kerning groups conversion #82

Open
typemytype opened this issue Jul 23, 2017 · 2 comments
Open

kerning groups conversion #82

typemytype opened this issue Jul 23, 2017 · 2 comments

Comments

@typemytype
Copy link
Collaborator

Converting UFO2 to UFO3 goes fine. When save it back to UFO2 the new (UFO3)groups are there and cause issues while reopening/reconverting the UFO back to UFO3, cause both old and new groups are available. This should not happen, a simple check on the glyphList should be enough to determine if the group should have an additional prefix number.

"The glyph "%s" occurs in too many kerning groups."

https://github.com/unified-font-object/ufoLib/blob/master/Lib/ufoLib/converters.py#L37

@anthrotype
Copy link
Member

i'm not sure what to do with this. @typemytype please send a patch when you get to it, thanks.

@anthrotype
Copy link
Member

When save it back to UFO2 the new (UFO3)groups are there

hm that's strange. If you set formatVersion=2, and call the writer.setKerningGroupConversionRenameMaps method with the same conversion mapping that you got from the reader.getKerningGroupConversionRenameMaps, then the writer should restore the old kerning group names, unless I'm missing something.
There's even a test for that:

class KerningDownConversionTestCase(unittest.TestCase):
expectedKerning = {
("public.kern1.BGroup", "public.kern2.CGroup"): 7,
("public.kern1.BGroup", "public.kern2.DGroup"): 8,
("public.kern1.BGroup", "A"): 5,
("public.kern1.BGroup", "B"): 6,
("public.kern1.CGroup", "public.kern2.CGroup"): 11,
("public.kern1.CGroup", "public.kern2.DGroup"): 12,
("public.kern1.CGroup", "A"): 9,
("public.kern1.CGroup", "B"): 10,
("A", "public.kern2.CGroup"): 3,
("A", "public.kern2.DGroup"): 4,
("A", "A"): 1,
("A", "B"): 2
}
groups = {
"BGroup": ["B"],
"CGroup": ["C"],
"DGroup": ["D"],
"public.kern1.BGroup": ["B"],
"public.kern1.CGroup": ["C", "Ccedilla"],
"public.kern2.CGroup": ["C", "Ccedilla"],
"public.kern2.DGroup": ["D"],
"Not A Kerning Group" : ["A"]
}
expectedWrittenGroups = {
"BGroup": ["B"],
"CGroup": ["C", "Ccedilla"],
"DGroup": ["D"],
"Not A Kerning Group" : ["A"]
}
kerning = {
("public.kern1.BGroup", "public.kern2.CGroup"): 7,
("public.kern1.BGroup", "public.kern2.DGroup"): 8,
("public.kern1.BGroup", "A"): 5,
("public.kern1.BGroup", "B"): 6,
("public.kern1.CGroup", "public.kern2.CGroup"): 11,
("public.kern1.CGroup", "public.kern2.DGroup"): 12,
("public.kern1.CGroup", "A"): 9,
("public.kern1.CGroup", "B"): 10,
("A", "public.kern2.CGroup"): 3,
("A", "public.kern2.DGroup"): 4,
("A", "A"): 1,
("A", "B"): 2
}
expectedWrittenKerning = {
"BGroup" : {
"CGroup" : 7,
"DGroup" : 8,
"A" : 5,
"B" : 6
},
"CGroup" : {
"CGroup" : 11,
"DGroup" : 12,
"A" : 9,
"B" : 10
},
"A" : {
"CGroup" : 3,
"DGroup" : 4,
"A" : 1,
"B" : 2
}
}
downConversionMapping = {
"side1" : {
"BGroup" : "public.kern1.BGroup",
"CGroup" : "public.kern1.CGroup"
},
"side2" : {
"CGroup" : "public.kern2.CGroup",
"DGroup" : "public.kern2.DGroup"
}
}
def setUp(self):
self.tempDir = tempfile.mktemp()
os.mkdir(self.tempDir)
self.dstDir = os.path.join(self.tempDir, "test.ufo")
def tearDown(self):
shutil.rmtree(self.tempDir)
def tearDownUFO(self):
shutil.rmtree(self.dstDir)
def testWrite(self):
writer = UFOWriter(self.dstDir, formatVersion=2)
writer.setKerningGroupConversionRenameMaps(self.downConversionMapping)
writer.writeKerning(self.kerning)
writer.writeGroups(self.groups)
# test groups
path = os.path.join(self.dstDir, "groups.plist")
with open(path, "rb") as f:
writtenGroups = plistlib.load(f)
self.assertEqual(writtenGroups, self.expectedWrittenGroups)
# test kerning
path = os.path.join(self.dstDir, "kerning.plist")
with open(path, "rb") as f:
writtenKerning = plistlib.load(f)
self.assertEqual(writtenKerning, self.expectedWrittenKerning)
self.tearDownUFO()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants