Last active
November 26, 2021 05:45
-
-
Save Finii/a496cff7eb38933b169110be3e4e8af2 to your computer and use it in GitHub Desktop.
Change font-patcher to show in more detail how it renames fonts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 8c1b31f5a8378130713ed13a125bf78005401d41 Mon Sep 17 00:00:00 2001 | |
From: Fini Jastrow <ulf.fini.jastrow@desy.de> | |
Date: Wed, 24 Nov 2021 19:04:01 +0100 | |
Subject: [PATCH] Debug: Do not patch, just show naming process | |
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de> | |
--- | |
font-patcher | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- | |
1 file changed, 50 insertions(+), 2 deletions(-) | |
diff --git a/font-patcher b/font-patcher | |
index 1c6d90ef..0b6daf18 100755 | |
--- a/font-patcher | |
+++ b/font-patcher | |
@@ -52,6 +52,30 @@ class font_patcher: | |
self.setup_arguments() | |
self.config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True) | |
self.sourceFont = fontforge.open(self.args.font) | |
+ sys.stdout.write("### Opening {}\n".format(os.path.abspath(self.args.font))) | |
+ # if self.sourceFont.cidfamilyname: | |
+ # sys.stdout.write("Source CID Family {}\n".format(self.sourceFont.cidfamilyname)) | |
+ # if self.sourceFont.cidfontname: | |
+ # sys.stdout.write("Source CID Font {}\n".format(self.sourceFont.cidfontname)) | |
+ # if self.sourceFont.cidfullname: | |
+ # sys.stdout.write("Source CID Full {}\n".format(self.sourceFont.cidfullname)) | |
+ # if self.sourceFont.cidsubfont: | |
+ # sys.stdout.write("Source CID Sub {}\n".format(self.sourceFont.cidsubfont)) | |
+ sys.stdout.write("Source PS Full {}\n".format(self.sourceFont.fullname)) | |
+ sys.stdout.write("Source PS Family {}\n".format(self.sourceFont.familyname)) | |
+ sys.stdout.write("Source PS Font {}\n".format(self.sourceFont.fontname)) | |
+ # if self.sourceFont.fondname: | |
+ # sys.stdout.write("Source Mac Fond {}\n".format(self.sourceFont.fondname)) | |
+ sys.stdout.write("Source Weight {}\n".format(self.sourceFont.weight)) | |
+ l = [] | |
+ for i, el in enumerate(self.sourceFont.sfnt_names): | |
+ l += [(el[1], el[2])] | |
+ sfnt = dict(l) | |
+ sys.stdout.write("Source SFNT PSName {}\n".format(sfnt["PostScriptName"])) | |
+ sys.stdout.write("Source SFNT Fullname {}\n".format(sfnt["Fullname"])) | |
+ sys.stdout.write("Source SFNT Family {}\n".format(sfnt["Family"])) | |
+ sys.stdout.write("Source SFNT SubFamily {}\n".format(sfnt["SubFamily"])) | |
+ | |
self.setup_font_names() | |
self.remove_ligatures() | |
make_sure_path_exists(self.args.outputdir) | |
@@ -82,7 +106,7 @@ class font_patcher: | |
symfont = None | |
for patch in self.patch_set: | |
- if patch['Enabled']: | |
+ if False: #patch['Enabled']: | |
if PreviousSymbolFilename != patch['Filename']: | |
# We have a new symbol font, so close the previous one if it exists | |
if symfont: | |
@@ -219,6 +243,7 @@ class font_patcher: | |
def setup_font_names(self): | |
+ sys.stdout.write("### Output naming progress:\n") | |
verboseAdditionalFontNameSuffix = " " + projectNameSingular | |
if self.args.windows: # attempt to shorten here on the additional name BEFORE trimming later | |
additionalFontNameSuffix = " " + projectNameAbbreviation | |
@@ -261,6 +286,9 @@ class font_patcher: | |
additionalFontNameSuffix += " M" | |
verboseAdditionalFontNameSuffix += " Mono" | |
+ sys.stdout.write("FontNameSuffix {}\n".format(additionalFontNameSuffix)) | |
+ sys.stdout.write("FontNameSuffix verbose {}\n".format(verboseAdditionalFontNameSuffix)) | |
+ | |
# basically split the font name around the dash "-" to get the fontname and the style (e.g. Bold) | |
# this does not seem very reliable so only use the style here as a fallback if the font does not | |
# have an internal style defined (in sfnt_names) | |
@@ -270,14 +298,17 @@ class font_patcher: | |
# dont trust 'sourceFont.familyname' | |
familyname = fontname | |
+ sys.stdout.write("Familyname {}\n".format(familyname)) | |
# fullname (filename) can always use long/verbose font name, even in windows | |
if self.sourceFont.fullname != None: | |
fullname = self.sourceFont.fullname + verboseAdditionalFontNameSuffix | |
else: | |
fullname = self.sourceFont.cidfontname + verboseAdditionalFontNameSuffix | |
+ sys.stdout.write("Fullname {}\n".format(fullname)) | |
fontname = fontname + additionalFontNameSuffix.replace(" ", "") | |
+ sys.stdout.write("Fontname {}\n".format(fontname)) | |
# let us try to get the 'style' from the font info in sfnt_names and fallback to the | |
# parse fontname if it fails: | |
@@ -294,6 +325,7 @@ class font_patcher: | |
sys.stderr.write("{}: Could not find 'SubFamily' for given font, falling back to parsed fontname\n".format(projectName)) | |
subFamily = fallbackStyle | |
+ sys.stdout.write("SubFamily {}\n".format(subFamily)) | |
# some fonts have inaccurate 'SubFamily', if it is Regular let us trust the filename more: | |
if subFamily == "Regular": | |
subFamily = fallbackStyle | |
@@ -302,6 +334,7 @@ class font_patcher: | |
if len(subFamily) < len(fallbackStyle): | |
subFamily = fallbackStyle | |
+ sys.stdout.write("SubFamily 2 {}\n".format(subFamily)) | |
if self.args.windows: | |
maxFamilyLength = 31 | |
maxFontLength = maxFamilyLength - len('-' + subFamily) | |
@@ -317,10 +350,13 @@ class font_patcher: | |
familyname += " " + projectNameSingular | |
if self.args.single: | |
familyname += " Mono" | |
+ sys.stdout.write("Familyname 2 {}\n".format(familyname)) | |
# Don't truncate the subfamily to keep fontname unique. MacOS treats fonts with | |
# the same name as the same font, even if subFamily is different. | |
fontname += '-' + subFamily | |
+ sys.stdout.write("Fontname 2 {}\n".format(fontname)) | |
+ | |
# rename font | |
# | |
@@ -397,6 +433,21 @@ class font_patcher: | |
self.sourceFont.appendSFNTName(str('English (US)'), str('SubFamily'), subFamily) | |
self.sourceFont.comment = projectInfo | |
self.sourceFont.fontlog = projectInfo | |
+ sys.stdout.write("### Final Output naming:\n") | |
+ l = [] | |
+ for i, el in enumerate(self.sourceFont.sfnt_names): | |
+ l += [(el[1], el[2])] | |
+ sfnt = dict(l) | |
+ sys.stdout.write("Output PS Full {}\n".format(self.sourceFont.fullname)) | |
+ sys.stdout.write("Output PS Family {}\n".format(self.sourceFont.familyname)) | |
+ sys.stdout.write("Output PS Font {}\n".format(self.sourceFont.fontname)) | |
+ sys.stdout.write("Output Weight {}\n".format(self.sourceFont.weight)) | |
+ sys.stdout.write("Output SFNT PSName {}\n".format(sfnt["PostScriptName"])) | |
+ sys.stdout.write("Output SFNT Fullname {}\n".format(sfnt["Fullname"])) | |
+ sys.stdout.write("Output SFNT Family {}\n".format(sfnt["Family"])) | |
+ sys.stdout.write("Output SFNT SubFamily {}\n".format(sfnt["SubFamily"])) | |
+ sys.stdout.write("SFNT {}\n".format(self.sourceFont.sfnt_names)) | |
+ sys.exit() | |
# TODO version not being set for all font types (e.g. ttf) | |
# print("Version was {}".format(sourceFont.version)) | |
-- | |
2.32.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment