Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to newest FontForge #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./FontForge.AppImage
28 changes: 27 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 16 additions & 8 deletions scripts/generate_font.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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()
Expand All @@ -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 = []
Expand Down