From 755c9c37e6f02f5be908e98ec7ad9ab26116ef5d Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Thu, 25 Nov 2021 17:28:18 +0100 Subject: [PATCH] font-patcher: Really set SubFamily to what we want [why] The most convenient way to set something in the SFNT table is by using Fontforge's appendSFNTName(). When we try to set the SubFamily, this will succeed in many instances, but not in all. Sometimes the function seems to be ignored. This is for example the case for VictorMono-Medium.ttf where we want to set the SubFamily "Regular", but the final patched file has the SubFamily "Medium". [how] The reason for the unexpected behavior of Fontforge is as follows. It almost seems like a bug, but then it is coded explicitely in this way. Maybe noone ever stumbled about it, or it has only been designed only with creating new fonts in mind. Fontforge lets you set any value, unless it is the default value. If it is the default value it does not set anything. It also does not remove a previously existing non-default value. Why it is done this way is unclear: fontforge/python.c SetSFNTName() line 11431 return( 1 ); /* If they set it to the default, there's nothing to do */ Then is the question: What is the default? It is taken from the currently set fontname (??!). The fontname is parsed and everything behind the dash is the default SubFamily: fontforge/tottf.c DefaultTTFEnglishNames() fontforge/splinefont.c _GetModifiers() To stick to the example above, the fontname is there "VictorMonoNerdFontM-Medium". Afterwards we want to set the SubFamily to "Medium" - which is the 'default' and Fontforge decides that nothing has to be done. Albeigth the current SubFamily is "Regular" (from the source font load). Well. To fix this without touching Fontforge we need to set the SubFamily directly in the SFNT table, which is a little bit unhandy but possible. Now in the generated files the SubFamily is again as expected the same es the fontname's last part. Signed-off-by: Fini Jastrow --- font-patcher | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/font-patcher b/font-patcher index 1c6d90efa7..4d21ee99d4 100755 --- a/font-patcher +++ b/font-patcher @@ -394,7 +394,12 @@ class font_patcher: self.sourceFont.appendSFNTName(str('English (US)'), str('Preferred Family'), self.sourceFont.familyname) self.sourceFont.appendSFNTName(str('English (US)'), str('Family'), self.sourceFont.familyname) self.sourceFont.appendSFNTName(str('English (US)'), str('Compatible Full'), self.sourceFont.fullname) - self.sourceFont.appendSFNTName(str('English (US)'), str('SubFamily'), subFamily) + # Fontforge does not allow to set SubFamily to any value (see commit message), so + # instead of self.sourceFont.appendSFNTName(str('English (US)'), str('SubFamily'), subFamily) we do: + sfnt_list = list(self.sourceFont.sfnt_names) + sfnt_list[subFamilyTupleIndex] = ( sfnt_list[subFamilyTupleIndex][0], sfnt_list[subFamilyTupleIndex][1], subFamily ) + self.sourceFont.sfnt_names = tuple(sfnt_list) + self.sourceFont.comment = projectInfo self.sourceFont.fontlog = projectInfo