Skip to content

Commit

Permalink
font-patcher: Add possibility to generate proportional font
Browse files Browse the repository at this point in the history
[why]
Theoretically we can produce 3 types on fonts:
* A: Strictly monospaced font
* B: Allow bigger symbols, but advance width still monospaced
* C: Allow bigger symbols, advance width will vary

All have their uses.

Historically Nerd Fonts produced A and B.
Then we had kind of a breaking change with 2.2.0 that it produces
now A and C.

The commit
  b9b7a5080  Revert "Remove negative bearings on 2048-em glyphs"
restores the old (pre 2.2.0) behavior. But the type C fonts can be
useful, so maybe we can have them as option?

[how]
Add commandline option to be able to create all fonts types:
* A: specify -s or --mono or --use-single-width-glyphs
* B: specify nothing
* C: specify --variable-width-glyphs

Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Sep 1, 2022
1 parent 1bb174e commit 63db683
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion 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 @@ -1065,6 +1070,10 @@ class font_patcher:
# It should come after setting the glyph bearings
self.set_glyph_width_mono(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:
(xmin, _, xmax, _) = self.sourceFont[currentSourceFontGlyph].boundingBox()
Expand Down Expand Up @@ -1115,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

0 comments on commit 63db683

Please sign in to comment.