#!/bin/sh
#
# This script will convert all PFA and AFM files in the current directory
# and its subdirectories into PFB and TFM files. Additionally, it normalizes
# the font matrix so that the subfonts work with pdfTeX.
#
# The programs t1asm, t1disasm, and afm2tfm must be in the path.

for f in `find . -name '*.pfa' -print`; do
  echo processing $f
  name=`basename $f .pfa`
  t1disasm < $name.pfa > $name.old

  cat $name.old | \
  sed -e "
    s/\[.001 0 0 .001 0 -0.16\]/[.001 0 0 .001 0 0]/
    s/\[0 0 1000 1000\]/[0 -160 1000 840]/
    /hsbw/ a\\
	0 -160 rmoveto
  " > $name.asm
  rm $name.old

  t1asm < $name.asm > $name.pfb
  rm $name.asm
done

for f in `find . -name '*.afm' -print`; do
  echo processing $f
  name=`basename $f .afm`
  mv $name.afm $name.old

  cat $name.old | \
  sed -e "
      s/FontBBox 0 0 1000 1000/FontBBox 0 -160 1000 840/
      s/B 0 0 1000 1000/B 0 -160 1000 840/
  " > $name.afm

  rm $name.old

  afm2tfm $name.afm &> /dev/null
done

# EOF
