blob: af7fe56966e73ce88bf53fa39f52d8f86608698d [file] [log] [blame]
Peter Ganten0ea83642000-05-30 20:49:07 +00001#! /bin/bash
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00002#
3# Copyright 2000 Peter Ganten
4#
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.
9#
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.
14#
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
18#
Peter Ganten0ea83642000-05-30 20:49:07 +000019
20# default settings
21TMPDIR=/tmp/fconv.$$;
22TFILE=`tempfile`;
23
Alexandre Julliard7cae5582002-06-01 02:55:48 +000024# Where the fnt2bdf utility resides
Peter Ganten0ea83642000-05-30 20:49:07 +000025FC=$HOME""/wine/tools/fnt2bdf;
26# which OEM_CHARSET to use
27CHARSET="winsys";
28TARGET=/usr/X11R6/lib/X11/fonts/misc;
29BDFTOPCF=/usr/X11R6/bin/bdftopcf;
30PAT="*.fon";
31Q="";
Alexandre Julliard7cae5582002-06-01 02:55:48 +000032OLDPWD=`pwd`;
Peter Ganten0ea83642000-05-30 20:49:07 +000033
34usage () {
35 echo "usage: "`basename $0`" [-q] [-c charset] [-t fontdir] [-b bdftopcf] [-f fnt2bdf]"
36 echo " [-p pattern] windir"
Alexandre Julliard7cae5582002-06-01 02:55:48 +000037 echo
Peter Ganten0ea83642000-05-30 20:49:07 +000038 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."
Alexandre Julliard7cae5582002-06-01 02:55:48 +000041 echo
Peter Ganten0ea83642000-05-30 20:49:07 +000042 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;
56}
57
58
59while [ "$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; ;;
Alexandre Julliard7cae5582002-06-01 02:55:48 +000068 * ) if [ "$WIND" ]; then usage; else WIND=$1; shift; fi; ;;
Peter Ganten0ea83642000-05-30 20:49:07 +000069 esac;
70done;
71
72if [ ! "$WIND" ]; then usage; fi;
73if [ ! -d "$WIND" ]; then $Q echo "$WIND is not a directory"; exit 1; fi;
74if [ ! -d "$TARGET" ]; then $Q echo "$TARGET is not a directory"; exit 1; fi;
75type -p $BDFTOPCF 1>/dev/null || { $Q echo "Can 't execute $BDFTOPCF"; exit 1; }
76type -p $FC 1>/dev/null || { $Q echo "Can't execute $FC"; exit 1; }
77
78$Q echo -n "looking for bitmap fonts... "
79FONTS=`find "$WIND" -iname $PAT 1>$TFILE 2>/dev/null`;
Alexandre Julliard7cae5582002-06-01 02:55:48 +000080if [ $? -ne 0 ]; then
Peter Ganten0ea83642000-05-30 20:49:07 +000081 $Q echo "$PAT is a invalid sarch expression"; exit 1;
82fi;
83i=0;
84{ while read dummy; do FONTS[$i]="$dummy"; i=$[$i+1]; done; } < $TFILE
85rm $TFILE;
86$Q echo "done."
87
Alexandre Julliard7cae5582002-06-01 02:55:48 +000088if [ -z "$FONTS" ]; then $Q echo "Can't find any fonts in $WIND"; exit 1; fi;
Peter Ganten0ea83642000-05-30 20:49:07 +000089
Andreas Mohr8c2e5732001-11-25 00:51:36 +000090mkdir "$TMPDIR"
91cd "$TMPDIR"
Peter Ganten0ea83642000-05-30 20:49:07 +000092
Alexandre Julliard7cae5582002-06-01 02:55:48 +000093for i in "${FONTS[@]}"; do
Peter Ganten0ea83642000-05-30 20:49:07 +000094 FNT=`basename "$i"`; FNT=${FNT%.???};
95 $Q echo "converting $i";
Alexandre Julliard7cae5582002-06-01 02:55:48 +000096 if [ "$Q" ]; then
Peter Ganten0ea83642000-05-30 20:49:07 +000097 $FC -c $CHARSET -f $FNT "$i" 2>/dev/null;
98 else
99 $FC -c $CHARSET -f $FNT "$i";
100 fi;
101done;
102
103for i in *.bdf; do
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000104 if [ "$i" == "*.bdf" ]; then echo "No fonts extracted"; exit 0; fi;
Peter Ganten0ea83642000-05-30 20:49:07 +0000105 bdftopcf -o "${i%.???}.pcf" "$i";
106 $Q echo "installing ${i%.???}.pcf";
107 mv "${i%.???}.pcf" $TARGET 2>/dev/null
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000108 if [ $? -ne 0 ]; then
Andreas Mohr8c2e5732001-11-25 00:51:36 +0000109 $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 +0000110 rm "$i";
111done;
112
113cd $TARGET;
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000114$Q echo "running mkfontdir";
Peter Ganten0ea83642000-05-30 20:49:07 +0000115if [ "$Q" ]; then
116 mkfontdir 1>/dev/null 2>/dev/null;
117else
118 mkfontdir
119fi;
Andreas Mohr8c2e5732001-11-25 00:51:36 +0000120rmdir "$TMPDIR"
Peter Ganten0ea83642000-05-30 20:49:07 +0000121
122if [ "$DISPLAY" ]; then $Q echo "adjusting X font database"; xset fp rehash; fi;