From 768ba112ff90bbb5540d78a07445121f3ee4c887 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Wed, 17 Jan 2018 20:20:33 -0500 Subject: [PATCH] Add support for copying individual characters as well --- README.md | 2 +- ligatures.py | 16 ++++++++++++++++ ligaturize.py | 11 +++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a2be214..a547e9f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ they are available via brew (`brew install fontforge`). ## Using the Script ## 1. Move/copy the font you want to ligaturize into `input-fonts/` (or somewhere else convenient). -2. Edit `ligatures.py` to disable any ligatures you don't want. +2. Edit `ligatures.py` to disable any ligatures you don't want, and/or enable any (non-ligature) characters you want from Fira Code in addition to the ligatures. 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. diff --git a/ligatures.py b/ligatures.py index 697aa4e..c96d638 100644 --- a/ligatures.py +++ b/ligatures.py @@ -1,4 +1,20 @@ ligatures = [ + ## These are all the punctuation characters used in Fira Code ligatures. + ## Uncomment this block to enable copying of these characters as well; it + ## will make punctuation blend in with the ligatures more cleanly, at the + ## cost of blending in with the rest of the font not as well. + ## You can also edit the 'chars' list to change exactly which characters + ## will be copied. + # { + # 'chars': [ + # 'ampersand', 'asciicircum', 'asciitilde', 'asterisk', 'at', + # 'backslash', 'bar', 'braceleft', 'braceright', 'bracketleft', 'bracketright', + # 'colon', 'dollar', 'equal', 'exclam', 'greater', 'hyphen', + # 'less', 'numbersign', 'parenleft', 'percent', 'period', 'plus', + # 'question', 'semicolon', 'slash', 'underscore', + # ], + # 'firacode_ligature_name': None, + # }, { # <- 'chars': ['less', 'hyphen'], 'firacode_ligature_name': 'less_hyphen.liga', diff --git a/ligaturize.py b/ligaturize.py index e8effd6..f7d0037 100644 --- a/ligaturize.py +++ b/ligaturize.py @@ -87,6 +87,17 @@ class LigatureCreator(object): def add_ligature(self, input_chars, firacode_ligature_name): + if firacode_ligature_name is None: + # No ligature name -- we're just copying a bunch of individual characters. + for char in input_chars: + self.firacode.selection.none() + self.firacode.selection.select(char) + self.firacode.copy() + self.font.selection.none() + self.font.selection.select(char) + self.font.paste() + return + if not self.copy_ligature_from_source(firacode_ligature_name): print('Error reading ligature %s from %s -- skipping' % ( firacode_ligature_name, self.firacode.fontname))