home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / 1_1_beta / upgrades / maketexpk_ / maketexpk_~
Encoding:
Text File  |  1996-07-04  |  9.9 KB  |  277 lines

  1. #!/bin/sh
  2. # original MakeTeXPK -- make a new PK font, because one wasn't found.
  3. # Version of 12dec94.
  4. # (If you change or delete the word `original' on the previous line,
  5. # installation won't write this MakeTeXPK over yours.)
  6. #
  7. # This script must echo the name of the generated PK file (and nothing
  8. # else) to standard output. Yes, this is different from the original dvips.
  9. # Parameters:
  10. #   name dpi bdpi magnification [mode [destdir]]
  11. #
  12. #   `name' is the base name of the font, such as `cmr10'.
  13. #   `dpi' is the resolution the font is needed at.
  14. #   `bdpi' is the base resolution, used to intuit the mode to use.
  15. #   `magnification' is a string to pass to MF as the value of `mag'.
  16. #   `mode', if supplied, is the mode to use. Unless it's `default', in
  17. #     which case we guess. (This is so people can specify a destdir
  18. #     without a mode.)
  19. #   `destdir', if supplied, is either the absolute directory name to use
  20. #     (if it starts with a /) or relative to the default DESTDIR (if not).
  21.  
  22. # The root of where to put the new file. (Using the sh construct
  23. # ${var=value} is the tersest construct that lets an environment
  24. # variable `var' override the value given here.)
  25. : ${DESTROOT=${MTPK_DESTROOT-/usr/local/lib/texmf/fonts}}
  26.  
  27. # Define to `gsftopk' or `ps2pk' or whatever to make PK files for
  28. # PostScript fonts. If this is defined, PSMAPFILE must also be defined to
  29. # be your psfonts.map file or some equivalent.
  30. : ${ps_to_pk=gsftopk}
  31. : ${PSMAPFILE=/usr/local/lib/texmf/dvips/psfonts.map}
  32.  
  33. # Location of the files that map font name parts to directory names.
  34. : ${NAMEMAPDIR=/usr/local/lib/texmf/fontname}
  35.  
  36. # This is needed only if all the font directories were not included in
  37. # the compile-time path for gsftopk. 
  38. : ${DVIPSHEADERS=/usr/local/lib/ghostscript/type1:}
  39.  
  40. # If this directory doesn't exist, the DC fonts won't be attempted.
  41. : ${dcfontdir=/usr/local/lib/texmf/fonts/public/dc}
  42.  
  43. # If this directory doesn't exist, the Sauter stuff won't be attempted.
  44. : ${sauterdir=/usr/local/lib/texmf/fonts/public/sauter}
  45.  
  46. # If the true typeface directory cannot be determined from the fontname,
  47. # the files are installed here, relative to $DESTROOT.
  48. : ${default_namepart=tmp/pk}
  49.  
  50. # TEMPDIR needs to be unique for each process because of the possibility
  51. # of processes simultaneously running this script.
  52. TEMPDIR=${TMPDIR-/tmp}/mtpk.$$
  53.  
  54. if test $# -lt 4; then
  55.   echo "Usage: $0 name dpi bdpi mag [mode [destdir]]." >&2
  56.   exit 1
  57. fi
  58.  
  59. NAME=$1
  60. DPI=$2
  61. BDPI=$3
  62. MAG=$4
  63. MODE=$5
  64.  
  65. # DESTDIR is harder.
  66. case "$6" in
  67.   "")
  68.       # Nothing specified, so try to intuit the directory from the
  69.       # fontname. First the special cases: either $NAME matches an entire
  70.       # name in special.map, or it matches the abbreviation in
  71.       # special.map and ends with a numeral (for the pointsize).
  72.       # We (painfully) use only the minimal features in original awk.
  73.       if test -r $NAMEMAPDIR/special.map; then
  74.         namepart=`awk \
  75. '{if ($1 == NAME || (substr (NAME, 1, length ($1)) == $1 \
  76.                       && substr (NAME, length (NAME), 1) ~ /[0-9]/)) \
  77.      { print $2 "/" $3; exit; }}' NAME=$NAME $NAMEMAPDIR/special.map`
  78.  
  79.         if test -z "$namepart"; then
  80.           # Try the normal case. Source first.
  81.           s_abbrev=`echo $NAME | cut -c 1-1`
  82.           sourcedir=`awk '{ if ($1 == s_abbrev) { print $2; exit; }}' \
  83.                      s_abbrev=$s_abbrev $NAMEMAPDIR/source.map`
  84.  
  85.           if test -n "$sourcedir"; then
  86.             # We found the source. Try for the typeface.
  87.             t_abbrev=`echo $NAME | cut -c 2-3`
  88.             typefacedir=`awk '{ if ($1 == t_abbrev) { print $2; exit; }}' \
  89.                          t_abbrev=$t_abbrev $NAMEMAPDIR/typeface.map`
  90.  
  91.             if test -n "$typefacedir"; then
  92.               # Found everything.
  93.               namepart=$sourcedir/$typefacedir
  94.  
  95.             else
  96.               echo "$0: Could not map typeface abbreviation $t_abbrev." >&2
  97.             fi
  98.           else
  99.             echo "$0: Could not map source abbreviation $s_abbrev." >&2
  100.           fi
  101.         fi
  102.       else
  103.         # No map files.
  104.         :
  105.       fi
  106.       if test -z "$namepart"; then
  107.         # If we failed for whatever reason, default to a generic subdir.
  108.         namepart=$default_namepart
  109.       else
  110.         # Otherwise, get the `pk' in before we append the mode.
  111.         namepart=$namepart/pk 
  112.       fi
  113.       
  114.       # Finally, update the parent of the installation directory.
  115.       DESTROOT="$DESTROOT/$namepart"
  116.       ;;
  117.   /*) DESTDIR=$6;;           # Absolute, explicit destdir => use it.
  118.    *) DESTDIR=$DESTROOT/$6;; # Relative destdir => append to the default.
  119. esac
  120.  
  121. GFNAME=$NAME.$DPI'gf'
  122. PKNAME=$NAME.$DPI'pk'
  123.  
  124. # Clean up on normal or abnormal exit. DESTDIR changes, hence the eval.
  125. trap "cd /; eval rm -rf $TEMPDIR \$DESTDIR/pktmp.$$" 0 1 2 15
  126.  
  127. # Allow fonts to be read and written (especially in case we make
  128. # directories) by everyone.  
  129. umask 0
  130.  
  131. # Possible local customizations?
  132. test -r /usr/local/lib/texmf/web2c/MakeTeXPK.site && . /usr/local/lib/texmf/web2c/MakeTeXPK.site
  133.  
  134. # Remember where we were for the paths. We'd most like to replace `.',
  135. # wherever it is in the path, with $SAVEPWD, but we don't have access to the
  136. # compile-time path. So we are conservative, and put this at the end.
  137. SAVEPWD=`pwd`
  138.  
  139. # Go to the unique working directory.
  140. test -d $TEMPDIR || mkdir $TEMPDIR 
  141. cd $TEMPDIR || exit 1
  142.  
  143. # grep for the font in $PSMAPFILE, if some ps-to-pk is claimed to be supported.
  144. # We have to figure out the name of the base font -- $NAME is probably
  145. # something like pplr, but it's rpplr or pplr0 or pplr8r that's in psfonts.map.
  146. pattern="^r?$NAME"'(0|8r)?([     ]|$)' 
  147. test -n "$ps_to_pk" && egrep "$pattern" $PSMAPFILE >psline
  148. if test -s psline; then
  149.   # This is a PostScript font.
  150.   MODE=$ps_to_pk
  151.   case $ps_to_pk in
  152.        ps2pk*) special_part=`cat psline | sed -e 's/^.*"//' -e 's/".*$//'`
  153.                # .167 SlantFont
  154.                slant=`echo $special_part \
  155.                       | awk '{ if ($2 == SlantFont) print "-S" $1 }'`
  156.                extend=`echo $special_part \
  157.                        | awk '{ if ($2 == ExtendFont) print "-E" $1 }'`
  158.                cmd="$ps_to_pk -v -X$DPI $slant $extend $NAME";;
  159.             *) cmd="$ps_to_pk $NAME $DPI";;
  160.   esac
  161.  
  162.   # Update DESTDIR for new mode, and check if we were spuriously called.
  163.   test -z "$6" && DESTDIR="$DESTROOT/$MODE"
  164.   if test -r $DESTDIR/$PKNAME; then # sigh, this is repeated below
  165.     echo "$0: $DESTDIR/$PKNAME already exists." >&2
  166.     echo $DESTDIR/$PKNAME
  167.     exit 0
  168.   fi
  169.  
  170.   DVIPSHEADERS="$DVIPSHEADERS:$SAVEPWD"
  171.   export DVIPSHEADERS
  172.   echo "$0: Running $cmd" >&2
  173.   $cmd >&2 || { echo "$0: $ps_to_pk failed." >&2; exit 1; }
  174.  
  175. else
  176.   # Try Metafont.
  177.   MFINPUTS="$MFINPUTS:$SAVEPWD"
  178.   export MFINPUTS
  179.  
  180.   # If an explicit mode is not supplied, try to guess. You can get a
  181.   # list of extant modes from ftp.cs.umb.edu:pub/tex/modes.mf.
  182.   if test -z "$MODE" || test "$MODE" = default; then
  183.     case "$BDPI" in
  184.       85) MODE=sun;;
  185.      300) MODE=cx;;
  186.      600) MODE=ljfour;;
  187.     1270) MODE=linolo;;
  188.        *) echo "$0: Can't guess mode for $BDPI dpi devices." >&2
  189.           echo "$0: Use a config file, or update me." >&2
  190.           exit 1
  191.     esac
  192.   fi
  193.  
  194.   # If no destination directory specified, install font in directory
  195.   # named for the mode.
  196.   test -z "$6" && DESTDIR="$DESTROOT/$MODE"
  197.  
  198.   if test -r $DESTDIR/$PKNAME; then # sigh, this is repeated above
  199.     echo "$0: $DESTDIR/$PKNAME already exists." >&2
  200.     echo $DESTDIR/$PKNAME
  201.     exit 0
  202.   fi
  203.  
  204.   # Run Metafont. Always use plain Metafont, since reading cmbase.mf
  205.   # does not noticeably slow things down. Separate the filename from the
  206.   # rest, since we have to use ./$NAME if we generate something.
  207.   cmd="mf \mode:=$MODE; mag:=$MAG; scrollmode; input"
  208.   echo "$0: Running $cmd $NAME" >&2
  209.   if $cmd $NAME </dev/null >&2; then
  210.     : # Success already.
  211.   
  212.   else
  213.     # These other cases should really be part of MakeTeXMF.
  214.     # First have to figure out the real magnification, which means
  215.     # extracting the point size from the name -- a trailing number.
  216.     rootname=`echo $NAME | sed 's/[0-9]*$//'`
  217.     pointsize=`echo $NAME | sed "s/^$rootname//"`
  218.     case "$pointsize" in
  219.       11) realsize=10.95444;;    # \magstephalf
  220.       14) realsize=14.4;;    # \magstep2
  221.       17) realsize=17.28;;    # \magstep3
  222.       20) realsize=20.74;;    # \magstep4
  223.       25) realsize=24.88;;    # \magstep5
  224.        *) realsize=$pointsize;;
  225.     esac
  226.     mfname=$NAME.mf
  227.     rm -f $mfname # We are in $TEMPDIR, so this is safe.
  228.  
  229.     if test -z "$pointsize"; then
  230.       # No point size, so it can't be a DC or Sauter font. Give up.
  231.       :
  232.  
  233.     elif echo $NAME | grep '^dc' >/dev/null; then
  234.       echo "$0: Trying DC font." >&2
  235.       echo "if unknown dxbase: input dxbase fi;" >$mfname
  236.       echo "gensize:=$realsize;" >>$mfname
  237.       echo "generate $rootname." >>$mfname
  238.       echo "$0: Running $cmd ./$NAME" >&2
  239.       $cmd ./$mfname </dev/null >&2
  240.  
  241.     elif test -d $sauterdir; then
  242.       echo "$0: Trying interpolated/extrapolated (Sauter) font." >&2
  243.       echo "design_size:=$realsize;" >>$mfname
  244.       echo "input b-$rootname;" >>$mfname
  245.       echo "$0: Running $cmd ./$NAME" >&2
  246.       $cmd ./$mfname </dev/null >&2
  247.       # Result should go in the sauterdir, not the cm dir.
  248.       test -z "$6" && $DESTDIR=$sauterdir/pk/$MODE
  249.     fi # alternative mf sources
  250.   fi # first mf failed
  251.   
  252.   # If we couldn't make the font, quit.
  253.   test -r $GFNAME || \
  254.     { echo "$0: Metafont failed to make $GFNAME." >&2; exit 1; }
  255.  
  256.   # Success.  Make the PK file.
  257.   gftopk ./$GFNAME $PKNAME || exit 1
  258. fi
  259.  
  260. # If we get here, we've succeeded; move the final font to $DESTDIR.
  261. test -d $DESTDIR \
  262.   || mkdir $DESTDIR \
  263.   || { echo "$0: Could not mkdir $DESTDIR." >&2; exit 1; }
  264.  
  265. # Install the PK file carefully, since others may be working simultaneously.
  266. mv $PKNAME $DESTDIR/pktmp.$$ \
  267.   || { echo "$0: Could not mv $PKNAME $DESTDIR/pktmp.$$." >&2; exit 1; }
  268.  
  269. cd $DESTDIR || exit 1
  270. mv pktmp.$$ $PKNAME
  271.  
  272. # If this line (or an equivalent) is not present, dvipsk/xdvik/dviljk
  273. # will think MakeTeXPK failed.  Any other output to stdout will also lose.
  274. echo $DESTDIR/$PKNAME
  275.