Compute dwLen after passing the string through
[wine/multimedia.git] / tools / font_convert.sh
blobaf7fe56966e73ce88bf53fa39f52d8f86608698d
1 #! /bin/bash
3 # Copyright 2000 Peter Ganten
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # default settings
21 TMPDIR=/tmp/fconv.$$;
22 TFILE=`tempfile`;
24 # Where the fnt2bdf utility resides
25 FC=$HOME""/wine/tools/fnt2bdf;
26 # which OEM_CHARSET to use
27 CHARSET="winsys";
28 TARGET=/usr/X11R6/lib/X11/fonts/misc;
29 BDFTOPCF=/usr/X11R6/bin/bdftopcf;
30 PAT="*.fon";
31 Q="";
32 OLDPWD=`pwd`;
34 usage () {
35 echo "usage: "`basename $0`" [-q] [-c charset] [-t fontdir] [-b bdftopcf] [-f fnt2bdf]"
36 echo " [-p pattern] windir"
37 echo
38 echo "this utility scans a directory and its subdirectories for bitmap-fonts"
39 echo "in Windows format, converts them to PCF-fons and installs them. If X"
40 echo "is running, the X fontpath is re-adjusted."
41 echo
42 echo "options:"
43 echo " -q quit operation."
44 echo " -c charset charset name for OEM_CHARSET fonts, default: $CHARSET"
45 echo " -t fontdir directory to install the converted fonts in. This"
46 echo " directory should be a known fontdirectory to X, default:"
47 echo " $TARGET";
48 echo " -b bdftopcf name of the program to call for bdf to pcf conversion,"
49 echo " default: $BDFTOPCF";
50 echo " -f fnt2bdf name of the program to call for winfont to bdf conversion,"
51 echo " default: $FC"
52 echo " -p pattern Shell-Pattern of the filenames to look for. By default, the"
53 echo " utility will look for the pattern "$PAT" (case insensitive)."
54 echo " windir base directory to search."
55 exit 1;
59 while [ "$1" ]; do
60 case $1 in
61 -c ) shift; if [ "$1" ]; then CHARSET=$1; shift; else usage; fi; ;;
62 -t ) shift; if [ "$1" ]; then TARGET=$1; shift; else usage; fi; ;;
63 -b ) shift; if [ "$1" ]; then BDFTOPCF=$1; shift; else usage; fi; ;;
64 -f ) shift; if [ "$1" ]; then FC=$1; shift; else usage; fi; ;;
65 -p ) shift; if [ "$1" ]; then PAT=$1; shift; else usage; fi; ;;
66 -q ) shift; Q=":"; ;;
67 -* ) usage; ;;
68 * ) if [ "$WIND" ]; then usage; else WIND=$1; shift; fi; ;;
69 esac;
70 done;
72 if [ ! "$WIND" ]; then usage; fi;
73 if [ ! -d "$WIND" ]; then $Q echo "$WIND is not a directory"; exit 1; fi;
74 if [ ! -d "$TARGET" ]; then $Q echo "$TARGET is not a directory"; exit 1; fi;
75 type -p $BDFTOPCF 1>/dev/null || { $Q echo "Can 't execute $BDFTOPCF"; exit 1; }
76 type -p $FC 1>/dev/null || { $Q echo "Can't execute $FC"; exit 1; }
78 $Q echo -n "looking for bitmap fonts... "
79 FONTS=`find "$WIND" -iname $PAT 1>$TFILE 2>/dev/null`;
80 if [ $? -ne 0 ]; then
81 $Q echo "$PAT is a invalid sarch expression"; exit 1;
82 fi;
83 i=0;
84 { while read dummy; do FONTS[$i]="$dummy"; i=$[$i+1]; done; } < $TFILE
85 rm $TFILE;
86 $Q echo "done."
88 if [ -z "$FONTS" ]; then $Q echo "Can't find any fonts in $WIND"; exit 1; fi;
90 mkdir "$TMPDIR"
91 cd "$TMPDIR"
93 for i in "${FONTS[@]}"; do
94 FNT=`basename "$i"`; FNT=${FNT%.???};
95 $Q echo "converting $i";
96 if [ "$Q" ]; then
97 $FC -c $CHARSET -f $FNT "$i" 2>/dev/null;
98 else
99 $FC -c $CHARSET -f $FNT "$i";
101 done;
103 for i in *.bdf; do
104 if [ "$i" == "*.bdf" ]; then echo "No fonts extracted"; exit 0; fi;
105 bdftopcf -o "${i%.???}.pcf" "$i";
106 $Q echo "installing ${i%.???}.pcf";
107 mv "${i%.???}.pcf" $TARGET 2>/dev/null
108 if [ $? -ne 0 ]; then
109 $Q echo "Can't install fonts to $TARGET. Are your root?"; cd "$OLDPWD"; rm -rf "$TMPDIR"; exit 1; fi;
110 rm "$i";
111 done;
113 cd $TARGET;
114 $Q echo "running mkfontdir";
115 if [ "$Q" ]; then
116 mkfontdir 1>/dev/null 2>/dev/null;
117 else
118 mkfontdir
120 rmdir "$TMPDIR"
122 if [ "$DISPLAY" ]; then $Q echo "adjusting X font database"; xset fp rehash; fi;