#!/bin/sh
# $Id: pfbgen-t2d.sh,v 1.5 2010/07/19 11:12:34 isao Exp $
#
# Cyrillic LH Fonts Generation into Type1: T2D all families
# using mftrace 1.2.16 and t1binary.
# 2006(c) isao yasuda, All Rights Reserved.
#

# CAUTION 
# -------
# The processing of this script will cost about 7.5 hours
# in the executing condition: 1.8 GHz PowerMac G5 with 1 GB DDR. 

# Fonts with genb
# font family type 1: 0500-3583
# cmr cmss cmdh cmfib cmfr
GENB1="0500 0600 0700 0800 0900 1000 1095 1200 1440 1728 2074 2488 2986 3583"
FFT1="ldrm ldsl ldti ldcc ldbx ldrb ldbi ldbl ldxc ldui ldss ldsi ldsx ldso \
lddh ldci ldoc ldsc"

# font family type 2: 0500-2074
# cmfib
GENB2="0500 0600 0700 0800 0900 1000 1095 1200 1440 1728 2074"
FFT2="ldfb ldfs"

# font family type 3: 0900-3583
# cmfr
GENB3="0900 1000 1095 1200 1440 1728 2074 2488 2986 3583"
FFT3="ldff ldfi"

# font family type 4: 0800-3583
# cmtt cmvtt
GENB4="0800 0900 1000 1095 1200 1440 1728 2074 2488 2986 3583"
FFT4="ldtt ldst ldit ldtc ldvt ldvi"

# Fonts without genb
# font family type 5: non genb
# cmss cmbr cmtl lcmss lcmtt ccr
FFT5="ldssdc10 ldbmr8 ldbmr9 ldbmr10 ldbmr17 ldbmo8 ldbmo9 ldbmo10 ldbmo17 \
ldbsr8 ldbsr9 ldbsr10 ldbsr17 ldbso8 ldbso9 ldbso10 ldbso17 ldbbx10 ldbtl10 \
ldbto10 ldlq8 ildlq8 ldli8 ildli8 ldlb8 ildlb8 ldlo8 ildlo8 ldltt8 ildltt8 \
ldorm5 ldorm6 ldorm7 ldorm8 ldorm9 ldorm10 \
ldosl5 ldosl6 ldosl7 ldosl8 ldosl9 ldosl10 \
ldoti10 ldocc10"

# Map file
MAPF="cyrillic-t2d.map"

# Encoding file
ENCF="t2d.enc"

# starting.
echo "* T2D Type1 fonts generation started at `date`."
touch $MAPF

# font list generation
FLIST=""
# type 1 list
for i in $FFT1; do for j in $GENB1; do FLIST="$FLIST $i$j"; done; done
# type 2 list
for i in $FFT2; do for j in $GENB2; do FLIST="$FLIST $i$j"; done; done
# type 3 list
for i in $FFT3; do for j in $GENB3; do FLIST="$FLIST $i$j"; done; done
# type 4 list
for i in $FFT4; do for j in $GENB4; do FLIST="$FLIST $i$j"; done; done
# type 5 list
FLIST="$FLIST $FFT5"

# T2D Computer Modern Type1 Fonts generation
# cmr, cmtt, cmss, cmbr, cmdh, cmfib, cmfr, cmtl, cmvtt, lcmss, lcmtt
for i in $FLIST
do
	# When return code == 0 (mftrace normal end)
	# - break and go to processing of the next fonts
	# When return code != 0 (mftrace abnormal end)
	# - decrease mag by  10 and retry mftrace
	mag=830
	while [ $mag -ne 0 ]
	do
		echo "* $i try --magnification=$mag --encoding=$ENCF"
		mftrace --magnification=$mag --encoding=$ENCF $i
		if [ $? -eq 0 ]
		then
			echo "* mftrace $i pfa gen succeeded at $mag magnification."
			t1binary $i.pfa $i.pfb
			echo "* t1binary $i pfb gen succeeded."
			rm -f $i.pfa
			echo "$i $i <$i.pfb" >> $MAPF
			mag=0
		else
			mag=`expr $mag - 10`
		fi
	done
done
echo "* T2D Type1 fonts generation ended at `date`."

