font-patcher: Add possibility to generate normal and Windows font in one go

[why]
The normal and the Windows Compatible fonts differ just in the naming.
The patching is all the same.

For the CI we patch the original font for each output font. That is not
needed if we just want to create two differently named exports.

Skipping the patching where it is possible would save some time. Not
half the time, but the patching process itself is not too quick either.

[how]
Backup the original font names (as we need them again to deduce the new
Windows Compatible names).

Then do the patching once and the export twice, if parameter is given.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2022-09-01 10:21:16 +02:00 committed by Fini
parent 3c3e2a49a7
commit 98b28c8f3d

View file

@ -6,7 +6,7 @@
from __future__ import absolute_import, print_function, unicode_literals
# Change the script version when you edit this script:
script_version = "3.0.2"
script_version = "3.0.3"
version = "2.2.1"
projectName = "Nerd Fonts"
@ -181,6 +181,7 @@ class font_patcher:
except Exception:
sys.exit(projectName + ": Can not open font, try to open with fontforge interactively to get more information")
self.setup_version()
self.setup_name_backup()
self.remove_ligatures()
make_sure_path_exists(self.args.outputdir)
self.check_position_conflicts()
@ -325,6 +326,7 @@ class font_patcher:
progressbars_group_parser.add_argument('--progressbars', dest='progressbars', action='store_true', help='Show percentage completion progress bars per Glyph Set')
progressbars_group_parser.add_argument('--no-progressbars', dest='progressbars', action='store_false', help='Don\'t show percentage completion progress bars per Glyph Set')
parser.set_defaults(progressbars=True)
parser.add_argument('--also-windows', dest='alsowindows', default=False, action='store_true', help='Create two fonts, the normal and the --windows version')
# symbol fonts to include arguments
sym_font_group = parser.add_argument_group('Symbol Fonts')
@ -375,6 +377,9 @@ class font_patcher:
font_complete = False
self.args.complete = font_complete
if self.args.alsowindows:
self.args.windows = False
# this one also works but it needs to be updated every time a font is added
# it was a conditional in self.setup_font_names() before, but it was missing
# a symbol font, so it would name the font complete without being so sometimes.
@ -395,7 +400,17 @@ class font_patcher:
# ])
def setup_name_backup(self):
""" Store the original font names to be able to rename the font multiple times """
self.original_fontname = self.sourceFont.fontname
self.original_fullname = self.sourceFont.fullname
self.original_familyname = self.sourceFont.familyname
def setup_font_names(self):
self.sourceFont.fontname = self.original_fontname
self.sourceFont.fullname = self.original_fullname
self.sourceFont.familyname = self.original_familyname
verboseAdditionalFontNameSuffix = " " + projectNameSingular
if self.args.windows: # attempt to shorten here on the additional name BEFORE trimming later
additionalFontNameSuffix = " " + projectNameAbbreviation
@ -1232,6 +1247,11 @@ def main():
print("\nDone with Patch Sets, generating font...\n")
patcher.setup_font_names()
patcher.generate()
# This mainly helps to improve CI runtime
if patcher.args.alsowindows:
patcher.args.windows = True
patcher.setup_font_names()
patcher.generate()
if __name__ == "__main__":