Skip to content

Commit

Permalink
font-patcher: Allow to run without Fontname* modules
Browse files Browse the repository at this point in the history
[why]
People might want to use the font-patcher with just the one script file.
The error message does not help them to understand the problem.

[how]
Require the modules only if the user wants to use it (i.e. --makegroups).
Give the expected path in the error message.

We could also download the missing files instead, similar to #741
But that PR did not get any feedback yet, so I do not know if this is
something we want.

Anyhow, the fetching of missing parts should then be unified for both
usecases (i.e. Fontname* and src/glyphs).

And then, there is font-patcher.zip (which needs to be adapted), maybe
that is the way to go.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
  • Loading branch information
Finii committed Aug 20, 2022
1 parent 6720e97 commit 97591ad
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ except ImportError:
)
)

# This is (for experimenting) far far away...
# This is for experimenting
sys.path.insert(0, os.path.abspath(os.path.dirname(sys.argv[0])) + '/bin/scripts/name_parser/')
from FontnameParser import FontnameParser
from FontnameTools import FontnameTools
try:
from FontnameParser import FontnameParser
from FontnameTools import FontnameTools
FontnameParserOK = True
except ImportError:
FontnameParserOK = False

class TableHEADWriter:
""" Access to the HEAD table without external dependencies """
Expand Down Expand Up @@ -334,6 +338,9 @@ class font_patcher:

self.args = parser.parse_args()

if self.args.makegroups and not FontnameParserOK:
sys.exit(projectName + ": FontnameParser module missing (bin/scripts/name_parser/Fontname*), can not --makegroups".format(projectName))

# if you add a new font, set it to True here inside the if condition
if self.args.complete:
self.args.fontawesome = True
Expand Down Expand Up @@ -430,7 +437,7 @@ class font_patcher:
additionalFontNameSuffix += " M"
verboseAdditionalFontNameSuffix += " Mono"

if self.args.makegroups:
if FontnameParserOK and self.args.makegroups:
use_fullname = type(self.sourceFont.fullname) == str # Usually the fullname is better to parse
# Use fullname if it is 'equal' to the fontname
if self.sourceFont.fullname:
Expand Down Expand Up @@ -584,7 +591,7 @@ class font_patcher:
fullname = replace_font_name(fullname, additionalFontNameReplacements2)
fontname = replace_font_name(fontname, additionalFontNameReplacements2)

if not self.args.makegroups:
if not (FontnameParserOK and self.args.makegroups):
# replace any extra whitespace characters:
self.sourceFont.familyname = " ".join(familyname.split())
self.sourceFont.fullname = " ".join(fullname.split())
Expand Down

0 comments on commit 97591ad

Please sign in to comment.