Skip to content

Commit

Permalink
font-patcher: Add possibility to create single with icons without tou…
Browse files Browse the repository at this point in the history
…ching existing glyphs

Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Jan 8, 2025
1 parent dacf6e4 commit 7f7a9fd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1974,7 +1974,8 @@ 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('-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('--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')
Expand Down Expand Up @@ -2088,8 +2089,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)
Expand Down

0 comments on commit 7f7a9fd

Please sign in to comment.