font-patcher: Improve Nerd Font Propo with ScaleGroups

[why]
Assume a set of monospaced icons in a ScaleGroup that scatter all about
(like Braille).

With --variable-width-glyphs we forcefully remove all left side
bearings and set the width to the width of the combined bounding box.

This is not correct, usually with monospaced ScaleGroup icons we should
preserve the original advance width.

[how]
Do not remove left side bearings on ScaleGroup glyphs in
--variable-width-glyphs mode.

Set the width of any glyph in --variable-width-glyphs to the 'monoscaped
advance width' if that particular glyph has one (from a ScaleGroup).

The effect is that all positive bearings will be 'added' and put on the
right hand side of the glyph, while the glyph itself, or rather the
combined bounding box, is still strictly left aligned.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-01-04 10:50:37 +01:00
parent e4e6887d9e
commit 70c4d034a9

View file

@ -1089,8 +1089,9 @@ class font_patcher:
# Handle glyph l/r/c alignment
x_align_distance = 0
if self.args.nonmono:
if self.args.nonmono and sym_dim['advance'] is None:
# Remove left side bearing
# (i.e. do not remove left side bearing when combined BB is in use)
x_align_distance = -self.sourceFont[currentSourceFontGlyph].left_side_bearing
elif sym_attr['align']:
# First find the baseline x-alignment (left alignment amount)
@ -1127,8 +1128,12 @@ class font_patcher:
self.set_glyph_width_mono(self.sourceFont[currentSourceFontGlyph])
else:
# Target font with variable advance width get the icons with their native widths
# and keeping possible (negative) bearings in effect
width = sym_dim['width']
# and keeping possible (right and/or negative) bearings in effect
if sym_dim['advance'] is not None:
# 'Width' from monospaced scale group
width = sym_dim['advance']
else:
width = sym_dim['width']
# If we have overlap we need to subtract that to keep/get negative bearings
if overlap and (sym_attr['align'] == 'l' or sym_attr['align'] == 'r'):
width -= overlap_width