-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile-fonts.sh
executable file
·60 lines (47 loc) · 1.27 KB
/
compile-fonts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
#https://github.com/gsandf/svg-to-ttf
set -eu -o pipefail
__dirname="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
createConfiguration() {
local input="$1"
local fileCount="$(ls ${input} | wc -l)"
local startUnicode=59905
local endUnicode=$(( startUnicode + fileCount - 1 ))
local currentUnicode=$startUnicode
echo '{'
for file in ${input}; do
iconName="$(basename "$file" .svg)"
printf ' "%s": %d' "$iconName" "$currentUnicode"
if [[ "$currentUnicode" != "$endUnicode" ]]; then
echo ','
else
echo
fi
currentUnicode=$(( currentUnicode + 1 ))
done
echo '}'
}
main() {
local name
local inputSVGs
local config
local fontFile
while (( $# > 0 )); do
arg="$1"
case $arg in
-n|--name) name=$2; shift;;
-s|--svgs) inputSVGs=$2; shift;;
-c|--config) config=$2; shift;;
-f|--font) fontFile=$2; shift;;
*) echo "Error: unrecognized argument '$1'" >&2; exit 1;
esac
shift
done
local tmpFontFile="$(mktemp || exit 1)"
trap "{ rm -f ${tmpFontFile}; }" EXIT
createConfiguration "$inputSVGs" > "$config"
npx svgicons2svgfont --fontname "$name" -o "$tmpFontFile" "$inputSVGs" -h 1001 -n
npx svg2ttf "$tmpFontFile" "${fontFile}/${name}.ttf"
cp "${fontFile}/${name}.ttf" "../android/app/src/main/assets/fonts"
}
main "$@"