|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +glyphs_source="Cairo" |
| 5 | +output_dir="fonts" |
| 6 | +family_name="Cairo" |
| 7 | +build_static_fonts=true # Set to `true` if you want to build static fonts |
| 8 | +autohint=false # Set to true if you want to use auto-hinting (ttfautohint) |
| 9 | +nohinting=true # Set to true if you want the fonts unhinted |
| 10 | + |
| 11 | +echo "[INFO] Starting build script for $family_name font family" |
| 12 | + |
| 13 | +if [ -d .git ]; then |
| 14 | + echo "[TEST] Running from a Git root directory, looks good" |
| 15 | +else |
| 16 | + echo "[WARN] Font family Git root not found, please run from the root directory" |
| 17 | + echo "[WARN] Build process cancelled" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +for sources in $glyphs_source; do |
| 22 | + echo "[TEST] Queued source file: $sources.glyphs" |
| 23 | +done |
| 24 | + |
| 25 | +for sources in $glyphs_source; do |
| 26 | + echo "[INFO] Building $sources.glyphs VFs with Fontmake..." |
| 27 | + fontmake -g sources/$sources.glyphs -o variable \ |
| 28 | + --output-path $output_dir/vf/$sources-VF.ttf \ |
| 29 | + --verbose ERROR |
| 30 | +done |
| 31 | + |
| 32 | +if [ "$build_static_fonts" = true ]; then |
| 33 | + echo "[INFO] Building static fonts" |
| 34 | + fontmake -g sources/Cairo.glyphs -i "Cairo ExtraLight" --verbose ERROR |
| 35 | + fontmake -g sources/Cairo.glyphs -i "Cairo Light" --verbose ERROR |
| 36 | + fontmake -g sources/Cairo.glyphs -i "Cairo Regular" --verbose ERROR |
| 37 | + fontmake -g sources/Cairo.glyphs -i "Cairo SemiBold" --verbose ERROR |
| 38 | + fontmake -g sources/Cairo.glyphs -i "Cairo Bold" --verbose ERROR |
| 39 | + fontmake -g sources/Cairo.glyphs -i "Cairo Black" --verbose ERROR |
| 40 | + #fontmake -g sources/Cairo-Italic.glyphs -i "Cairo ExtraLight Italic" --verbose INFO |
| 41 | + #fontmake -g sources/Cairo-Italic.glyphs -i "Cairo Light Italic" --verbose INFO |
| 42 | + #fontmake -g sources/Cairo-Italic.glyphs -i "Cairo Italic" --verbose INFO |
| 43 | + #fontmake -g sources/Cairo-Italic.glyphs -i "Cairo SemiBold Italic" --verbose INFO |
| 44 | + #fontmake -g sources/Cairo-Italic.glyphs -i "Cairo Bold Italic" --verbose INFO |
| 45 | +fi |
| 46 | + |
| 47 | +if [ "$build_static_fonts" = true ]; then |
| 48 | + echo "[INFO] Moving static fonts" |
| 49 | + for font in instance_ttf/Cairo-*; do |
| 50 | + echo "[INFO] Moving $font ..." |
| 51 | + mv $font fonts/ttf/ |
| 52 | + done |
| 53 | +fi |
| 54 | + |
| 55 | +echo "[INFO] Removing build directories" |
| 56 | +rm -rf instance_ufo instance_otf instance_ttf master_ufo |
| 57 | + |
| 58 | +echo "[INFO] Fixing VF DSIG tables" |
| 59 | +for sources in $glyphs_source; do |
| 60 | + if gftools fix-dsig -f fonts/vf/$sources-VF.ttf >/dev/null; then |
| 61 | + echo "[INFO] DSIG fixed for $sources-VF.ttf" |
| 62 | + else |
| 63 | + echo "[ERROR] GFtools is not working, please update or install: https://github.com/googlefonts/gftools" |
| 64 | + fi |
| 65 | +done |
| 66 | + |
| 67 | +if [ "$build_static_fonts" = true ]; then |
| 68 | + echo "[INFO] Fixing Static DSIG tables" |
| 69 | + for font in fonts/ttf/Cairo-*; do |
| 70 | + echo "[INFO] Fixing DSIG table for $font ..." |
| 71 | + gftools fix-dsig -f $font >/dev/null |
| 72 | + done |
| 73 | +fi |
| 74 | + |
| 75 | +if [ "$autohint" = true ]; then |
| 76 | + echo "[INFO] Autohinting variable fonts with ttfautohint" |
| 77 | + for font in fonts/vf/Cairo-*; do |
| 78 | + echo "[INFO] Hinting $font "; |
| 79 | + ttfautohint $font temp.ttf |
| 80 | + mv temp.ttf $font |
| 81 | + gftools fix-hinting $font |
| 82 | + mv $font.fix $font |
| 83 | + done |
| 84 | +fi |
| 85 | + |
| 86 | +if [ "$build_static_fonts" = true ] && [ "$autohint" = true ]; then |
| 87 | + echo "[INFO] Autohinting static fonts with ttfautohint" |
| 88 | + for font in fonts/ttf/Cairo-*; do |
| 89 | + echo "[INFO] Hinting $font "; |
| 90 | + ttfautohint $font temp.ttf |
| 91 | + mv temp.ttf $font |
| 92 | + gftools fix-hinting $font |
| 93 | + mv $font.fix $font |
| 94 | + done |
| 95 | +fi |
| 96 | + |
| 97 | +if [ "$nohinting" = true ]; then |
| 98 | + for font in fonts/vf/Cairo-*; do |
| 99 | + echo "[INFO] Fixing nonhinting for $font "; |
| 100 | + gftools fix-nonhinting $font fonts/vf/temp.ttf >/dev/null |
| 101 | + mv fonts/vf/temp.ttf $font |
| 102 | + rm -rf fonts/vf/*backup-fonttools-prep-gasp.ttf |
| 103 | + done |
| 104 | +fi |
| 105 | + |
| 106 | +if [ "$build_static_fonts" = true ] && [ "$nohinting" = true ]; then |
| 107 | + echo "[INFO] Fixing nonhinting for static fonts" |
| 108 | + for font in fonts/ttf/Cairo-*; do |
| 109 | + echo "[INFO] Fixing nonhinting for $font "; |
| 110 | + gftools fix-nonhinting $font fonts/ttf/temp.ttf >/dev/null |
| 111 | + mv fonts/ttf/temp.ttf $font |
| 112 | + rm -rf fonts/ttf/*backup-fonttools-prep-gasp.ttf |
| 113 | + done |
| 114 | +fi |
| 115 | + |
| 116 | +echo "[INFO] Done building $family_name font family" |
0 commit comments