Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

name-parser: Remove filename parsing code and more #1259

Merged
merged 6 commits into from
May 26, 2023

Conversation

Finii
Copy link
Collaborator

@Finii Finii commented May 25, 2023

[why]
Patching CartographCF-Bold.ttf creates this naming:

Family (ID 1)      : CartographF Nerd Font Condensed
SubFamily (ID 2)   : Bold
Fullname (ID 4)    : CartographF Nerd Font Condensed Bold
PSN (ID 6)         : CartographFNF-CondensedBold
PrefFamily (ID 16) : CartographF Nerd Font
PrefStyles (ID 17) : Condensed Bold

CartographF Nerd Font Condensed Bold
\===> 'CartographFNerdFont-CondensedBold.ttf'

[how]
The font-patcher historically used the file name of the to-be-patched font to come up with the new name. When the FontnameParser has been developed that mechanics has been copied at least for fallback. The earliest tests compared old and new naming with all the filenames.

Later, when the FontnameParser has been used to really apply name changes it has always based the parsing on the Fullname or the PSname, because they really hold the information (or at least should hold); while the filename might be completely random.

Still code the dealt with specific problems in FILEnames prevailed. The Ubuntu font for example has a file name like Ubuntu-C.ttf, and we needed to convert the C to Condensed.

As that requirement vanished we can drop all the code that has been added specifically only for parsing the Ubuntu font filenames.

Side note: USUALLY font filenames should be roughly equal to the PSname.

Fixes: #1258

Requirements / Checklist

What does this Pull Request (PR) do?

How should this be manually tested?

Check all generated font names from prepatched fonts

Any background context you can provide?

What are the relevant tickets (if any)?

Screenshots (if appropriate or helpful)

[why]
Patching CartographCF-Bold.ttf creates this naming:

    Family (ID 1)      : CartographF Nerd Font Condensed
    SubFamily (ID 2)   : Bold
    Fullname (ID 4)    : CartographF Nerd Font Condensed Bold
    PSN (ID 6)         : CartographFNF-CondensedBold
    PrefFamily (ID 16) : CartographF Nerd Font
    PrefStyles (ID 17) : Condensed Bold

    CartographF Nerd Font Condensed Bold
    \===> 'CartographFNerdFont-CondensedBold.ttf'

[how]
The font-patcher historically used the file name of the to-be-patched
font to come up with the new name. When the FontnameParser has been
developed that mechanics has been copied at least for fallback. The
earliest tests compared old and new naming with all the filenames.

Later, when the FontnameParser has been used to really apply name
changes it has always based the parsing on the Fullname or the PSname,
because they really hold the information (or at least should hold);
while the filename might be completely random.

Still code the dealt with specific problems in FILEnames prevailed. The
Ubuntu font for example has a file name like 'Ubuntu-C.ttf', and we
needed to convert the C to Condensed.

As that requirement vanished we can drop all the code that has been
added specifically only for parsing the Ubuntu font filenames.

Side note: USUALLY font filenames should be roughly equal to the PSname.

Fixes: #1258

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii Finii added the Bug fix label May 25, 2023
@Finii Finii added this to the v3.0.2 milestone May 25, 2023
[why]
The code is obviously wrong. No effect has been seen, though.

First we check if a certain string is a key in the dict.
If it is, we retrieve the value with the string lower-cased as key.

This does not make sense.

[how]
All the keys are lower case anyhow, so the code seems unneeded. Maybe it
is a leftover. The styles that go into it _and are in the dict_ all come
from a regex-enabled search and thus are lower-cased.

Whatever, to have the correct code we use the lower-cased string for
both, checking for existance and retrieving the value - this is the only
sane approach.
Also change to dict.get() method instead of a self made if code.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii Finii changed the title name-parser: Remove filename parsing code name-parser: Remove filename parsing code and more May 26, 2023
@Finii
Copy link
Collaborator Author

Finii commented May 26, 2023

Used this to check the names before/after:

From 48bbdc68f9d2b75550957d7dd5d9219a33547e8b Mon Sep 17 00:00:00 2001
From: Fini Jastrow <ulf.fini.jastrow@desy.de>
Date: Fri, 26 May 2023 10:58:10 +0200
Subject: [PATCH] DEBUG

