mirror of
https://github.com/ToxicFrog/Ligaturizer.git
synced 2024-09-11 09:55:47 +03:00
Add --copy-character-glyphs option
Whether character glyphs are copied is now controlled by the command line options rather than by `ligatures.py`.
This commit is contained in:
parent
ba71329c48
commit
ce11b2e92f
@ -49,12 +49,12 @@ Use automatic mode to easily convert 1 or more font(s).
|
|||||||
### Manual ###
|
### Manual ###
|
||||||
|
|
||||||
1. Move/copy the font you want to ligaturize into `input-fonts/` (or somewhere else convenient).
|
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, and/or enable any (non-ligature) characters you want from Fira Code in addition to the ligatures.
|
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`
|
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.
|
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.
|
||||||
|
|
||||||
`ligatures.py` supports some additional command line options to (e.g.) change which font ligatures are copied from; run `fontforge -lang=py ligaturize.py --help` to list them.
|
`ligatures.py` supports some additional command line options to (e.g.) change which font ligatures are copied from or enable copying of individual character glyphs; run `fontforge -lang=py ligaturize.py --help` to list them.
|
||||||
|
|
||||||
## Misc. ##
|
## Misc. ##
|
||||||
### Credit ###
|
### Credit ###
|
||||||
|
40
ligatures.py
40
ligatures.py
@ -1,20 +1,28 @@
|
|||||||
|
## This is the master list of ligatures that ligaturize.py will attempt to copy
|
||||||
|
## from Fira Code to your output font. Ligatures that aren't present in the
|
||||||
|
## version of Fira Code you're using will be skipped.
|
||||||
|
## To disable ligatures, simply comment them out in this file.
|
||||||
ligatures = [
|
ligatures = [
|
||||||
## These are all the punctuation characters used in Fira Code ligatures.
|
{
|
||||||
## Uncomment this block to enable copying of these characters as well; it
|
## These are all the punctuation characters used in Fira Code ligatures.
|
||||||
## will make punctuation blend in with the ligatures more cleanly, at the
|
## Use the `--copy-character-glyphs` option to copy these into the output
|
||||||
## cost of blending in with the rest of the font not as well.
|
## font along with the ligatures themselves.
|
||||||
## You can also edit the 'chars' list to change exactly which characters
|
'chars': [
|
||||||
## will be copied.
|
## These characters generally look good in most fonts and are
|
||||||
# {
|
## enabled by default if you use `--copy-character-glyphs`.
|
||||||
# 'chars': [
|
'ampersand', 'asciicircum', 'asciitilde', 'asterisk',
|
||||||
# 'ampersand', 'asciicircum', 'asciitilde', 'asterisk', 'at',
|
'backslash', 'bar',
|
||||||
# 'backslash', 'bar', 'braceleft', 'braceright', 'bracketleft', 'bracketright',
|
'colon', 'equal', 'exclam', 'greater', 'hyphen',
|
||||||
# 'colon', 'dollar', 'equal', 'exclam', 'greater', 'hyphen',
|
'less', 'numbersign', 'percent', 'period', 'plus',
|
||||||
# 'less', 'numbersign', 'parenleft', 'percent', 'period', 'plus',
|
'question', 'semicolon', 'slash', 'underscore',
|
||||||
# 'question', 'semicolon', 'slash', 'underscore',
|
|
||||||
# ],
|
## These characters are also used by the ligatures, but are likely
|
||||||
# 'firacode_ligature_name': None,
|
## to look more out of place when spliced into another font.
|
||||||
# },
|
# 'at', 'braceleft', 'braceright', 'bracketleft', 'bracketright',
|
||||||
|
# 'dollar', 'parenleft', 'parenright', 'underscore',
|
||||||
|
],
|
||||||
|
'firacode_ligature_name': None,
|
||||||
|
},
|
||||||
{ # &&
|
{ # &&
|
||||||
'chars': ['ampersand', 'ampersand'],
|
'chars': ['ampersand', 'ampersand'],
|
||||||
'firacode_ligature_name': 'ampersand_ampersand.liga',
|
'firacode_ligature_name': 'ampersand_ampersand.liga',
|
||||||
|
@ -66,10 +66,10 @@ def split_camel_case(str):
|
|||||||
|
|
||||||
class LigatureCreator(object):
|
class LigatureCreator(object):
|
||||||
|
|
||||||
def __init__(self, font, firacode):
|
def __init__(self, font, firacode, opts):
|
||||||
self.font = font
|
self.font = font
|
||||||
self.firacode = firacode
|
self.firacode = firacode
|
||||||
|
self.opts = opts
|
||||||
self._lig_counter = 0
|
self._lig_counter = 0
|
||||||
|
|
||||||
def copy_ligature_from_source(self, ligature_name):
|
def copy_ligature_from_source(self, ligature_name):
|
||||||
@ -81,16 +81,24 @@ class LigatureCreator(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def copy_character_glyphs(self, chars):
|
||||||
|
if not self.opts.copy_character_glyphs:
|
||||||
|
return
|
||||||
|
print("Copying %d character glyphs from %s..." % (
|
||||||
|
len(chars), self.firacode.fullname))
|
||||||
|
|
||||||
|
for char in 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()
|
||||||
|
|
||||||
def add_ligature(self, input_chars, firacode_ligature_name):
|
def add_ligature(self, input_chars, firacode_ligature_name):
|
||||||
if firacode_ligature_name is None:
|
if firacode_ligature_name is None:
|
||||||
# No ligature name -- we're just copying a bunch of individual characters.
|
# No ligature name -- we're just copying a bunch of individual characters.
|
||||||
for char in input_chars:
|
self.copy_character_glyphs(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
|
return
|
||||||
|
|
||||||
if not self.copy_ligature_from_source(firacode_ligature_name):
|
if not self.copy_ligature_from_source(firacode_ligature_name):
|
||||||
@ -98,7 +106,6 @@ class LigatureCreator(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._lig_counter += 1
|
self._lig_counter += 1
|
||||||
|
|
||||||
ligature_name = 'lig.{}'.format(self._lig_counter)
|
ligature_name = 'lig.{}'.format(self._lig_counter)
|
||||||
|
|
||||||
self.font.createChar(-1, ligature_name)
|
self.font.createChar(-1, ligature_name)
|
||||||
@ -106,7 +113,6 @@ class LigatureCreator(object):
|
|||||||
self.font.selection.select(ligature_name)
|
self.font.selection.select(ligature_name)
|
||||||
self.font.paste()
|
self.font.paste()
|
||||||
|
|
||||||
|
|
||||||
self.font.selection.none()
|
self.font.selection.none()
|
||||||
self.font.selection.select('space')
|
self.font.selection.select('space')
|
||||||
self.font.copy()
|
self.font.copy()
|
||||||
@ -191,6 +197,12 @@ def parse_args():
|
|||||||
help="The file to copy ligatures from. If unspecified, ligaturize will"
|
help="The file to copy ligatures from. If unspecified, ligaturize will"
|
||||||
" attempt to pick a suitable one from fira/ based on the input"
|
" attempt to pick a suitable one from fira/ based on the input"
|
||||||
" font's weight.")
|
" font's weight.")
|
||||||
|
parser.add_argument("--copy-character-glyphs",
|
||||||
|
default=False, action='store_true',
|
||||||
|
help="Copy glyphs for (some) individual characters from the ligature"
|
||||||
|
" font as well. This will result in punctuation that matches the"
|
||||||
|
" ligatures more closely, but may not fit in as well with the rest"
|
||||||
|
" of the font.")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
@ -207,7 +219,7 @@ print('Reading ligatures from %s' % ligature_font_path)
|
|||||||
firacode = fontforge.open(ligature_font_path)
|
firacode = fontforge.open(ligature_font_path)
|
||||||
firacode.em = font.em
|
firacode.em = font.em
|
||||||
|
|
||||||
creator = LigatureCreator(font, firacode)
|
creator = LigatureCreator(font, firacode, args)
|
||||||
ligature_length = lambda lig: len(lig['chars'])
|
ligature_length = lambda lig: len(lig['chars'])
|
||||||
for lig_spec in sorted(ligatures, key = ligature_length):
|
for lig_spec in sorted(ligatures, key = ligature_length):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user