summaryrefslogtreecommitdiff
path: root/obsolete/fonts/utilities/safemtpk/MakeTeXTFM
blob: 78b53fbd5fb2b389bd094202a74f611a619489e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/sh
# This script must echo the name of the generated PK file (and nothing
# else) to standard output. Yes, this is different from the original MakeTeXPK
# 
# Parameters:
#   name [destdir]
#
#   `name' is the base name of the font, such as `cmr10'.
#   `destdir' is the name of the destination directory.

# setup section

TOOLS="/usr/local/tex/kpsetools-0.2/bin"
SCRIPTS="/usr/local/tex/scripts-0.2/bin"

KPSEXPAND="$TOOLS/kpsexpand"
APPENDDB="$SCRIPTS/append_db"

MF="/usr/local/bin/mf"
GSFTOPK="/usr/local/bin/gsftopk"
GFK="/usr/local/bin/gftopk"

AWK="/usr/bin/awk"
EGREP="/usr/bin/egrep"
RM="/bin/rm -f"
MV="/bin/mv -f"
MD="/bin/mkdir"
CHM="/bin/chmod"

# if we are going to install resulting pk, then let us use
# a reasonable mode on this installation

DPI=400
MAG=1
MODE=nexthi


# The root of where to put the new file. (Using the sh construct
# ${var=value} is the tersest construct that lets an environment
# variable `var' override the value given here.)
progname=`basename $0`
TEXMF=`$KPSEXPAND '$TEXMF'`
DESTROOT=${MTPK_DESTROOT-"$TEXMF/fonts"}

# Location of the files that map font name parts to directory names.
NAMEMAPDIR="$TEXMF/fontmaps"

# If this directory doesn't exist, the DC fonts won't be attempted.
dcfontdir="$TEXMF/fonts/public/dc"

# If this directory doesn't exist, the Sauter stuff won't be attempted.
sauterdir="$TEXMF/fonts/public/sauter"

# If the true typeface directory cannot be determined from the fontname,
# the files are installed here, relative to $DESTROOT.
# TE: change: tfm will be appended later
default_namepart=tmp

# TEMPDIR needs to be unique for each process because of the possibility
# of simultaneous processes running this script.
TEMPDIR=${TMPDIR-/tmp}/mttfm.$$

NAME=`basename $1 .tfm`

DIR_PERMS=755
FILE_PERMS=444

if test $# -lt 1 ; then
  echo "Usage: $progname name [destdir]." >&2
  exit 1
fi

