Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font-patcher: Make Nerd Fonts Monospaced Again #764

Merged
merged 6 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import absolute_import, print_function, unicode_literals

# Change the script version when you edit this script:
script_version = "3.0.3"
script_version = "3.0.4"

version = "2.2.1"
projectName = "Nerd Fonts"
Expand Down Expand Up @@ -320,6 +320,7 @@ class font_patcher:
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('--makegroups', dest='makegroups', default=False, action='store_true', help='Use alternative method to name patched fonts (experimental)')
parser.add_argument('--variable-width-glyphs', dest='nonmono', default=False, action='store_true', help='Do not adjust advance width (no "overhang")')

# progress bar arguments - https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse
progressbars_group_parser = parser.add_mutually_exclusive_group(required=False)
Expand Down Expand Up @@ -380,6 +381,10 @@ class font_patcher:
if self.args.alsowindows:
self.args.windows = False

if self.args.nonmono and self.args.single:
print("Warniung: Specified contradicting --variable-width-glyphs and --use-single-width-glyph. Ignoring --variable-width-glyphs.")
self.args.nonmono = False

# this one also works but it needs to be updated every time a font is added
# it was a conditional in self.setup_font_names() before, but it was missing
# a symbol font, so it would name the font complete without being so sometimes.
Expand Down Expand Up @@ -1054,15 +1059,20 @@ class font_patcher:
align_matrix = psMat.translate(x_align_distance, y_align_distance)
self.sourceFont[currentSourceFontGlyph].transform(align_matrix)

# Ensure after horizontal adjustments and centering that the glyph
# does not overlap the bearings (edges)
self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])

# Needed for setting 'advance width' on each glyph so they do not overlap,
# also ensures the font is considered monospaced on Windows by setting the
# same width for all character glyphs. This needs to be done for all glyphs,
# even the ones that are empty and didn't go through the scaling operations.
# It should come after setting the glyph bearings
self.set_glyph_width_mono(self.sourceFont[currentSourceFontGlyph])

# Ensure after horizontal adjustments and centering that the glyph
# does not overlap the bearings (edges)
self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])
# Re-remove negative bearings for target font with variable advance width
if self.args.nonmono:
self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])

# Check if the inserted glyph is scaled correctly for monospace
if self.args.single:
Expand Down Expand Up @@ -1114,6 +1124,10 @@ class font_patcher:
self.font_dim.width is set with self.get_sourcefont_dimensions().
"""
try:
# Fontforge handles the width change like this:
# - Keep existing left_side_bearing
# - Set width
# - Calculate and set new right_side_bearing
glyph.width = self.font_dim['width']
except:
pass
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Full options:
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -416,6 +416,8 @@ options:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Show percentage completion progress bars per Glyph Set
--no-progressbars Don't show percentage completion progress bars per Glyph Set
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ The list is not complete, but you can [search for a complete list here](https://
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -427,6 +427,8 @@ optional arguments:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars 显示每个Glyph Set的完成度进度条
--no-progressbars 不显示每个Glyph Set的完成度进度条
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Parcha la fuente de tu preferencia para usar los [VimDevIcons ➶][vim-devicons]
uso: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -375,6 +375,8 @@ argumentos opcionales:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Muestra barras de progreso con porcentajes de completitud por cada Conjunto de Glifos
--no-progressbars No muestra barras de progreso con porcentajes de completitud por cada Conjunto de Glifos
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Générer la police de votre choix pour l'utiliser avec [VimDevIcons ➶][vim-de
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -453,6 +453,8 @@ options:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Show percentage completion progress bars per Glyph Set
--no-progressbars Don't show percentage completion progress bars per Glyph Set
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_hi.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ The list is not complete, but you can [search for a complete list here](https://
प्रयोग: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -408,6 +408,8 @@ The list is not complete, but you can [search for a complete list here](https://
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars प्रति ग्लिफ़ सेट प्रतिशत पूर्णता प्रगति बार दिखाएं
--no-progressbars प्रति ग्लिफ़ सेट प्रतिशत पूर्णता प्रगति बार न दिखाएं
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_it.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ Modificare il font di tua scelta per utilizzare i [VimDevIcons ➶][vim-devicons
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -376,6 +376,8 @@ options:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Show percentage completion progress bars per Glyph Set
--no-progressbars Don't show percentage completion progress bars per Glyph Set
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ The list is not complete, but you can [search for a complete list here](https://
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -371,6 +371,8 @@ optional arguments:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars グリフセットごとに進捗を百分率で表示します。
--no-progressbars グリフセットごとの進捗を表示しません。
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ The list is not complete, but you can [search for a complete list here](https://
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -372,6 +372,8 @@ options:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Show percentage completion progress bars per Glyph Set
--no-progressbars Don't show percentage completion progress bars per Glyph Set
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ Patchowanie wybranych przez ciebie fontów z wykorzystaniem [VimDevIcons ➶][vi
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -448,6 +448,8 @@ options:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Show percentage completion progress bars per Glyph Set
--no-progressbars Don't show percentage completion progress bars per Glyph Set
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_pt-pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Modificar o tipo de letra à tua escolha com [VimDevIcons ➶][vim-devicons]:
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -372,6 +372,8 @@ argumentos opcionais:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Mostrar barras de progresso de conclusão percentual por Glyph Set
--no-progressbars Não mostrar barras de progresso de conclusão percentual por Glyph Set
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ The list is not complete, but you can [search for a complete list here](https://
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -427,6 +427,8 @@ options:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars Show percentage completion progress bars per Glyph Set
--no-progressbars Don't show percentage completion progress bars per Glyph Set
--also-windows Create two fonts, the normal and the --windows version
Expand Down
4 changes: 3 additions & 1 deletion readme_tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ The list is not complete, but you can [search for a complete list here](https://
usage: font-patcher [-h] [-v] [-s] [-l] [-q] [-w] [-c] [--careful] [--removeligs]
[--postprocess [POSTPROCESS]] [--configfile [CONFIGFILE]]
[--custom [CUSTOM]] [-ext [EXTENSION]] [-out [OUTPUTDIR]]
[--glyphdir [GLYPHDIR]] [--makegroups]
[--glyphdir [GLYPHDIR]] [--makegroups] [--variable-width-glyphs]
[--progressbars | --no-progressbars] [--also-windows]
[--fontawesome] [--fontawesomeextension] [--fontlinux]
[--octicons] [--codicons] [--powersymbols] [--pomicons]
Expand Down Expand Up @@ -427,6 +427,8 @@ optional arguments:
--glyphdir [GLYPHDIR]
Path to glyphs to be used for patching
--makegroups Use alternative method to name patched fonts (experimental)
--variable-width-glyphs
Do not adjust advance width (no "overhang")
--progressbars 顯示每個Glyph Set的完成度進度條
--no-progressbars 不顯示每個Glyph Set的完成度進度條
--also-windows Create two fonts, the normal and the --windows version
Expand Down
Loading