Expired
分类: LINUX
2007-09-23 17:09:23
#!/bin/sh
## Texlive 安装目录
TEX_HOME=/usr/tex
## TTF 字体目录
TTF_FONTDIR=/usr/share/fonts/local
echo
if [ ! -e /usr/tex ]; then
echo -e "\n** ERR: TeX home doest not exist ! \n"
exit 1
fi
## 检查 Fontforge 是否安装
FFVER=`fontforge -version 2>/dev/null|awk '{print $2}'`
if [ -z "$FFVER" ]; then
echo -e "** ERR: fontforge program not found ! \n"
exit 1
fi
## 版本检查, 最好使用 2005 版本(3分钟左右/字体)
## 如果使用最新,处理字体信息时会非常慢(30分钟左右/字体)
case $FFVER in
2005*)
echo "Fontforge $FFVER found, Good ! "
;;
*)
echo "** WARNING: not recommended fontforge version: $FFVER ! "
echo -e "It will slow down the process \n"
sleep 1
;;
esac
## 需要添加的字体列表,格式:字体文件名称 字体名
# font list pair:
fontlist=(\
simsun.ttf song \
simhei.ttf hei \
simyou.ttf youyuan \
simli.ttf lishu \
simkai.ttf kai)
total=${#fontlist[*]}
total=`expr $total / 2`
BASEDIR=texmf-var
logfile=`pwd`/logfile
echo "Removing old files ..."
rm -rf $BASEDIR tmp common logfile
rm -rf ~/.texlive2007/$BASEDIR
updmap &> /dev/null
echo "Create essential directory for CJK ..."
mkdir -p $BASEDIR/fonts/map/dvips/CJK/
mkdir -p $BASEDIR/fonts/tfm/CJK/
mkdir -p $BASEDIR/fonts/type1/CJK/
mkdir -p $BASEDIR/tex/latex/CJK/UTF8/
mkdir -p tmp common
cp -f $TEX_HOME/texmf-dist/source/latex/CJK/utils/subfonts/* common
cp -f $TEX_HOME/texmf/fonts/sfd/*.sfd common
> $logfile
echo -e "\nTotal: $total font to be processed ..."
for ((i=0; i< $total; i++)) ; do
index=`expr $i \* 2`
fontfile=${fontlist[$index]}
fontname=${fontlist[$index+1]}
echo -e "\n==== Processing font: $fontfile ($fontname) ===="
rm -rf tmp/*
cp common/* tmp
cd tmp
if [ ! -e $TTF_FONTDIR/$fontfile ]; then
echo "*** ERR: Font: $fontfile does not exist ! "
exit 1
fi
fontforge -script subfonts.pe \
$TTF_FONTDIR/$fontfile $fontname Unicode.sfd >> $logfile
if [ $? -ne 0 ]; then
echo -e "\nError occurs while run the fontforge program ! \n"
exit 1
fi
> $fontname.map
for j in *.tfm; do
cat >> $fontname.map <<-EOF
${j%.tfm} ${j%.tfm} < ${j%.tfm}.pfb
EOF
done
cat > c70${fontname}.fd <<-EOF
% This is c70${fontname}.fd for CJK package.
% created by Edward G.J. Lee
% modify by Yue Wang
\ProvidesFile{c70${fontname}.fd}
\DeclareFontFamily{C70}{${fontname}}{\hyphenchar \font\m@ne}
\DeclareFontShape{C70}{${fontname}}{m}{n}{<-> CJK * ${fontname}}{}
\DeclareFontShape{C70}{${fontname}}{bx}{n}{<-> CJKb * ${fontname}}{\CJKbold}
\endinput
EOF
cp $fontname.map ../$BASEDIR/fonts/map/dvips/CJK/
mkdir -p ../$BASEDIR/fonts/tfm/CJK/$fontname/
mkdir -p ../$BASEDIR/fonts/type1/CJK/$fontname/
cp *.tfm ../$BASEDIR/fonts/tfm/CJK/$fontname/
cp *.pfb ../$BASEDIR/fonts/type1/CJK/$fontname/
cp c70$fontname.fd ../$BASEDIR/tex/latex/CJK/UTF8/
cd ..
echo "Finished process of $fontfile ..."
sleep 1
done
cp -af $BASEDIR ~/.texlive2007
texhash >> $logfile
echo "Update TeX database information ..."
for ((i=0; i< $total; i++)) ; do
index=`expr $i \* 2`
fontname=${fontlist[$index+1]}
updmap --enable Map $fontname.map >> $logfile
done
updmap >> $logfile
mktexlsr >> $logfile
rm -rf tmp common
echo -e "\nAll Done ! for more information, please see $logfile \n"