# DESTDIR is harder.
case "$2" in
  "")
      # Nothing specified, so try to intuit the directory from the
      # fontname. First the special cases: either $NAME matches an entire
      # name in special.map, or it matches the abbreviation in
      # special.map and ends with a numeral (for the pointsize).
      # We (painfully) use only the minimal features in original awk.
      if test -r $NAMEMAPDIR/special.map ; then
        namepart=`$AWK \
'{if ($1 == NAME || (substr (NAME, 1, length ($1)) == $1 \
                      && substr (NAME, length (NAME), 1) ~ /[0-9]/)) \
     { print $2 "/" $3; exit; }}' NAME=$NAME $NAMEMAPDIR/special.map`

        if test -z "$namepart" ; then
          # Try the normal case. Source first.
          s_abbrev=`echo $NAME | cut -c 1-1`
          sourcedir=`$AWK '{ if ($1 == s_abbrev) { print $2 ; exit ; }}' \
                     s_abbrev=$s_abbrev $NAMEMAPDIR/source.map`

          if test -n "$sourcedir" ; then
            # We found the source. Try for the typeface.
            t_abbrev=`echo $NAME | cut -c 2-3`
            typefacedir=`$AWK '{ if ($1 == t_abbrev) { print $2; exit; }}' \
                         t_abbrev=$t_abbrev $NAMEMAPDIR/typeface.map`

            if test -n "$typefacedir" ; then
              # Found everything.
              namepart=$sourcedir/$typefacedir

            else
              echo "$progname: Could not map typeface abbreviation $t_abbrev." >&2
            fi
          else
            echo "$progname: Could not map source abbreviation $s_abbrev." >&2
          fi
        fi
      else
        # No map files.
        :
      fi
      # If we failed for whatever reason, default to a generic subdir.
      test -z "$namepart" && namepart=$default_namepart
      namepart=$namepart/tfm
      
      # Finally, update the parent of the installation directory.
      DESTDIR="$DESTROOT/$namepart"
      ;;
  /*) DESTDIR=$2 ;;           # Absolute, explicit destdir => use it.
   *) DESTDIR=$DESTROOT/$2 ;; # Relative destdir => append to the default.
esac

PK_DESTDIR=`echo $DESTDIR | sed s@/tfm\$\@/pk/${MODE}@`

GFNAME=$NAME.$DPI'gf'
PKNAME=$NAME.$DPI'pk'
TFMNAME=$NAME.tfm

# Clean up on normal or abnormal exit. DESTDIR changes, hence the eval.
trap "cd / ; eval $RM -r $TEMPDIR $DESTDIR/pktmp.$$" 0 1 2 15

# Remember where we were for the paths. We'd most like to replace `.',
# wherever it is in the path, with $PWD, but we don't have access to the
# compile-time path. So we are conservative, and put this at the end.
MFINPUTS="$MFINPUTS:$PWD"
export MFINPUTS

# Go to the unique working directory.
test -d $TEMPDIR || $MD $TEMPDIR 
cd $TEMPDIR || exit 1

# grep for the font in $PSMAPFILE, if some ps-to-pk is claimed to be supported.
test -n "$ps_to_pk" && $EGREP \^$NAME'([ 	]|$)' $PSMAPFILE >psline
if test -s psline ; then
  # This is a PostScript font.
  echo "$progname: Sorry. No support for PostScript fonts here." >&2
  exit

else
  if test -r $DESTDIR/$TFMNAME ; then # sigh, this is repeated above
    echo "$progname: $DESTDIR/$TFMNAME already exists." >&2
    echo $DESTDIR/$TFMNAME
    $APPENDDB $DESTDIR $TFMNAME
    exit 0
  fi

  # Run Metafont. Always use plain Metafont, since reading cmbase.mf
  # does not noticeably slow things down. Separate the filename from the
  # rest, since we have to use ./$NAME if we generate something.
  cmd="$MF \mode:=$MODE; mag:=$MAG; scrollmode; input"
  echo "$progname: Running $cmd $NAME" >&2
  if $cmd $NAME </dev/null >&2 ; then
    : # Success already.
  
  else
    # These other cases should really be part of MakeTeXMF.
    # First have to figure out the real magnification, which means
    # extracting the point size from the name -- a trailing number.
    rootname=`echo $NAME | sed 's/[0-9]*$//'`
    pointsize=`echo $NAME | sed "s/^$rootname//"`
    case "$pointsize" in
      11) realsize=10.95444 ;;	# \magstephalf
      14) realsize=14.4 ;;	# \magstep2
      17) realsize=17.28 ;;	# \magstep3
      20) realsize=20.74 ;;	# \magstep4
      25) realsize=24.88 ;;	# \magstep5
       *) realsize=$pointsize ;;
    esac
    mfname=$NAME.mf
    $RM $mfname # We are in $TEMPDIR, so this is safe.

    if test -z "$pointsize" ; then
      # No point size, so it can't be a DC or Sauter font. Give up.
      :

    elif echo $NAME | $GREP '^dc' >/dev/null ; then
      echo "$progname: Trying DC font." >&2
      echo "if unknown dxbase: input dxbase fi;" >$mfname
      echo "gensize:=$realsize;" >>$mfname
      echo "generate $rootname;" >>$mfname
      echo "$progname: Running $cmd ./$NAME" >&2
      $cmd ./$mfname </dev/null >&2

    elif test -d $sauterdir ; then
      echo "$progname: Trying interpolated/extrapolated (Sauter) font." >&2
      echo "design_size:=$realsize;" >>$mfname
      echo "input b-$rootname;" >>$mfname
      echo "$progname: Running $cmd ./$NAME" >&2
      $cmd ./$mfname </dev/null >&2
      # Result should go in the sauterdir, not the cm dir.
      test -z "$6" && $DESTDIR=$sauterdir/pk/$MODE
    fi # alternative mf sources
  fi # first mf failed
  
  # If we couldn't make the font, quit.
  test -r $GFNAME || \
    { echo "$progname: Metafont failed to make $GFNAME." >&2 ; exit 1 ; }

  # Success.  Make the PK file.
  $GFK ./$GFNAME $PKNAME || exit 1
fi

# If we get here, we've succeeded; move the final font to $DESTDIR.
test -d $DESTDIR \
  || ($MD $DESTDIR && $CHM $DIR_PERMS $DESTDIR) \
  || { echo "$progname: Could not mkdir $DESTDIR." >&2 ; exit 1 ; }

test -d $PK_DESTDIR \
  || ($MD $PK_DESTDIR && $CHM $DIR_PERMS $PK_DESTDIR) \
  || { echo "$progname: Could not mkdir $PK_DESTDIR." >&2 ; exit 1 ; }

# Install the PK file carefully, since others may be working simultaneously.
$MV $TFMNAME $DESTDIR/tfmtmp.$$ \
  || { echo "$progname: Could not mv $TFMNAME $DESTDIR/tfmtmp.$$." >&2 ; exit 1 ; }

# Install the PK file carefully, since others may be working simultaneously.
if [ ! -f $PK_DESTDIR/$PKNAME ] ; then
  $MV $PKNAME $PK_DESTDIR/pktmp.$$ \
    || { echo "$progname: Could not mv $PKNAME $PK_DESTDIR/pktmp.$$." >&2 ; exit 1 ; }
  cd $PK_DESTDIR || exit 1
  $MV pktmp.$$ $PKNAME
  $CHM $FILE_PERMS $PKNAME
  $APPENDDB $DESTDIR $PKNAME
fi

cd $DESTDIR || exit 1
$MV tfmtmp.$$ $TFMNAME
$CHM $FILE_PERMS $TFMNAME

# If this line (or an equivalent) is not present, dvipsk/xdvik/dviljk
# will think MakeTeXPK failed.  Any other output to stdout will also lose.
echo $DESTDIR/$TFMNAME
$APPENDDB $DESTDIR $TFMNAME
exit 0