nerd-fonts/bin/scripts/name_parser
Fini Jastrow be48f93710 name-parser: Fix style names two-language-mode
[why]
The code needlessly create two language ID17 even if ID16 is only one
entry / one languange. ID17 is always the same for both languages.

This is an example for the wrong way:

======== BlexMonoNerdFont-Text.ttf ========
SFNT Fullname      ID 4     BlexMono Nerd Font Text
SFNT Family        ID 1     BlexMono Nerd Font Text
SFNT SubFamily     ID 2     Regular
SFNT Pref Family   ID 16    BlexMono Nerd Font
SFNT Pref Styles   ID 17    ('Text', 'Text')
SFNT PS Name       ID 6     BlexMonoNF-Text
SFNT Compatible    ID 18    -
SFNT CID findfont  ID 20    -
SFNT WWS Family    ID 21    -
SFNT WWS SubFamily ID 22    -
PS fontname                 BlexMonoNF-Text
PS fullname                 BlexMono Nerd Font Text
PS familyname               BlexMono Nerd Font Text
fondname                    None

This is an example for the correct way (two ID17 when we have two ID16):

======== NotoSerifCondensedNerdFont-BlackItalic.ttf ========
SFNT Fullname      ID 4     NotoSerif Condensed NF Black Italic
SFNT Family        ID 1     NotoSerif Cond NF Black
SFNT SubFamily     ID 2     Italic
SFNT Pref Family   ID 16    ('NotoSerif Condensed Nerd Font', 'NotoSerif Cond NF')
SFNT Pref Styles   ID 17    ('Black Italic', 'Black Italic')
SFNT PS Name       ID 6     NotoSerifCondensedNF-BlackItalic
SFNT Compatible    ID 18    -
SFNT CID findfont  ID 20    -
SFNT WWS Family    ID 21    -
SFNT WWS SubFamily ID 22    -
PS fontname                 NotoSerifCondensedNF-BlackItalic
PS fullname                 NotoSerif Condensed NF Black Italic
PS familyname               NotoSerif Cond NF Black
fondname                    None

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2024-04-03 16:18:46 +02:00
..
check_glyphs Add tool to find problematic glyphs 2024-03-18 19:59:31 +01:00
FontnameParser.py name-parser: Fix style names two-language-mode 2024-04-03 16:18:46 +02:00
FontnameTools.py Add Ubuntu Sans 2024-04-02 18:21:29 +02:00
query_monospace font-patcher: Prevent --mono on proportional fonts 2022-09-24 16:56:30 +02:00
query_name query_name: Examine all languages 2024-03-17 20:36:52 +01:00
query_names Remove name_parser_test scripts 2023-04-23 13:44:14 +02:00
query_panose name-parser: Specify python version 2022-08-22 10:53:05 +02:00
query_sftn name-parser: Specify python version 2022-08-22 10:53:05 +02:00
query_version name-parser: Specify python version 2022-08-22 10:53:05 +02:00
README.md Remove name_parser_test scripts 2023-04-23 13:44:14 +02:00

Creating Consistently Grouped Patched Fonts

This is a small sub-project to font-patcher that uses a little bit more knowledge to come up with font names and name parts. In applications multiple fonts are grouped under a 'Family'. Each member of the Family has a different 'SubFamily' or 'Style'.

Consider a font named 'Times' that has two variants: normal and bold. For this font the Family would be 'Times' and the 'Style' would be 'Regular' (i.e normal) in one file and 'Bold' in the other file.

With this information applications are able to group all 'Times' together and additionally choose the 'Bold' font if the user pushes the 'B' button on the font style dialog in that application.

Motivation

Quite a number of patched fonts have inconsistent or simply wrong font grouping. The naming in general is sometimes surprising and not following naming conventions. This is in part due to the font-patcher, but in part the source fonts are already strange. This results in invisible (but installed) fonts in some applications, inconsistent naming (Familyname differs from Fullname) and not correctly working bold/italic selectors in some applications.

And we would like to have the information within the names sorted in a consistent way. usually a font name consists of these parts (in this order):

  1. Name base (e.g. Noto)
  2. Variant (e.g. Sans)
  3. Subvariant (e.g. Display)
  4. Weight (e.g. Black)
  5. Style (e.g. Italic)

This is important because we want to add subvariant information, namely the Nerd Font part.

Example:

  • (old) Iosevka Term Light Italic Nerd Font
  • (new) Iosevka Term Nerd Font Light Italic

The Plan

To solve these issues the font name parts have to be analyzed more thoroughly and then categorized. These categories are then used to assemble the names in correct order. The simple (not typographically aware) applications shall always get groups of at most four styles, and these are Regular, Bold, Italic, and Bold-Italic. Other styles turn up as Families, because this is the only way they would work in these more simple applications.

Typographically aware applications, on the other hand, get all styles grouped under one Family name.

First experiments showed that the full information can usually be restored already from the file names that our source fonts have.

This new naming is complete optional (but recommended). Give the option --makegroups to font-patcher and it will try to come up with reasonable grouping and naming. Leave the option out and it will work as it always did.

The Tests

In this directory were two tests. If interested you need to go back in the git history. They are not needed anymore.

Helper scripts

There are some helper scripts that help examining the font files. Of course there are other, more professional tools to dump font information, but here we get all we need in a concise way:

  • query_mono font_name [font_name ...]
  • query_names font_name [font_name ...]
  • query_panose font_name
  • query_sftn [<sfnt-name>] font_name
  • query_version font_name

They can be invoked like this $ fontforge query_sfnt foo.ttf.