blob: 19fd96a72ed37e734ad4310e710a2cbd7c864a3b [file] [log] [blame]
Peter Ganten0ea83642000-05-30 20:49:07 +00001#! /bin/bash
2
3# default settings
4TMPDIR=/tmp/fconv.$$;
5TFILE=`tempfile`;
6
7# Where the fnt2bdf utility resides
8FC=$HOME""/wine/tools/fnt2bdf;
9# which OEM_CHARSET to use
10CHARSET="winsys";
11TARGET=/usr/X11R6/lib/X11/fonts/misc;
12BDFTOPCF=/usr/X11R6/bin/bdftopcf;
13PAT="*.fon";
14Q="";
15OLDPWD=`pwd`;
16
17usage () {
18 echo "usage: "`basename $0`" [-q] [-c charset] [-t fontdir] [-b bdftopcf] [-f fnt2bdf]"
19 echo " [-p pattern] windir"
20 echo
21 echo "this utility scans a directory and its subdirectories for bitmap-fonts"
22 echo "in Windows format, converts them to PCF-fons and installs them. If X"
23 echo "is running, the X fontpath is re-adjusted."
24 echo
25 echo "options:"
26 echo " -q quit operation."
27 echo " -c charset charset name for OEM_CHARSET fonts, default: $CHARSET"
28 echo " -t fontdir directory to install the converted fonts in. This"
29 echo " directory should be a known fontdirectory to X, default:"
30 echo " $TARGET";
31 echo " -b bdftopcf name of the program to call for bdf to pcf conversion,"
32 echo " default: $BDFTOPCF";
33 echo " -f fnt2bdf name of the program to call for winfont to bdf conversion,"
34 echo " default: $FC"
35 echo " -p pattern Shell-Pattern of the filenames to look for. By default, the"
36 echo " utility will look for the pattern "$PAT" (case insensitive)."
37 echo " windir base directory to search."
38 exit 1;
39}
40
41
42while [ "$1" ]; do
43 case $1 in
44 -c ) shift; if [ "$1" ]; then CHARSET=$1; shift; else usage; fi; ;;
45 -t ) shift; if [ "$1" ]; then TARGET=$1; shift; else usage; fi; ;;
46 -b ) shift; if [ "$1" ]; then BDFTOPCF=$1; shift; else usage; fi; ;;
47 -f ) shift; if [ "$1" ]; then FC=$1; shift; else usage; fi; ;;
48 -p ) shift; if [ "$1" ]; then PAT=$1; shift; else usage; fi; ;;
49 -q ) shift; Q=":"; ;;
50 -* ) usage; ;;
51 * ) if [ "$WIND" ]; then usage; else WIND=$1; shift; fi; ;;
52 esac;
53done;
54
55if [ ! "$WIND" ]; then usage; fi;
56if [ ! -d "$WIND" ]; then $Q echo "$WIND is not a directory"; exit 1; fi;
57if [ ! -d "$TARGET" ]; then $Q echo "$TARGET is not a directory"; exit 1; fi;
58type -p $BDFTOPCF 1>/dev/null || { $Q echo "Can 't execute $BDFTOPCF"; exit 1; }
59type -p $FC 1>/dev/null || { $Q echo "Can't execute $FC"; exit 1; }
60
61$Q echo -n "looking for bitmap fonts... "
62FONTS=`find "$WIND" -iname $PAT 1>$TFILE 2>/dev/null`;
63if [ $? -ne 0 ]; then
64 $Q echo "$PAT is a invalid sarch expression"; exit 1;
65fi;
66i=0;
67{ while read dummy; do FONTS[$i]="$dummy"; i=$[$i+1]; done; } < $TFILE
68rm $TFILE;
69$Q echo "done."
70
71if [ -z "$FONTS" ]; then $Q echo "Can't find any fonts in $WIND"; exit 1; fi;
72
Andreas Mohr8c2e5732001-11-25 00:51:36 +000073mkdir "$TMPDIR"
74cd "$TMPDIR"
Peter Ganten0ea83642000-05-30 20:49:07 +000075
76for i in "${FONTS[@]}"; do
77 FNT=`basename "$i"`; FNT=${FNT%.???};
78 $Q echo "converting $i";
79 if [ "$Q" ]; then
80 $FC -c $CHARSET -f $FNT "$i" 2>/dev/null;
81 else
82 $FC -c $CHARSET -f $FNT "$i";
83 fi;
84done;
85
86for i in *.bdf; do
87 if [ "$i" == "*.bdf" ]; then echo "No fonts extracted"; exit 0; fi;
88 bdftopcf -o "${i%.???}.pcf" "$i";
89 $Q echo "installing ${i%.???}.pcf";
90 mv "${i%.???}.pcf" $TARGET 2>/dev/null
91 if [ $? -ne 0 ]; then
Andreas Mohr8c2e5732001-11-25 00:51:36 +000092 $Q echo "Can't install fonts to $TARGET. Are your root?"; cd "$OLDPWD"; rm -rf "$TMPDIR"; exit 1; fi;
Peter Ganten0ea83642000-05-30 20:49:07 +000093 rm "$i";
94done;
95
96cd $TARGET;
97$Q echo "running mkfontdir";
98if [ "$Q" ]; then
99 mkfontdir 1>/dev/null 2>/dev/null;
100else
101 mkfontdir
102fi;
Andreas Mohr8c2e5732001-11-25 00:51:36 +0000103rmdir "$TMPDIR"
Peter Ganten0ea83642000-05-30 20:49:07 +0000104
105if [ "$DISPLAY" ]; then $Q echo "adjusting X font database"; xset fp rehash; fi;
106