name-parser: Change naming behavior

[why]
We created two fonts, one 'normal' and one 'Windows Compatible'. The
later one used shorter names because there are some Microsoft
applications that can not work with long (family-) names.

But it would be better to have universally usable fonts, like all our
sourcefonts. It would reduce confusion and also reduce the size of
installation packages.

[how]
ID 1 (Family) family()
  Unchanged
  Take the short form font name. Appends depending on mode short or long
  weight.

ID 2 (SubFamily) subfamily()
  Unchanged
  Transmogifies Oblique to Italic.
  Returns long form styles (i.e. RIBBI)

ID 4 (Fullname) CFF.Fullname fullname()
  Take the short form font name (instead of long).
  Depending on mode take short or long styles.
  This is now in line with ID 4 = ID 1 + ID 2

ID 6 (PS Fullname) CFF.FontName psname()
  We limited the length to 31 characters, which is sometimes too short
  to have different names for fonts of one same family.
  Now we take the short forms of name suffix and styles, for example
  VictorMonoNFM-BdIt

ID 16 (Typogr. Family) preferred_family()
  The name itself is unchanged (short form name plus verbose suffix),
  but the suppression check has been fixed to really compare the
  resulting name with the ID 1 name.

ID 17 (Typogr. Subfamily) preferred_styles()
  This is unchanged (long form styles) but the suppression check has been
  fixed to really compare the resulting string with ID 2.

CFF.Familyname ps_familyname()
  Uses ID 16 now and ID 1 as fallback. Was always ID 1 before, which is
  wrong.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-04-07 16:29:32 +02:00
parent f99e108273
commit 4394824977

View file

@ -142,41 +142,46 @@ class FontnameParser:
styles.remove('Regular')
# For naming purposes we want Oblique to be part of the styles
(weights, styles) = FontnameTools.make_oblique_style(weights, styles)
return FontnameTools.concat(self.basename, self.rest, self.other_token, self.fullname_suff, weights, styles)
(name, rest) = self._shortened_name()
if self.use_short_families[1]:
weights = FontnameTools.short_styles(weights)
styles = FontnameTools.short_styles(styles)
return FontnameTools.concat(name, rest, self.other_token, self.family_suff, weights, styles)
def psname(self):
"""Get the SFNT PostScriptName (ID 6)"""
# This is almost self.family() + '-' + self.subfamily() but without short styles
fam = FontnameTools.camel_casify(FontnameTools.concat(self.basename, self.rest, self.other_token, self.fontname_suff))
sub = FontnameTools.camel_casify(FontnameTools.concat(self.weight_token, self.style_token))
# This is almost self.family() + '-' + self.subfamily()
(name, rest) = self._shortened_name()
styles = FontnameTools.short_styles(self.style_token)
weights = FontnameTools.short_styles(self.weight_token)
fam = FontnameTools.camel_casify(FontnameTools.concat(name, rest, self.other_token, self.fontname_suff))
sub = FontnameTools.camel_casify(FontnameTools.concat(weights, styles))
if len(sub) > 0:
sub = '-' + sub
fam = FontnameTools.postscript_char_filter(fam)
sub = FontnameTools.postscript_char_filter(sub)
# The name string must be no longer than 63 characters
if len(fam) + len(sub) > 63:
print('Shortening too long PostScriptName')
fam = fam[:(63 - len(sub))]
return fam + sub
return self._make_ps_name(fam + sub, False)
def preferred_family(self):
"""Get the SFNT Preferred Familyname (ID 16)"""
if self.suppress_preferred_if_identical and len(self.weight_token) == 0:
(name, rest) = self._shortened_name()
pfn = FontnameTools.concat(name, rest, self.other_token, self.fullname_suff)
if self.suppress_preferred_if_identical and pfn == self.family():
# Do not set if identical to ID 1
return ''
(name, rest) = self._shortened_name()
return FontnameTools.concat(name, rest, self.other_token, self.family_suff)
return pfn
def preferred_styles(self):
"""Get the SFNT Preferred Styles (ID 17)"""
styles = self.style_token
weights = self.weight_token
if self.suppress_preferred_if_identical and len(weights) == 0:
# Do not set if identical to ID 2
return ''
# For naming purposes we want Oblique to be part of the styles
(weights, styles) = FontnameTools.make_oblique_style(weights, styles)
return FontnameTools.concat(weights, styles)
pfs = FontnameTools.concat(weights, styles)
if self.suppress_preferred_if_identical and pfs == self.subfamily():
# Do not set if identical to ID 2
return ''
return pfs
def family(self):
"""Get the SFNT Familyname (ID 1)"""
@ -201,15 +206,10 @@ class FontnameParser:
def ps_familyname(self):
"""Get the PS Familyname"""
return self._make_ps_name(self.family(), True)
def ps_fontname(self):
"""Get the PS fontname"""
# This Adobe restriction is classically ignored
# if len(n) > 29:
# print('Shortening too long PS fontname')
# return n[:29]
return self._make_ps_name(self.psname(), False)
fam = self.preferred_family()
if len(fam) < 1:
fam = self.family()
return self._make_ps_name(fam, True)
def macstyle(self, style):
"""Modify a given macStyle value for current name, just bits 0 and 1 touched"""
@ -238,7 +238,7 @@ class FontnameParser:
def rename_font(self, font):
"""Rename the font to include all information we found (font is fontforge font object)"""
font.fondname = None
font.fontname = self.ps_fontname()
font.fontname = self.psname()
font.fullname = self.fullname()
font.familyname = self.ps_familyname()