font-patcher: Add option to select postscript name as name source

[why]
In the post we used these information sources to determine the name and
weights/styles of the to-be-patched font:
* The filename
* The fullname (ID 4)
* The postscriptname (ID 6)

Usually it is best to use the Fullname of a font to determine its real
name and styles/weights:

The Postscript name has the advantage to have a hyphen between name and
styles/weight; but as it can not contain blanks the correct name can not
be determined by this. To get the styles/weights back we use a list of
all possible (?!) weights and styles and sort all the string parts.

This works reasonably well and the fullname is usually best.

Not so with Input Mono Condensed. Here are its names:
ID4: "InputMonoCondensed LightIta"
IF6: "InputMonoConsensed-LightItalic"

[how]
Add option to select between fullname and postscriptname as font naming
source.

For special purposes, also allow a custom (arbitrary) name input.
If that is given the specified name will be used to name the patched
font without adding any suffix - the user has full control on the name.

Fixes: #1314

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-07-17 09:21:37 +02:00 committed by Fini
parent 2f5c6ab6c6
commit 64cf3e9d93

View file

@ -6,7 +6,7 @@
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
# Change the script version when you edit this script: # Change the script version when you edit this script:
script_version = "4.4.2" script_version = "4.5.0"
version = "3.0.2" version = "3.0.2"
projectName = "Nerd Fonts" projectName = "Nerd Fonts"
@ -557,17 +557,28 @@ class font_patcher:
additionalFontNameSuffix = " " + projectNameSingular + variant_full + additionalFontNameSuffix additionalFontNameSuffix = " " + projectNameSingular + variant_full + additionalFontNameSuffix
if FontnameParserOK and self.args.makegroups > 0: if FontnameParserOK and self.args.makegroups > 0:
use_fullname = isinstance(font.fullname, str) # Usually the fullname is better to parse if not isinstance(self.args.force_name, str):
# Use fullname if it is 'equal' to the fontname use_fullname = isinstance(font.fullname, str) # Usually the fullname is better to parse
if font.fullname: # Use fullname if it is 'equal' to the fontname
use_fullname |= font.fontname.lower() == FontnameTools.postscript_char_filter(font.fullname).lower() if font.fullname:
# Use fullname for any of these source fonts (that are impossible to disentangle from the fontname, we need the blanks) use_fullname |= font.fontname.lower() == FontnameTools.postscript_char_filter(font.fullname).lower()
for hit in [ 'Meslo' ]: # Use fullname for any of these source fonts (that are impossible to disentangle from the fontname, we need the blanks)
use_fullname |= font.fontname.lower().startswith(hit.lower()) for hit in [ 'Meslo' ]:
parser_name = font.fullname if use_fullname else font.fontname use_fullname |= font.fontname.lower().startswith(hit.lower())
# Gohu fontnames hide the weight, but the file names are ok... parser_name = font.fullname if use_fullname else font.fontname
if parser_name.startswith('Gohu'): # Gohu fontnames hide the weight, but the file names are ok...
parser_name = os.path.splitext(os.path.basename(self.args.font))[0] if parser_name.startswith('Gohu'):
parser_name = os.path.splitext(os.path.basename(self.args.font))[0]
else:
if self.args.force_name == 'full':
parser_name = font.fullname
elif self.args.force_name == 'postscript':
parser_name = font.fontname
else:
parser_name = self.args.force_name
if not isinstance(parser_name, str) or len(parser_name) < 1:
logger.critical("Specified --name not usable because the name will be empty")
sys.exit(2)
n = FontnameParser(parser_name, logger) n = FontnameParser(parser_name, logger)
if not n.parse_ok: if not n.parse_ok:
logger.warning("Have only minimal naming information, check resulting name. Maybe specify --makegroups 0") logger.warning("Have only minimal naming information, check resulting name. Maybe specify --makegroups 0")
@ -719,9 +730,11 @@ class font_patcher:
font.appendSFNTName(str('English (US)'), str('Compatible Full'), font.fullname) font.appendSFNTName(str('English (US)'), str('Compatible Full'), font.fullname)
font.appendSFNTName(str('English (US)'), str('SubFamily'), subFamily) font.appendSFNTName(str('English (US)'), str('SubFamily'), subFamily)
else: else:
short_family = projectNameAbbreviation + variant_abbrev if self.args.makegroups >= 4 else projectNameSingular + variant_full # Add Nerd Font suffix unless user specifically asked for some excplicit name via --name
# inject_suffix(family, ps_fontname, short_family) if not self.args.force_name or self.args.force_name == 'full' or self.args.force_name == 'postscript':
n.inject_suffix(verboseAdditionalFontNameSuffix, ps_suffix, short_family) short_family = projectNameAbbreviation + variant_abbrev if self.args.makegroups >= 4 else projectNameSingular + variant_full
# inject_suffix(family, ps_fontname, short_family)
n.inject_suffix(verboseAdditionalFontNameSuffix, ps_suffix, short_family)
n.rename_font(font) n.rename_font(font)
font.comment = projectInfo font.comment = projectInfo
@ -1860,6 +1873,7 @@ def setup_arguments():
# <none> - copy from sourcefont (default) # <none> - copy from sourcefont (default)
# 0 - calculate from font according to OS/2-version-2 # 0 - calculate from font according to OS/2-version-2
# 500 - set to 500 # 500 - set to 500
parser.add_argument('--name', dest='force_name', default=None, type=str, help='Specify naming source (\'full\', \'postscript\', or concrete free name-string)')
# symbol fonts to include arguments # symbol fonts to include arguments
sym_font_group = parser.add_argument_group('Symbol Fonts') sym_font_group = parser.add_argument_group('Symbol Fonts')