Skip to content

Commit

Permalink
uvsDict uses list of tuples instead of dict
Browse files Browse the repository at this point in the history
  • Loading branch information
moyogo committed Apr 15, 2021
1 parent e8a1128 commit 737ffc8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
21 changes: 14 additions & 7 deletions Lib/ufo2ft/outlineCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,22 @@ def setupTable_cmap(self):
cmap14_0_5.platformID = 0
cmap14_0_5.platEncID = 5
cmap14_0_5.language = 0
cmap14_0_5.cmap = {}
if nonBMP:
mapping = nonBMP
cmap14_0_5.uvsDict = {
uvs: {
uv: None if glyphName == mapping[uv] else glyphName
for (uv, glyphName) in glyphMapping.items()
}
for (uvs, glyphMapping) in uvsMapping.items()
}
uvsDict = dict()
# public.unicodeVariationSequences uses hex strings as keys and
# a dict of dicts, while cmap uses ints and a dict of tuples.
for hexvs, glyphMapping in uvsMapping.items():
uvsList = []
for hexvalue, glyphName in glyphMapping.items():
value = int(hexvalue, 16)
if glyphName == mapping[value]:
uvsList.append((value, None))
else:
uvsList.append((value, glyphName))
uvsDict[int(hexvs, 16)] = uvsList
cmap14_0_5.uvsDict = uvsDict
# update tables registry
cmap.tables.append(cmap14_0_5)

Expand Down
20 changes: 10 additions & 10 deletions tests/outlineCompiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,11 +830,11 @@ def test_cmap_nonBMP_with_UVS(self, testufo):
u1F170.unicode = 0x1F170
testufo.newGlyph("u1F170.text")
testufo.lib["public.unicodeVariationSequences"] = {
0xFE0E: {
0x1F170: "u1F170.text",
"FE0E": {
"1F170": "u1F170.text",
},
0xFE0F: {
0x1F170: "u1F170",
"FE0F": {
"1F170": "u1F170",
},
}

Expand All @@ -846,10 +846,10 @@ def test_cmap_nonBMP_with_UVS(self, testufo):
cmap.compile(otf)
assert len(cmap.tables) == 5
cmap4_0_3 = cmap.tables[0]
cmap4_3_1 = cmap.tables[1]
cmap12_0_4 = cmap.tables[2]
cmap12_3_10 = cmap.tables[3]
cmap14_0_5 = cmap.tables[4]
cmap12_0_4 = cmap.tables[1]
cmap14_0_5 = cmap.tables[2]
cmap4_3_1 = cmap.tables[3]
cmap12_3_10 = cmap.tables[4]

assert (cmap4_0_3.platformID, cmap4_0_3.platEncID) == (0, 3)
assert (cmap4_3_1.platformID, cmap4_3_1.platEncID) == (3, 1)
Expand All @@ -871,8 +871,8 @@ def test_cmap_nonBMP_with_UVS(self, testufo):
assert (cmap14_0_5.platformID, cmap14_0_5.platEncID) == (0, 5)
assert cmap14_0_5.language == 0
assert cmap14_0_5.uvsDict == {
0xFE0E: {0x1F170: "u1F170.text"},
0xFE0F: {0x1F170: None},
0xFE0E: [(0x1F170, "u1F170.text")],
0xFE0F: [(0x1F170, None)],
}


Expand Down

0 comments on commit 737ffc8

Please sign in to comment.