From b984447921c465613b75d2f7073c412a2d36a846 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 19 Apr 2024 14:29:01 +0200 Subject: [PATCH 1/7] font-patcher: Allow to specify more options in config file [why] At the moment we have two different config files: config.cfg: Is read by gotta-patch-em and allows to specify some needed commandline options for a font-patcher run config.json: Is read by font-patcher and can contain ligature table removal instructions It would be nice to combine/unify them. [how] Add the possibility to add commandline options in the config.cfg file. Of course we need commandline options to specify the config file first, so the options are parsed in two steps. The config.file takes precedence (if possible) over directly specified options. This is how the new section in the config file can look like: [Config] commandline: --powerlineextra --mono Signed-off-by: Fini Jastrow --- font-patcher | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/font-patcher b/font-patcher index c2535a1dce..7cca47b2e2 100755 --- a/font-patcher +++ b/font-patcher @@ -1961,6 +1961,23 @@ def setup_arguments(): args = parser.parse_args() + # if we have a config file: fetch commandline arguments from there and process again with all arguments + if args.configfile: + if not os.path.isfile(args.configfile): + logger.critical("Configfile does not exist: %s", args.configfile) + sys.exit(1) + if not os.access(args.configfile, os.R_OK): + logger.critical("Can not open configfile for reading: %s", args.configfile) + sys.exit(1) + config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True) + config.read(args.configfile) + extraflags = config.get("Config", "commandline", fallback='') + if len(extraflags): + # We have no level less severe than warning here, logger will be set up later + logger.warning("Adding config commandline options: %s", extraflags) + extraflags += ' ' + args.font + args = parser.parse_args(extraflags.split(), args) + if args.makegroups > 0 and not FontnameParserOK: logger.critical("FontnameParser module missing (bin/scripts/name_parser/Fontname*), specify --makegroups 0") sys.exit(1) From 88d63ff8277ef4fed3d8d3410c8f0f0c2ec07a5f Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 19 Apr 2024 10:23:46 +0200 Subject: [PATCH 2/7] gotta-patch-em: Correct file type of config files [why] The config files are called `config.json` while the contents is INI-like. The usual extension would be `.cfg`. [how] We use `.cfg` already for the shell variable configuration. Combine both config file variants into one (real) cfg file, that is directly read by the font-patcher and no shell variables files are used anymore. This needs some rewrite in gotta-patch-em to get the quoting right. To make this simpler we remove the `--debug 1` option from the variable and insert it directly (as it is applied always anyhow). Signed-off-by: Fini Jastrow --- .../gotta-patch-em-all-font-patcher!.sh | 46 +++++++------------ font-patcher | 4 +- src/config.sample.cfg | 9 ++++ src/config.sample.json | 18 -------- src/unpatched-fonts/3270/config.cfg | 3 +- .../BitstreamVeraSansMono/config.cfg | 3 +- src/unpatched-fonts/CascadiaCode/config.cfg | 3 +- src/unpatched-fonts/CascadiaMono/config.cfg | 3 +- src/unpatched-fonts/D2Coding/config.cfg | 3 +- src/unpatched-fonts/DaddyTimeMono/config.cfg | 3 +- src/unpatched-fonts/DejaVuSansMono/config.cfg | 3 +- src/unpatched-fonts/DroidSansMono/config.cfg | 1 - .../FantasqueSansMono/config.cfg | 1 - src/unpatched-fonts/FiraCode/config.cfg | 4 +- src/unpatched-fonts/GeistMono/config.cfg | 3 +- src/unpatched-fonts/Hack/config.cfg | 1 - src/unpatched-fonts/Hasklig/config.cfg | 4 +- src/unpatched-fonts/Hermit/config.cfg | 1 - src/unpatched-fonts/IBMPlexMono/config.cfg | 1 - src/unpatched-fonts/IntelOneMono/config.cfg | 3 +- src/unpatched-fonts/Iosevka/config.cfg | 4 +- src/unpatched-fonts/IosevkaTerm/config.cfg | 4 +- .../IosevkaTermSlab/config.cfg | 4 +- src/unpatched-fonts/JetBrainsMono/config.cfg | 3 +- src/unpatched-fonts/Lekton/config.cfg | 6 +++ src/unpatched-fonts/Lekton/config.json | 4 -- src/unpatched-fonts/MPlus/config.cfg | 3 +- src/unpatched-fonts/MartianMono/config.cfg | 3 +- src/unpatched-fonts/Meslo/config.cfg | 1 - src/unpatched-fonts/Monaspace/config.cfg | 3 +- src/unpatched-fonts/Monofur/config.cfg | 1 - .../NerdFontsSymbolsOnly/config.cfg | 3 +- src/unpatched-fonts/Noto/Sans-Mono/config.cfg | 7 +++ .../Noto/Sans-Mono/config.json | 5 -- src/unpatched-fonts/Noto/Sans/config.cfg | 8 ++++ src/unpatched-fonts/Noto/Sans/config.json | 6 --- src/unpatched-fonts/Noto/config.cfg | 3 +- src/unpatched-fonts/OpenDyslexic/config.cfg | 8 ++++ src/unpatched-fonts/OpenDyslexic/config.json | 6 --- src/unpatched-fonts/Overpass/Mono/config.cfg | 5 ++ src/unpatched-fonts/Overpass/Mono/config.json | 3 -- .../Overpass/Non-Mono/config.cfg | 6 +++ .../Overpass/Non-Mono/config.json | 4 -- src/unpatched-fonts/Overpass/config.cfg | 1 - src/unpatched-fonts/RobotoMono/config.cfg | 3 +- src/unpatched-fonts/SourceCodePro/config.cfg | 4 +- src/unpatched-fonts/SpaceMono/config.cfg | 6 +++ src/unpatched-fonts/SpaceMono/config.json | 4 -- src/unpatched-fonts/Ubuntu/config.cfg | 8 +++- src/unpatched-fonts/Ubuntu/config.json | 5 -- src/unpatched-fonts/UbuntuMono/config.cfg | 3 +- src/unpatched-fonts/UbuntuSans/config.cfg | 3 +- src/unpatched-fonts/VictorMono/config.cfg | 3 +- .../ZedMono/Extended/config.cfg | 3 +- src/unpatched-fonts/ZedMono/Normal/config.cfg | 3 +- 55 files changed, 134 insertions(+), 129 deletions(-) create mode 100644 src/config.sample.cfg delete mode 100644 src/config.sample.json delete mode 100644 src/unpatched-fonts/DroidSansMono/config.cfg delete mode 100644 src/unpatched-fonts/FantasqueSansMono/config.cfg delete mode 100644 src/unpatched-fonts/Hack/config.cfg delete mode 100644 src/unpatched-fonts/Hermit/config.cfg delete mode 100644 src/unpatched-fonts/IBMPlexMono/config.cfg create mode 100644 src/unpatched-fonts/Lekton/config.cfg delete mode 100644 src/unpatched-fonts/Lekton/config.json delete mode 100644 src/unpatched-fonts/Meslo/config.cfg delete mode 100644 src/unpatched-fonts/Monofur/config.cfg create mode 100644 src/unpatched-fonts/Noto/Sans-Mono/config.cfg delete mode 100644 src/unpatched-fonts/Noto/Sans-Mono/config.json create mode 100644 src/unpatched-fonts/Noto/Sans/config.cfg delete mode 100644 src/unpatched-fonts/Noto/Sans/config.json create mode 100644 src/unpatched-fonts/OpenDyslexic/config.cfg delete mode 100644 src/unpatched-fonts/OpenDyslexic/config.json create mode 100644 src/unpatched-fonts/Overpass/Mono/config.cfg delete mode 100644 src/unpatched-fonts/Overpass/Mono/config.json create mode 100644 src/unpatched-fonts/Overpass/Non-Mono/config.cfg delete mode 100644 src/unpatched-fonts/Overpass/Non-Mono/config.json delete mode 100644 src/unpatched-fonts/Overpass/config.cfg create mode 100644 src/unpatched-fonts/SpaceMono/config.cfg delete mode 100644 src/unpatched-fonts/SpaceMono/config.json delete mode 100644 src/unpatched-fonts/Ubuntu/config.json diff --git a/bin/scripts/gotta-patch-em-all-font-patcher!.sh b/bin/scripts/gotta-patch-em-all-font-patcher!.sh index 73dd8a12b0..36053b748e 100755 --- a/bin/scripts/gotta-patch-em-all-font-patcher!.sh +++ b/bin/scripts/gotta-patch-em-all-font-patcher!.sh @@ -214,32 +214,19 @@ function patch_font { config_parent_dir=$( cd "$( dirname "$f" )" && cd ".." && pwd) config_dir=$( cd "$( dirname "$f" )" && pwd) - # source the font config file if exists: - # fetches for example config_patch_flags - unset config_patch_flags + # find the font config file: if [ -f "$config_dir/config.cfg" ] then - # shellcheck source=/dev/null - source "$config_dir/config.cfg" + font_config="--configfile=$config_dir/config.cfg" elif [ -f "$config_parent_dir/config.cfg" ] then - # shellcheck source=/dev/null - source "$config_parent_dir/config.cfg" + font_config="--configfile=$config_parent_dir/config.cfg" elif [ -f "$(find_font_root "$config_parent_dir")/config.cfg" ] then - # shellcheck source=/dev/null - source "$(find_font_root "$config_parent_dir")/config.cfg" - fi - - if [ -f "$config_dir/config.json" ] - then - # load font configuration file and remove selected ligatures: - font_config="--removeligatures --configfile $config_dir/config.json" - elif [ -f "$config_parent_dir/config.json" ] - then - font_config="--removeligatures --configfile $config_parent_dir/config.json" + font_config="--configfile=$(find_font_root "$config_parent_dir")/config.cfg" else - font_config="" + # We need to give some argument because empty arguments will break the patcher call + font_config="-q" fi if [ "$post_process" ] @@ -255,38 +242,37 @@ function patch_font { echo >&2 "# Could not find project parent directory" exit 3 } - # Add logfile always (but can be overridden by config_patch_flags in config.cfg and env var NERDFONTS) - config_patch_flags="--debug 1 ${config_patch_flags}" + # Add logfile always (but can be overridden by config.cfg and env var NERDFONTS) # Use absolute path to allow fontforge being an AppImage (used in CI) PWD=$(pwd) # Create "Nerd Font" if [ -n "${verbose}" ] then - echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}" + echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" fi # shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them - { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q ${font_config} $post_process -c --no-progressbars \ - --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 + { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q "${font_config}" $post_process -c --no-progressbars \ + --outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 # shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi # Create "Nerd Font Mono" if [ -n "${verbose}" ] then - echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q -s ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}" + echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q -s \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" fi # shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them - { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q -s ${font_config} $post_process -c --no-progressbars \ - --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 + { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q -s "${font_config}" $post_process -c --no-progressbars \ + --outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 # shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi # Create "Nerd Font Propo" if [ -n "${verbose}" ] then - echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q --variable ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}" + echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q --variable \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" fi # shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them - { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q --variable ${font_config} $post_process -c --no-progressbars \ - --outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 + { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q --variable "${font_config}" $post_process -c --no-progressbars \ + --outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 # shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi diff --git a/font-patcher b/font-patcher index 7cca47b2e2..f717e7901e 100755 --- a/font-patcher +++ b/font-patcher @@ -1935,7 +1935,7 @@ def setup_arguments(): expert_group = parser.add_argument_group('Expert Options') expert_group.add_argument('--boxdrawing', dest='forcebox', default=False, action='store_true', help='Force patching in (over existing) box drawing glyphs') - expert_group.add_argument('--configfile', dest='configfile', default=False, type=str, help='Specify a file path for JSON configuration file (see sample: src/config.sample.json)') + expert_group.add_argument('--configfile', dest='configfile', default=False, type=str, help='Specify a file path for configuration file (see sample: src/config.sample.cfg)') expert_group.add_argument('--custom', dest='custom', default=False, type=str, help='Specify a custom symbol font, all glyphs will be copied; absolute path suggested') expert_group.add_argument('--dry', dest='dry_run', default=False, action='store_true', help='Do neither patch nor store the font, to check naming') @@ -1946,7 +1946,7 @@ def setup_arguments(): expert_group.add_argument('--name', dest='force_name', default=None, type=str, help='Specify naming source (\'full\', \'postscript\', \'filename\', or concrete free name-string)') expert_group.add_argument('--postprocess', dest='postprocess', default=False, type=str, help='Specify a Script for Post Processing') progressbars_group_parser = expert_group.add_mutually_exclusive_group(required=False) - expert_group.add_argument('--removeligs', '--removeligatures', dest='removeligatures', default=False, action='store_true', help='Removes ligatures specificed in JSON configuration file (needs --configfile)') + expert_group.add_argument('--removeligs', '--removeligatures', dest='removeligatures', default=False, action='store_true', help='Removes ligatures specificed in configuration file (needs --configfile)') expert_group.add_argument('--xavgcharwidth', dest='xavgwidth', default=None, type=int, nargs='?', help='Adjust xAvgCharWidth (optional: concrete value)', const=True) # --xavgcharwidth for compatibility with old applications like notepad and non-latin fonts # Possible values with examples: diff --git a/src/config.sample.cfg b/src/config.sample.cfg new file mode 100644 index 0000000000..71b81621e6 --- /dev/null +++ b/src/config.sample.cfg @@ -0,0 +1,9 @@ +# These config files are read by the font-patcher +# They are INI style files, but some keys have JSON values +[Config] +commandline: --removeligatures --makegroups 2 +[Subtables] +ligatures: [ + "'dlig' Discretionary Ligatures lookup 9 subtable", + "'dlig' Discretionary Ligatures lookup 11 subtable", + "'dlig' Discretionary Ligatures lookup 12 contextual 0" ] diff --git a/src/config.sample.json b/src/config.sample.json deleted file mode 100644 index 886fdbcd06..0000000000 --- a/src/config.sample.json +++ /dev/null @@ -1,18 +0,0 @@ -[Subtables] - ligatures: [ - "'dlig' Discretionary Ligatures lookup 9 subtable", - "'dlig' Discretionary Ligatures lookup 11 subtable", - "'dlig' Discretionary Ligatures lookup 12 contextual 0", - "'dlig' Discretionary Ligatures lookup 12 contextual 1", - "'dlig' Discretionary Ligatures lookup 12 contextual 2", - "'dlig' Discretionary Ligatures lookup 18 subtable", - "'dlig' Discretionary Ligatures lookup 19 contextual 0", - "'dlig' Discretionary Ligatures lookup 24 contextual 0", - "'dlig' Discretionary Ligatures lookup 24 contextual 1", - "'dlig' Discretionary Ligatures lookup 24 contextual 2", - "'dlig' Discretionary Ligatures lookup 24 contextual 3", - "'dlig' Discretionary Ligatures lookup 24 contextual 4", - "'dlig' Discretionary Ligatures lookup 24 contextual 5", - "'dlig' Discretionary Ligatures lookup 26 subtable", - "'dlig' Discretionary Ligatures lookup 33 contextual 0", - "'dlig' Discretionary Ligatures lookup 33 contextual 1" ] diff --git a/src/unpatched-fonts/3270/config.cfg b/src/unpatched-fonts/3270/config.cfg index f397cae70e..31aab6217a 100644 --- a/src/unpatched-fonts/3270/config.cfg +++ b/src/unpatched-fonts/3270/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 2" +[Config] +commandline: --makegroups 2 diff --git a/src/unpatched-fonts/BitstreamVeraSansMono/config.cfg b/src/unpatched-fonts/BitstreamVeraSansMono/config.cfg index 132baa477a..8c0dc26934 100644 --- a/src/unpatched-fonts/BitstreamVeraSansMono/config.cfg +++ b/src/unpatched-fonts/BitstreamVeraSansMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--has-no-italic" +[Config] +commandline: --has-no-italic diff --git a/src/unpatched-fonts/CascadiaCode/config.cfg b/src/unpatched-fonts/CascadiaCode/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/CascadiaCode/config.cfg +++ b/src/unpatched-fonts/CascadiaCode/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/CascadiaMono/config.cfg b/src/unpatched-fonts/CascadiaMono/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/CascadiaMono/config.cfg +++ b/src/unpatched-fonts/CascadiaMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/D2Coding/config.cfg b/src/unpatched-fonts/D2Coding/config.cfg index 538ce70100..776021eb30 100644 --- a/src/unpatched-fonts/D2Coding/config.cfg +++ b/src/unpatched-fonts/D2Coding/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--xavgcharwidth 500" +[Config] +commandline: --xavgcharwidth 500 diff --git a/src/unpatched-fonts/DaddyTimeMono/config.cfg b/src/unpatched-fonts/DaddyTimeMono/config.cfg index fe1bf31378..24da489a0b 100644 --- a/src/unpatched-fonts/DaddyTimeMono/config.cfg +++ b/src/unpatched-fonts/DaddyTimeMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--ext ttf" +[Config] +commandline: --ext ttf diff --git a/src/unpatched-fonts/DejaVuSansMono/config.cfg b/src/unpatched-fonts/DejaVuSansMono/config.cfg index 132baa477a..8c0dc26934 100644 --- a/src/unpatched-fonts/DejaVuSansMono/config.cfg +++ b/src/unpatched-fonts/DejaVuSansMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--has-no-italic" +[Config] +commandline: --has-no-italic diff --git a/src/unpatched-fonts/DroidSansMono/config.cfg b/src/unpatched-fonts/DroidSansMono/config.cfg deleted file mode 100644 index 53c38882b7..0000000000 --- a/src/unpatched-fonts/DroidSansMono/config.cfg +++ /dev/null @@ -1 +0,0 @@ -config_has_powerline=1 diff --git a/src/unpatched-fonts/FantasqueSansMono/config.cfg b/src/unpatched-fonts/FantasqueSansMono/config.cfg deleted file mode 100644 index 53c38882b7..0000000000 --- a/src/unpatched-fonts/FantasqueSansMono/config.cfg +++ /dev/null @@ -1 +0,0 @@ -config_has_powerline=1 diff --git a/src/unpatched-fonts/FiraCode/config.cfg b/src/unpatched-fonts/FiraCode/config.cfg index 11945eed01..31aab6217a 100644 --- a/src/unpatched-fonts/FiraCode/config.cfg +++ b/src/unpatched-fonts/FiraCode/config.cfg @@ -1,2 +1,2 @@ -config_has_powerline=1 -config_patch_flags="--makegroups 2" +[Config] +commandline: --makegroups 2 diff --git a/src/unpatched-fonts/GeistMono/config.cfg b/src/unpatched-fonts/GeistMono/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/GeistMono/config.cfg +++ b/src/unpatched-fonts/GeistMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/Hack/config.cfg b/src/unpatched-fonts/Hack/config.cfg deleted file mode 100644 index 53c38882b7..0000000000 --- a/src/unpatched-fonts/Hack/config.cfg +++ /dev/null @@ -1 +0,0 @@ -config_has_powerline=1 diff --git a/src/unpatched-fonts/Hasklig/config.cfg b/src/unpatched-fonts/Hasklig/config.cfg index 11945eed01..31aab6217a 100644 --- a/src/unpatched-fonts/Hasklig/config.cfg +++ b/src/unpatched-fonts/Hasklig/config.cfg @@ -1,2 +1,2 @@ -config_has_powerline=1 -config_patch_flags="--makegroups 2" +[Config] +commandline: --makegroups 2 diff --git a/src/unpatched-fonts/Hermit/config.cfg b/src/unpatched-fonts/Hermit/config.cfg deleted file mode 100644 index 53c38882b7..0000000000 --- a/src/unpatched-fonts/Hermit/config.cfg +++ /dev/null @@ -1 +0,0 @@ -config_has_powerline=1 diff --git a/src/unpatched-fonts/IBMPlexMono/config.cfg b/src/unpatched-fonts/IBMPlexMono/config.cfg deleted file mode 100644 index 19f21c8167..0000000000 --- a/src/unpatched-fonts/IBMPlexMono/config.cfg +++ /dev/null @@ -1 +0,0 @@ -#config_has_powerline=1 diff --git a/src/unpatched-fonts/IntelOneMono/config.cfg b/src/unpatched-fonts/IntelOneMono/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/IntelOneMono/config.cfg +++ b/src/unpatched-fonts/IntelOneMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/Iosevka/config.cfg b/src/unpatched-fonts/Iosevka/config.cfg index 32c1cec77a..e9dff85dc2 100644 --- a/src/unpatched-fonts/Iosevka/config.cfg +++ b/src/unpatched-fonts/Iosevka/config.cfg @@ -1,2 +1,2 @@ -config_has_powerline=1 -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/IosevkaTerm/config.cfg b/src/unpatched-fonts/IosevkaTerm/config.cfg index 32c1cec77a..e9dff85dc2 100644 --- a/src/unpatched-fonts/IosevkaTerm/config.cfg +++ b/src/unpatched-fonts/IosevkaTerm/config.cfg @@ -1,2 +1,2 @@ -config_has_powerline=1 -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/IosevkaTermSlab/config.cfg b/src/unpatched-fonts/IosevkaTermSlab/config.cfg index 32c1cec77a..e9dff85dc2 100644 --- a/src/unpatched-fonts/IosevkaTermSlab/config.cfg +++ b/src/unpatched-fonts/IosevkaTermSlab/config.cfg @@ -1,2 +1,2 @@ -config_has_powerline=1 -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/JetBrainsMono/config.cfg b/src/unpatched-fonts/JetBrainsMono/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/JetBrainsMono/config.cfg +++ b/src/unpatched-fonts/JetBrainsMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/Lekton/config.cfg b/src/unpatched-fonts/Lekton/config.cfg new file mode 100644 index 0000000000..05bd07b119 --- /dev/null +++ b/src/unpatched-fonts/Lekton/config.cfg @@ -0,0 +1,6 @@ +[Config] +commandline: --removeligatures +[Subtables] +ligatures: [ + "'liga' Standard Ligatures in Latin lookup 6 subtable", + "'liga' Standard Ligatures in Latin lookup 5 subtable" ] diff --git a/src/unpatched-fonts/Lekton/config.json b/src/unpatched-fonts/Lekton/config.json deleted file mode 100644 index fa308418d3..0000000000 --- a/src/unpatched-fonts/Lekton/config.json +++ /dev/null @@ -1,4 +0,0 @@ -[Subtables] - ligatures: [ - "'liga' Standard Ligatures in Latin lookup 6 subtable", - "'liga' Standard Ligatures in Latin lookup 5 subtable" ] diff --git a/src/unpatched-fonts/MPlus/config.cfg b/src/unpatched-fonts/MPlus/config.cfg index f397cae70e..31aab6217a 100644 --- a/src/unpatched-fonts/MPlus/config.cfg +++ b/src/unpatched-fonts/MPlus/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 2" +[Config] +commandline: --makegroups 2 diff --git a/src/unpatched-fonts/MartianMono/config.cfg b/src/unpatched-fonts/MartianMono/config.cfg index b0539643c5..a31acd3709 100644 --- a/src/unpatched-fonts/MartianMono/config.cfg +++ b/src/unpatched-fonts/MartianMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--name filename --makegroups 5" +[Config] +commandline: --name filename --makegroups 5 diff --git a/src/unpatched-fonts/Meslo/config.cfg b/src/unpatched-fonts/Meslo/config.cfg deleted file mode 100644 index 53c38882b7..0000000000 --- a/src/unpatched-fonts/Meslo/config.cfg +++ /dev/null @@ -1 +0,0 @@ -config_has_powerline=1 diff --git a/src/unpatched-fonts/Monaspace/config.cfg b/src/unpatched-fonts/Monaspace/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/Monaspace/config.cfg +++ b/src/unpatched-fonts/Monaspace/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/Monofur/config.cfg b/src/unpatched-fonts/Monofur/config.cfg deleted file mode 100644 index 53c38882b7..0000000000 --- a/src/unpatched-fonts/Monofur/config.cfg +++ /dev/null @@ -1 +0,0 @@ -config_has_powerline=1 diff --git a/src/unpatched-fonts/NerdFontsSymbolsOnly/config.cfg b/src/unpatched-fonts/NerdFontsSymbolsOnly/config.cfg index e96c2cf4cc..367275da8a 100644 --- a/src/unpatched-fonts/NerdFontsSymbolsOnly/config.cfg +++ b/src/unpatched-fonts/NerdFontsSymbolsOnly/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--ext ttf --variable-width-glyphs" +[Config] +commandline: --ext ttf --variable-width-glyphs diff --git a/src/unpatched-fonts/Noto/Sans-Mono/config.cfg b/src/unpatched-fonts/Noto/Sans-Mono/config.cfg new file mode 100644 index 0000000000..9cde43eeea --- /dev/null +++ b/src/unpatched-fonts/Noto/Sans-Mono/config.cfg @@ -0,0 +1,7 @@ +[Config] +commandline: --removeligatures --makegroups 5 +[Subtables] +ligatures: [ + "Ligature Substitution lookup 15 subtable", + "Ligature Substitution lookup 14 subtable", + "Ligature Substitution lookup 13 subtable" ] diff --git a/src/unpatched-fonts/Noto/Sans-Mono/config.json b/src/unpatched-fonts/Noto/Sans-Mono/config.json deleted file mode 100644 index c6bb0c5b8c..0000000000 --- a/src/unpatched-fonts/Noto/Sans-Mono/config.json +++ /dev/null @@ -1,5 +0,0 @@ -[Subtables] - ligatures: [ - "Ligature Substitution lookup 15 subtable", - "Ligature Substitution lookup 14 subtable", - "Ligature Substitution lookup 13 subtable" ] diff --git a/src/unpatched-fonts/Noto/Sans/config.cfg b/src/unpatched-fonts/Noto/Sans/config.cfg new file mode 100644 index 0000000000..86326b209f --- /dev/null +++ b/src/unpatched-fonts/Noto/Sans/config.cfg @@ -0,0 +1,8 @@ +[Config] +commandline: --removeligatures --makegroups 5 +[Subtables] +ligatures: [ + "'liga' Standard Ligatures lookup 41 subtable", + "Ligature Substitution lookup 15 subtable", + "Ligature Substitution lookup 14 subtable", + "Ligature Substitution lookup 13 subtable" ] diff --git a/src/unpatched-fonts/Noto/Sans/config.json b/src/unpatched-fonts/Noto/Sans/config.json deleted file mode 100644 index 74e407e0ce..0000000000 --- a/src/unpatched-fonts/Noto/Sans/config.json +++ /dev/null @@ -1,6 +0,0 @@ -[Subtables] - ligatures: [ - "'liga' Standard Ligatures lookup 41 subtable", - "Ligature Substitution lookup 15 subtable", - "Ligature Substitution lookup 14 subtable", - "Ligature Substitution lookup 13 subtable" ] diff --git a/src/unpatched-fonts/Noto/config.cfg b/src/unpatched-fonts/Noto/config.cfg index 152146fbe5..6fb60abcec 100644 --- a/src/unpatched-fonts/Noto/config.cfg +++ b/src/unpatched-fonts/Noto/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 5" +[Config] +commandline: --makegroups 5 diff --git a/src/unpatched-fonts/OpenDyslexic/config.cfg b/src/unpatched-fonts/OpenDyslexic/config.cfg new file mode 100644 index 0000000000..4d22a03ea6 --- /dev/null +++ b/src/unpatched-fonts/OpenDyslexic/config.cfg @@ -0,0 +1,8 @@ +[Config] +commandline: --removeligatures +[Subtables] +ligatures: [ + "Ligature Substitution lookup 8 subtable", + "Ligature Substitution lookup 7 subtable", + "'liga' Standard Ligature lookup 7 subtable", + "'liga' Standard Ligature lookup 4 subtable" ] diff --git a/src/unpatched-fonts/OpenDyslexic/config.json b/src/unpatched-fonts/OpenDyslexic/config.json deleted file mode 100644 index 6c2dc33885..0000000000 --- a/src/unpatched-fonts/OpenDyslexic/config.json +++ /dev/null @@ -1,6 +0,0 @@ -[Subtables] - ligatures: [ - "Ligature Substitution lookup 8 subtable", - "Ligature Substitution lookup 7 subtable", - "'liga' Standard Ligature lookup 7 subtable", - "'liga' Standard Ligature lookup 4 subtable" ] diff --git a/src/unpatched-fonts/Overpass/Mono/config.cfg b/src/unpatched-fonts/Overpass/Mono/config.cfg new file mode 100644 index 0000000000..a0401b8360 --- /dev/null +++ b/src/unpatched-fonts/Overpass/Mono/config.cfg @@ -0,0 +1,5 @@ +[Config] +commandline: --removeligatures --makegroups 2 +[Subtables] +ligatures: [ + "Ligature Substitution lookup 23 subtable" ] diff --git a/src/unpatched-fonts/Overpass/Mono/config.json b/src/unpatched-fonts/Overpass/Mono/config.json deleted file mode 100644 index 0aef5a6f56..0000000000 --- a/src/unpatched-fonts/Overpass/Mono/config.json +++ /dev/null @@ -1,3 +0,0 @@ -[Subtables] - ligatures: [ - "Ligature Substitution lookup 23 subtable" ] diff --git a/src/unpatched-fonts/Overpass/Non-Mono/config.cfg b/src/unpatched-fonts/Overpass/Non-Mono/config.cfg new file mode 100644 index 0000000000..1587f50d84 --- /dev/null +++ b/src/unpatched-fonts/Overpass/Non-Mono/config.cfg @@ -0,0 +1,6 @@ +[Config] +commandline: --removeligatures --makegroups 2 +[Subtables] +ligatures: [ + "Ligature Substitution lookup 20 subtable", + "'liga' Standard Ligatures in Latin lookup 18 subtable" ] diff --git a/src/unpatched-fonts/Overpass/Non-Mono/config.json b/src/unpatched-fonts/Overpass/Non-Mono/config.json deleted file mode 100644 index 13cd8526e2..0000000000 --- a/src/unpatched-fonts/Overpass/Non-Mono/config.json +++ /dev/null @@ -1,4 +0,0 @@ -[Subtables] - ligatures: [ - "Ligature Substitution lookup 20 subtable", - "'liga' Standard Ligatures in Latin lookup 18 subtable" ] diff --git a/src/unpatched-fonts/Overpass/config.cfg b/src/unpatched-fonts/Overpass/config.cfg deleted file mode 100644 index f397cae70e..0000000000 --- a/src/unpatched-fonts/Overpass/config.cfg +++ /dev/null @@ -1 +0,0 @@ -config_patch_flags="--makegroups 2" diff --git a/src/unpatched-fonts/RobotoMono/config.cfg b/src/unpatched-fonts/RobotoMono/config.cfg index c68e3cf15a..6a166d1646 100644 --- a/src/unpatched-fonts/RobotoMono/config.cfg +++ b/src/unpatched-fonts/RobotoMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 3" +[Config] +commandline: --makegroups 3 diff --git a/src/unpatched-fonts/SourceCodePro/config.cfg b/src/unpatched-fonts/SourceCodePro/config.cfg index 32c1cec77a..e9dff85dc2 100644 --- a/src/unpatched-fonts/SourceCodePro/config.cfg +++ b/src/unpatched-fonts/SourceCodePro/config.cfg @@ -1,2 +1,2 @@ -config_has_powerline=1 -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/SpaceMono/config.cfg b/src/unpatched-fonts/SpaceMono/config.cfg new file mode 100644 index 0000000000..e5f2be3775 --- /dev/null +++ b/src/unpatched-fonts/SpaceMono/config.cfg @@ -0,0 +1,6 @@ +[Config] +commandline: --removeligatures +[Subtables] +ligatures: [ + "'liga' Standard Ligatures in Latin lookup 9 subtable", + "'liga' Standard Ligatures in Latin lookup 8 subtable" ] diff --git a/src/unpatched-fonts/SpaceMono/config.json b/src/unpatched-fonts/SpaceMono/config.json deleted file mode 100644 index f22b63e631..0000000000 --- a/src/unpatched-fonts/SpaceMono/config.json +++ /dev/null @@ -1,4 +0,0 @@ -[Subtables] - ligatures: [ - "'liga' Standard Ligatures in Latin lookup 9 subtable", - "'liga' Standard Ligatures in Latin lookup 8 subtable" ] diff --git a/src/unpatched-fonts/Ubuntu/config.cfg b/src/unpatched-fonts/Ubuntu/config.cfg index f397cae70e..880fe63f34 100644 --- a/src/unpatched-fonts/Ubuntu/config.cfg +++ b/src/unpatched-fonts/Ubuntu/config.cfg @@ -1 +1,7 @@ -config_patch_flags="--makegroups 2" +[Config] +commandline: --removeligatures --makegroups 2 +[Subtables] +ligatures: [ + "'liga' Standard Ligatures in Latin lookup 20 subtable", + "'liga' Standard Ligatures in Greek lookup 21 subtable", + "'liga' Standard Ligatures in Cyrillic lookup 22 subtable" ] diff --git a/src/unpatched-fonts/Ubuntu/config.json b/src/unpatched-fonts/Ubuntu/config.json deleted file mode 100644 index e2b3cb10a7..0000000000 --- a/src/unpatched-fonts/Ubuntu/config.json +++ /dev/null @@ -1,5 +0,0 @@ -[Subtables] - ligatures: [ - "'liga' Standard Ligatures in Latin lookup 20 subtable", - "'liga' Standard Ligatures in Greek lookup 21 subtable", - "'liga' Standard Ligatures in Cyrillic lookup 22 subtable" ] diff --git a/src/unpatched-fonts/UbuntuMono/config.cfg b/src/unpatched-fonts/UbuntuMono/config.cfg index f397cae70e..31aab6217a 100644 --- a/src/unpatched-fonts/UbuntuMono/config.cfg +++ b/src/unpatched-fonts/UbuntuMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 2" +[Config] +commandline: --makegroups 2 diff --git a/src/unpatched-fonts/UbuntuSans/config.cfg b/src/unpatched-fonts/UbuntuSans/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/UbuntuSans/config.cfg +++ b/src/unpatched-fonts/UbuntuSans/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/VictorMono/config.cfg b/src/unpatched-fonts/VictorMono/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/VictorMono/config.cfg +++ b/src/unpatched-fonts/VictorMono/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 diff --git a/src/unpatched-fonts/ZedMono/Extended/config.cfg b/src/unpatched-fonts/ZedMono/Extended/config.cfg index 152146fbe5..6fb60abcec 100644 --- a/src/unpatched-fonts/ZedMono/Extended/config.cfg +++ b/src/unpatched-fonts/ZedMono/Extended/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 5" +[Config] +commandline: --makegroups 5 diff --git a/src/unpatched-fonts/ZedMono/Normal/config.cfg b/src/unpatched-fonts/ZedMono/Normal/config.cfg index bf003486cd..e9dff85dc2 100644 --- a/src/unpatched-fonts/ZedMono/Normal/config.cfg +++ b/src/unpatched-fonts/ZedMono/Normal/config.cfg @@ -1 +1,2 @@ -config_patch_flags="--makegroups 4" +[Config] +commandline: --makegroups 4 From 378d97cf1b69da468ddc9a1134167295da369abd Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Thu, 18 Apr 2024 16:46:14 +0200 Subject: [PATCH 3/7] font-patcher: Allow to rehint some Cascadia glyphs [why] Some Caskaydia Cove glyphs that are used in ligatures (to create endless arrows for example) show uneven line thickness on some platforms. The reason is the not-matching hinting of glyphs that are places next to each other and so minuscule differences are quite visible. Note that the 'original' hinting is generated by VTT on the static Cascadia Code instances, which upstream just have ttfautohint hints that are different from the hints in the variable fonts and people complained that the look is different. [how] Add a new field to the config.cfg file that holds regexes of glyph names for glyphs that should be re-hinted by fontforge on patching time. In principle we could also implement that as an additional pre-step that needs to be manually done after running VTT on the static font files. I'm not sure which is better. Note that fontforge generates a lot of debug output because the hinting is not ideal - the global tables are kept and probably less compatible to fontforge's own hinting... But the results are good. Fixes: #1291 Fixes: #1609 Signed-off-by: Fini Jastrow --- font-patcher | 38 ++++++++++++++++++--- src/unpatched-fonts/CascadiaCode/config.cfg | 5 +++ src/unpatched-fonts/CascadiaMono/config.cfg | 5 +++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/font-patcher b/font-patcher index f717e7901e..479a64fb64 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,9 +792,28 @@ 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 diff --git a/src/unpatched-fonts/CascadiaCode/config.cfg b/src/unpatched-fonts/CascadiaCode/config.cfg index e9dff85dc2..03900dfd3f 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 e9dff85dc2..03900dfd3f 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)" ] From 098fa410a6b2932d3492e12c54382ce0dba76ccb Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 19 Apr 2024 17:48:24 +0200 Subject: [PATCH 4/7] font-patcher: Load config file only once Signed-off-by: Fini Jastrow --- font-patcher | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/font-patcher b/font-patcher index 479a64fb64..6f45fb34e9 100755 --- a/font-patcher +++ b/font-patcher @@ -320,10 +320,10 @@ def create_filename(fonts): class font_patcher: - def __init__(self, args): + def __init__(self, args, conf): self.args = args # class 'argparse.Namespace' self.sym_font_args = [] - self.config = None # class 'configparser.ConfigParser' + self.config = conf # class 'configparser.ConfigParser' self.sourceFont = None # class 'fontforge.font' self.patch_set = None # class 'list' self.font_dim = None # class 'dict' @@ -332,14 +332,12 @@ class font_patcher: self.symbolsonly = False # Are we generating the SymbolsOnly font? self.onlybitmaps = 0 self.essential = set() - self.config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True) self.xavgwidth = [] # list of ints def patch(self, font): self.sourceFont = font self.setup_version() self.assert_monospace() - self.load_config() self.remove_ligatures() self.manipulate_hints() self.get_essential_references() @@ -771,13 +769,6 @@ 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' @@ -1914,6 +1905,7 @@ def check_version_with_git(version): return False def setup_arguments(): + """ Parse the command line parameters and load the config file if needed """ parser = argparse.ArgumentParser( description=( 'Nerd Fonts Font Patcher: patches a given font with programming and development related glyphs\n\n' @@ -1990,6 +1982,7 @@ def setup_arguments(): args = parser.parse_args() # if we have a config file: fetch commandline arguments from there and process again with all arguments + config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True) if args.configfile: if not os.path.isfile(args.configfile): logger.critical("Configfile does not exist: %s", args.configfile) @@ -1997,7 +1990,6 @@ def setup_arguments(): if not os.access(args.configfile, os.R_OK): logger.critical("Can not open configfile for reading: %s", args.configfile) sys.exit(1) - config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True) config.read(args.configfile) extraflags = config.get("Config", "commandline", fallback='') if len(extraflags): @@ -2087,7 +2079,7 @@ def setup_arguments(): logger.critical("--xavgcharwidth takes only numbers up to 16384") sys.exit(2) - return args + return (args, config) def main(): global logger @@ -2104,7 +2096,7 @@ def main(): if git_version: version = git_version check_fontforge_min_version() - args = setup_arguments() + (args, conf) = setup_arguments() logger = logging.getLogger(os.path.basename(args.font)) logger.setLevel(logging.DEBUG) @@ -2127,7 +2119,7 @@ def main(): logger.info("Can not write logfile, disabling") logger.debug("Naming mode %d", args.makegroups) - patcher = font_patcher(args) + patcher = font_patcher(args, conf) sourceFonts = [] all_fonts = fontforge.fontsInFile(args.font) From 6c6177d6a516906b839ff2fa652ff64cdd365c3f Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sat, 20 Apr 2024 09:49:26 +0200 Subject: [PATCH 5/7] 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 6f45fb34e9..75c30a4ab4 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: From e5f63a3d7a7c865e41cefae1221a26fcb8d9bd61 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sat, 20 Apr 2024 10:11:35 +0200 Subject: [PATCH 6/7] font-patcher: Improve logging while setup options [why] The logging to files does not work correctly for the messages given while the options themselves are parsed. [how] As soon as we have enough information (after the first argument parsing) we set the logger up. When processing the config file arguments we have a full functioning logger now. Signed-off-by: Fini Jastrow --- font-patcher | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/font-patcher b/font-patcher index 75c30a4ab4..d7d27355e2 100755 --- a/font-patcher +++ b/font-patcher @@ -1980,6 +1980,7 @@ def setup_arguments(): expert_group.set_defaults(progressbars=True) args = parser.parse_args() + setup_global_logger(args) # if we have a config file: fetch commandline arguments from there and process again with all arguments config = configparser.ConfigParser(empty_lines_in_values=False, allow_no_value=True) @@ -1993,9 +1994,8 @@ def setup_arguments(): config.read(args.configfile) extraflags = config.get("Config", "commandline", fallback='') if len(extraflags): - # We have no level less severe than warning here, logger will be set up later - logger.warning("Adding config commandline options: %s", extraflags) - extraflags += ' ' + args.font + logger.info("Adding config commandline options: %s", extraflags) + extraflags += ' ' + args.font # Need to re-add the mandatory argument args = parser.parse_args(extraflags.split(), args) if args.makegroups > 0 and not FontnameParserOK: @@ -2081,23 +2081,9 @@ def setup_arguments(): return (args, config) -def main(): +def setup_global_logger(args): + """ Set up the logger and take options into account """ global logger - logger = logging.getLogger("start") # Use start logger until we can set up something sane - s_handler = logging.StreamHandler(stream=sys.stdout) - s_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) - logger.addHandler(s_handler) - - global version - git_version = check_version_with_git(version) - allversions = "Patcher v{} ({}) (ff {})".format( - git_version if git_version else version, script_version, fontforge.version()) - print("{} {}".format(projectName, allversions)) - if git_version: - version = git_version - check_fontforge_min_version() - (args, conf) = setup_arguments() - logger = logging.getLogger(os.path.basename(args.font)) logger.setLevel(logging.DEBUG) log_to_file = (args.debugmode & 1 == 1) @@ -2117,6 +2103,24 @@ def main(): logger.addHandler(c_handler) if (args.debugmode & 1 == 1) and not log_to_file: logger.info("Can not write logfile, disabling") + +def main(): + global logger + logger = logging.getLogger("start") # Use start logger until we can set up something sane + s_handler = logging.StreamHandler(stream=sys.stdout) + s_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) + logger.addHandler(s_handler) + + global version + git_version = check_version_with_git(version) + global allversions + allversions = "Patcher v{} ({}) (ff {})".format( + git_version if git_version else version, script_version, fontforge.version()) + print("{} {}".format(projectName, allversions)) + if git_version: + version = git_version + check_fontforge_min_version() + (args, conf) = setup_arguments() logger.debug("Naming mode %d", args.makegroups) patcher = font_patcher(args, conf) From cd80b9eccc944216b98a2f2bee9dafbd2ee07c89 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Mon, 22 Apr 2024 14:03:55 +0200 Subject: [PATCH 7/7] gotta-patch-em: Remove post_process [why] The previous change(s) removed executing the config.cfg **shell script** which would pull in some environment variables like `post_process`. With that change the appropriate option has to be given with the commandline value of the new config.cfg **INI** file. [how] Remove defunct leftover code. Signed-off-by: Fini Jastrow --- .../gotta-patch-em-all-font-patcher!.sh | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/bin/scripts/gotta-patch-em-all-font-patcher!.sh b/bin/scripts/gotta-patch-em-all-font-patcher!.sh index 36053b748e..0b7941b008 100755 --- a/bin/scripts/gotta-patch-em-all-font-patcher!.sh +++ b/bin/scripts/gotta-patch-em-all-font-patcher!.sh @@ -229,15 +229,6 @@ function patch_font { font_config="-q" fi - if [ "$post_process" ] - then - # There is no postprocess active anymore, see the commit that introduced - # this comment for the Hack postprocess we once had. It called e.g. ttfautohint. - post_process="--postprocess=${repo_root_dir}/${post_process}" - else - post_process="" - fi - cd "$repo_root_dir" || { echo >&2 "# Could not find project parent directory" exit 3 @@ -248,30 +239,30 @@ function patch_font { # Create "Nerd Font" if [ -n "${verbose}" ] then - echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" + echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q \"${font_config}\" -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" fi # shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them - { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q "${font_config}" $post_process -c --no-progressbars \ + { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q "${font_config}" -c --no-progressbars \ --outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 # shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi # Create "Nerd Font Mono" if [ -n "${verbose}" ] then - echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q -s \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" + echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q -s \"${font_config}\" -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" fi # shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them - { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q -s "${font_config}" $post_process -c --no-progressbars \ + { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q -s "${font_config}" -c --no-progressbars \ --outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 # shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi # Create "Nerd Font Propo" if [ -n "${verbose}" ] then - echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q --variable \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" + echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q --variable \"${font_config}\" -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}" fi # shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them - { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q --variable "${font_config}" $post_process -c --no-progressbars \ + { OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q --variable "${font_config}" -c --no-progressbars \ --outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1 # shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi