From 702e4be81336b37d3a8e2a079b15f42c67aaa922 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Wed, 5 Jan 2022 16:55:52 +0100 Subject: [PATCH] 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 --- font-patcher | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/font-patcher b/font-patcher index 9440b2a52..480bf3ba1 100755 --- a/font-patcher +++ b/font-patcher @@ -55,6 +55,9 @@ class font_patcher: sys.exit("{}: Font file does not exist: {}".format(projectName, self.args.font)) if not os.access(self.args.font, os.R_OK): sys.exit("{}: Can not open font file for reading: {}".format(projectName, self.args.font)) + if len(fontforge.fontsInFile(self.args.font)) > 1: + sys.exit("{}: Font file contains {} fonts, can only handle single font files".format(projectName, + len(fontforge.fontsInFile(self.args.font)))) try: self.sourceFont = fontforge.open(self.args.font, 1) # 1 = ("fstypepermitted",)) except Exception: @@ -72,6 +75,8 @@ class font_patcher: self.extension = os.path.splitext(self.args.font)[1] else: self.extension = '.' + self.args.extension + if re.match("\.ttc$", self.extension, re.IGNORECASE): + sys.exit(projectName + ": Can not create True Type Collections") def patch(self):