#!/bin/bash

#unicode="--unicode"

#DESTDIR="$HOME/.mplayer/font/gkai00mp24"

BASENAME="gkai00mp"
SBFONT="arial.ttf"
DBFONT="gkai00mp.ttf"
SBENC="iso-8859-1"
DBENC="encodings/GB2312"

fontsize=24
symbolssize=35
blur=2
outline=1.5

#=======================================================================
# directory for storing temporary splitted encoding files
ENCDIR="/tmp/$$enc"
[ -e "$ENCDIR" ] && { echo "error: $ENCDIR already exist."; exit; }

make || exit

## add single-byte characters (eg, english) first
./subfont $unicode --blur $blur --outline $outline "$SBENC" $fontsize "$SBFONT" || exit

## add double-byte characters (eg, chinese)
# having all characters in one big .raw file does not work.
# so have to split encoding files into smaller parts.
mkdir "$ENCDIR"
split -l 1024 "$DBENC" "$ENCDIR/$BASENAME"

for encoding in "$ENCDIR/$BASENAME"*; do
  ./subfont --append $unicode --blur $blur --outline $outline "$encoding" $fontsize "$DBFONT" || exit
done

# Remove the temporary directory...
pushd .
cd "$ENCDIR" && \rm *
rmdir "$ENCDIR"
popd

## finally add OSD font
./subfont --append --blur $blur --outline $outline encodings/osd-mplayer $symbolssize osd/osd.pfb || exit

exit
[ -d "$DESTDIR" ] || { mkdir "$DESTDIR" || exit; }
mv font.desc *.raw "$DESTDIR"
