fontParts
fontParts copied to clipboard
Add auto renaming to `newGlyph` to preserve existing glyphs.
With the current default setting of clear=True, I think newGlyph operates a little dangerously.
I'm guessing changing this default value is out of the question, but perhaps it would be possible to add some sort of auto-renaming feature, to provide more flexibility in how to deal with existing glyphs?
A replacement name generator could be as simple as:
def generateReplacementName(self, name):
if name not in self:
return name
i = 1
while f"{name}.{i}" in self:
i += 1
return f"{name}.{i}"
An optional rename argument with the possible truthy values of "new"or "existing" might work similarly to how FontLab preserves existing glyphs, by optionally changing the name of the new glyph, or the existing one. It would take effect only when clear=False.