cec9b4102c6f77a4e86957717201bfc8f7874099 — Fini Jastrow 7 months ago 4cb816c
font-patcher: Handle TTCs gracefully

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

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.

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

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

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
1 files changed, 5 insertions(+), 0 deletions(-)

M font-patcher
M font-patcher => font-patcher +5 -0
@@ 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,
            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]
            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):