-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_woff.sh
executable file
·62 lines (51 loc) · 1.68 KB
/
make_woff.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
61
62
#!/bin/bash
# Creates .WOFF format font from base64 .txt files
# FIXME: Font weights, name and other details aren't added to the fonts themselves, only
# to the file names. This can be fixed using fontforge.
# Constants
OUTPUTDIR="output"
GITURL="https://github.com/hanikesn/woff2otf/blob/master"
EXTRACTFONT="extract_font.py"
WOFF2OTF="woff2otf.py"
# Functions
download() {
printf "Downloading WOFF to OTF converter from GitHub…\n"
curl -sLS "${GITURL}/${WOFF2OTF}?raw=true" --output "${OUTPUTDIR}/${WOFF2OTF}"
}
# Start
# Check arguments
[ "$1" == "" ] && printf "Please provide at least one file as an argument.\n" && exit 1
# Check output dir
convert=0 && [ ! -d "$OUTPUTDIR" ] && mkdir "$OUTPUTDIR"
# Check convert to OTF script, try to download if missing
[ ! -r "$OUTPUTDIR/$WOFF2OTF" ] && download
[ -r "$OUTPUTDIR/$WOFF2OTF" ] && convert=1 || printf "$WOFF2OTF not found, WOFF will not be converted to OTF.\n"
# Cycle through arguments
for inputfile in "${@}"
do
printf "Extracting from file: ${inputfile}\n"
if [ -r "$inputfile" ]
then
# Extrack fonts as TXT files
python3 "$EXTRACTFONT" "$inputfile"
cd "$OUTPUTDIR"
# Cycle through exported TXT files
for filename in `ls *.txt 2>/dev/null`
do
if [ -r "$filename" ]
then
# Convert the base64 text into WOFF format
file="${filename%.*}"
printf "Converting $filename to ${file}.woff\n"
base64 --decode "$filename" > "${file}.woff"
# OPTIONAL
# Convert the WOFF font to OTF using woff2Otf tool
[ $convert == "1" ] && python3 "$WOFF2OTF" "${file}.woff" "${file}.otf"
fi
done
# Clean up
[ -r "${filename}" ] && rm *.txt && cd ..
else
printf "Cannot access: ${inputfile}\n"
fi
done