mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-19 09:51:48 +02:00
font-patcher: Handle argument checks with arguments
[why] The extension handling is a bit out-of-place and could be handled by the arguments handling, which simplifies the code. Somes goes for other argument validity checks. [how] Put argument checks into setup_arguments(). Dropping self.extensions in favour of self.args.extensions. No functional change. Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
ec4cb0a8c5
commit
2432a5700a
1 changed files with 18 additions and 17 deletions
35
font-patcher
35
font-patcher
|
@ -163,16 +163,8 @@ class font_patcher:
|
|||
self.patch_set = None # class 'list'
|
||||
self.font_dim = None # class 'dict'
|
||||
self.onlybitmaps = 0
|
||||
self.extension = ""
|
||||
self.essential = set()
|
||||
self.config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True)
|
||||
if not os.path.isfile(self.args.font):
|
||||
sys.exit("{}: Font file does not exist: {}".format(projectName, self.args.font))
|
||||
if not os.access(self.args.font, os.R_OK):
|
||||
sys.exit("{}: Can not open font file for reading: {}".format(projectName, self.args.font))
|
||||
if len(fontforge.fontsInFile(self.args.font)) > 1:
|
||||
sys.exit("{}: Font file contains {} fonts, can only handle single font files".format(projectName,
|
||||
len(fontforge.fontsInFile(self.args.font))))
|
||||
try:
|
||||
self.sourceFont = fontforge.open(self.args.font, 1) # 1 = ("fstypepermitted",))
|
||||
except Exception:
|
||||
|
@ -181,19 +173,12 @@ class font_patcher:
|
|||
self.get_essential_references()
|
||||
self.setup_name_backup()
|
||||
self.remove_ligatures()
|
||||
make_sure_path_exists(self.args.outputdir)
|
||||
self.check_position_conflicts()
|
||||
self.setup_patch_set()
|
||||
self.setup_line_dimensions()
|
||||
self.get_sourcefont_dimensions()
|
||||
self.sourceFont.encoding = 'UnicodeFull' # Update the font encoding to ensure that the Unicode glyphs are available
|
||||
self.onlybitmaps = self.sourceFont.onlybitmaps # Fetch this property before adding outlines. NOTE self.onlybitmaps initialized and never used
|
||||
if self.args.extension == "":
|
||||
self.extension = os.path.splitext(self.args.font)[1]
|
||||
else:
|
||||
self.extension = '.' + self.args.extension
|
||||
if re.match("\.ttc$", self.extension, re.IGNORECASE):
|
||||
sys.exit(projectName + ": Can not create True Type Collections")
|
||||
|
||||
|
||||
def patch(self):
|
||||
|
@ -261,11 +246,11 @@ class font_patcher:
|
|||
def generate(self):
|
||||
# the `PfEd-comments` flag is required for Fontforge to save '.comment' and '.fontlog'.
|
||||
if self.sourceFont.fullname != None:
|
||||
outfile = self.args.outputdir + "/" + self.sourceFont.fullname + self.extension
|
||||
outfile = self.args.outputdir + "/" + self.sourceFont.fullname + self.args.extension
|
||||
self.sourceFont.generate(outfile, flags=(str('opentype'), str('PfEd-comments')))
|
||||
message = "\nGenerated: {} in '{}'".format(self.sourceFont.fullname, outfile)
|
||||
else:
|
||||
outfile = self.args.outputdir + "/" + self.sourceFont.cidfontname + self.extension
|
||||
outfile = self.args.outputdir + "/" + self.sourceFont.cidfontname + self.args.extension
|
||||
self.sourceFont.generate(outfile, flags=(str('opentype'), str('PfEd-comments')))
|
||||
message = "\nGenerated: {} in '{}'".format(self.sourceFont.fontname, outfile)
|
||||
|
||||
|
@ -1270,6 +1255,22 @@ def setup_arguments():
|
|||
print("Warniung: Specified contradicting --variable-width-glyphs and --use-single-width-glyph. Ignoring --variable-width-glyphs.")
|
||||
args.nonmono = False
|
||||
|
||||
make_sure_path_exists(args.outputdir)
|
||||
if not os.path.isfile(args.font):
|
||||
sys.exit("{}: Font file does not exist: {}".format(projectName, args.font))
|
||||
if not os.access(args.font, os.R_OK):
|
||||
sys.exit("{}: Can not open font file for reading: {}".format(projectName, args.font))
|
||||
if len(fontforge.fontsInFile(args.font)) > 1:
|
||||
sys.exit("{}: Font file contains {} fonts, can only handle single font files".format(projectName,
|
||||
len(fontforge.fontsInFile(args.font))))
|
||||
|
||||
if args.extension == "":
|
||||
args.extension = os.path.splitext(args.font)[1]
|
||||
else:
|
||||
args.extension = '.' + args.extension
|
||||
if re.match("\.ttc$", args.extension, re.IGNORECASE):
|
||||
sys.exit(projectName + ": Can not create True Type Collections")
|
||||
|
||||
return args
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue