font-patcher: Preserve symbol advance with variable width font

[why]
Very slender symbols added to a proportional patch end up being at least
one mono-width wide, which mixes proportional and monospaces metrics.

[how]
When we create a proportional font we should
a) not try to align them in a (non existing) monocpace cell
b) insert the symbols with their own (advance) width

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2022-12-21 18:35:27 +01:00
parent 417395c1a0
commit 946c1d09dd

View file

@ -1085,7 +1085,9 @@ class font_patcher:
# Handle glyph l/r/c alignment
x_align_distance = 0
if sym_attr['align']:
if self.args.nonmono:
pass
elif sym_attr['align']:
# First find the baseline x-alignment (left alignment amount)
x_align_distance = self.font_dim['xmin'] - sym_dim['xmin']
if sym_attr['align'] == 'c':
@ -1117,9 +1119,13 @@ 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
# Target font with variable advance width get the icons with their native advance
# or at least width
if self.args.nonmono:
self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])
if sym_dim['advance']:
self.sourceFont[currentSourceFontGlyph].width = int(sym_dim['advance'])
else:
self.sourceFont[currentSourceFontGlyph].width = int(sym_dim['width'])
# Check if the inserted glyph is scaled correctly for monospace
if self.args.single: