Development

How to Patch Your Own Nerd Font

Did you know you can take a font you like and patch it with all the developer icons and glpyhs using the nerd font patcher? Read this.
Captain Salem 8 min read
How to Patch Your Own Nerd Font

Nerd Fonts is a collection of fonts or typefaces that have been modified or enhanced and exteneded to include a wide array of development related symbols and icons.

The role of nerd fonts is to cater for those of us into the world of development. From sysadmins, devs, and other nerd who might find the use for dev glyphs and icons.

Features of Nerd Fonts

The following are some of the features offered by Nerd Fonts:

  • Glyphs and Icons - Nerd Fonts include a vast library of icons and glpyhs that rnages from programming language logos, version control symbols, file and directory icons, etc.
  • Improved Readability - Nerd Fonts are specificially designed to call attention to code readability. This makes them easy on the eyes both in code editors and the terminal. Features such as clear and distinct character shapes, exceptionall spaces, consistent line heigts are more than essentil for long development hours.
  • Compatibility - Nerd Fonts are compatible with various terminal emulators, text editors, and integrated development environments (IDEs).
  • Unicode Support - Nerd Fonts support a wide array of Unicode character and symbols which are a fundamental part of working with different character sets, special symbols, and international languages.
  • Customization - Nerd Fonts are incredibly customizable. You can enable or disable specific glyphys and icons as you desire. What more do nerds love than customization?
  • VCS Integration - Many Nerd Fonts include icons and symbols associated with popular version control systems like Git, making it easier to identify the status of files and repositories at a glance.
  • Theming and Aesthetics - Nerd Fonts can enhance the aesthetics of a code editor or terminal by adding visually appealing symbols and icons to your interface. If you want to develop for longer, try having a perfect environment tailored just for you.
  • Open Source - Nerd Fonts are open-source and freely available. You can download, use contribute, etc.

With the features out of the way.

There is a high chance that you know and probly using Nerd Fonts on your machine. If not, you can check the tutorials below.

How to Install Nerd Fonts on Linux
This tutorial will teach how to install the Nerd Fonts pack on Ubuntu or any Debian-based distribution.
How to setup Nerd Fonts in Windows
This tutorial will show you how you can customize your terminal or code editor by adding great fonts that will suit a wide range of us geeks.
How to Install Nerd Fonts on mac
This tutorial will show you how you can customize your terminal or code editor by installing the Nerd Fonts package on macOS system.

However, did you know that nerd fonts actually allow you to patch your own font.

For example, let us say you have bought a proprietary font to which you wish to add all the development icons and glyphs.

Nerd Fonts has an actual binary called patcher that allows us to do just exactly that.

What is Nerd Font Patcher

Nerd Font Patcher is a utility or tool that allows us to customize and patch a preferred programming or monospaced fonts with additional symbols, icons, and glyphs from the Nerd Fonts collection.

Patch Your Font

Let us walk through the steps we can take to patch our own font into a Nerd Font equivalent. For this tutorial, we will use the Red Hat Mono.

Red Hat Mono is a Red Hat's Open Source Fonts that works very well with development environments. The repository is provided in the link below.

GitHub - RedHatOfficial/RedHatFont: Red Hat’s Open Source Fonts - Red Hat Display and Red Hat Text
Red Hat’s Open Source Fonts - Red Hat Display and Red Hat Text - GitHub - RedHatOfficial/RedHatFont: Red Hat’s Open Source Fonts - Red Hat Display and Red Hat Text

Start by downloading the font by going to the releases page.

