From 2bda0614d93b98b0cb97c6676ba04f7acd2ae06e Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 31 Dec 2024 14:16:14 +0100 Subject: [PATCH] font-patcher: Add possibility to create single width icons without touching existing glyphs [why] This can help if you want monospaced icons but not-force the other glyphs to be monospaced (which we do to make the whole font monospace-detectable which was a major issue in the beginning, esp with Windows). [how] Add option --single-width-glyphs that makes the added glyphs single width (like --mono), but leaves preexisting glyphs untouched. Fixes: #1772 Signed-off-by: Fini Jastrow --- font-patcher | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/font-patcher b/font-patcher index 3b5c3b711..9fb3d7293 100755 --- a/font-patcher +++ b/font-patcher @@ -358,7 +358,7 @@ class font_patcher: 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.single: + if self.args.forcemono: # Force width to be equal on all glyphs to ensure the font is considered monospaced on Windows. # This needs to be done on all characters, as some information seems to be lost from the original font file. self.set_sourcefont_glyph_widths() @@ -832,11 +832,11 @@ class font_patcher: logger.warning("Monospaced check: %s and %s", report_advance_widths(self.sourceFont), panose_check_to_text(panose_mono, self.sourceFont.os2_panose)) - if self.args.single and not width_mono: + if self.args.forcemono and not width_mono: logger.warning("Sourcefont is not monospaced - forcing to monospace not advisable, " "results might be useless%s", " - offending char: {:X}".format(offending_char) if offending_char is not None else "") - if self.args.single <= 1: + if self.args.forcemono <= 1: logger.critical("Font will not be patched! Give --mono (or -s) twice to force patching") sys.exit(1) if width_mono: @@ -1974,8 +1974,9 @@ def setup_arguments(): # optional arguments parser.add_argument('font', help='The path to the font to patch (e.g., Inconsolata.otf)') parser.add_argument('-v', '--version', action='version', version=projectName + ": %(prog)s (" + version + ")") - parser.add_argument('-s', '--mono', dest='single', default=False, action='count', help='Whether to generate the glyphs as single-width not double-width (default is double-width) (Nerd Font Mono)') - parser.add_argument('--use-single-width-glyphs', dest='single', default=False, action='count', help=argparse.SUPPRESS) + parser.add_argument('-s', '--mono', dest='forcemono', default=False, action='count', help='Create monospaced font, existing and added glyphs are single-width (implies --single-width-glyphs)') + parser.add_argument('--use-single-width-glyphs', dest='forcemono', default=False, action='count', help=argparse.SUPPRESS) + parser.add_argument('--single-width-glyphs', dest='single', default=False, action='store_true', help='Whether to generate the glyphs as single-width not double-width (default is double-width) (Nerd Font Mono)') parser.add_argument('--variable-width-glyphs', dest='nonmono', default=False, action='store_true', help='Do not adjust advance width (no "overhang") (Nerd Font Propo)') parser.add_argument('--debug', dest='debugmode', default=0, type=int, nargs='?', help='Verbose mode (optional: 1=just to file; 2*=just to terminal; 3=display and file)', const=2, choices=range(0, 3 + 1)) parser.add_argument('-q', '--quiet', dest='quiet', default=False, action='store_true', help='Do not generate verbose output') @@ -2089,8 +2090,10 @@ def setup_arguments(): font_complete = False args.complete = font_complete + if args.forcemono: + args.single = True if args.nonmono and args.single: - logger.warning("Specified contradicting --variable-width-glyphs and --mono. Ignoring --variable-width-glyphs.") + logger.warning("Specified contradicting --variable-width-glyphs together with --mono or --single-width-glyphs. Ignoring --variable-width-glyphs.") args.nonmono = False make_sure_path_exists(args.outputdir)