robotools / fontParts

The replacement for RoboFab
MIT License
134 stars 44 forks source link

NewFont defaultLayerName argument #632

Open typemytype opened 2 years ago

typemytype commented 2 years ago

When creating a new font object it would be nice to set the name of the default layer.

When the default layer name is not "public.default", the layer name "public.default" cannot exists, defcon asserts

proposal, similar to the optional arguments familyName, styleName

NewFont(familyName="MyFont", styleName="Regular", defaultLayerName="foreground") 

A tiny script to show the problem:

from fontParts.world import NewFont

font = NewFont(familyName="MyFont", styleName="Regular")
layer = font.newLayer("foreground")

font.defaultLayer = layer
font.save("test.ufo")   # this raises an issue

the patch:

if defaultLayerName is not None:
    # change the name of the newly created default layer
     font.defaultLayer.name = defaultLayerName
typemytype commented 2 years ago

I can make a PR and discus it there...