From 6c6177d6a516906b839ff2fa652ff64cdd365c3f Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sat, 20 Apr 2024 09:49:26 +0200 Subject: [PATCH] font-patcher: Do not rely on args.configfile [why] We now have two places where we can detect if a config file is given. This should be unified. Also handling of missing (?) sections in the config file is not always handled gracefully. Signed-off-by: Fini Jastrow --- font-patcher | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/font-patcher b/font-patcher index 6f45fb34e..75c30a4ab 100755 --- a/font-patcher +++ b/font-patcher @@ -773,28 +773,28 @@ class font_patcher: # let's deal with ligatures (mostly for monospaced fonts) # Usually removes 'fi' ligs that end up being only one cell wide, and 'ldot' if self.args.removeligatures: - if self.args.configfile: - logger.info("Removing ligatures from configfile `Subtables` section") - ligature_subtables = json.loads(self.config.get("Subtables", "ligatures")) - for subtable in ligature_subtables: - logger.debug("Removing subtable: %s", subtable) - try: - self.sourceFont.removeLookupSubtable(subtable) - logger.debug("Successfully removed subtable: %s", subtable) - except Exception: - logger.error("Failed to remove subtable: %s", subtable) - else: - logger.error("No configfile, unable to remove ligatures") + logger.info("Removing ligatures from configfile `Subtables` section") + if 'Subtables' not in self.config: + logger.warning("No ligature data (config file missing?)") + return + ligature_subtables = json.loads(self.config.get('Subtables', 'ligatures', fallback='[]')) + for subtable in ligature_subtables: + logger.debug("Removing subtable: %s", subtable) + try: + self.sourceFont.removeLookupSubtable(subtable) + logger.debug("Successfully removed subtable: %s", subtable) + except Exception: + logger.error("Failed to remove subtable: %s", subtable) def manipulate_hints(self): """ Redo the hinting on some problematic glyphs """ - if not self.args.configfile: + if 'Hinting' not in self.config: return - redo = json.loads(self.config.get("Hinting", "re_hint")) + redo = json.loads(self.config.get('Hinting', 're_hint', fallback='[]')) if not len(redo): return - logger.debug("Working on {} rehinting rules".format(len(redo))) + logger.debug("Working on {} rehinting rules (this may create a lot of fontforge warnings)".format(len(redo))) count = 0 for gname in self.sourceFont: for regex in redo: