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 63 64 65 66 67 68 69 70 71 72 73 74
|
#!/bin/bash
# Generate font files with FontForge, and a CSS declaration for this font.
basename=$1
ttf="${basename}.ttf"
otf="OTF/${basename}.otf"
echo -e "\e[1;37mGenerating ${basename}... \e[0m"
output=$(fontforge -lang=py -script - <<EOF
import fontforge;
font = fontforge.open("Sources/${basename}.sfd");
# Extract interesting informations
print font.fontname
print font.familyname
print font.fullname
print font.os2_weight
print font.italicangle
bitmask = font.validate();
if bitmask != 0:
exit(42);
font.generate("${basename}.ttf", flags=("opentype", "dummy-dsig"));
font.generate("OTF/${basename}.otf", flags=("opentype", "dummy-dsig"));
font.generate("Webfonts/${basename}.svg");
EOF
)
error=$?
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
cat > Webfonts/${basename}-decl.css <<EOF
@font-face {
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};
}
EOF
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
|