Skip to content

Commit

Permalink
Fix subfamily names so the converted font's subfamily match the origi…
Browse files Browse the repository at this point in the history
…nal ones

The converted fonts get a subfamily named (i.e.) "ReguItal" when
it should be "Regular Italic" so they match the original name and
applications can interpret them correctly.

This commit adds a step in the font conversion workflow to converts
family names from those "short names" to the original ones.
  • Loading branch information
antlarr-suse committed Jun 19, 2020
1 parent a2540b8 commit 812bc9c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ttf-converter
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@ def fix_font(font):

return True

def fix_subfamily(font):
sfnt_names = list(font.sfnt_names)
subfamily_index = [x[1] for x in sfnt_names].index('SubFamily')
translations = {'BoldCondItal': 'Bold Condensed Italic',
'BoldItal': 'Bold Italic',
'BoldItalic': 'Bold Italic',
'BoldOblique': 'Bold Oblique',
'BookObli': 'Book Oblique',
'DemiObli': 'Demi Oblique',
'DemiBold': 'Demi Bold',
'DemiBoldItal': 'Demi Bold Italic',
'LighItal': 'Light Italic',
'MediItal': 'Medium Italic',
'ReguCond': 'Regular Condensed',
'ReguCondItal': 'Regular Condensed Italic',
'ReguItal': 'Regular Italic',
'ReguObli': 'Regular Oblique',
'StandardSymL': 'Regular'} # This is for the Standard Symbols L font
try:
new_value = translations[sfnt_names[subfamily_index][2]]
except KeyError:
# Nothing to fix
return

print(f'Fixing subfamily: Renaming {sfnt_names[subfamily_index][2]} to {new_value}.')
sfnt_names[subfamily_index] = sfnt_names[subfamily_index][0:2] + (new_value,)
font.sfnt_names = tuple(sfnt_names)


def convert_font(input_filename, output_filename=None, output_dir='.'):
font = fontforge.open(input_filename)
Expand All @@ -140,6 +168,8 @@ def convert_font(input_filename, output_filename=None, output_dir='.'):

fix_font(font)

fix_subfamily(font)

font.generate(output_filename, flags=("opentype",))

print('ok')
Expand Down

0 comments on commit 812bc9c

Please sign in to comment.