Linux下CJK的UTF8字体配置

搜索了好些, 找到李果正的脚本很好用. 是以为志.
#!/bin/sh
#
# Origin By Edward G.J. Lee 2001.11.25
# http://www.study-area.org/tips/latex/pdftex.html
# This code is Public Domain.
#
# Enhanced by intron@intron.ac, 2006.1.9
# Modified for NetBSD by jungle@soforge.com, 2006.1.14
# Italic support added by robert.zhangle@gmail.com, 2006.5.19
#

if [ $# -ne 3 ]
then
   cat << EOF
Usage: `basename $0` font.ttf <TeX_Internal_Font_Name> <Tex_Font_Name>
 <TeX_Internal_Font_Name>: Used to name *.enc, *.afm, *.pfb, *.tfm & *.map
 <Tex_Font_Name>: Used in TeX source:   \CJKencfamily{UTF8}{Tex_Font_Name}

 An example:  `basename $0`  gbsn00lp.ttf gbsn00lp songpt1

EOF

   exit 1
fi

if ! which ttf2pt1; then
   echo "Please install pkgsrc fonts/ttf2pt1 before you can run me."
   exit 1
fi

if ! which t1asm; then
   echo "Please install pkgsrc fonts/t1utils before you can run me."
   exit 1
fi

if ! which extconv; then
   echo "Please install pkgsrc chinese/CJK before you can run me."    exit 1
fi


cat <<EOF
***************************************************************************
* Please confirm that current working directory is EMPTY except scripts   *
* and HAS ENOUGH SPACE to contain so many intermediate files.             *
* If it is not empty, this script may DAMAGE INNOCENT FILES!!!            *
***************************************************************************
EOF

read -p "Go ahead?[n]" a

if [ "$a" != "y" ] && [ "$a" != "Y" ]; then
   exit 0
fi

FONTFILENAME="$1"
FONTNAME="$2"
FONTTEXNAME="$3"

TEXMFHOME=`kpsexpand '$TEXMFHOME'`
ENCDIR=${TEXMFHOME}/fonts/enc/dvips/local/${FONTNAME}
AFMDIR=${TEXMFHOME}/fonts/afm/local/${FONTNAME}
TFMDIR=${TEXMFHOME}/fonts/tfm/local/${FONTNAME}
PFBDIR=${TEXMFHOME}/fonts/type1/local/${FONTNAME}
MAPDIR=${TEXMFHOME}/fonts/map/dvips/local

UPDMAPCFG=${TEXMFHOME}/web2c/updmap.cfg

if [ ! -f $UPDMAPCFG ]
then
   SYSUPDMAPCFG=`kpsewhich -format 'web2c files' updmap.cfg`    cp $SYSUPDMAPCFG $UPDMAPCFG
fi

CIDXMAP=${TEXMFHOME}/dvipdfm/config/cid-x.map

if [ ! -f $CIDXMAP ]
then
   touch $CIDXMAP
fi

CJKDIR=${TEXMFHOME}/tex/latex/CJK/UTF8

INSTALLDIRMODE="-m 0755"
INSTALLMODE="-m 0644"

FONTFILEBASENAME=`basename "$FONTFILENAME"`
FDNAME=c70${FONTTEXNAME}.fd

#MAPFILE=/usr/local/share/ttf2pt1/maps/cugb.map
PLANENUM=255

# Initialize ${FONTNAME}.map
echo -n "" > ${FONTNAME}.map


n=0

echo "Generating subfonts from plane $n to plane $PLANENUM ..."

while [ $n -le $PLANENUM ]
do
   m=`printf %02x $n`

   echo -n "[$n]"

   SUBFONTNAME=${FONTNAME}${m}

 # Generate *.t1a *.afm *.enc
    ttf2pt1 -GAE -pft -OHUBs -W0 -l plane+pid=3,eid=1,0x$m         "$FONTFILENAME" ${SUBFONTNAME}

 # avoid dvips(k)(before v5.86) t1part module bug.
    perl -pi -e 's/_/Z/g' ${SUBFONTNAME}.t1a ${SUBFONTNAME}.afm

 # Generate *.pfb
    t1asm -b ${SUBFONTNAME}.t1a > ${SUBFONTNAME}.pfb 2>/dev/null

 # Generate *.tfm
    afm2tfm ${FONTNAME}$m.afm ${FONTNAME}$m.tfm >/dev/null
   afm2tfm ${FONTNAME}$m.afm -s .167 ${FONTNAME}sl$m.tfm >/dev/null

 # Generate ${FONTNAME}.map
    AFMNAME=`grep -m 1 -i fontname ${SUBFONTNAME}.afm | cut -d ' ' -f 2`
   echo "${FONTNAME}$m ${AFMNAME}  <${FONTNAME}$m.pfb" >> ${FONTNAME}.map
   echo "${FONTNAME}sl$m ${AFMNAME} \" .167 SlantFont \" <${FONTNAME}$m.pfb"         >> ${FONTNAME}.map

   n=`expr $n + 1`
done

echo

cat > ${FDNAME} << EOF
% This file is automatically generated by `basename $0`
\\def\\fileversion{0.0.1}
\\def\\filedate{`date +%Y/%m/%d`}
\\ProvidesFile{${FDNAME}}[\\filedate\\space\\fileversion]

\\DeclareFontFamily{C70}{${FONTTEXNAME}}{\\hyphenchar \\font\\m@ne}

\\DeclareFontShape{C70}{${FONTTEXNAME}}{m}{n}{<-> CJK * ${FONTNAME}}{}
\\DeclareFontShape{C70}{${FONTTEXNAME}}{bx}{n}{<-> CJKb * ${FONTNAME}}{\\CJKbold}
\\DeclareFontShape{C70}{${FONTTEXNAME}}{m}{it}{<-> CJK * ${FONTNAME}sl}{}
\\DeclareFontShape{C70}{${FONTTEXNAME}}{bx}{it}{<-> CJKb * ${FONTNAME}sl}{\\CJKbold}
\\DeclareFontShape{C70}{${FONTTEXNAME}}{m}{sl}{<-> CJK * ${FONTNAME}sl}{}
\\DeclareFontShape{C70}{${FONTTEXNAME}}{bx}{sl}{<-> CJKb * ${FONTNAME}sl}{\\CJKbold}

\\endinput
EOF


#exit 0;

echo
echo "Installing ..."

install -d $INSTALLDIRMODE $ENCDIR $AFMDIR $TFMDIR $PFBDIR $MAPDIR $CJKDIR

n=0
while [ $n -le $PLANENUM ]
do
   m=`printf %02x $n`
   echo -n "[$n]"

   install $INSTALLMODE ${FONTNAME}${m}.enc $ENCDIR
   install $INSTALLMODE ${FONTNAME}${m}.afm $AFMDIR
   install $INSTALLMODE ${FONTNAME}${m}.tfm $TFMDIR
   install $INSTALLMODE ${FONTNAME}sl${m}.tfm $TFMDIR
   install $INSTALLMODE ${FONTNAME}${m}.pfb $PFBDIR

   n=`expr $n + 1`
done

echo

install $INSTALLMODE ${FONTNAME}.map $MAPDIR
install $INSTALLMODE $FDNAME $CJKDIR

echo >> $UPDMAPCFG
echo "Map ${FONTNAME}.map" >> $UPDMAPCFG

# update cid-x.map

echo "${FONTNAME}@Unicode@    unicode    :0:${FONTFILENAME}" >> $CIDXMAP
echo "${FONTNAME}sl@Unicode@    unicode    :0:${FONTFILENAME}" >> $CIDXMAP

mktexlsr

#updmap-sys
updmap

read -p "Do you want remove all intermediate files?[n]" a
if [ "$a" = "y" ] || [ "$a" = "Y" ]; then

   n=0
   while [ $n -le $PLANENUM ]
   do
       m=`printf %02x $n`
       echo -n "[$n]"

       rm -f ${FONTNAME}${m}.enc ${FONTNAME}${m}.afm ${FONTNAME}${m}.t1a             ${FONTNAME}${m}.pfb ${FONTNAME}sl${m}.tfm ${FONTNAME}${m}.tfm

       n=`expr $n + 1`
   done

   echo

   rm -fv $FDNAME ${FONTNAME}.map
fi

echo
echo "OK, all done. :-)"
echo

又写了个删除字体的脚本:

#!/bin/sh
##
## cvtremovefont.sh
##
## Made by Changsheng Jiang
## Login   <pointer@localhost.localdomain>
##
## Started on  Sun Jun 11 03:14:26 2006 Changsheng Jiang
## Last update Sun Jun 11 03:14:26 2006 Changsheng Jiang
##

if [ $# -ne 2 ]
then
   cat << EOF
Usage: `basename $0` <TeX_Internal_Font_Name> <Tex_Font_Name>

 An example:  `basename $0` gbsn00lp songpt1

EOF

   exit 1
fi


FONTNAME="$1"
FONTTEXNAME="$2"

TEXMFHOME=`kpsexpand '$TEXMFHOME'`
ENCDIR=${TEXMFHOME}/fonts/enc/dvips/local/${FONTNAME}
AFMDIR=${TEXMFHOME}/fonts/afm/local/${FONTNAME}
TFMDIR=${TEXMFHOME}/fonts/tfm/local/${FONTNAME}
PFBDIR=${TEXMFHOME}/fonts/type1/local/${FONTNAME}
MAPDIR=${TEXMFHOME}/fonts/map/dvips/local

UPDMAPCFG=${TEXMFHOME}/web2c/updmap.cfg
CIDXMAP=${TEXMFHOME}/dvipdfm/config/cid-x.map

CJKDIR=${TEXMFHOME}/tex/latex/CJK/UTF8

FDNAME=c70${FONTTEXNAME}.fd

rm -rf $ENCDIR $AFMDIR $TFMDIR $PFBDIR
rm -f $CJKDIR/$FDNAME $MAPDIR/${FONTTEXNAME}.map

perl -pi -e "s/Map ${FONTTEXNAME}.map//g" $UPDMAPCFG

perl -pi -e "s/^${FONTTEXNAME}(|sl)@Unicode@ .*\$//g" $CIDXMAP

No comments: