From b8a5f5b7e81a1208ea785fe291dd9a906dbf245a Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 9 May 2023 12:40:24 +0200 Subject: [PATCH 1/3] font-patcher: Do scale icons added via --custom [why] If you add a custom icon it probably has to fit with the rest of the font. So why should we patch it in completely unscaled? [how] Just scale the custom icon like all other icons at least. If someone wants to add just a symbol or two and keep the glyphs exactly (more or less) unscaled there are simpler ways than this patcher script. I believe persons that are able to pre-scale the custom font are also able to just patch it in. So this option is more for the generic patching of extra glyphs but they need to be scaled somehow. Signed-off-by: Fini Jastrow --- font-patcher | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/font-patcher b/font-patcher index 02d32c0bf..542d91b5c 100755 --- a/font-patcher +++ b/font-patcher @@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals # Change the script version when you edit this script: -script_version = "4.1.5" +script_version = "4.2.0" version = "3.0.0" projectName = "Nerd Fonts" @@ -896,8 +896,9 @@ class font_patcher: # 0x2593: {'align': 'c', 'valign': 'c', 'stretch': 'xy', 'params': {'dont_copy': box_keep}}, } CUSTOM_ATTR = { - # 'pa' == preserve aspect ratio - 'default': {'align': 'c', 'valign': '', 'stretch': '', 'params': {}} + # previous custom scaling => do not touch the icons + # 'default': {'align': 'c', 'valign': '', 'stretch': '', 'params': {}} + 'default': {'align': 'c', 'valign': 'c', 'stretch': 'pa', 'params': {}} } # Most glyphs we want to maximize (individually) during the scale @@ -1808,7 +1809,7 @@ def setup_arguments(): parser.add_argument('--removeligs', '--removeligatures', dest='removeligatures', default=False, action='store_true', help='Removes ligatures specificed in JSON configuration file') parser.add_argument('--postprocess', dest='postprocess', default=False, type=str, nargs='?', help='Specify a Script for Post Processing') parser.add_argument('--configfile', dest='configfile', default=False, type=str, nargs='?', help='Specify a file path for JSON configuration file (see sample: src/config.sample.json)') - parser.add_argument('--custom', dest='custom', default=False, type=str, nargs='?', help='Specify a custom symbol font. All new glyphs will be copied, with no scaling applied.') + parser.add_argument('--custom', dest='custom', default=False, type=str, nargs='?', help='Specify a custom symbol font, all new glyphs will be copied') parser.add_argument('-ext', '--extension', dest='extension', default="", type=str, nargs='?', help='Change font file type to create (e.g., ttf, otf)') parser.add_argument('-out', '--outputdir', dest='outputdir', default=".", type=str, nargs='?', help='The directory to output the patched font file to') parser.add_argument('--glyphdir', dest='glyphdir', default=__dir__ + "/src/glyphs/", type=str, nargs='?', help='Path to glyphs to be used for patching') From de78d080770d5fee2f19c7ed155f323dd6073adb Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 9 May 2023 13:37:02 +0200 Subject: [PATCH 2/3] font-patcher: Be not needlessly careful [why] When a user want to patch some glyph in, and at that position is already a glyph, there is no way to overwrite it. The reason is that --custom glyphs are always patched in --careful, and there is no --not-careful option to override that. [how] Add glyphs via --custom always, except --careful has also been given. Signed-off-by: Fini Jastrow --- font-patcher | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/font-patcher b/font-patcher index 542d91b5c..f409456c3 100755 --- a/font-patcher +++ b/font-patcher @@ -898,7 +898,7 @@ class font_patcher: CUSTOM_ATTR = { # previous custom scaling => do not touch the icons # 'default': {'align': 'c', 'valign': '', 'stretch': '', 'params': {}} - 'default': {'align': 'c', 'valign': 'c', 'stretch': 'pa', 'params': {}} + 'default': {'align': 'c', 'valign': 'c', 'stretch': 'pa', 'params': {'careful': self.args.careful}} } # Most glyphs we want to maximize (individually) during the scale @@ -1337,7 +1337,8 @@ class font_patcher: sys.stdout.flush() # check if a glyph already exists in this location - if careful or 'careful' in sym_attr['params'] or currentSourceFontGlyph in self.essential: + do_careful = sym_attr['params'].get('careful', careful) # params take precedence + if do_careful or currentSourceFontGlyph in self.essential: if currentSourceFontGlyph in self.sourceFont: careful_type = 'essential' if currentSourceFontGlyph in self.essential else 'existing' logger.debug("Found %s Glyph at %X. Skipping...", careful_type, currentSourceFontGlyph) @@ -1809,7 +1810,7 @@ def setup_arguments(): parser.add_argument('--removeligs', '--removeligatures', dest='removeligatures', default=False, action='store_true', help='Removes ligatures specificed in JSON configuration file') parser.add_argument('--postprocess', dest='postprocess', default=False, type=str, nargs='?', help='Specify a Script for Post Processing') parser.add_argument('--configfile', dest='configfile', default=False, type=str, nargs='?', help='Specify a file path for JSON configuration file (see sample: src/config.sample.json)') - parser.add_argument('--custom', dest='custom', default=False, type=str, nargs='?', help='Specify a custom symbol font, all new glyphs will be copied') + parser.add_argument('--custom', dest='custom', default=False, type=str, nargs='?', help='Specify a custom symbol font, all glyphs will be copied') parser.add_argument('-ext', '--extension', dest='extension', default="", type=str, nargs='?', help='Change font file type to create (e.g., ttf, otf)') parser.add_argument('-out', '--outputdir', dest='outputdir', default=".", type=str, nargs='?', help='The directory to output the patched font file to') parser.add_argument('--glyphdir', dest='glyphdir', default=__dir__ + "/src/glyphs/", type=str, nargs='?', help='Path to glyphs to be used for patching') From af2573aac2f650dfb0ba10e1caa4c7121f392146 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 9 May 2023 12:50:33 +0200 Subject: [PATCH 3/3] Fix: font-patcher: Allow to specify custom symbolfont with absolute path [skip ci] [why] While the commit 7cda32651 font-patcher: Allow to specify custom symbolfont with absolute path would have allowed to specify the custom glyph font with an absolute path, it is in fact still not possible. [how] The file-exists checks also need to observe the absolute path. [note] Normally (with a relative path) the custom font is search for in the ordinary glyphs directory - but that would mean people need to copy it there. Signed-off-by: Fini Jastrow --- font-patcher | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/font-patcher b/font-patcher index f409456c3..aac307ed2 100755 --- a/font-patcher +++ b/font-patcher @@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals # Change the script version when you edit this script: -script_version = "4.2.0" +script_version = "4.2.1" version = "3.0.0" projectName = "Nerd Fonts" @@ -373,15 +373,16 @@ class font_patcher: if symfont: symfont.close() symfont = None - if not os.path.isfile(self.args.glyphdir + patch['Filename']): + symfont_file = os.path.join(self.args.glyphdir, patch['Filename']) + if not os.path.isfile(symfont_file): logger.critical("Can not find symbol source for '%s' (i.e. %s)", - patch['Name'], self.args.glyphdir + patch['Filename']) + patch['Name'], symfont_file) sys.exit(1) - if not os.access(self.args.glyphdir + patch['Filename'], os.R_OK): + if not os.access(symfont_file, os.R_OK): logger.critical("Can not open symbol source for '%s' (i.e. %s)", - patch['Name'], self.args.glyphdir + patch['Filename']) + patch['Name'], symfont_file) sys.exit(1) - symfont = fontforge.open(os.path.join(self.args.glyphdir, patch['Filename'])) + symfont = fontforge.open(symfont_file) symfont.encoding = 'UnicodeFull' # Match the symbol font size to the source font size @@ -1810,7 +1811,7 @@ def setup_arguments(): parser.add_argument('--removeligs', '--removeligatures', dest='removeligatures', default=False, action='store_true', help='Removes ligatures specificed in JSON configuration file') parser.add_argument('--postprocess', dest='postprocess', default=False, type=str, nargs='?', help='Specify a Script for Post Processing') parser.add_argument('--configfile', dest='configfile', default=False, type=str, nargs='?', help='Specify a file path for JSON configuration file (see sample: src/config.sample.json)') - parser.add_argument('--custom', dest='custom', default=False, type=str, nargs='?', help='Specify a custom symbol font, all glyphs will be copied') + parser.add_argument('--custom', dest='custom', default=False, type=str, nargs='?', help='Specify a custom symbol font, all glyphs will be copied; absolute path suggested') parser.add_argument('-ext', '--extension', dest='extension', default="", type=str, nargs='?', help='Change font file type to create (e.g., ttf, otf)') parser.add_argument('-out', '--outputdir', dest='outputdir', default=".", type=str, nargs='?', help='The directory to output the patched font file to') parser.add_argument('--glyphdir', dest='glyphdir', default=__dir__ + "/src/glyphs/", type=str, nargs='?', help='Path to glyphs to be used for patching')