2007年8月1日星期三

一个用 ttf2pt1 和 afm2tfm 生成 UTF-8 的字体文件的脚本

一个用 ttf2pt1 和 afm2tfm 生成 UTF-8 的字体文件的脚本
 
#!/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 AT intron DOT ac, 2006.1.9  # Modified for NetBSD by jungle AT soforge DOT com, 2006.1.14  # Italic support added by robert.zhangle AT gmail DOT com, 2006.5.19  #  # Modified for TeXLive 2005 by cyfdecyf AT gmail DOT com 2006.12.23  #    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 ttf2pt1 before you can run me."    exit 1  fi  #if ! which t1asm; then  # echo "Please install t1utils before you can run me."  # exit 1  #fi    if ! which extconv; then    echo "Please 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/chinese/${FONTNAME}  AFMDIR=${TEXMFHOME}/fonts/afm/chinese/${FONTNAME}  TFMDIR=${TEXMFHOME}/fonts/tfm/chinese/${FONTNAME}  PFBDIR=${TEXMFHOME}/fonts/type1/chinese/${FONTNAME}  MAPDIR=${TEXMFHOME}/fonts/map/dvips    UPDMAPCFGDIR=${TEXMFHOME}/web2c  UPDMAPCFG=${UPDMAPCFGDIR}/updmap.cfg    if [ ! -f $UPDMAPCFG ]  then      SYSUPDMAPCFG=`kpsewhich -format 'web2c files' updmap.cfg`      if [ ! -d ${UPDMAPCFGDIR} ]; then  	mkdir -p ${UPDMAPCFGDIR}      fi      cp $SYSUPDMAPCFG $UPDMAPCFG  fi    CIDXMAPDIR=${TEXMFHOME}/fonts/map/dvipdfm/dvipdfmx/  CIDXMAP=${CIDXMAPDIR}/cid-x.map    if [ ! -f $CIDXMAP ]  then      if [ ! -d ${CIDXMAPDIR} ]; then  	mkdir -p ${CIDXMAPDIR}      fi      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 -b -GAEF -p ft -Ohub -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}}{}  \\DeclareFontShape{C70}{${FONTTEXNAME}}{m}{it}{<-> CJK * ${FONTNAME}sl}{}  \\DeclareFontShape{C70}{${FONTTEXNAME}}{bx}{it}{<-> CJKb * ${FONTNAME}sl}{}  \\DeclareFontShape{C70}{${FONTTEXNAME}}{m}{sl}{<-> CJK * ${FONTNAME}sl}{}  \\DeclareFontShape{C70}{${FONTTEXNAME}}{bx}{sl}{<-> CJKb * ${FONTNAME}sl}{}    \\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 "Map ${FONTNAME}.map" >> $UPDMAPCFG    # update cid-x.map  FONTFILEBASENAME=`basename ${FONTFILENAME}`    echo "${FONTNAME}@Unicode@    UniGB-UCS2-H    :0:${FONTFILEBASENAME}" >> $CIDXMAP  echo "${FONTNAME}sl@Unicode@    UniGB-UCS2-H    :0:${FONTFILEBASENAME}" >> $CIDXMAP    #mktexlsr    #updmap-sys  #updmap    #read -p "Do you want remove all intermediate files?[n]"  #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
 

海阔天空,做什么就记什么。主要是 Ubuntu Linux 和 Latex 及编程相关的东东: http://www.pkblogs.com/hai-kuo/ 
r01ustc
2007-08-01

没有评论: