beta-0.89.2
[luatex.git] / source / texk / kpathsea / mktexpk
blob2672dc7f78cedb24cfe8d32650ff4a7a62d84992
1 #!/bin/sh
2 # original mktexpk -- make a new PK font, because one wasn't found.
3 #
4 # (If you change or delete the word `original' on the previous line,
5 # installation won't write this script over yours.)
6 #
7 # Originally written by Thomas Esser, Karl Berry, and Olaf Weber.
8 # Public domain.
10 version='$Id: mktexpk 34656 2014-07-18 23:38:50Z karl $'
11 progname=`echo $0 | sed 's%.*/%%'`
13 # preferentially use subprograms from our own directory.
14 mydir=`echo "$0" | sed 's,/[^/]*$,,'`
15 mydir=`cd "$mydir" && pwd`
16 PATH="$mydir:$PATH"; export PATH
18 usage="Usage: $progname [OPTIONS] NAME [REDIRECT],
19 Create a PK font.
21 --dpi DPI use resolution DPI.
22 --bdpi BDPI use base resolution BDPI.
23 --mag MAG use magnificiation MAG.
24 --mfmode MODE use MODE as the METAFONT mode.
25 --destdir DESTDIR write fonts in DESTDIR.
27 Try to create a bitmap PK file for NAME at resolution DPI, with an
28 assumed device base resolution of BDPI, and a Metafont \`mag' of
29 MAG. Use MODE for the METAFONT mode. Use DESTDIR for the root of where
30 to install into, either the absolute directory name to use (if it starts
31 with a /) or relative to the default DESTDIR (if not). REDIRECT, if
32 supplied, is a string of the form '>&n', where n is the number of the
33 file descriptor which is to receive, instead of stdout, the name of the
34 newly created pk file.
36 If you expected the font to be available as an outline, and thus this
37 script does not work and should not have been called, most likely the
38 font's .tfm name is missing from the relevant map file (e.g.,
39 psfonts.map for dvips, pdftex.map for pdftex). These map files are
40 typically maintained using updmap; q.v.
42 For step-by-step instructions on making new fonts known to TeX, see
43 http://tug.org/fonts/fontinstall.html.
45 Report bugs to: tex-k@tug.org
46 TeX Live home page: <http://tug.org/texlive/>
49 # Handle non-positional options, except for --version/--help
50 while test $# -gt 0; do
51 case "$1" in
52 --destdir) shift; DEST="$1"; shift ;;
53 --destdir=*) DEST=`echo "$1" | sed 's/--destdir=//'`; shift ;;
54 --dpi) shift; DPI="$1"; shift ;;
55 --dpi=*) DPI=`echo "$1" | sed 's/--dpi=//'`; shift ;;
56 --bdpi) shift; BDPI="$1"; shift ;;
57 --bdpi=*) BDPI=`echo "$1" | sed 's/--bdpi=//'`; shift ;;
58 --mfmode) shift; test "x$1" != "x/" && MODE="$1"; shift ;;
59 --mfmode=*) test "x$1" != "x--mfmode/" \
60 && MODE=`echo "$1" | sed 's/--mfmode=//'`; shift ;;
61 --mag) shift; MAG="$1"; shift;;
62 --mag=*) MAG=`echo "$1" | sed '/s--mag=//'`; shift;;
63 --version|-version) break ;;
64 --help|-help) break ;;
65 *) break ;;
66 esac
67 done
69 if test "x$2" != x; then
70 tail="`echo \"x$2\" | sed 's/^x>&//' | grep '^[0-9]*$'`"
71 if test -z "$tail"; then
72 echo "$progname: argument '$2' ignored - bad file number" >&2
73 elif test "$tail" != 1; then
74 eval 'exec 1>&$tail'
78 mt_max_args=2
80 # Common code for all scripts.
81 : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
82 : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
83 test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
84 if test ! -f "$MT_MKTEX_OPT"; then
85 echo "$progname: Cannot find mktex.opt; check your installation." >&2
86 exit 1
89 . "$MT_MKTEX_OPT"
91 # Where do potential driver files belong?
92 case "$MT_FEATURES" in
93 *nomfdrivers*)
94 : ${MT_MFDESTDIR=`pwd`}
95 export MT_MFDESTDIR;;
96 esac
98 # Since we want to pass the generated filename and only that filename
99 # back to the caller on standard output, we do some redirections so
100 # regular echo's will end up on stderr, and do an echo >$STDOUT at the end.
101 # Then the contents of $STDOUT will be echoed to stdout by a trap.
103 # start of redirection stdout -> stderr, stdin <- /dev/null
106 NAME=$1
108 if kpsewhich $NAME.mf >/dev/null 2>&1 || mktexmf $NAME >/dev/null 2>&1; then
109 # determine the progname of metafont to use; prefer mf-nowin.
110 if (mf-nowin --version) >/dev/null 2>&1; then
111 MF="mf-nowin -progname=mf"
112 else
113 MF=mf
116 # Check that $BDPI and $MODE are consistent; if not, ignore the mode and
117 # hope we can correctly guess it from bdpi. (People like to specify the
118 # resolution on the command line, not the mode so much.)
119 if test -n "$MODE"; then
120 mf_bdpi=`$MF \
121 '\mode:='$MODE';mode_setup;message"BDPI= "&decimal round pixels_per_inch;end.'\
122 </dev/null \
123 | awk '/DPI=/ {print $2}'`
124 if test "x$mf_bdpi" != x$BDPI; then
125 echo "$progname: Mismatched mode $MODE and resolution $BDPI; ignoring mode." >&2
126 MODE=
130 # If an explicit mode is not supplied, try to guess. You can get a
131 # list of extant modes from ftp://ftp.tug.org/tex/modes.mf.
132 if test -z "$MODE" || test "x$MODE" = xdefault; then
133 case "$BDPI" in
134 85) MODE=sun;;
135 100) MODE=nextscrn;;
136 180) MODE=toshiba;;
137 300) MODE=cx;;
138 360) MODE=epstylus;;
139 400) MODE=nexthi;;
140 600) MODE=ljfour;;
141 720) MODE=epscszz;;
142 1200) MODE=ultre;;
143 1270) MODE=linoone;;
144 8000) MODE=dpdfezzz;;
145 *) echo "$progname: Can't guess mode for $BDPI dpi devices." >&2
146 echo "$progname: Use a config file or option to specify the mode; see:" >&2
147 echo "$progname: http://tug.org/texinfohtml/kpathsea.html#Unable-to-generate-fonts" >&2
148 exit 1
149 esac
152 # Run Metafont. Always use plain Metafont, since reading cmbase.mf
153 # does not noticeably slow things down.
154 cmd="$MF \mode:=$MODE; mag:=$MAG; nonstopmode; input $NAME"
155 else
156 MODE=modeless
157 # ps_to_pk is set in mktex.opt
158 case $ps_to_pk in
159 gsftopk)
160 if $ps_to_pk -t "$NAME"; then
161 cmd="$ps_to_pk $NAME $DPI"
162 fi;;
163 ps2pk)
164 # grep for the font in $PSMAPFILE. These are base font names, such as
165 # rpplr (the original) or pplr0 (an interim step) or pplr8r (current).
166 : ${PSMAPFILE=`kpsewhich --format=map psfonts.map ps2pk.map`}
167 pattern="^$NAME"'([ ]|$)'
168 psline=`egrep "$pattern" $PSMAPFILE | tail -1`
169 if test -n "$psline"; then
170 set x `echo "$psline" | sed 's%[<["]%%g'`
171 shift; shift; shift;
172 encoding=; psname=; slant=; extend=
173 while test ! -z "$1"; do
174 case "$1" in
175 *.enc) encoding="-e $1";;
176 *.pf[ab]) psname="$1";;
177 *SlantFont) slant="-S $lastopt";;
178 *ExtendFont) extend="-E $lastopt";;
179 esac
180 lastopt="$1"
181 shift
182 done
183 # Guessing the name of the type1 font file as fallback:
184 ANAME=`echo $NAME | sed 's/8r$/8a/'`
185 for i in $NAME.pfa $NAME.pfb $ANAME.pfa $ANAME.pfb; do
186 if kpsewhich $i >/dev/null 2>&1; then
187 psname=$i
188 break
190 done
192 if [ -n "$psname" ]; then
193 cmd="ps2pk -v -X$DPI -R$BDPI $slant $extend $encoding $psname $NAME.${DPI}pk"
194 else
195 if gsftopk -t "$NAME"; then
196 echo "$progname: cannot find $NAME.pfa or $NAME.pfb. Trying gsftopk." >&2
197 cmd="gsftopk $NAME $DPI"
200 fi;;
201 esac
203 # unsupported by $ps_to_pk, try other conversions:
204 if test -z "$cmd"; then
205 if (ttf2pk -t -q $NAME) >/dev/null 2>&1; then
206 cmd="ttf2pk -q $NAME $DPI"
207 elif (hbf2gf -t -q $NAME) >/dev/null 2>&1; then
208 cmd="hbf2gf -q -p $NAME $DPI"
209 else
210 echo "$progname: don't know how to create bitmap font for $NAME." >&2
211 echo "$progname: perhaps $NAME is missing from the map file." >&2
212 exit 1
217 OIFS=$IFS; IFS=$SEP
218 set x `"$MT_MKTEXNAM" $NAME $DPI $MODE $DEST`; shift
219 IFS=$OIFS
221 PKDEST="$1"
222 PKDESTDIR=`echo "$PKDEST" | sed 's%/[^/][^/]*$%%'` # can't rely on dirname
223 PKNAME=`basename "$PKDEST"`
224 GFNAME=$NAME.${DPI}gf
226 if test -r "$PKDESTDIR/$PKNAME"; then
227 echo "$progname: $PKDESTDIR/$PKNAME already exists." >&2
228 echo "$PKDESTDIR/$PKNAME" >$STDOUT
229 "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
230 exit 0
233 "$MT_MKTEXDIR" "$PKDESTDIR"
234 if test ! -d "$PKDESTDIR"; then
235 echo "$progname: $MT_MKTEXDIR $PKDESTDIR failed." >&2
236 exit 1
239 echo "$progname: Running $cmd"
240 $cmd </dev/null || {
241 # Don't abort if only "Strange path", "bad pos" or "angle(0,0)"
242 # errors occurr.
243 grep '^!' $NAME.log | sort >$$.errs 2>/dev/null
244 grep '^! Strange path' $$.errs >$$.strange 2>/dev/null
245 grep '^! bad pos.' $$.errs >$$.badpos 2>/dev/null
246 grep '^! angle(0,0) is taken as zero.' $$.errs >$$.angle 2>/dev/null
247 cat $$.badpos $$.strange $$.angle | sort > $$.errs_accept
248 if cmp $$.errs $$.errs_accept >/dev/null 2>&1; then
249 test -s $$.strange >/dev/null 2>&1 \
250 && echo "$progname: warning: \`$cmd' caused strange path errors." >&2
251 test -s $$.badpos >/dev/null 2>&1 \
252 && echo "$progname: warning: \`$cmd' caused bad pos errors." >&2
253 test -s $$.angle >/dev/null 2>&1 \
254 && echo "$progname: warning: \`$cmd' caused angle(0,0) errors." >&2
255 else
256 echo "$progname: \`$cmd' failed." >&2
257 test -s $NAME.log && mv -f $NAME.log "$KPSE_DOT"
258 exit 1;
262 test -r $GFNAME && { gftopk ./$GFNAME $PKNAME || exit 1; }
263 test ! -f $PKNAME && test -f $NAME.${DPI}pk && mv $NAME.${DPI}pk $PKNAME
264 if test ! -s $PKNAME; then
265 echo "$progname: \`$cmd' failed to make $PKNAME." >&2
266 exit 1
269 # Install the PK file carefully, since others may be working simultaneously.
270 # Use cp when mv fails, since DOS will fail mv for deeply-nested directories.
271 mv $PKNAME "$PKDESTDIR/pk$$.tmp" 2>/dev/null \
272 || cp $PKNAME "$PKDESTDIR/pk$$.tmp" || exit 1
273 cd "$PKDESTDIR" || exit 1
274 chmod `kpsestat -xst,go-w .` pk$$.tmp
275 test -r $PKNAME || mv pk$$.tmp $PKNAME || exit 1
277 # Update ls-R if necessary.
278 "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
280 # If this line (or an equivalent) is not present, dvipsk/xdvik/dviljk
281 # will think mktexpk failed. Any other output to stdout will also lose.
282 echo "$PKDESTDIR/$PKNAME" >$STDOUT
283 echo "$progname: $PKDESTDIR/$PKNAME: successfully generated." >&2
284 ) 1>&2 </dev/null