---
 .../gotta-patch-em-all-font-patcher!.sh       | 30 +++++++++----------
 bin/scripts/name_parser/FontnameParser.py     |  2 ++
 font-patcher                                  |  3 +-
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/bin/scripts/gotta-patch-em-all-font-patcher!.sh b/bin/scripts/gotta-patch-em-all-font-patcher!.sh
index a5020690e..128b74ddd 100755
--- a/bin/scripts/gotta-patch-em-all-font-patcher!.sh
+++ b/bin/scripts/gotta-patch-em-all-font-patcher!.sh
@@ -259,21 +259,21 @@ function patch_font {
   { OUT=$(fontforge -quiet -script ${PWD}/font-patcher "$f" -q ${font_config} $powerline $post_process -c --no-progressbars \
                     --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
   if [ $? -ne 0 ]; then printf "$OUT\nPatcher run aborted!\n\n"; fi
-  # Create "Nerd Font Mono"
-  if [ -n "${verbose}" ]
-  then
-    echo "fontforge -quiet -script ${PWD}/font-patcher "$f" -q -s ${font_config} $powerline $post_process -c --no-progressbars --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS}"
-  fi
-  { OUT=$(fontforge -quiet -script ${PWD}/font-patcher "$f" -q -s ${font_config} $powerline $post_process -c --no-progressbars \
-                    --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
-  if [ $? -ne 0 ]; then printf "$OUT\nPatcher run aborted!\n\n"; fi
-  # Create "Nerd Font Propo"
-  if [ -n "${verbose}" ]
-  then
-    echo "fontforge -quiet -script ${PWD}/font-patcher "$f" -q --variable ${font_config} $powerline $post_process -c --no-progressbars --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS}"
-  fi
-  { OUT=$(fontforge -quiet -script ${PWD}/font-patcher "$f" -q --variable ${font_config} $powerline $post_process -c --no-progressbars \
-                    --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
+  # # Create "Nerd Font Mono"
+  # if [ -n "${verbose}" ]
+  # then
+  #   echo "fontforge -quiet -script ${PWD}/font-patcher "$f" -q -s ${font_config} $powerline $post_process -c --no-progressbars --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS}"
+  # fi
+  # { OUT=$(fontforge -quiet -script ${PWD}/font-patcher "$f" -q -s ${font_config} $powerline $post_process -c --no-progressbars \
+  #                   --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
+  # if [ $? -ne 0 ]; then printf "$OUT\nPatcher run aborted!\n\n"; fi
+  # # Create "Nerd Font Propo"
+  # if [ -n "${verbose}" ]
+  # then
+  #   echo "fontforge -quiet -script ${PWD}/font-patcher "$f" -q --variable ${font_config} $powerline $post_process -c --no-progressbars --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS}"
+  # fi
+  # { OUT=$(fontforge -quiet -script ${PWD}/font-patcher "$f" -q --variable ${font_config} $powerline $post_process -c --no-progressbars \
+  #                   --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
   if [ $? -ne 0 ]; then printf "$OUT\nPatcher run aborted!\n\n"; fi
 
   # wait for this group of background processes to finish to avoid forking too many processes
diff --git a/bin/scripts/name_parser/FontnameParser.py b/bin/scripts/name_parser/FontnameParser.py
index 248f0d154..0a1098a38 100644
--- a/bin/scripts/name_parser/FontnameParser.py
+++ b/bin/scripts/name_parser/FontnameParser.py
@@ -269,6 +269,7 @@ class FontnameParser:
             self.logger.debug('=====> {:18} ok       ({:2} <={:2}): {}'.format(entry_id, len(name), max_len, name))
         else:
             self.logger.error('====-< {:18} too long ({:2} > {:2}): {}'.format(entry_id, len(name), max_len, name))
+        print("| {:50}".format(name), end='')
         return name
 
     def rename_font(self, font):
@@ -330,6 +331,7 @@ class FontnameParser:
         p_sty = self.preferred_styles()
         if len(p_sty):
             sfnt_list += [( 'English (US)', 'Preferred Styles', self.checklen(31, 'PrefStyles (ID 17)', p_sty) )] # 17
+        print("|")
 
         font.sfnt_names = tuple(sfnt_list)
 
diff --git a/font-patcher b/font-patcher
index 0434458ea..e7b55f941 100755
--- a/font-patcher
+++ b/font-patcher
@@ -721,6 +721,7 @@ class font_patcher:
             short_family = projectNameAbbreviation + variant_abbrev if self.args.makegroups >= 4 else projectNameSingular + variant_full
             # inject_suffix(family, ps_fontname, short_family)
             n.inject_suffix(verboseAdditionalFontNameSuffix, ps_suffix, short_family)
+            print("NAMES | {:40}".format(os.path.basename(self.args.font)), end='')
             n.rename_font(font)
 
         font.comment = projectInfo
@@ -1977,7 +1978,7 @@ def main():
 
     global logger
     logger = logging.getLogger(os.path.basename(args.font))
-    logger.setLevel(logging.DEBUG)
+    logger.setLevel(logging.CRITICAL)
     log_to_file = (args.debugmode & 1 == 1)
     if log_to_file:
         try:
-- 
2.39.2
$ NERDFONTS='--dry --debug 0' ./gotta-patch-em-all-font-patcher\!.sh -c  | tee -a XXX

(for both branches, master and this)

$ cat XXX | sort | uniq -u

NAMES | IBMPlexMono-TextItalic.ttf              | BlexMono Nerd Font                                | Italic                                            | BlexMono Nerd Font Italic                         | BlexMonoNF-Italic                                 |
NAMES | IBMPlexMono-TextItalic.ttf              | BlexMono Text Nerd Font                           | Italic                                            | BlexMono Text Nerd Font Italic                    | BlexMonoTextNF-Italic                             |
NAMES | IBMPlexMono-Text.ttf                    | BlexMono Nerd Font                                | Regular                                           | BlexMono Nerd Font                                | BlexMonoNF                                        |
NAMES | IBMPlexMono-Text.ttf                    | BlexMono Text Nerd Font                           | Regular                                           | BlexMono Text Nerd Font                           | BlexMonoTextNF                                    |

Hmm, 2 font files differently named

[why]
Some fonts might have a non-standard (i.e. broken) weight naming scheme:
They put a blank or a dash between the modifier and the weight, for
example "Extra Bold" or "Demi-Condensed", when they mean "ExtraBold"
resp "DemiCondensed".

The former happens with CartographCF, the later with IBM3270.

[how]
Automatically allow a dash between modifier and weight, which comes up
as CamelCase boundary. Insert an optional dash (r'-?') into such
boundaries.
For the further lookup we need to remove the dash in the found keyword,
if there is any, to get back to standard naming.

This might break if the font name ends in a modifier. So we can not
really distinguish

       Font Name Extra Bold Italic
    => Font Name - ExtraBold Italic
    => Font Name Extra - Bold Italic

The known modifiers are 'Demi', 'Ultra', 'Semi', 'Extra'.

It is possible but unlikely that a font name ends in one of these.
For example "Modern Ultra - Bold".

[note]
The question arises if we should not parse the PSname instead of the
Fullname; and stick to the dash there as boundary.
The problem might be prepatched fonts with broken naming, that would be
parsed completely wrong then. So maybe the current approach is still the
best, with the caveat given above (fontnames ending in a modifier).

[note 2]
Funny enough the variable allow_regex_token was not used at all :->
Some leftover? Anyhow we use it now.

[note 3]
We can still not remove the special handling for IBM3270, because the
font initially looks like a PSname and this is parsed as such, which
breaks the name in the incorrect place:

        PSname template  = "Name-StylesWeights"
        Fullname of 3270 = "IBM 3270 Semi-Condensed"

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii Finii force-pushed the bugfix/remove-filename-specials branch from bb21d28 to e4637d7 Compare May 26, 2023 10:13
Finii added 3 commits May 26, 2023 12:14
[why]
Function get_name_token has a Cognitive Complexity of 12 (exceeds 9 allowed).
Consider refactoring.

[how]
Remove not really needed special case.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The 'Text' weight of Plex is handled as 'other', means that this is
added to the font's name and is a distrinct own family.

But in the original font it is used as weight.

[how]
Remove special handling of 'text' in the font name.
Add 'Text' to known_weights list.

"Text" is not a standard naming, but I see no problems when we handle it
as one. This keeps the family relationships in Blex like Plex.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
IBM Plex uses some abbreviations also in the fullname and we do not try
abbreviations when resolving weights.

[how]
As this is the only font that has such specials we handle it beforehand
and do not try all combinations of abbreviated and long keywords.

And then their abbreviations are also not standard - at least not used
by us or Adobe, etc.

For such a small amount of affected font files it seems in order to
specifically just fix them instead of a general solution.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii Finii force-pushed the bugfix/remove-filename-specials branch from e4637d7 to 7a224c6 Compare May 26, 2023 10:20
@Finii
Copy link
Collaborator Author

Finii commented May 26, 2023

More specials of IBM Plex fixed 😬

@Finii
Copy link
Collaborator Author

Finii commented May 26, 2023

This PR introduces the following name changes (corrections):

GohuFont uni-11 Nerd Font       => GohuFont uni11 Nerd Font
GohuFont uni-14 Nerd Font       => GohuFont uni14 Nerd Font

BlexMonoExtLt Nerd Font         => BlexMono Nerd Font ExtraLight
BlexMonoMedm Nerd Font          => BlexMono Nerd Font Medium
BlexMonoSmBld Nerd Font         => BlexMono Nerd Font SemiBold
BlexMono Text Nerd Font         => BlexMono Nerd Font Text

@Finii
Copy link
Collaborator Author

Finii commented May 26, 2023

@sounak-kun Carto looks also good:

CartographCF-ExtraLight.ttf             | CartographCF Nerd Font ExtraLight                 | Regular                                           | CartographCF Nerd Font ExtraLight                 | CartographCFNF-ExtraLight                         | CartographCF Nerd Font                            | ExtraLight                                        |
CartographCF-Regular.ttf                | CartographCF Nerd Font                            | Regular                                           | CartographCF Nerd Font                            | CartographCFNF                                    |
CartographCF-DemiBoldItalic.ttf         | CartographCF Nerd Font DemiBold                   | Italic                                            | CartographCF Nerd Font DemiBold Italic            | CartographCFNF-DemiBoldItalic                     | CartographCF Nerd Font                            | DemiBold Italic                                   |
CartographCF-ExtraBoldItalic.ttf        | CartographCF Nerd Font ExtraBold                  | Italic                                            | CartographCF Nerd Font ExtraBold Italic           | CartographCFNF-ExtraBoldItalic                    | CartographCF Nerd Font                            | ExtraBold Italic                                  |
CartographCF-ThinItalic.ttf             | CartographCF Nerd Font Thin                       | Italic                                            | CartographCF Nerd Font Thin Italic                | CartographCFNF-ThinItalic                         | CartographCF Nerd Font                            | Thin Italic                                       |
CartographCF-Light.ttf                  | CartographCF Nerd Font Light                      | Regular                                           | CartographCF Nerd Font Light                      | CartographCFNF-Light                              | CartographCF Nerd Font                            | Light                                             |
CartographCF-LightItalic.ttf            | CartographCF Nerd Font Light                      | Italic                                            | CartographCF Nerd Font Light Italic               | CartographCFNF-LightItalic                        | CartographCF Nerd Font                            | Light Italic                                      |
CartographCF-Thin.ttf                   | CartographCF Nerd Font Thin                       | Regular                                           | CartographCF Nerd Font Thin                       | CartographCFNF-Thin                               | CartographCF Nerd Font                            | Thin                                              |
CartographCF-Heavy.ttf                  | CartographCF Nerd Font Heavy                      | Regular                                           | CartographCF Nerd Font Heavy                      | CartographCFNF-Heavy                              | CartographCF Nerd Font                            | Heavy                                             |
CartographCF-BoldItalic.ttf             | CartographCF Nerd Font                            | Bold Italic                                       | CartographCF Nerd Font Bold Italic                | CartographCFNF-BoldItalic                         |
CartographCF-DemiBold.ttf               | CartographCF Nerd Font DemiBold                   | Regular                                           | CartographCF Nerd Font DemiBold                   | CartographCFNF-DemiBold                           | CartographCF Nerd Font                            | DemiBold                                          |
CartographCF-ExtraLightItalic.ttf       | CartographCF Nerd Font ExtraLight                 | Italic                                            | CartographCF Nerd Font ExtraLight Italic          | CartographCFNF-ExtraLightItalic                   | CartographCF Nerd Font                            | ExtraLight Italic                                 |
CartographCF-ExtraBold.ttf              | CartographCF Nerd Font ExtraBold                  | Regular                                           | CartographCF Nerd Font ExtraBold                  | CartographCFNF-ExtraBold                          | CartographCF Nerd Font                            | ExtraBold                                         |
CartographCF-RegularItalic.ttf          | CartographCF Nerd Font                            | Italic                                            | CartographCF Nerd Font Italic                     | CartographCFNF-Italic                             |
CartographCF-HeavyItalic.ttf            | CartographCF Nerd Font Heavy                      | Italic                                            | CartographCF Nerd Font Heavy Italic               | CartographCFNF-HeavyItalic                        | CartographCF Nerd Font                            | Heavy Italic                                      |
CartographCF-Bold.ttf                   | CartographCF Nerd Font                            | Bold                                              | CartographCF Nerd Font Bold                       | CartographCFNF-Bold                               |

@Finii Finii merged commit 930eef2 into master May 26, 2023
@Finii Finii deleted the bugfix/remove-filename-specials branch May 26, 2023 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CartographCF becomes CartographF Nerd Font Condensed
1 participant