283 lines
8.4 KiB
Bash
283 lines
8.4 KiB
Bash
#! /bin/bash
|
|
#
|
|
# Multi-channel signed distance field atlas generator
|
|
# This is a utility for generating compact font atlases using MSDFgen.
|
|
#
|
|
# The atlas generator loads a subset of glyphs from a TTF or OTF font file,
|
|
# generates a distance field for each of them, and tightly packs them into
|
|
# an atlas bitmap (example below). The finished atlas and/or its layout
|
|
# metadata can be exported as an Artery Font file, a plain image file,
|
|
# a CSV sheet or a structured JSON file.
|
|
# https://github.com/Chlumsky/msdf-atlas-gen
|
|
#
|
|
# it uses cmake build system, and depends on msdfgen (also downloaded)
|
|
#
|
|
# linux notes:
|
|
# should you not have libtinyxml2-dev installed with cmake files
|
|
# check with for example (Debian, Ubuntu): dpkg -L libtinyxml2-dev
|
|
# if cmake files are present
|
|
#
|
|
# if not then install libtinyxml2 from https://github.com/leethomason/tinyxml2.git
|
|
#
|
|
# for example:
|
|
# $ cd your/favorite/persistent/build/directory
|
|
# $ git clone https://github.com/leethomason/tinyxml2.git
|
|
# $ cd tinyxml2
|
|
# $ mkdir build && cd build
|
|
# $ cmake ..
|
|
# $ make
|
|
# $ sudo make install
|
|
#
|
|
# emscripten notes:
|
|
# additionally to the depencies below
|
|
# you may have to build freetype from source
|
|
# and with that also bzip2
|
|
# $
|
|
# $ # tinyxml2:
|
|
# $ cd your/favorite/persistent/build/directory
|
|
# $ git clone https://github.com/leethomason/tinyxml2.git
|
|
# $ cd tinyxml2
|
|
# $ mkdir build && cd build
|
|
# $ emcmake cmake ..
|
|
# $ emmake make
|
|
# $ emmake make install
|
|
# $
|
|
# $ # zlib:
|
|
# $ cd your/favorite/persistent/build/directory
|
|
# $ wget https://www.zlib.net/zlib-1.2.13.tar.gz
|
|
# $ tar -xf zlib-1.2.13.tar.gz
|
|
# $ cd zlib-1.2.13.tar.gz
|
|
# $ mkdir build && cd build
|
|
# $ emcmake cmake ..
|
|
# $ emmake make
|
|
# $ emmake make install
|
|
# $
|
|
# $ # libpng:
|
|
# $ cd your/favorite/persistent/build/directory
|
|
# $ wget https://sourceforge.net/projects/libpng/files/libpng16/1.6.39/libpng-1.6.39.tar.xz/download -O libpng-1.6.39.tar.xz
|
|
# $ tar -xf libpng-1.6.39.tar.xz
|
|
# $ cd libpng-1.6.39
|
|
# $ mkdir build && cd build
|
|
# $ emcmake cmake ..
|
|
# $ emmake make
|
|
# $ emmake make install
|
|
|
|
|
|
# array of build types supported by this formula
|
|
# you can delete this to implicitly support *all* types
|
|
FORMULA_TYPES=( "osx" "linux" "linux64" "vs" "msys2" "ios" "android" "emscripten" )
|
|
|
|
# define the version
|
|
VER=1.2.2
|
|
|
|
# tools for git use
|
|
GIT_URL=https://github.com/Chlumsky/msdf-atlas-gen.git
|
|
GIT_TAG="v${VER}"
|
|
|
|
# bash utilities
|
|
YES=0
|
|
NO=1
|
|
PROBABLY_YES=$YES
|
|
PROBABLY_NOT=$NO
|
|
REMEMBORY_AUTOPILOT=$NO
|
|
THIRDPARTY_BUILD_DIRECTORY="thirdparty"
|
|
|
|
decision() {
|
|
# get default
|
|
if [ "$2" = "$YES" ]; then
|
|
default="yes"
|
|
else
|
|
default="no"
|
|
fi
|
|
|
|
# should we go autopilot
|
|
if [ "${REMEMBORY_AUTOPILOT}" = "$YES" ];
|
|
then
|
|
echo "$1? -> $default"
|
|
return $2
|
|
fi
|
|
|
|
echo ""
|
|
echo "$0 NEEDS A DECISION"
|
|
echo ""
|
|
echo "> $1?"
|
|
read -r -p "> Do you want? [y]es / [n]o / [d]efault ($default): " input
|
|
|
|
case $input in
|
|
[yY][eE][sS]|[yY])
|
|
return $YES
|
|
;;
|
|
[nN][oO]|[nN])
|
|
return $NO
|
|
;;
|
|
[dD])
|
|
return "$2" = "$YES"
|
|
;;
|
|
*)
|
|
return $NO
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# download the source code and unpack it into LIB_NAME
|
|
function download() {
|
|
echo "download msdf-atlas-gen"
|
|
wget --quiet https://pointer.click/files/msdf-atlas-gen.tar.gz -O msdf-atlas-gen.tar.gz
|
|
mkdir -p msdf-atlas-gen
|
|
tar -xzf msdf-atlas-gen.tar.gz -C msdf-atlas-gen --strip-components=1
|
|
rm msdf-atlas-gen.tar.gz
|
|
}
|
|
|
|
# prepare the build environment, executed inside the lib src dir
|
|
function prepare() {
|
|
mkdir -p lib/$TYPE
|
|
|
|
PREV_DIR="$(pwd)"
|
|
|
|
if [ "$TYPE" == "emscripten" ] ; then
|
|
echo "preparing $TYPE thirdparty dependencies"
|
|
if decision "download, build and install all thirdparty dependencies" $PROBABLY_YES; then
|
|
REMEMBORY_AUTOPILOT=$YES
|
|
fi
|
|
if decision "download and build tinyxml2 for $TYPE" $PROBABLY_YES; then
|
|
mkdir -p "thirdparty"
|
|
cd "thirdparty"
|
|
if [ -d "tinyxml2" ] ; then
|
|
echo "apparently already done"
|
|
else
|
|
git clone --depth=1 https://github.com/leethomason/tinyxml2.git
|
|
cd tinyxml2
|
|
mkdir build && cd build
|
|
emcmake cmake ..
|
|
emmake make
|
|
emmake make install
|
|
fi
|
|
cd "$PREV_DIR"
|
|
fi
|
|
if decision "download and build zlib for $TYPE" $PROBABLY_YES; then
|
|
mkdir -p "thirdparty"
|
|
cd "thirdparty"
|
|
if [ -d "zlib" ] ; then
|
|
echo "apparently already done"
|
|
else
|
|
wget https://pointer.click/files/zlib-1.3.1.tar.gz
|
|
mkdir -p zlib
|
|
tar -xzf zlib-1.3.1.tar.gz -C zlib --strip-components=1
|
|
cd zlib
|
|
mkdir build && cd build
|
|
emcmake cmake ..
|
|
emmake make
|
|
emmake make install
|
|
fi
|
|
cd "$PREV_DIR"
|
|
fi
|
|
if decision "download and build libpng for $TYPE" $PROBABLY_YES; then
|
|
mkdir -p "thirdparty"
|
|
cd "thirdparty"
|
|
if [ -d "libpng-1.6.39" ] ; then
|
|
echo "apparently already done"
|
|
else
|
|
wget https://sourceforge.net/projects/libpng/files/libpng16/1.6.39/libpng-1.6.39.tar.xz/download -O libpng-1.6.39.tar.xz
|
|
tar -xf libpng-1.6.39.tar.xz
|
|
cd libpng-1.6.39
|
|
mkdir build && cd build
|
|
emcmake cmake ..
|
|
emmake make
|
|
emmake make install
|
|
fi
|
|
cd "$PREV_DIR"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# executed inside the lib src dir
|
|
function build() {
|
|
if [ "$TYPE" == "linux64" ] ; then
|
|
cd lib/$TYPE
|
|
cmake \
|
|
-DMSDF_ATLAS_BUILD_STANDALONE=OFF \
|
|
-DMSDF_ATLAS_USE_VCPKG=OFF \
|
|
-DMSDF_ATLAS_USE_SKIA=OFF \
|
|
-DMSDF_ATLAS_NO_ARTERY_FONT=OFF \
|
|
-DMSDF_ATLAS_MSDFGEN_EXTERNAL=OFF \
|
|
-DMSDF_ATLAS_INSTALL=OFF \
|
|
-DMSDF_ATLAS_DYNAMIC_RUNTIME=OFF \
|
|
-DBUILD_SHARED_LIBS=OFF \
|
|
-DMSDFGEN_CORE_ONLY=OFF \
|
|
-DMSDFGEN_BUILD_STANDALONE=OFF \
|
|
-DMSDFGEN_USE_VCPKG=OFF \
|
|
-DMSDFGEN_USE_OPENMP=OFF \
|
|
-DMSDFGEN_USE_CPP11=ON \
|
|
-DMSDFGEN_USE_SKIA=OFF \
|
|
-DMSDFGEN_INSTALL=OFF \
|
|
-DMSDFGEN_DYNAMIC_RUNTIME=OFF \
|
|
../..
|
|
make
|
|
elif [ "$TYPE" == "emscripten" ] ; then
|
|
cd lib/$TYPE
|
|
emcmake cmake \
|
|
-DCMAKE_CXX_FLAGS="-pthread" \
|
|
-DMSDF_ATLAS_BUILD_STANDALONE=OFF \
|
|
-DMSDF_ATLAS_USE_VCPKG=OFF \
|
|
-DMSDF_ATLAS_USE_SKIA=OFF \
|
|
-DMSDF_ATLAS_NO_ARTERY_FONT=OFF \
|
|
-DMSDF_ATLAS_MSDFGEN_EXTERNAL=OFF \
|
|
-DMSDF_ATLAS_INSTALL=OFF \
|
|
-DMSDF_ATLAS_DYNAMIC_RUNTIME=OFF \
|
|
-DBUILD_SHARED_LIBS=OFF \
|
|
-DMSDFGEN_CORE_ONLY=OFF \
|
|
-DMSDFGEN_BUILD_STANDALONE=OFF \
|
|
-DMSDFGEN_USE_VCPKG=OFF \
|
|
-DMSDFGEN_USE_OPENMP=OFF \
|
|
-DMSDFGEN_USE_CPP11=ON \
|
|
-DMSDFGEN_USE_SKIA=OFF \
|
|
-DMSDFGEN_INSTALL=OFF \
|
|
-DMSDFGEN_DYNAMIC_RUNTIME=OFF \
|
|
../..
|
|
emmake make
|
|
else
|
|
echoWarning "TODO: $TYPE build"
|
|
fi
|
|
}
|
|
|
|
# executed inside the lib src dir, first arg $1 is the dest libs dir root
|
|
function copy() {
|
|
if [ "$TYPE" == "linux64" ] || [ "$TYPE" == "emscripten" ] ; then
|
|
# lib
|
|
cd lib/$TYPE
|
|
dest_lib=$1/lib/$TYPE
|
|
mkdir -p $dest_lib
|
|
find . -iname "*.a" -exec cp {} $dest_lib/ \;
|
|
|
|
# include
|
|
cd ../..
|
|
dest_include=$1/include
|
|
mkdir -p $dest_include
|
|
mkdir -p $1/license
|
|
cp LICENSE.txt $1/license/
|
|
cp ./*.h $dest_include/
|
|
cp -r artery-font-format $dest_include/
|
|
cp -r msdfgen $dest_include/
|
|
rm -rf $dest_include/msdfgen/cmake
|
|
cp -r msdf-atlas-gen $dest_include/
|
|
|
|
# post
|
|
sed -i 's/MSDFGEN_PUBLIC //g' $dest_include/msdfgen/core/generator-config.h
|
|
sed -i 's/MSDF_ATLAS_PUBLIC //g' $dest_include/msdf-atlas-gen/Charset.h
|
|
else
|
|
echoWarning "TODO: $TYPE copy"
|
|
fi
|
|
}
|
|
|
|
# executed inside the lib src dir
|
|
function clean() {
|
|
if [ "$TYPE" == "linux64" ] ; then
|
|
cd lib/$TYPE
|
|
make clean
|
|
elif [ "$TYPE" == "emscripten" ] ; then
|
|
cd lib/$TYPE
|
|
emmake make clean
|
|
else
|
|
echoWarning "TODO: $TYPE clean"
|
|
fi
|
|
}
|