mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2025-01-25 03:32:02 +02:00
font-patcher: Use standard filenames
[why] The filenames of the patched fonts are rather ... unique: - they contain blanks to separate name parts - they do not separate name and style/weight This is in part due to history reasons, because the names were not parsed at all and just some suffix added. Example (contrived): Victor Mono Nerd Font Propo Bold.ttf Normally font file names would be: VictorMonoNerdFontPropo-Bold.ttf We ourselves relied in part on that naming scheme, but do not follow it. There are a lot powerline fonts out there that all add blanks to the filename. Some filename recommendation can be found in [1]. [how] The filename is now always constructed directly from name ID 16 and name ID 17. If one of them is empty ID 1 and ID 2 are used as fallback, as customary. ID 16 (ID 1) and ID 17 (ID 2) are separated by a hyphen. The result is that in can differ from the fontname (ID 6) and uses always the longest most readable name parts. [1] https://forum.fontlab.com/fontlab-studio-tips-and-tricks/font-family-naming-in-fontlab-studio-5/ Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
68405398bc
commit
179dae01e0
15
font-patcher
15
font-patcher
@ -300,6 +300,17 @@ def get_old_average_x_width(font):
|
||||
s += font[g].width * weights[g]
|
||||
return int(s / 1000)
|
||||
|
||||
def create_filename(fonts):
|
||||
""" Determine filename from font object(s) """
|
||||
sfnt = { k: v for l, k, v in fonts[0].sfnt_names }
|
||||
sfnt_pfam = sfnt.get('Preferred Family', sfnt['Family'])
|
||||
sfnt_psubfam = sfnt.get('Preferred Styles', sfnt['SubFamily'])
|
||||
if len(fonts) > 1:
|
||||
return sfnt_pfam
|
||||
if len(sfnt_psubfam) > 0:
|
||||
sfnt_psubfam = '-' + sfnt_psubfam
|
||||
return (sfnt_pfam + sfnt_psubfam).replace(' ', '')
|
||||
|
||||
|
||||
class font_patcher:
|
||||
def __init__(self, args):
|
||||
@ -403,11 +414,11 @@ class font_patcher:
|
||||
break
|
||||
outfile = os.path.normpath(os.path.join(
|
||||
sanitize_filename(self.args.outputdir, True),
|
||||
sanitize_filename(sourceFont.familyname) + ".ttc"))
|
||||
sanitize_filename(create_filename(sourceFonts)) + ".ttc"))
|
||||
sourceFonts[0].generateTtc(outfile, sourceFonts[1:], flags=gen_flags, layer=layer)
|
||||
message = " Generated {} fonts\n \===> '{}'".format(len(sourceFonts), outfile)
|
||||
else:
|
||||
fontname = sourceFont.fullname
|
||||
fontname = create_filename(sourceFonts)
|
||||
if not fontname:
|
||||
fontname = sourceFont.cidfontname
|
||||
outfile = os.path.normpath(os.path.join(
|
||||
|
Loading…
x
Reference in New Issue
Block a user