#!/bin/sh

TEXMF="./"
VENDOR="linotype"
FONT="palatinox"
MAP="${FONT}.map"

mkdir -p "${TEXMF}/fonts/afm/${VENDOR}/${FONT}/"
mkdir -p "${TEXMF}/fonts/enc/dvips/${FONT}/"
mkdir -p "${TEXMF}/fonts/map/dvips/${FONT}/"
mkdir -p "${TEXMF}/fonts/tfm/${VENDOR}/${FONT}/"
mkdir -p "${TEXMF}/fonts/truetype/${VENDOR}/${FONT}/"
mkdir -p "${TEXMF}/fonts/vf/${VENDOR}/${FONT}/"
mkdir -p "${TEXMF}/tex/latex/${VENDOR}/${FONT}/"

cmap2enc              -x pala.sub pala.ttf t1.enc      
cmap2enc -f pnum      -x pala.sub pala.ttf t1.enc      
cmap2enc -f onum      -x pala.sub pala.ttf t1.enc      
cmap2enc -f smcp      -x pala.sub pala.ttf t1.enc      
cmap2enc -f pnum,smcp -x pala.sub pala.ttf t1.enc      
cmap2enc -f onum,smcp -x pala.sub pala.ttf t1.enc      
cmap2enc -f sups      -x pala.sub pala.ttf t1.enc      

cmap2enc -f onum      -x pala.sub pala.ttf ts1.enc     

ttf2afm -a -h -o pala.afm   pala.ttf
ttf2afm -a -h -o palai.afm  palai.ttf
ttf2afm -a -h -o palab.afm  palab.ttf
ttf2afm -a -h -o palabi.afm palabi.ttf

rm ${MAP}

afm2afm -e t1-tlf-pala.enc     -o Palatino-tlf-t1-raw.afm pala.afm >>${MAP}
afm2afm -e t1-tlf-pala.enc     -o Palatino-Italic-tlf-t1-raw.afm palai.afm >>${MAP}
afm2afm -e t1-tlf-pala.enc     -o Palatino-Bold-tlf-t1-raw.afm palab.afm >>${MAP}
afm2afm -e t1-tlf-pala.enc     -o Palatino-BoldItalic-tlf-t1-raw.afm palabi.afm >>${MAP}
afm2afm -e t1-lf-pala.enc      -o Palatino-lf-t1-raw.afm pala.afm >>${MAP}
afm2afm -e t1-lf-pala.enc      -o Palatino-Italic-lf-t1-raw.afm palai.afm >>${MAP}
afm2afm -e t1-lf-pala.enc      -o Palatino-Bold-lf-t1-raw.afm palab.afm >>${MAP}
afm2afm -e t1-lf-pala.enc      -o Palatino-BoldItalic-lf-t1-raw.afm palabi.afm >>${MAP}
afm2afm -e t1-tosf-pala.enc    -o Palatino-tosf-t1-raw.afm pala.afm >>${MAP}
afm2afm -e t1-tosf-pala.enc    -o Palatino-Italic-tosf-t1-raw.afm palai.afm >>${MAP}
afm2afm -e t1-tosf-pala.enc    -o Palatino-Bold-tosf-t1-raw.afm palab.afm >>${MAP}
afm2afm -e t1-tosf-pala.enc    -o Palatino-BoldItalic-tosf-t1-raw.afm palabi.afm >>${MAP}

afm2afm -e t1-tlf-sc-pala.enc  -o Palatino-tlf-sc-t1-raw.afm pala.afm >>${MAP}
afm2afm -e t1-tlf-sc-pala.enc  -o Palatino-Italic-tlf-sc-t1-raw.afm palai.afm >>${MAP}
afm2afm -e t1-tlf-sc-pala.enc  -o Palatino-Bold-tlf-sc-t1-raw.afm palab.afm >>${MAP}
afm2afm -e t1-tlf-sc-pala.enc  -o Palatino-BoldItalic-tlf-sc-t1-raw.afm palabi.afm >>${MAP}
afm2afm -e t1-lf-sc-pala.enc   -o Palatino-lf-sc-t1-raw.afm pala.afm >>${MAP}
afm2afm -e t1-lf-sc-pala.enc   -o Palatino-Italic-lf-sc-t1-raw.afm palai.afm >>${MAP}
afm2afm -e t1-lf-sc-pala.enc   -o Palatino-Bold-lf-sc-t1-raw.afm palab.afm >>${MAP}
afm2afm -e t1-lf-sc-pala.enc   -o Palatino-BoldItalic-lf-sc-t1-raw.afm palabi.afm >>${MAP}
afm2afm -e t1-tosf-sc-pala.enc -o Palatino-tosf-sc-t1-raw.afm pala.afm >>${MAP}
afm2afm -e t1-tosf-sc-pala.enc -o Palatino-Italic-tosf-sc-t1-raw.afm palai.afm >>${MAP}
afm2afm -e t1-tosf-sc-pala.enc -o Palatino-Bold-tosf-sc-t1-raw.afm palab.afm >>${MAP}
afm2afm -e t1-tosf-sc-pala.enc -o Palatino-BoldItalic-tosf-sc-t1-raw.afm palabi.afm >>${MAP}

afm2afm -e t1-sup-pala.enc     -o Palatino-sup-t1-raw.afm pala.afm >>${MAP}
afm2afm -e t1-sup-pala.enc     -o Palatino-Italic-sup-t1-raw.afm palai.afm >>${MAP}
afm2afm -e t1-sup-pala.enc     -o Palatino-Bold-sup-t1-raw.afm palab.afm >>${MAP}
afm2afm -e t1-sup-pala.enc     -o Palatino-BoldItalic-sup-t1-raw.afm palabi.afm >>${MAP}

afm2afm -e ts1-tosf-pala.enc   -o Palatino-tosf-ts1-raw.afm pala.afm >>${MAP}
afm2afm -e ts1-tosf-pala.enc   -o Palatino-Italic-tosf-ts1-raw.afm palai.afm >>${MAP}
afm2afm -e ts1-tosf-pala.enc   -o Palatino-Bold-tosf-ts1-raw.afm palab.afm >>${MAP}
afm2afm -e ts1-tosf-pala.enc   -o Palatino-BoldItalic-tosf-ts1-raw.afm palabi.afm >>${MAP}

tex Palatino_fnst.tex

for PL in *.pl
do
    pltotf "$PL"
done

for VPL in *.vpl
do
    vptovf "$VPL"
done

rm *.pl *.vpl *.afm Palatino*.mtx resetpala-*.mtx

mv *.afm "${TEXMF}/fonts/afm/${VENDOR}/${FONT}/"
mv *.enc "${TEXMF}/fonts/enc/dvips/${FONT}/"    	  	
mv *.map "${TEXMF}/fonts/map/dvips/${FONT}/"    	  	
mv *.tfm "${TEXMF}/fonts/tfm/${VENDOR}/${FONT}/" 	  	
cp *.ttf "${TEXMF}/fonts/truetype/${VENDOR}/${FONT}/"
mv *.vf	 "${TEXMF}/fonts/vf/${VENDOR}/${FONT}/"
mv *.fd	 "${TEXMF}/tex/latex/${VENDOR}/${FONT}/"
cp *.sty "${TEXMF}/tex/latex/${VENDOR}/${FONT}/"

texhash ${TEXMF}
