From 3e478f7cf85a6129568a34a21409c27f9d93e29c Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Wed, 12 Oct 2022 11:49:28 +0200 Subject: [PATCH] font-patcher: Fix empty input font detection [why] If we have an empty input font (i.e. for Symbols Only font) and that font has a gap.. That gap will be redistributed to a gapless font where the ascenders and descenders are expanded to fill/keep the gap. If the font has no height (i.e. == ) and a gap, the height will afterwards be > 0 and the empty font detection breaks. [how] Detect empty fonts before gaps. Fixes: #965 Signed-off-by: Fini Jastrow --- font-patcher | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/font-patcher b/font-patcher index 6b2ad712a..c245d3b0d 100755 --- a/font-patcher +++ b/font-patcher @@ -840,6 +840,20 @@ class font_patcher: self.font_dim['ymin'] = self.sourceFont.os2_typodescent self.font_dim['ymax'] = self.sourceFont.os2_typoascent + # Calculate font height + self.font_dim['height'] = -self.font_dim['ymin'] + self.font_dim['ymax'] + if self.font_dim['height'] == 0: + # This can only happen if the input font is empty + # Assume we are using our prepared templates + self.font_dim = { + 'xmin' : 0, + 'ymin' : -self.sourceFont.descent, + 'xmax' : self.sourceFont.em, + 'ymax' : self.sourceFont.ascent, + 'width' : self.sourceFont.em, + 'height': self.sourceFont.descent + self.sourceFont.ascent, + } + # Line gap add extra space on the bottom of the line which # doesn't allow the powerline glyphs to fill the entire line. # Put half of the gap into the 'cell', each top and bottom @@ -853,6 +867,7 @@ class font_patcher: gap_bottom = gap - gap_top self.font_dim['ymin'] -= gap_bottom self.font_dim['ymax'] += gap_top + self.font_dim['height'] = -self.font_dim['ymin'] + self.font_dim['ymax'] self.sourceFont.os2_typoascent = self.sourceFont.os2_typoascent + gap_top self.sourceFont.os2_typodescent = self.sourceFont.os2_typodescent - gap_bottom # TODO Check what to do with win and hhea values @@ -875,20 +890,6 @@ class font_patcher: self.font_dim['xmax'] = xmax # print("New MAXWIDTH-B {} {} {}".format(glyph, self.sourceFont[glyph].width, xmax)) - # Calculate font height - self.font_dim['height'] = -self.font_dim['ymin'] + self.font_dim['ymax'] - if self.font_dim['height'] == 0: - # This can only happen if the input font is empty - # Assume we are using our prepared templates - self.font_dim = { - 'xmin' : 0, - 'ymin' : -self.sourceFont.descent, - 'xmax' : self.sourceFont.em, - 'ymax' : self.sourceFont.ascent, - 'width' : self.sourceFont.em, - 'height': self.sourceFont.descent + self.sourceFont.ascent, - } - def get_scale_factor(self, sym_dim): scale_ratio = 1