#!/bin/sh
# $Id: pfbgen-ot2.sh,v 1.5 2010/07/19 11:28:41 isao Exp $
#
# Cyrillic LH Fonts Generation into Type1: OT2 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 2 hours
# in the executing condition: 1.8 GHz PowerMac G5 with 1 GB DDR. 

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

# Encoding file
ENCF="cm-lgc-ot2.enc"

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

# OT2 Computer Modern Fonts pfa generation
# cmr, cmtt, cmss, cmbr, cmdh, cmfib, cmfr, cmtl, cmvtt, lcmss, lcmtt
for i in \
    wnr5 wnr6 wnr7 wnr8 wnr9 wnr10 wnr12 wnr17 wnsl8 wnsl9 wnsl10 wnsl12 \
	wnti7 wnti8 wnti9 wnti10 wnti12 wncsc10 wnu10 wnb10 \
	wnbx5 wnbx6 wnbx7 wnbx8 wnbx9 wnbx10 wnbx12 wnbxsl10 wnbxti10 \
	wntt8 wntt9 wntt10 wntt12 wnitt10 wnsltt10 wntcsc10 \
	wnss8 wnss9 wnss10 wnss12 wnss17 \
	wnssi8 wnssi9 wnssi10 wnssi12 wnssi17 wnssdc10 wnssbx10 \
	wnbr8 wnbr9 wnbr10 wnbr17 wnbrsl8 wnbrsl9 wnbrsl10 wnbrsl17 \
	wnbrbx10 wndunh10 wnfib8 wnff10 wnfi10 wntl10 wnsltl10 \
	wnvtt10 wnvtti10 lwnss8 lwnssi8 lwnssb8 iwntt8
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 100 and retry while mag is under 3000 and beyond 1000
	# - decrease mag by  10 and retry while mag is under 1000
	mag=3000
	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
			if [ $mag -gt 1000 ]
			then
				mag=`expr $mag - 100`
			else
				mag=`expr $mag - 10`
			fi
		fi
	done
done
echo "* OT2 Type1 fonts generation ended at `date`."

