#!/bin/bash

# This script rebuilds the algorithmically-generated ftml files.

set -e

if [ ! -f wscript ]
then
	echo "Must be in the root of the project"
	exit 2
fi

# configure tests
tests="AllChars Matras"
urls='url(../references/DaiBannaSIL-Light.ttf)=RefL url(../references/DaiBannaSIL-Bold.ttf)=RefB url(../references/DaiBannaSIL-LightItalic.ttf)=RefLI url(../references/DaiBannaSIL-BoldItalic.ttf)=RefBI url(../results/DaiBannaSIL-Light.ttf)=L url(../results/DaiBannaSIL-Bold.ttf)=B url(../results/DaiBannaSIL-LightItalic.ttf)=LI url(../results/DaiBannaSIL-BoldItalic.ttf)=BI url(../references/Nokyung-Regular.ttf)=Nokyung url(../references/NotoSansNewTaiLue-Regular.ttf)=Noto'
ufo='source/masters/DaiBannaSIL-Light.ufo'

# list all the fonts to test
fonts=''
for url in $urls
do
	fonts="$fonts -s '$url'"
done

echo "Rebuilding ftml files..."
for test in $tests
do
	base=${test,,}
	title="\"${test} auto\""
	ftml=tests/${base}.ftml
	log=tests/logs/${base}.log
	eval tools/psfgenftml.py -q -t "$title" --norendercheck --scale 200 -i source/glyph_data.csv --xsl ../tools/ftml.xsl "$fonts" -l $log $ufo $ftml &
done
wait
echo "done."
