Skip to content

Commit

Permalink
Fix compatibility issues with the font patcher
Browse files Browse the repository at this point in the history
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 Lokaltog#194.
  • Loading branch information
upsidedwn authored and Lokaltog committed Aug 10, 2012
1 parent 9f3a6e2 commit 20ab08c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fontpatcher/fontpatcher
Expand Up @@ -22,6 +22,7 @@ from __future__ import division
import argparse
import os
import sys
import re

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

args = parser.parse_args()

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

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

if onlybitmaps:
# Generate BDF font
Expand Down

0 comments on commit 20ab08c

Please sign in to comment.