From ca263826449515eed17c57315dbbc21623b31a33 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 16 Mar 2021 12:15:55 +0100 Subject: [PATCH] font-patcher: Use correct source font metrics [why] With a source font where Win Ascent/Descent differs from Typo Ascend/Descent newly added symbols that are intended to be centered _within the visual space_ can end up too far up or down. The happens for example when patching CascadiaCode. Added glyphs like the Ubuntu logo (unicode 0xF31B) is not centered between the square brackets or on a line with the less then and other centered glyphs. [how] The calculation takes the Win Ascent/Descent to calculate the visual hight. That information is a mix of hight and line spacing and can be misleading. Therefore, if use_typo_metrics is set in a font, we obey that flag and use the typo metrics values instead. [note] Some websites with further information follow. https://github.com/googlefonts/gf-docs/tree/main/VerticalMetrics > Hhea metrics are used in Mac OS X, whilst Microsoft uses > Typo when Use_Typo_Metrics is enabled https://docs.microsoft.com/en-us/typography/opentype/otspec160/os2#fsselection https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6hhea.html Signed-off-by: Fini Jastrow --- font-patcher | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/font-patcher b/font-patcher index aa701ce57..1a8e20589 100755 --- a/font-patcher +++ b/font-patcher @@ -553,6 +553,9 @@ class font_patcher: self.sourceFont.os2_winascent += 1 # Make the line size identical for windows and mac + # ! This is broken because hhea* is changed but os2_typo* is not + # ! On the other hand we need intact (i.e. original) typo values + # ! in get_sourcefont_dimensions() @TODO FIXME self.sourceFont.hhea_ascent = self.sourceFont.os2_winascent self.sourceFont.hhea_descent = -self.sourceFont.os2_windescent @@ -572,6 +575,9 @@ class font_patcher: 'width' : 0, 'height': 0, } + if self.sourceFont.os2_use_typo_metrics: + self.font_dim['ymin'] = self.sourceFont.os2_typodescent + self.font_dim['ymax'] = self.sourceFont.os2_typoascent # Find the biggest char width # Ignore the y-values, os2_winXXXXX values set above are used for line height