font-patcher: Wide fonts get only 1 cell Powerline glyphs

[why]
The change introduced with commit
  Default some Powerline glyphs to '2 cells wide'

scales some Powerline glyphs to fit exactly into a 2 cell width. That
looks good on 'normal' fonts, but when the font becomes wider and less
tall at some point that is just too wide.

This is especially the case with the SymbolsOnly font which has a 1:1
aspect ratio. Two cell Powerline glyphs would have an aspect ratio of
2:1 which is unusable.

[how]
Check the destination font cell aspect ratio.
When a two-cell glyph would be wider than 1.6 times its height the
two-cell-mode is forbitten and all Powerline glyphs are scaled into one
cell width.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-01-12 16:37:09 +01:00
parent f311401e32
commit ed929aa7f4

View file

@ -245,6 +245,7 @@ class font_patcher:
self.sourceFont = None # class 'fontforge.font' self.sourceFont = None # class 'fontforge.font'
self.patch_set = None # class 'list' self.patch_set = None # class 'list'
self.font_dim = None # class 'dict' self.font_dim = None # class 'dict'
self.font_extrawide = False
self.onlybitmaps = 0 self.onlybitmaps = 0
self.essential = set() self.essential = set()
self.config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True) self.config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True)
@ -275,6 +276,11 @@ class font_patcher:
panose[3] = 9 # 3 (4th value) = propotion; 9 = monospaced panose[3] = 9 # 3 (4th value) = propotion; 9 = monospaced
self.sourceFont.os2_panose = tuple(panose) self.sourceFont.os2_panose = tuple(panose)
# For very wide (almost square or wider) fonts we do not want to generate 2 cell wide Powerline glyphs
if self.font_dim['height'] * 1.8 < self.font_dim['width'] * 2:
print("Very wide and short font, disabling 2 cell Powerline glyphs")
self.font_extrawide = True
# Prevent opening and closing the fontforge font. Makes things faster when patching # Prevent opening and closing the fontforge font. Makes things faster when patching
# multiple ranges using the same symbol font. # multiple ranges using the same symbol font.
PreviousSymbolFilename = "" PreviousSymbolFilename = ""
@ -1036,15 +1042,19 @@ class font_patcher:
sys.stdout.write("Adding " + str(max(1, glyphSetLength)) + " Glyphs from " + setName + " Set \n") sys.stdout.write("Adding " + str(max(1, glyphSetLength)) + " Glyphs from " + setName + " Set \n")
currentSourceFontGlyph = -1 # initialize for the exactEncoding case currentSourceFontGlyph = -1 # initialize for the exactEncoding case
width_warning = False
for index, sym_glyph in enumerate(symbolFontSelection): for index, sym_glyph in enumerate(symbolFontSelection):
index = max(1, index) index = max(1, index)
try: sym_attr = attributes.get(sym_glyph.unicode)
sym_attr = attributes[sym_glyph.unicode] if sym_attr is None:
except KeyError:
sym_attr = attributes['default'] sym_attr = attributes['default']
if self.font_extrawide:
# Do not allow 'xy2' scaling
sym_attr['stretch'] = sym_attr['stretch'].replace('2', '')
if exactEncoding: if exactEncoding:
# Use the exact same hex values for the source font as for the symbol font. # Use the exact same hex values for the source font as for the symbol font.
# Problem is we do not know the codepoint of the sym_glyph and because it # Problem is we do not know the codepoint of the sym_glyph and because it