From ed929aa7f44def6a3250901a27d4473f417cec64 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Thu, 12 Jan 2023 16:37:09 +0100 Subject: [PATCH] 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 --- font-patcher | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/font-patcher b/font-patcher index 5f7bd88e2..68d8210dc 100755 --- a/font-patcher +++ b/font-patcher @@ -245,6 +245,7 @@ class font_patcher: self.sourceFont = None # class 'fontforge.font' self.patch_set = None # class 'list' self.font_dim = None # class 'dict' + self.font_extrawide = False self.onlybitmaps = 0 self.essential = set() 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 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 # multiple ranges using the same symbol font. PreviousSymbolFilename = "" @@ -1036,15 +1042,19 @@ class font_patcher: sys.stdout.write("Adding " + str(max(1, glyphSetLength)) + " Glyphs from " + setName + " Set \n") currentSourceFontGlyph = -1 # initialize for the exactEncoding case + width_warning = False for index, sym_glyph in enumerate(symbolFontSelection): index = max(1, index) - try: - sym_attr = attributes[sym_glyph.unicode] - except KeyError: + sym_attr = attributes.get(sym_glyph.unicode) + if sym_attr is None: sym_attr = attributes['default'] + if self.font_extrawide: + # Do not allow 'xy2' scaling + sym_attr['stretch'] = sym_attr['stretch'].replace('2', '') + if exactEncoding: # 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