def main(font_path):
    filename = os.path.basename(font_path)
    font = TTFont(font_path)
    desired_style = style_parse(font)
    current_weight_class = font["OS/2"].usWeightClass
    updated = False
    if current_weight_class != desired_style.usWeightClass:
        print(
            f"{filename}: Updating weightClass to {desired_style.usWeightClass}"
        )
        font['OS/2'].usWeightClass = desired_style.usWeightClass
        updated = True
    # If static otf, update Thin and ExtraLight
    # TODO (M Foley) fontbakery's style_parse should do this
    if "CFF " in font and 'fvar' not in font:
        if desired_style.usWeightClass == 100:
            print(f"{filename}: Updating weightClass to {250}")
            font['OS/2'].usWeightClass = 250
            updated = True
        elif desired_style.usWeightClass == 200:
            print(f"{filename}: Updating weightClass to {275}")
            font['OS/2'].usWeightClass = 275
            updated = True
    if updated:
        font.save(font.reader.file.name + ".fix")
    else:
        print("{}: Skipping. Current WeightClass is correct".format(filename))
Ejemplo n.º 2
0
def expected_style(ttFont):
    from fontbakery.parse import style_parse
    return style_parse(ttFont)
Ejemplo n.º 3
0
import unicodedata
import os
import fontTools.ttLib
from fontbakery.parse import style_parse

file = sys.argv[1]
ttFont = fontTools.ttLib.TTFont(file)


# Variable Font
if 'fvar' in ttFont:

    # Sub family name
    for name in ttFont['name'].names:
        if name.nameID == 2:
            name.string = style_parse(ttFont).win_style_name
        if name.nameID == 17:
            name.string = style_parse(ttFont).win_style_name

    # macStyle & fsSelection
    if '-Italic' in file:
        ttFont['head'].macStyle |= 1 << 1  # Set  bit 1
        ttFont['OS/2'].fsSelection |= 1 << 0  # Set bit 0 (Italic)
        # Unset bit 5 (Bold)
        ttFont['OS/2'].fsSelection = ttFont['OS/2'].fsSelection & ~(1 << 5)
        # Unset bit 6 (Regular)
        ttFont['OS/2'].fsSelection = ttFont['OS/2'].fsSelection & ~(1 << 6)



ttFont.save(file)