From 9977429cabc69f49ad050572810fa5bbab4b0027 Mon Sep 17 00:00:00 2001 From: Ruby Allison Rose Date: Thu, 3 Dec 2020 21:23:44 -0800 Subject: [PATCH 1/2] fix!: Migrated to the latest FontForge, added dependency autofetch. --- build.sh | 28 +++++++++++++++++++++++++++- scripts/generate_font.py | 24 ++++++++++++++++-------- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index a019d27..9159bff 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,35 @@ #!/usr/bin/env bash +//RUNNER=./FontForge-2020-11-07-21ad4a1-x86_64.AppImage; + set -xe rm -rf ./build/ mkdir -p ./build -./scripts/generate_font.py ./config.json > ./build/mapping.txt + +# If we don't have FontForge dependency, fetch it. +if ! test -x ./FontForge.AppImage; then + echo "Downloading the latest FontForge AppImage from Github..."; + # Download the latest fontforge. It comes bundled with Python 3. + curl -s https://api.github.com/repos/fontforge/fontforge/releases | + grep -m 1 "https://.*\.AppImage" | sed -E 's/.*(https:.*\.AppImage).*/\1/' | + xargs curl -L --output FontForge.AppImage; + # Make sure it's executable + chmod +x ./FontForge.AppImage; +fi; + +# Use the fontforge binary to execute our generator script. +# NOTE: +# There are limitations to this. Due to how AppImages are packaged, +# the builtin python executable will always be started in a temporary +# environment because it's assumed that said binary will be self-contained +# and not need access to the CWD at all. (At least I think, that's what +# I gathered from my time experimenting with it trying to get this to work) +# So we can only inject a script to load from STDIN which removes our ability +# to append any command line arguments. To work around this, I added +cat ./scripts/generate_font.py | + sed "1 i\\argv = [\"$PWD\", \"/config.json\"]" | + ./FontForge.AppImage -lang=py -script > ./build/mapping.txt; + ./scripts/inte_fish.sh > ./build/icons.fish ./scripts/inte_bash.sh > ./build/icons_bash.sh ./scripts/inte_bash_export.sh > ./build/icons_bash_export.sh diff --git a/scripts/generate_font.py b/scripts/generate_font.py index 45c5ad5..6bc6e3d 100755 --- a/scripts/generate_font.py +++ b/scripts/generate_font.py @@ -1,4 +1,9 @@ -#!/usr/bin/env python3 +# XXX: +# `argv` will be injected here by the invoker. Since FontForge is now +# an AppImage, this script can no longer be invoked using a shebang. +# the $PWD will be provided as `argv[0]` and you must access files +# using their full path, otherwise the paths get clobbered. +PWD = argv[0] import string import os @@ -7,6 +12,9 @@ import fontforge import psMat +os.chdir(PWD) +print(f"Running in '{PWD}'", file=sys.stderr) + PUA_START = 0xE000 PUA_END = 0xF8FF FONT_EM = 1024 @@ -38,9 +46,9 @@ def lookup_map_name(map_names, codepoint, fallback_name): # our font compatible with most of plugins/modules that insert those glyphs def insert_powerline_extra(dest): codepoint = POWERLINE_START - font = fontforge.open("./fonts/PowerlineExtraSymbols.otf") + font = fontforge.open(f"{PWD}/fonts/PowerlineExtraSymbols.otf") font.em = FONT_EM - map_names = read_map_names("./fonts/PowerlineExtraSymbols-map") + map_names = read_map_names(f"{PWD}/fonts/PowerlineExtraSymbols-map") excludes = [ 0xE0A4, 0xE0A5, 0xE0A6, 0xE0A7, 0xE0A8, 0xE0A9, 0xE0AA, 0xE0AB, 0xE0AC, 0xE0AD, 0xE0AE, 0xE0AF, 0xE0C9, 0xE0CB, 0xE0D3 ] inserted = [] @@ -78,11 +86,11 @@ def make_name(name, name_font): return name_font + "_" + name[-4:] return name_font + "_" + name.replace("-", "_") -if len(sys.argv) < 2: - print("Give me a config file", file=sys.stderr) - sys.exit(1) +# if len(sys.argv) < 2: +# print("Give me a config file", file=sys.stderr) +# sys.exit(1) -with open(sys.argv[1]) as config_file: +with open(PWD+argv[1]) as config_file: config_data = json.load(config_file) dest = fontforge.font() @@ -96,7 +104,7 @@ def make_name(name, name_font): for json_file in config_data: - font = fontforge.open(json_file["path"]) + font = fontforge.open(PWD+"/"+json_file["path"]) font.em = FONT_EM excludes = [] From d594e2e5b9e5bb064d27280dbbbb0adbeeb8d311 Mon Sep 17 00:00:00 2001 From: Ruby Allison Rose Date: Thu, 3 Dec 2020 21:26:35 -0800 Subject: [PATCH 2/2] chore: Added dependency binary to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e69de29..ef448d1 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +./FontForge.AppImage