From 540073db9863755e7d3f955416c0a9f589d2c831 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Wed, 12 Oct 2022 11:31:17 +0200 Subject: [PATCH 1/3] font-patcher: Clarify height code [why] Use of abs() looks like we do not know if the descenders are expected to be positive or negative. But it is well defined. Furthermore on abnormal fonts (where the descenders are nonexisting) we can use the wrong value. Well, that is academic I guess. [how] In our own `ymin` value we store a value like os2_descender, which means that it is on the same axis as the ascender (ymax). Typical values where the baseline is on y-coordinate 0 ymax will be positive and ymin (being below the baseline) will be negative. The total height has to be calculated from adding ascender + -descender (when the descenders are lower than the ascenders, which is guaranteed). The older descender values have positive values; are on an opposite y axis... The height with them would be ascender + descender. Well, WE have in the font_dim os2-like values... Signed-off-by: Fini Jastrow --- font-patcher | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/font-patcher b/font-patcher index 84d84b45f2..6b2ad712a4 100755 --- a/font-patcher +++ b/font-patcher @@ -876,7 +876,7 @@ class font_patcher: # print("New MAXWIDTH-B {} {} {}".format(glyph, self.sourceFont[glyph].width, xmax)) # Calculate font height - self.font_dim['height'] = abs(self.font_dim['ymin']) + self.font_dim['ymax'] + 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 @@ -886,7 +886,7 @@ class font_patcher: 'xmax' : self.sourceFont.em, 'ymax' : self.sourceFont.ascent, 'width' : self.sourceFont.em, - 'height': abs(self.sourceFont.descent) + self.sourceFont.ascent, + 'height': self.sourceFont.descent + self.sourceFont.ascent, } From d1b1d4bd2b455037d4c76b78645b6776d9db0bb3 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Wed, 12 Oct 2022 11:49:28 +0200 Subject: [PATCH 2/3] 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 6b2ad712a4..c245d3b0dd 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 From fc05d810732a90f8a8e904edace7042ed30958ff Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Wed, 12 Oct 2022 11:58:10 +0200 Subject: [PATCH 3/3] Symbols Only font: Remove gaps [why] We do not want fonts with gap. Gaps are explicitely removed on patching anyhow. Why should the templates have gaps? Signed-off-by: Fini Jastrow --- .../NerdFontsSymbols 1000 EM Nerd Font Complete Blank.sfd | 4 ++-- .../NerdFontsSymbols 2048 EM Nerd Font Complete Blank.sfd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 1000 EM Nerd Font Complete Blank.sfd b/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 1000 EM Nerd Font Complete Blank.sfd index 3e8e0659a0..3436194661 100644 --- a/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 1000 EM Nerd Font Complete Blank.sfd +++ b/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 1000 EM Nerd Font Complete Blank.sfd @@ -24,14 +24,14 @@ ModificationTime: 1646316690 PfmFamily: 17 TTFWeight: 400 TTFWidth: 5 -LineGap: 90 +LineGap: 0 VLineGap: 0 Panose: 2 0 5 9 0 0 0 0 0 0 OS2TypoAscent: 0 OS2TypoAOffset: 1 OS2TypoDescent: 0 OS2TypoDOffset: 1 -OS2TypoLinegap: 90 +OS2TypoLinegap: 0 OS2WinAscent: 0 OS2WinAOffset: 1 OS2WinDescent: 0 diff --git a/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 2048 EM Nerd Font Complete Blank.sfd b/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 2048 EM Nerd Font Complete Blank.sfd index 25347bd01e..6b55926f99 100644 --- a/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 2048 EM Nerd Font Complete Blank.sfd +++ b/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbols 2048 EM Nerd Font Complete Blank.sfd @@ -24,14 +24,14 @@ ModificationTime: 1646316690 PfmFamily: 17 TTFWeight: 400 TTFWidth: 5 -LineGap: 184 +LineGap: 0 VLineGap: 0 Panose: 2 0 5 9 0 0 0 0 0 0 OS2TypoAscent: 0 OS2TypoAOffset: 1 OS2TypoDescent: 0 OS2TypoDOffset: 1 -OS2TypoLinegap: 184 +OS2TypoLinegap: 0 OS2WinAscent: 0 OS2WinAOffset: 1 OS2WinDescent: 0