mirror of
https://github.com/belluzj/fantasque-sans.git
synced 2024-12-22 23:41:30 +01:00
a6b8994df5
Closes #43.
85 lines
2.1 KiB
Bash
Executable File
85 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Generate font files with FontForge, and a CSS declaration for this font.
|
|
|
|
if ! type fontforge &> /dev/null; then echo "ERROR: Missing dependency: fontforge" 1>&2; exit 1; fi
|
|
|
|
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
|
|
$(if [[ "$(python --version 2>&1 | cut -d' ' -f2- | cut -c1)" == "3" ]]; then
|
|
echo 'print(font.fontname)'
|
|
echo 'print(font.familyname)'
|
|
echo 'print(font.fullname)'
|
|
echo 'print(font.os2_weight)'
|
|
echo 'print(font.italicangle)'
|
|
else
|
|
echo 'print font.fontname'
|
|
echo 'print font.familyname'
|
|
echo 'print font.fullname'
|
|
echo 'print font.os2_weight'
|
|
echo 'print font.italicangle'
|
|
fi)
|
|
|
|
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
|