Incompatible glyphs must be removed from designspace rules
I've added a set of rules to a variable font to swap .italic glyphs in for a high range in the slant axis.
However, that means that FontMake is now failing with messages like this:
File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fontTools/ttLib/ttFont.py", line 602, in getGlyphID
glyphID = d[glyphName]
KeyError: ('g', 'SingleSubst[0]', 'Lookup[0]', 'LookupList')
This is because some of the glyphs in my rules were incompatible for cu2qu, and therefore had to be removed. So, for instance, the font can't apply the GSUB rule g.italic, because this glyph is no longer in the varfont-prepped fonts.
Ideally, the prep script should check the designspace for rules, and remove rules that can no longer be supported.
This is dependant on the prep script doing a better job at catching things that can't be processed by cu2qu: https://github.com/thundernixon/varfont-prep/issues/2
Stumbled across the same problem recently too. I helped myself with this quickly amended version of your remove_list-of_glyphs.py script.
from vanilla.dialogs import *
from mojo.UI import AskString
from fontTools.designspaceLib import DesignSpaceDocument
glyphsToDelete = AskString(
'Input glyphnames to remove, then select designspace').replace("'", "").replace(",", "").split(" ")
instruction = f"select designspace to remove {glyphsToDelete} from"
docPath = getFile(
instruction, allowsMultipleSelection=False, fileTypes=["designspace"])
doc = DesignSpaceDocument()
doc.read(*docPath)
for gName in glyphsToDelete:
for rule in doc.rules:
newSubs = []
for sub in rule.subs:
if gName not in sub:
newSubs.append(sub)
rule.subs = newSubs
doc.write(*docPath)