2014-06-14 23:29:43 +02:00
|
|
|
#!/usr/bin/env bash
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2013-12-22 13:49:16 +01:00
|
|
|
# Generate font files with FontForge, and a CSS declaration for this font.
|
|
|
|
|
2014-06-15 05:10:29 +02:00
|
|
|
if ! type fontforge &> /dev/null; then echo "ERROR: Missing dependency: fontforge" 1>&2; exit 1; fi
|
|
|
|
|
2013-11-27 21:47:39 +01:00
|
|
|
basename=$1
|
|
|
|
ttf="${basename}.ttf"
|
|
|
|
otf="OTF/${basename}.otf"
|
|
|
|
|
2013-11-30 21:29:09 +01:00
|
|
|
echo -e "\e[1;37mGenerating ${basename}... \e[0m"
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2014-03-09 21:48:13 +01:00
|
|
|
output=$(fontforge -lang=py -script - <<EOF
|
2013-11-27 21:47:39 +01:00
|
|
|
import fontforge;
|
|
|
|
|
|
|
|
font = fontforge.open("Sources/${basename}.sfd");
|
|
|
|
|
2014-03-09 21:48:13 +01:00
|
|
|
# Extract interesting informations
|
2015-05-24 16:04:45 +02:00
|
|
|
print(font.fontname)
|
|
|
|
print(font.familyname)
|
|
|
|
print(font.fullname)
|
|
|
|
print(font.os2_weight)
|
|
|
|
print(font.italicangle)
|
2014-03-09 21:48:13 +01:00
|
|
|
|
2013-11-27 21:47:39 +01:00
|
|
|
bitmask = font.validate();
|
2015-12-21 05:06:56 +01:00
|
|
|
# if bitmask != 0:
|
|
|
|
# the exit(42);
|
2013-11-27 21:47:39 +01:00
|
|
|
|
2014-02-23 11:08:12 +01:00
|
|
|
font.generate("${basename}.ttf", flags=("opentype", "dummy-dsig"));
|
|
|
|
font.generate("OTF/${basename}.otf", flags=("opentype", "dummy-dsig"));
|
2013-12-22 13:49:16 +01:00
|
|
|
font.generate("Webfonts/${basename}.svg");
|
2013-11-30 21:29:09 +01:00
|
|
|
|
2013-11-27 21:47:39 +01:00
|
|
|
EOF
|
2014-03-09 21:48:13 +01:00
|
|
|
)
|
2014-01-20 14:55:37 +01:00
|
|
|
error=$?
|
2013-11-27 21:47:39 +01:00
|
|
|
|
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
|
|
|
|
|
2013-12-22 13:49:16 +01:00
|
|
|
cat > Webfonts/${basename}-decl.css <<EOF
|
|
|
|
@font-face {
|
2014-03-09 21:48:13 +01:00
|
|
|
font-family: '${familyname}';
|
|
|
|
src: url('${basename}.eot'); /* IE 9 Compatibility Mode */
|
|
|
|
src: url('${basename}.eot?#iefix') format('embedded-opentype'), /* IE < 9 */
|
|
|
|
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
|
|
|
|
|
2013-11-27 21:47:39 +01:00
|
|
|
if [ "x$error" != "x0" ]; then
|
|
|
|
echo -e "\e[1;31mError in ${basename}.\e[0m"
|
|
|
|
if [ "x$error" = "x42" ]; then
|
|
|
|
echo "Font ${basename}.sfd is not valid"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -e "\e[1;32m${basename} OK.\e[0m"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $error
|