[Python] How can I edit and save Variable .ttf font?

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    My goal is to add a little dash to a letter and paste it instead of random symbol. I did it with static font and it worked(FontForge), but when I'm using variable font(RobotoFlex-VariableFont) the program can't even save it. And if I get rid of errors, in the end all weights are not displaying correctly(they almost all look like approximately weight=400 except the bold ones). Is it possible? I used Python library "fonttools" with this code:

    from fontTools.ttLib import TTFont

    font = TTFont("RobotoFlex-VariableFont_GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght.ttf")

    for weight, name in [(100, "Thin"), (200, "ExtraLight"), (300, "Light"), (400, "Regular"), (500, "Medium"), (600, "SemiBold"), (700, "Bold"), (800, "ExtraBold"), (900, "Black")]:
    font["fvar"].instances = [inst for inst in font["fvar"].instances if inst.coordinates["wght"] == weight]
    font.save(f"Roboto-{name}.ttf")


    but it is also not displaying correctly.

    Continue reading...

Compartilhe esta Página