2014-06-14 23:29:43 +02:00
|
|
|
#!/usr/bin/env bash
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2017-07-10 18:47:01 +02:00
|
|
|
# Generate a CSS declaration for the given font
|
2013-12-22 13:49:16 +01:00
|
|
|
|
2014-06-15 05:10:29 +02:00
|
|
|
if ! type fontforge &> /dev/null; then echo "ERROR: Missing dependency: fontforge" 1>&2; exit 1; fi
|
|
|
|
|
2017-07-10 18:47:01 +02:00
|
|
|
fullname=$1
|
|
|
|
basename=$(basename "$fullname" .sfdir)
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2017-07-10 18:47:01 +02:00
|
|
|
output=$(fontforge --quiet -lang=py -script - "$fullname" <<EOF
|
2013-11-27 21:47:39 +01:00
|
|
|
import fontforge;
|
2017-07-10 18:47:01 +02:00
|
|
|
import sys;
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2017-07-10 18:47:01 +02:00
|
|
|
font = fontforge.open(sys.argv[1]);
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2014-03-09 21:48:13 +01:00
|
|
|
# Extract interesting informations
|
2016-04-03 21:27:03 +02:00
|
|
|
print("---")
|
2015-05-24 16:04:45 +02:00
|
|
|
print(font.fontname)
|
|
|
|
print(font.familyname)
|
|
|
|
print(font.fullname)
|
|
|
|
print(font.os2_weight)
|
|
|
|
print(font.italicangle)
|
2013-11-27 21:47:39 +01:00
|
|
|
EOF
|
2017-07-10 18:47:01 +02:00
|
|
|
) || exit 1
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2016-04-03 21:27:03 +02:00
|
|
|
output="${output##*---
|
|
|
|
}"
|
2014-03-09 21:48:13 +01:00
|
|
|
old_IFS="$IFS"
|
|
|
|
IFS='
|
|
|
|
'
|
|
|
|
output=($output)
|
|
|
|
IFS="$old_IFS"
|
|
|
|
|
|
|
|
fontname=${output[0]}
|
|
|
|
familyname=${output[1]}
|
|
|
|
fullname=${output[2]}
|
|
|
|
fontweight=${output[3]}
|
|
|
|
slope=${output[4]}
|
|
|
|
if [ x"$slope" = "x0.0" ]; then
|
|
|
|
fontstyle=normal
|
|
|
|
else
|
|
|
|
fontstyle=italic
|
|
|
|
fi
|
|
|
|
|
2017-07-10 18:47:01 +02:00
|
|
|
cat > "Webfonts/${basename}-decl.css" <<EOF
|
2013-12-22 13:49:16 +01:00
|
|
|
@font-face {
|
2014-03-09 21:48:13 +01:00
|
|
|
font-family: '${familyname}';
|
2019-11-16 17:56:56 +01:00
|
|
|
src: url('${basename}.woff2') format('woff2'),
|
2014-03-09 21:48:13 +01:00
|
|
|
url('${basename}.woff') format('woff'), /* Firefox >= 3.6, any other modern browser */
|
|
|
|
url('${basename}.ttf') format('truetype'), /* Safari, Android, iOS */
|
|
|
|
url('${basename}.svg#${fontname}') format('svg'); /* Chrome < 4, Legacy iOS */
|
|
|
|
font-weight: ${fontweight};
|
|
|
|
font-style: ${fontstyle};
|
2013-12-22 13:49:16 +01:00
|
|
|
}
|
|
|
|
EOF
|