Release 4.0.3 · RedHatOfficial/RedHatFont
4.0.3 (2022-08-02) Tag: 4.0.3 Updates fonts with bug fixes, specifically a fix for the ` character.

Downlaod the Font Files.

CleanShot 2024-02-05 at 18.52.08

Once downloaded, open the terminal and navigate to the location where you stored the zip

cd ~/Downloads

Unzip the file by running the command:

unzip RedHatFont-4.0.3.zip

Next, navigate into the font directory

cd RedHatFont-4.0.3/fonts/mono

This should contain the resulting font files:

total 1120
drwxr-xr-x@ 12 captain  staff    384 Aug  1  2022 .
drwxr-xr-x@  6 captain  staff    192 Aug  1  2022 ..
-rw-r--r--@  1 captain  staff  73156 Aug  1  2022 RedHatMono-Italic.ttf
-rw-r--r--@  1 captain  staff  73156 Aug  1  2022 RedHatMono-Italic[wght].ttf
-rw-r--r--@  1 captain  staff  67408 Aug  1  2022 RedHatMono.ttf
-rw-r--r--@  1 captain  staff  73012 Aug  1  2022 RedHatMonoVF-Italic.ttf
-rw-r--r--@  1 captain  staff  73012 Aug  1  2022 RedHatMonoVF-Italic[wght].ttf
-rw-r--r--@  1 captain  staff  67304 Aug  1  2022 RedHatMonoVF.ttf
-rw-r--r--@  1 captain  staff  67304 Aug  1  2022 RedHatMonoVF[wght].ttf
-rw-r--r--@  1 captain  staff  67408 Aug  1  2022 RedHatMono[wght].ttf
drwxr-xr-x@  5 captain  staff    160 Aug  1  2022 static
drwxr-xr-x@ 10 captain  staff    320 Aug  1  2022 web

Download the Font Patcher

Once we have the font ready, we can proceed and download the patcher script. We can do this by running the command below:

wget https://github.com/ryanoasis/nerd-fonts/releases/latest/download/FontPatcher.zip

This should download the script and the associated helper files.

Extract the resulting zip archive and head over to the resultig directory.

Install Required Dependencies

Before you can patch fonts, you need to install the required dependencies. These include python3, python-fontforge, and argparse.

You can install them by running the command:

MacOS

brew install python3 fontforge
python3 install python-fontforge argparse

Ubuntu:

On Ubuntu and Linux based system, clone the python-fontforge repo and run the command below:

sudo apt-get install libjpeg-dev libtiff5-dev libpng-dev libfreetype6-dev libgif-dev libgtk-3-dev libxml2-dev libpango1.0-dev libcairo2-dev libspiro-dev libwoff-dev python3-dev ninja-build cmake build-essential gettext;

Build and install.

cd fontforge
mkdir build
cd build
cmake -GNinja ..
ninja
ninja install

This should install the fontforge package on Ubuntu.

sudo apt install python3 python3-pip

Install the argparse package:

pip3 install argparse

If you are facing any problems with fontforge, you can check the resource below:

fontforge/INSTALL.md at master · fontforge/fontforge
Free (libre) font editor for Windows, Mac OS X and GNU+Linux - fontforge/fontforge

Patching the Font

To patch the target font, you can two main methods. The first is using fontforge package as shown:

fontforge -script font-patcher PATH_TO_FONT

For example:

fontforge -script font-patcher ~/Downloads/RedHatFont-4.0.3/fonts/mono/RedHatMono.ttf

This should patch the specified font and output it in the specified patched directory.

You can also call the patcher directly as shown, if it works for you.

./font-patcher PATH_TO_FONT

Font Patcher Syntax

The following shows the patcher command options and arguments:

Nerd Fonts Patcher v3.1.0-6 (4.8.1) (ff 20230101)
usage: font-patcher [-h] [-v] [-s] [--variable-width-glyphs]
                    [--debug [{0,1,2,3}]] [-q] [--careful] [-ext EXTENSION]
                    [-out OUTPUTDIR] [--makegroups [{-1,0,1,2,3,4,5,6}]] [-c]
                    [--codicons] [--fontawesome] [--fontawesomeext]
                    [--fontlogos] [--material] [--octicons] [--powersymbols]
                    [--pomicons] [--powerline] [--powerlineextra] [--weather]
                    [--boxdrawing] [--configfile CONFIGFILE] [--custom CUSTOM]
                    [--dry] [--glyphdir GLYPHDIR] [--has-no-italic] [-l]
                    [--metrics {HHEA,TYPO,WIN}] [--name FORCE_NAME]
                    [--postprocess POSTPROCESS] [--removeligs]
                    [--xavgcharwidth [XAVGWIDTH]]
                    [--progressbars | --no-progressbars]
                    font

Nerd Fonts Font Patcher: patches a given font with programming and development related glyphs

* Website: https://www.nerdfonts.com
* Version: 3.1.0-6
* Development Website: https://github.com/ryanoasis/nerd-fonts
* Changelog: https://github.com/ryanoasis/nerd-fonts/blob/-/changelog.md

positional arguments:
  font                  The path to the font to patch (e.g., Inconsolata.otf)

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -s, --mono, --use-single-width-glyphs
                        Whether to generate the glyphs as single-width not double-width (default is double-width) (Nerd Font Mono)
  --variable-width-glyphs
                        Do not adjust advance width (no "overhang") (Nerd Font Propo)
  --debug [{0,1,2,3}]   Verbose mode (optional: 1=just to file; 2*=just to terminal; 3=display and file)
  -q, --quiet           Do not generate verbose output
  --careful             Do not overwrite existing glyphs if detected
  -ext EXTENSION, --extension EXTENSION
                        Change font file type to create (e.g., ttf, otf)
  -out OUTPUTDIR, --outputdir OUTPUTDIR
                        The directory to output the patched font file to
  --makegroups [{-1,0,1,2,3,4,5,6}]
                        Use alternative method to name patched fonts (default=1)

Symbol Fonts:
  -c, --complete        Add all available Glyphs
  --codicons            Add Codicons Glyphs (https://github.com/microsoft/vscode-codicons)
  --fontawesome         Add Font Awesome Glyphs (http://fontawesome.io/)
  --fontawesomeext      Add Font Awesome Extension Glyphs (https://andrelzgava.github.io/font-awesome-extension/)
  --fontlogos           Add Font Logos Glyphs (https://github.com/Lukas-W/font-logos)
  --material, --mdi     Add Material Design Icons (https://github.com/templarian/MaterialDesign)
  --octicons            Add Octicons Glyphs (https://octicons.github.com)
  --powersymbols        Add IEC Power Symbols (https://unicodepowersymbol.com/)
  --pomicons            Add Pomicon Glyphs (https://github.com/gabrielelana/pomicons)
  --powerline           Add Powerline Glyphs
  --powerlineextra      Add Powerline Extra Glyphs (https://github.com/ryanoasis/powerline-extra-symbols)
  --weather             Add Weather Icons (https://github.com/erikflowers/weather-icons)

Expert Options:
  --boxdrawing          Force patching in (over existing) box drawing glyphs
  --configfile CONFIGFILE
                        Specify a file path for JSON configuration file (see sample: src/config.sample.json)
  --custom CUSTOM       Specify a custom symbol font, all glyphs will be copied; absolute path suggested
  --dry                 Do neither patch nor store the font, to check naming
  --glyphdir GLYPHDIR   Path to glyphs to be used for patching
  --has-no-italic       Font family does not have Italic (but Oblique), to help create correct RIBBI set
  -l, --adjust-line-height
                        Whether to adjust line heights (attempt to center powerline separators more evenly)
  --metrics {HHEA,TYPO,WIN}
                        Select vertical metrics source (for problematic cases)
  --name FORCE_NAME     Specify naming source ('full', 'postscript', 'filename', or concrete free name-string)
  --postprocess POSTPROCESS
                        Specify a Script for Post Processing
  --removeligs, --removeligatures
                        Removes ligatures specificed in JSON configuration file (needs --configfile)
  --xavgcharwidth [XAVGWIDTH]
                        Adjust xAvgCharWidth (optional: concrete value)
  --progressbars        Show percentage completion progress bars per Glyph Set (default)
  --no-progressbars     Don't show percentage completion progress bars per Glyph Set

Reference the docs for more.

Conclusion

In this tutorial, we showed you how you can use the Nerd Font patcher utility to patch a font to include Nerd Fonts features.

If you liked this tutorial, please share and leave a comment.

Faced a problem, leave a comment below and we will get back to you.

:) Later Gator!

Share
Comments
More from GeekBits

Join us at GeekBits

Join our members and get a currated list of awesome articles each month.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to GeekBits.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.