Search code examples
fontswebfonts

Bulk changing font properties


I have a directory of fonts like so:

├── Trenda Black It.ttf
├── Trenda Black.ttf
├── Trenda Bold It.ttf
├── Trenda Bold.ttf
├── Trenda ExtraLight It.ttf
├── Trenda ExtraLight.ttf
├── Trenda Heavy It.ttf
├── Trenda Heavy.ttf
├── Trenda Light It.ttf
├── Trenda Light.ttf
├── Trenda RegularIt.ttf
├── Trenda Regular.ttf
├── Trenda Semibold It.ttf
├── Trenda Semibold.ttf
├── Trenda Thin It.ttf
└── Trenda Thin.ttf

Unfortunately, the font families are not all Trenda, they are Trenda Black, Trenda Bold and so on.

Is there a way to automate the process of changing all of the Font-Families to Trenda?

Previously I have done it manually on each Font using Font Forge but this takes ages.

It would be great if I was also able to set the Weight Class as well based on the name.


Solution

  • For anyone looking, you can interface with font forge in python.

    Python is not what I normally program in so appologies for the poor code

    #!/usr/bin/env python
    import fontforge as ff
    import sys
    
    args = sys.argv[1:]
    
    if args[0] == '--help':
        print("changeFontFamily <font> <family> <newFont>")
    else:
        font = args[0]
        family = args[1]
        newfont = args[2]
        f = ff.open( font )
        f.familyname = family
        f.generate(newfont)
    

    I then just use this in a bash loop

    for file in *.ttf; do changeFontFamily "$file" "Trenda" "new/$file" 2> /dev/null; done