From 9620d47aedfc131203c2ba6a4af18e6d4df9cc8a Mon Sep 17 00:00:00 2001 From: ryanoasis Date: Sat, 19 Sep 2015 13:56:49 -0400 Subject: [PATCH] Fixes wrong unicode codepoints for Font Awesome glyphs (fixes #31) * if conflict between Font Awesome and Octicons, Font Awesome takes presedence in positioning --- font-patcher | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/font-patcher b/font-patcher index 8ff1d7c85..02422ddd8 100755 --- a/font-patcher +++ b/font-patcher @@ -133,11 +133,17 @@ if args.fontawesome: if args.octicons: octicons = fontforge.open("glyph-source-fonts/octicons.ttf") octicons.em = sourceFont.em + octiconsExactEncodingPosition = True if args.pomicons: pomicons = fontforge.open("glyph-source-fonts/Pomicons.otf") pomicons.em = sourceFont.em +# Prevent glyph encoding position conflicts between glyph sets + +if args.fontawesome and args.octicons: + octiconsExactEncodingPosition = False + # Define the character ranges # Symbol font ranges @@ -248,13 +254,15 @@ def get_dim(glyph): 'height': bbox[3] + (-bbox[1]), } -def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFontStart, symbolFontEnd): - sourceFontList = [] - sourceFontCounter = 0 +def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFontStart, symbolFontEnd, exactEncoding=False): - for i in xrange(sourceFontStart, sourceFontEnd + 1): - sourceFontList.append(format(i, 'X')) + if exactEncoding is False: + sourceFontList = [] + sourceFontCounter = 0 + + for i in xrange(sourceFontStart, sourceFontEnd + 1): + sourceFontList.append(format(i, 'X')) # Create glyphs from symbol font @@ -265,8 +273,14 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo #sym_attr = SYM_ATTR[sym_glyph.unicode] if args.quiet == False: print "updating glyph: " + str(sym_glyph) - # convince that this string really is a hex: - currentSourceFontGlyph = int("0x" + sourceFontList[sourceFontCounter], 16) + + if exactEncoding: + # use the exact same hex values for the source font as for the symbol font + currentSourceFontGlyph = sym_glyph.encoding + else: + # use source font defined hex values based on passed in start and end + # convince that this string really is a hex: + currentSourceFontGlyph = int("0x" + sourceFontList[sourceFontCounter], 16) # Prepare symbol glyph dimensions sym_dim = get_dim(sym_glyph) @@ -345,7 +359,9 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo # Ensure the font is considered monospaced on Windows sourceFont[currentSourceFontGlyph].width = font_dim['width'] - sourceFontCounter += 1 + if exactEncoding is False: + sourceFontCounter += 1 + # reset selection so iteration works propertly @todo fix? rookie misunderstanding? symbolFont.selection.select(("ranges","unicode"),symbolFontStart,symbolFontEnd) # end for @@ -361,10 +377,10 @@ if args.powerline: if args.fontawesome: - copy_glyphs(sourceFont, sourceFontFontAwesomeStart, sourceFontFontAwesomeEnd, fontawesome, symbolsFontAwesomeRangeStart, symbolsFontAwesomeRangeEnd) + copy_glyphs(sourceFont, sourceFontFontAwesomeStart, sourceFontFontAwesomeEnd, fontawesome, symbolsFontAwesomeRangeStart, symbolsFontAwesomeRangeEnd, True) if args.octicons: - copy_glyphs(sourceFont, sourceFontOcticonsStart, sourceFontOcticonsEnd, octicons, symbolsOcticonsRangeStart, symbolsOcticonsRangeEnd) + copy_glyphs(sourceFont, sourceFontOcticonsStart, sourceFontOcticonsEnd, octicons, symbolsOcticonsRangeStart, symbolsOcticonsRangeEnd, octiconsExactEncodingPosition) if args.pomicons: copy_glyphs(sourceFont, sourceFontPomiconsStart, sourceFontPomiconsEnd, pomicons, symbolsPomiconsRangeStart, symbolsPomiconsRangeEnd)