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
Remove redundant name table records #3185
Conversation
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.
Looks good!
Snippets/clean-nametable.py
Outdated
def __init__(self): | ||
self.seen = set() | ||
|
||
def removeUnusedNameRecords(self, font): |
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.
Maybe remove this from the visitor object, move it somewhere else.
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.
Thanks for looking. I've moved and converted the function so it's a static method of the name table. Imo it feels like belongs here. Happy to drop the static method and just have it as a plain func instead. I've moved it away from the Snippets dir so it can be imported into other libs and tools.
Happy to add tests if you're ok with the above. Still not too sure if I've found all the places in a font which can have a nameID though.
Thanks. We should see if we can use this, or at least compare notes with, the subsetter. That one looks very incomplete to me. https://github.com/fonttools/fonttools/blob/main/Lib/fontTools/subset/__init__.py#L2917 |
I'm not too familiar with all of the subsetting code. However, if I skim, I see |
Thanks. Checking the subset code, I think we need to move the name-table subsetting from There's also some "name" table code in the "CPAL" subsetting method, which should be removed. I don't remember why "name" table is in |
Can you please do this as well? Thanks. I let @anthrotype review the rest. |
Think I got it all. Thanks for your help Behdad! |
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.
LGTM, with comments
the snippet doesn't do much besides loading a TTFont, calling remoteUnusedNames method, and saving back; do we actually need it? |
Thanks Cosimo. I've implemented your feedback and removed the snippet. The comment may be too long for your liking. Lmk and I'll rephrase. |
I've needed a way to remove redundant name table records for many years so I thought I'd just write it. I'm using Behdad's visitor pattern to collect all the name records which are being used by the fvar, STAT, CPAL etc.
You can get redundant name records when you replace a font's STAT table using the builder's buildSTAT function or when hot fixing with other scripts etc.
My plan is to make
removeUnusedNameRecords
a method oftable__n_a_m_e
. I just wanted to open this pr to get feedback before I progress too far. No worries if you don't want this pr either.So far I've covered every table in ttLib/tables/otData, STAT, fvar and CPAL. Please let me know if I'm missing any.