1
0
mirror of https://github.com/ryanoasis/nerd-fonts.git synced 2024-12-19 20:12:52 +02:00

Merge pull request #1219 from ryanoasis/feature/improve-custom-patching

Improve custom patching
This commit is contained in:
Fini 2023-05-10 12:07:02 +02:00 committed by GitHub
commit 252ac6bb7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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.1.5" script_version = "4.2.1"
version = "3.0.0" version = "3.0.0"
projectName = "Nerd Fonts" projectName = "Nerd Fonts"
@ -373,15 +373,16 @@ class font_patcher:
if symfont: if symfont:
symfont.close() symfont.close()
symfont = None 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)", 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) 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)", 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) sys.exit(1)
symfont = fontforge.open(os.path.join(self.args.glyphdir, patch['Filename'])) symfont = fontforge.open(symfont_file)
symfont.encoding = 'UnicodeFull' symfont.encoding = 'UnicodeFull'
# Match the symbol font size to the source font size # Match the symbol font size to the source font size
@ -896,8 +897,9 @@ class font_patcher:
# 0x2593: {'align': 'c', 'valign': 'c', 'stretch': 'xy', 'params': {'dont_copy': box_keep}}, # 0x2593: {'align': 'c', 'valign': 'c', 'stretch': 'xy', 'params': {'dont_copy': box_keep}},
} }
CUSTOM_ATTR = { CUSTOM_ATTR = {
# 'pa' == preserve aspect ratio # previous custom scaling => do not touch the icons
'default': {'align': 'c', 'valign': '', 'stretch': '', 'params': {}} # 'default': {'align': 'c', 'valign': '', 'stretch': '', 'params': {}}
'default': {'align': 'c', 'valign': 'c', 'stretch': 'pa', 'params': {'careful': self.args.careful}}
} }
# Most glyphs we want to maximize (individually) during the scale # Most glyphs we want to maximize (individually) during the scale
@ -1336,7 +1338,8 @@ class font_patcher:
sys.stdout.flush() sys.stdout.flush()
# check if a glyph already exists in this location # 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: if currentSourceFontGlyph in self.sourceFont:
careful_type = 'essential' if currentSourceFontGlyph in self.essential else 'existing' careful_type = 'essential' if currentSourceFontGlyph in self.essential else 'existing'
logger.debug("Found %s Glyph at %X. Skipping...", careful_type, currentSourceFontGlyph) logger.debug("Found %s Glyph at %X. Skipping...", careful_type, currentSourceFontGlyph)
@ -1808,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('--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('--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('--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 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('-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('-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') parser.add_argument('--glyphdir', dest='glyphdir', default=__dir__ + "/src/glyphs/", type=str, nargs='?', help='Path to glyphs to be used for patching')