Merge pull request #2 from tomarcher101/add-error-when-duplicate-in-kerning-group

Add code that removes duplicates when parsing groups.plist
This commit is contained in:
Tom 2020-05-22 11:19:38 +01:00 committed by GitHub
commit 5c8c6b3c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 1 deletions

View File

@ -459,7 +459,12 @@ class UFOReader(_UFOBaseIO):
# groups.plist
def _readGroups(self):
return self._getPlist(GROUPS_FILENAME, {})
groups = self._getPlist(GROUPS_FILENAME, {})
# remove any duplicate glyphs in a kerning group
for groupName, glyphList in groups.items():
if groupName.startswith('public.kern1.') or groupName.startswith('public.kern2.'):
groups[groupName] = list(OrderedDict.fromkeys(glyphList))
return groups
def readGroups(self, validate=None):
"""

View File

@ -4192,6 +4192,19 @@ class UFO3ReadDataTestCase(unittest.TestCase):
fileObject = reader.getReadFileForPath("data/org.unifiedfontobject.doesNotExist")
self.assertEqual(fileObject, None)
def testUFOReaderKernGroupDuplicatesRemoved(self):
# Non-kerning group duplicates are kept
# Kerning group duplicates are removed
expected_groups = {
"group1" : ["A"],
"group2" : ["B", "C", "B"],
"public.kern1.A" : ["A"],
"public.kern2.B" : ["B", "A", "C"],
}
reader = UFOReader(self.getFontPath())
groups = reader.readGroups()
self.assertEqual(expected_groups, groups)
class UFO3WriteDataTestCase(unittest.TestCase):

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>group1</key>
<array>
<string>A</string>
</array>
<key>group2</key>
<array>
<string>B</string>
<string>C</string>
<string>B</string>
</array>
<key>public.kern1.A</key>
<array>
<string>A</string>
</array>
<key>public.kern2.B</key>
<array>
<string>B</string>
<string>A</string>
<string>B</string>
<string>A</string>
<string>C</string>
</array>
</dict>
</plist>