#!/bin/sh

PERL=${PERL:-perl}

if [ $1 = 'nopfa' ]; then
  DOPFA=false
  shift
else
  DOPFA=true
fi

echo '  working on encodings...'
# We don't really need a downloadable version of AdobeStandardEncoding
for encoding 
  in adobe ogonki latin1 latin2 latin3 latin4 latin5 latin6 latin7 latin9 \
  cp1250 ibmpc mac hp
do
  $PERL ./composeglyphs -e ${encoding}.afm -E ${encoding}.enc
done

encoding=ogonki
targetEncoding=adobe

echo '  working on fonts...'
# Notice there are literal tabs in the following lines
# Welcome to the wonderful world of `everything is a stream of bytes'.
for filename in `sed 's/	.*$//' fontname.dat` ; do
  fontname=`grep "${filename}	" fontname.dat | sed 's/^.*	//'`
  $PERL ./composeglyphs -i ${filename}.afm -c ${filename}-c.afm \
    -o ${filename}-o.ps -n ${fontname}-Ogonki \
    -a ${filename}-o.afm -e ${encoding}.afm \
    -t ${targetEncoding}.afm
  if $DOPFA ; then
    cat ${encoding}.enc ${targetEncoding}.enc compose.ps \
      ${filename}-o.ps \
        >${filename}-o.pfa
  fi
done
