2017-08-25 07:06:10 +03:00
#!/bin/sh
2017-08-26 05:40:43 +03:00
# ///////////////////////////////////////////////////////////////////
2017-08-25 07:06:10 +03:00
#
2017-08-26 05:40:43 +03:00
# build-woff.sh
# A shell script that builds the Hack woff web fonts from ttf files
2018-01-22 05:11:49 +03:00
# Copyright 2018 Christopher Simpkins
2017-08-25 07:06:10 +03:00
# MIT License
#
2017-08-26 05:40:43 +03:00
# Usage: ./build-woff.sh (--install-dependencies)
2017-08-25 07:06:10 +03:00
# Arguments:
# --install-dependencies (optional) - installs all
# build dependencies prior to the build script execution
#
# NOTE: If you change the source, you must build new ttf files
2017-08-25 23:46:58 +03:00
# with build.sh PRIOR to execution of this script.
# This script builds directly from previous ttf builds,
# not source files.
2017-08-25 07:06:10 +03:00
#
2017-08-26 05:40:43 +03:00
# ///////////////////////////////////////////////////////////////////
2017-08-25 07:06:10 +03:00
2017-08-25 23:46:58 +03:00
# The sfnt2woff-zopfli build directory.
2017-08-25 07:06:10 +03:00
BUILD = " $HOME /sfnt2woff-zopfli-build "
# sfnt2woff-zopfli version
SFNTWOFF_VERSION = "1.1.0"
SFNTWOFF = " sfnt2woff-zopfli- $SFNTWOFF_VERSION "
# Path to sfnt2woff-zopfli executable
SFNTWOFF_BIN = " $BUILD / $SFNTWOFF /sfnt2woff-zopfli "
2017-08-26 06:45:40 +03:00
ZOPFLI_ITERATIONS = "3"
2017-08-25 07:06:10 +03:00
2017-08-25 23:46:58 +03:00
# The font build directory paths and file paths for the woff builds
TTF_BUILD = "build/ttf"
2017-10-03 06:23:30 +03:00
WOFF_BUILD = "build/web/fonts"
2017-08-25 23:46:58 +03:00
REGULAR_TTF = "Hack-Regular.ttf"
REGULAR_PRE = "Hack-Regular.woff"
REGULAR_WOFF = "hack-regular.woff"
BOLD_TTF = "Hack-Bold.ttf"
BOLD_PRE = "Hack-Bold.woff"
BOLD_WOFF = "hack-bold.woff"
ITALIC_TTF = "Hack-Italic.ttf"
ITALIC_PRE = "Hack-Italic.woff"
ITALIC_WOFF = "hack-italic.woff"
BOLDITALIC_TTF = "Hack-BoldItalic.ttf"
BOLDITALIC_PRE = "Hack-BoldItalic.woff"
BOLDITALIC_WOFF = "hack-bolditalic.woff"
2017-08-25 07:06:10 +03:00
# test for number of arguments
if [ $# -gt 1 ]
then
echo "Inappropriate arguments included in your command." 1>& 2
2017-08-26 05:40:43 +03:00
echo "Usage: ./build-woff.sh (--install-dependencies)" 1>& 2
2017-08-25 07:06:10 +03:00
exit 1
fi
# Optional build dependency install request with syntax `./build-web.sh --install-dependencies`
if [ " $1 " = "--install-dependencies" ]
then
2017-08-26 05:40:43 +03:00
# define the current directory (Hack repository)
CUR_DIR = $( pwd )
2017-08-25 07:06:10 +03:00
if test -d " $BUILD " -o -f " $BUILD " ; then
echo " Build directory \` $BUILD ' must not exist. "
exit 1
fi
mkdir " $BUILD "
cd " $BUILD " || exit 1
echo "#####"
echo "Download archive."
echo "#####"
curl -L -O " https://github.com/bramstein/sfnt2woff-zopfli/archive/v $SFNTWOFF_VERSION .tar.gz "
echo "#####"
echo "Extract archives."
echo "#####"
tar -xzvf " v $SFNTWOFF_VERSION .tar.gz "
cd " $SFNTWOFF " || exit 1
echo "#####"
echo " Build $SFNTWOFF . "
echo "#####"
make
2017-08-26 05:40:43 +03:00
# make Hack repository the current directory again following the build
cd " $CUR_DIR " || exit 1
2017-08-25 07:06:10 +03:00
fi
if [ -f " $SFNTWOFF_BIN " ] ; then
echo " Beginning web font build with $SFNTWOFF "
else
2017-09-21 06:06:52 +03:00
echo " Unable to locate sfnt2woff-zopfli on the path $SFNTWOFF_BIN . Please attempt a manual install of this build dependency and then repeat your build attempt. " 1>& 2
2017-08-25 07:06:10 +03:00
exit 1
fi
2017-08-25 23:46:58 +03:00
# Build woff files from ttf files
# regular set
2017-08-26 06:45:40 +03:00
if ! " $SFNTWOFF_BIN " -n $ZOPFLI_ITERATIONS " $TTF_BUILD / $REGULAR_TTF " ; then
2017-08-25 23:46:58 +03:00
echo " Failed to build $REGULAR_WOFF from $REGULAR_TTF . " 1>& 2
exit 1
else
2017-08-26 05:40:43 +03:00
echo " Regular woff set successfully built from $REGULAR_TTF "
2017-08-25 23:46:58 +03:00
fi
# bold set
2017-08-26 06:45:40 +03:00
if ! " $SFNTWOFF_BIN " -n $ZOPFLI_ITERATIONS " $TTF_BUILD / $BOLD_TTF " ; then
2017-08-25 23:46:58 +03:00
echo " Failed to build $BOLD_WOFF from $BOLD_TTF " 1>& 2
exit 1
else
2017-08-26 05:40:43 +03:00
echo " Bold woff set successfully built from $BOLD_TTF "
fi
2017-08-25 23:46:58 +03:00
# italic set
2017-08-26 06:45:40 +03:00
if ! " $SFNTWOFF_BIN " -n $ZOPFLI_ITERATIONS " $TTF_BUILD / $ITALIC_TTF " ; then
2017-08-25 23:46:58 +03:00
echo " Failed to build $BOLD_WOFF from $ITALIC_TTF " 1>& 2
exit 1
else
2017-08-26 05:40:43 +03:00
echo " Italic woff set successfully built from $ITALIC_TTF "
2017-08-25 23:46:58 +03:00
fi
# bold italic set
2017-08-26 06:45:40 +03:00
if ! " $SFNTWOFF_BIN " -n $ZOPFLI_ITERATIONS " $TTF_BUILD / $BOLDITALIC_TTF " ; then
2017-08-25 23:46:58 +03:00
echo " Failed to build $BOLDITALIC_WOFF from $BOLDITALIC_TTF " 1>& 2
exit 1
else
2017-08-26 05:40:43 +03:00
echo " Bold Italic woff set successfully built from $BOLDITALIC_TTF "
2017-08-25 23:46:58 +03:00
fi
2017-08-26 05:40:43 +03:00
echo "Moving woff files to build directory..."
2017-08-30 06:17:46 +03:00
# create directory if it does not exist
# (occurs with git + empty directories)
if ! [ -d " $WOFF_BUILD " ] ; then
mkdir $WOFF_BUILD
fi
2017-08-25 23:46:58 +03:00
# move woff files to appropriate build directory
mv " $TTF_BUILD / $REGULAR_PRE " " $WOFF_BUILD / $REGULAR_WOFF "
mv " $TTF_BUILD / $BOLD_PRE " " $WOFF_BUILD / $BOLD_WOFF "
mv " $TTF_BUILD / $ITALIC_PRE " " $WOFF_BUILD / $ITALIC_WOFF "
mv " $TTF_BUILD / $BOLDITALIC_PRE " " $WOFF_BUILD / $BOLDITALIC_WOFF "
echo " "
if [ -f " $WOFF_BUILD / $REGULAR_WOFF " ] ; then
2017-08-26 05:40:43 +03:00
echo " Regular woff build path: $WOFF_BUILD / $REGULAR_WOFF "
2017-08-25 23:46:58 +03:00
fi
if [ -f " $WOFF_BUILD / $BOLD_WOFF " ] ; then
2017-08-26 05:40:43 +03:00
echo " Bold woff build path: $WOFF_BUILD / $BOLD_WOFF "
2017-08-25 23:46:58 +03:00
fi
if [ -f " $WOFF_BUILD / $ITALIC_WOFF " ] ; then
2017-08-26 05:40:43 +03:00
echo " Italic woff build path: $WOFF_BUILD / $ITALIC_WOFF "
2017-08-25 23:46:58 +03:00
fi
if [ -f " $WOFF_BUILD / $BOLDITALIC_WOFF " ] ; then
2017-08-26 05:40:43 +03:00
echo " Bold Italic woff build path: $WOFF_BUILD / $BOLDITALIC_WOFF "
2017-08-25 23:46:58 +03:00
fi
2017-08-25 07:06:10 +03:00