mirror of
https://github.com/ToxicFrog/Ligaturizer.git
synced 2024-08-16 13:20:41 +03:00
Infer font family and weight from output filename
In particular, this means you can generate (e.g.) 'CousineLigatures-Regular.ttf' and 'CousineLigatures-Bold.ttf', and they will both be in the font family 'Cousine Ligatures'.
This commit is contained in:
parent
833174fdc5
commit
55ca80572d
@ -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 <INPUT> <OUTPUT>`, 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:
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user