diff --git a/README.md b/README.md index 5a4fa61..a2be214 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ they are available via brew (`brew install fontforge`). 2. Edit `ligatures.py` to disable any ligatures you don't want. 3. Run the script: `$ fontforge -lang=py ligaturize.py `, e.g. `$ fontforge -lang=py ligaturize.py input-fonts/Cousine-Regular.ttf output-fonts/CousineLigaturized-Regular.ttf` +The font family and weight for the output font (as recorded in the file) will be automatically set based on the name; if the output is `CousineLigaturized-Regular.ttf`, the font family will be `CousineLigaturized` and the font weight will be `Regular`. If no weight is specified, `Regular` is the default. + ## Misc. ## For more awesome programming fonts with ligatures, check out: diff --git a/ligaturize.py b/ligaturize.py index bf4f811..f99fbe8 100644 --- a/ligaturize.py +++ b/ligaturize.py @@ -23,30 +23,19 @@ config = { 'firacode_ttf': 'FiraCode-Medium.otf', } - -# "input-fonts/RobotoMono-Regular.ttf" -> "RobotoMono-Regular" -def name_without_file_extension(fontpath): - return path.splitext(path.basename(fontpath))[0] - -# "RobotoMono-Regular" -> "RobotoMono" -def name_without_width_variant(fontname): - no_variant = fontname - if fontname.endswith("Regular"): - no_variant = fontname[:-7] - elif fontname.endswith("Book"): - no_variant = fontname[:-4] - return no_variant[:-1] if (no_variant.endswith(" ") or no_variant.endswith("-")) else no_variant - def get_output_font_details(fontpath): - fontname = name_without_width_variant(name_without_file_extension(fontpath)) - name_with_spaces = split_camel_case(fontname) + fontname = path.splitext(path.basename(fontpath))[0] + if '-' in fontname: + [family, weight] = fontname.split('-', 1) + else: + [family, weight] = [fontname, 'Regular'] return { 'filename': fontpath, - 'fontname': fontname, - 'fullname': name_with_spaces, - 'familyname': name_with_spaces, + 'fontname': '%s-%s' % (family, weight), + 'fullname': '%s %s' % (split_camel_case(family), split_camel_case(weight)), + 'familyname': family, 'copyright_add': COPYRIGHT, - 'unique_id': name_with_spaces, + 'unique_id': '%s-%s' % (family, weight), } # Add spaces to UpperCamelCase: 'DVCode' -> 'DV Code' @@ -64,6 +53,7 @@ def split_camel_case(str): acc += ch return acc + class LigatureCreator(object): def __init__(self, font, firacode):