diff --git a/font-patcher b/font-patcher index f717e7901..479a64fb6 100755 --- a/font-patcher +++ b/font-patcher @@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals # Change the script version when you edit this script: -script_version = "4.13.1" +script_version = "4.14.0" version = "3.2.1" projectName = "Nerd Fonts" @@ -339,7 +339,9 @@ class font_patcher: self.sourceFont = font self.setup_version() self.assert_monospace() + self.load_config() self.remove_ligatures() + self.manipulate_hints() self.get_essential_references() self.get_sourcefont_dimensions() self.setup_patch_set() @@ -769,11 +771,18 @@ class font_patcher: # print("Version now is {}".format(sourceFont.version)) + def load_config(self): + """ Try to read the config file (if specified) """ + if self.args.configfile: + if not self.config.read(self.args.configfile): + logger.error("Unable to read configfile") + + def remove_ligatures(self): # 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.configfile and self.config.read(self.args.configfile): - if self.args.removeligatures: + 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: @@ -783,10 +792,29 @@ class font_patcher: logger.debug("Successfully removed subtable: %s", subtable) except Exception: logger.error("Failed to remove subtable: %s", subtable) - elif self.args.removeligatures: - logger.error("Unable to read configfile, unable to remove ligatures") + else: + logger.error("No configfile, unable to remove ligatures") + def manipulate_hints(self): + """ Redo the hinting on some problematic glyphs """ + if not self.args.configfile: + return + redo = json.loads(self.config.get("Hinting", "re_hint")) + if not len(redo): + return + logger.debug("Working on {} rehinting rules".format(len(redo))) + count = 0 + for gname in self.sourceFont: + for regex in redo: + if re.fullmatch(regex, gname): + glyph = self.sourceFont[gname] + glyph.autoHint() + glyph.autoInstr() + count += 1 + break + logger.info("Rehinted {} glyphs".format(count)) + def assert_monospace(self): # Check if the sourcefont is monospaced width_mono, offending_char = is_monospaced(self.sourceFont) diff --git a/src/unpatched-fonts/CascadiaCode/config.cfg b/src/unpatched-fonts/CascadiaCode/config.cfg index e9dff85dc..03900dfd3 100644 --- a/src/unpatched-fonts/CascadiaCode/config.cfg +++ b/src/unpatched-fonts/CascadiaCode/config.cfg @@ -1,2 +1,7 @@ [Config] commandline: --makegroups 4 +[Hinting] +re_hint: [ + ".*hyphen.*\\.(liga|seq)", + ".*equal.*\\.(liga|seq)", + ".*numbersign.*\\.(liga|seq)" ] diff --git a/src/unpatched-fonts/CascadiaMono/config.cfg b/src/unpatched-fonts/CascadiaMono/config.cfg index e9dff85dc..03900dfd3 100644 --- a/src/unpatched-fonts/CascadiaMono/config.cfg +++ b/src/unpatched-fonts/CascadiaMono/config.cfg @@ -1,2 +1,7 @@ [Config] commandline: --makegroups 4 +[Hinting] +re_hint: [ + ".*hyphen.*\\.(liga|seq)", + ".*equal.*\\.(liga|seq)", + ".*numbersign.*\\.(liga|seq)" ]