Skip to content
This repository was archived by the owner on Jan 12, 2019. It is now read-only.

Commit 20ab08c

Browse files
upsidedwnLokaltog
authored andcommitted
Fix compatibility issues with the font patcher
Fontpatcher was unable to patch the Consolas font. This is due to the fact that Consolas is 'not' strictly a mono spaced font - it has some glyphs which are 0 width. The added option '--fix-mono' fixes this issue by setting all 0 width glyphs to a common width. Windows does not seem to respect the font family name that fontforge uses. Using the added option '--fix-win', the script will now set the font name to be the family name. In this manner, Windows will group these fonts under the same family. Windows still differentiates between different fonts of the same name by their weights, so having fonts of the same name is not a problem. Closes #61. Closes #194.
1 parent 9f3a6e2 commit 20ab08c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fontpatcher/fontpatcher

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ from __future__ import division
2222
import argparse
2323
import os
2424
import sys
25+
import re
2526

2627
try:
2728
import fontforge
@@ -42,6 +43,8 @@ parser = argparse.ArgumentParser(description='Font patcher for Powerline. Create
4243
parser.add_argument('fonts', help='font file to patch', metavar='font', nargs='+')
4344
parser.add_argument('--no-rename', help='don\'t add " for Powerline" to the font name', default=True, action='store_false', dest='rename')
4445
parser.add_argument('--symbol-font', help='font file with symbols', metavar='font', dest='symbol_font', default='{0}/PowerlineSymbols.sfd'.format(sys.path[0]))
46+
parser.add_argument('--fix-mono', help='fixes some mono-fonts which have glyphs of 0 widths', default=False, action='store_true', dest='fixmono')
47+
parser.add_argument('--fix-win', help='modifies font names such that Windows correctly recognizes font families', default=False, action='store_true', dest='fixwin')
4548

4649
args = parser.parse_args()
4750

@@ -78,6 +81,8 @@ for font_path in args.fonts:
7881
font.fontname += 'ForPowerline'
7982
font.appendSFNTName('English (US)', 'Preferred Family', font.familyname)
8083
font.appendSFNTName('English (US)', 'Compatible Full', font.fullname)
84+
if args.fixwin:
85+
font.fontname = re.sub(r'\W', '', font.familyname)
8186

8287
# Force the em size to be equal
8388
symbols.em = font.em
@@ -222,6 +227,9 @@ for font_path in args.fonts:
222227
if extension.lower() not in ['ttf', 'otf']:
223228
# Default to OpenType if input is not TrueType/OpenType
224229
extension = 'otf'
230+
if args.fixmono:
231+
for glyph in font.glyphs():
232+
if glyph.width == 0: glyph.width = font_dim['width']
225233

226234
if onlybitmaps:
227235
# Generate BDF font

0 commit comments

Comments
 (0)