Skip to content

Commit

Permalink
Merge pull request #727 from IvanUkhov/naming-table
Browse files Browse the repository at this point in the history
Respect overrides due to openTypeNameRecords for the predefined name IDs
  • Loading branch information
anthrotype committed Mar 9, 2023
2 parents 00a9627 + b56cd51 commit 46f4475
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
23 changes: 9 additions & 14 deletions Lib/ufo2ft/outlineCompiler.py
Expand Up @@ -382,20 +382,6 @@ def setupTable_name(self):
self.otf["name"] = name = newTable("name")
name.names = []

# Set name records from font.info.openTypeNameRecords
for nameRecord in getAttrWithFallback(font.info, "openTypeNameRecords"):
nameId = nameRecord["nameID"]
platformId = nameRecord["platformID"]
platEncId = nameRecord["encodingID"]
langId = nameRecord["languageID"]
# on Python 2, plistLib (used by ufoLib) returns unicode strings
# only when plist data contain non-ascii characters, and returns
# ascii-encoded bytes when it can. On the other hand, fontTools's
# name table `setName` method wants unicode strings, so we must
# decode them first
nameVal = nameRecord["string"]
name.setName(nameVal, nameId, platformId, platEncId, langId)

# Build name records
familyName = getAttrWithFallback(font.info, "styleMapFamilyName")
styleName = getAttrWithFallback(font.info, "styleMapStyleName").title()
Expand Down Expand Up @@ -452,6 +438,15 @@ def setupTable_name(self):
continue
name.setName(nameVal, nameId, platformId, platEncId, langId)

# Set name records from font.info.openTypeNameRecords
for nameRecord in getAttrWithFallback(font.info, "openTypeNameRecords"):
nameId = nameRecord["nameID"]
platformId = nameRecord["platformID"]
platEncId = nameRecord["encodingID"]
langId = nameRecord["languageID"]
nameVal = nameRecord["string"]
name.setName(nameVal, nameId, platformId, platEncId, langId)

def setupTable_maxp(self):
"""
Make the maxp table.
Expand Down
20 changes: 20 additions & 0 deletions tests/outlineCompiler_test.py
Expand Up @@ -228,6 +228,26 @@ def test_setupTable_meta(self, testufo):
assert meta.data["PRIA"] == b"Some private ascii string"
assert meta.data["PRIU"] == "Some private unicode string…".encode("utf-8")

def test_setupTable_name(self, testufo):
compiler = OutlineTTFCompiler(testufo)
compiler.compile()
actual = compiler.otf["name"].getName(1, 3, 1, 1033).string
assert actual == "Some Font Regular (Style Map Family Name)"

testufo.info.openTypeNameRecords.append(
{
"nameID": 1,
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"string": "Custom Name for Windows",
}
)
compiler = OutlineTTFCompiler(testufo)
compiler.compile()
actual = compiler.otf["name"].getName(1, 3, 1, 1033).string
assert actual == "Custom Name for Windows"


class OutlineOTFCompilerTest:
def test_setupTable_CFF_all_blues_defined(self, testufo):
Expand Down

0 comments on commit 46f4475

Please sign in to comment.