Skip to content

Commit 702e4be

Browse files
committed
font-patcher: Handle TTCs gracefully
[why] When a True Type Collection file (.ttc) is used as font source this is not handled and just the first file in the collection is processed and saved. But the user is not informed. When the target file format is True Type Collection, no file at all is written. These are two distinct cases, because you can in fact open a .ttc and save the first font (patched) when specifying a different extension via `-ext`. Or open a normal font and specify `ttc` as extension i.e. target file format. [how] Check if a collection is to be opened. As we currently have no code to loop through all fonts (and just the first font is processed) a message is issued and we exit. Typically a user would want all the fonts and would have to 'explode' the collection into multiple single font files beforehand. Prevent the target to be ttc, as that is not handled in fontforge at all. To save TTCs a different API function is to be used. Unfortunately fontforge does not care and just does nothing. font.generateTtc() would have to be used with ttc extensions... Anyhow. As the looping through all fonts is missing anyhow, and I feel the usefulness is very slim, we just prevent silent failures with this commit. Signed-off-by: Fini Jastrow <[email protected]>
1 parent 7043367 commit 702e4be

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

font-patcher

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class font_patcher:
5555
sys.exit("{}: Font file does not exist: {}".format(projectName, self.args.font))
5656
if not os.access(self.args.font, os.R_OK):
5757
sys.exit("{}: Can not open font file for reading: {}".format(projectName, self.args.font))
58+
if len(fontforge.fontsInFile(self.args.font)) > 1:
59+
sys.exit("{}: Font file contains {} fonts, can only handle single font files".format(projectName,
60+
len(fontforge.fontsInFile(self.args.font))))
5861
try:
5962
self.sourceFont = fontforge.open(self.args.font, 1) # 1 = ("fstypepermitted",))
6063
except Exception:
@@ -72,6 +75,8 @@ class font_patcher:
7275
self.extension = os.path.splitext(self.args.font)[1]
7376
else:
7477
self.extension = '.' + self.args.extension
78+
if re.match("\.ttc$", self.extension, re.IGNORECASE):
79+
sys.exit(projectName + ": Can not create True Type Collections")
7580

7681

7782
def patch(self):

0 commit comments

Comments
 (0)