-
Notifications
You must be signed in to change notification settings - Fork 475
Extend name table with more general functions #2526
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
Changes from all commits
c50f38e
17f4b76
1a16b24
79360a3
6d05b93
1649973
8dddbf4
5986107
8e0aad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ dist/ | |
*.egg-info/ | ||
*.egg | ||
MANIFEST | ||
.idea | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,44 @@ def getDebugName(self, nameID): | |
else: | ||
return None | ||
|
||
def getFirstDebugName(self, nameIDs): | ||
for nameID in nameIDs: | ||
name = self.getDebugName(nameID) | ||
if name is not None: | ||
return name | ||
return None | ||
|
||
def getBestFamilyName(self): | ||
# 21 = WWS Family Name | ||
# 16 = Typographic Family Name | ||
# 1 = Family Name | ||
return self.getFirstDebugName((21, 16, 1)) | ||
|
||
def getBestSubFamilyName(self): | 8000 tr>||
# 22 = WWS SubFamily Name | ||
# 17 = Typographic SubFamily Name | ||
# 2 = SubFamily Name | ||
return self.getFirstDebugName((22, 17, 2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should always priorise the record 22 and 17. There should be a parameter. For example, in my case, I would like to get the "real" SubFamily Name. |
||
|
||
def getBestFullName(self): | ||
# 4 = Full Name | ||
# 6 = PostScript Name | ||
for nameIDs in ((21, 22), (16, 17), (1, 2), (4, ), (6, )): | ||
if len(nameIDs) == 2: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you check if the lenght of nameIDs is 2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @moi15moi , thanks for asking. The reason behind is, because the loop starts with the preferred name table ID pairs (21, 22), (16, 17), (1, 2). And if none of them are present (which might be the case in obfuscated web font) then use only the (4, ), (6, ). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks. I am trying to understand why getBestFullName, getBestFamilyName and getBestSubFamilyName does not always return me the good name. I did some commit to make to get the right name, but I am not too sure if I am allow to use: utf-16-be Edit: Here is how FontConfig get the right name: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/src/fcfreetype.c#L693 |
||
name_fam = self.getDebugName(nameIDs[0]) | ||
name_subfam = self.getDebugName(nameIDs[1]) | ||
if None in [name_fam, name_subfam]: | ||
continue # if any is None, skip | ||
name = f"{name_fam} {name_subfam}" | ||
if name_subfam.lower() == 'regular': | ||
name = f"{name_fam}" | ||
return name | ||
else: | ||
name = self.getDebugName(nameIDs[0]) | ||
if name is not None: | ||
return name | ||
return None | ||
|
||
def setName(self, string, nameID, platformID, platEncID, langID): | ||
""" Set the 'string' for the name record identified by 'nameID', 'platformID', | ||
'platEncID' and 'langID'. If a record with that nameID doesn't exist, create it | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should always priorise the record 21 and 16.
There should be a parameter to specify what we want prioritized. For example, in my case, I would like to get the "real" Family Name.