Commit | Line | Data |
---|---|---|
0ea83643 | 1 | #! /bin/bash |
0799c1a7 AJ |
2 | # |
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 | |
360a3f91 | 17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
0799c1a7 | 18 | # |
0ea83643 PG |
19 | |
20 | # default settings | |
21 | TMPDIR=/tmp/fconv.$$; | |
cd7534e8 JG |
22 | if [ -f `which mktemp` ]; then |
23 | TFILE=`mktemp -q /tmp/fconv.XXXXXX` | |
24 | else | |
25 | TFILE=`tempfile`; | |
26 | fi | |
0ea83643 | 27 | |
7cae558b | 28 | # Where the fnt2bdf utility resides |
cd7534e8 JG |
29 | FC=`which fnt2bdf`; |
30 | if [ -z "$FC" ]; then FC=$HOME""/wine/tools/fnt2bdf; fi; | |
31 | ||
0ea83643 PG |
32 | # which OEM_CHARSET to use |
33 | CHARSET="winsys"; | |
34 | TARGET=/usr/X11R6/lib/X11/fonts/misc; | |
35 | BDFTOPCF=/usr/X11R6/bin/bdftopcf; | |
36 | PAT="*.fon"; | |
37 | Q=""; | |
7cae558b | 38 | OLDPWD=`pwd`; |
0ea83643 PG |
39 | |
40 | usage () { | |
41 | echo "usage: "`basename $0`" [-q] [-c charset] [-t fontdir] [-b bdftopcf] [-f fnt2bdf]" | |
42 | echo " [-p pattern] windir" | |
7cae558b | 43 | echo |
0ea83643 PG |
44 | echo "this utility scans a directory and its subdirectories for bitmap-fonts" |
45 | echo "in Windows format, converts them to PCF-fons and installs them. If X" | |
46 | echo "is running, the X fontpath is re-adjusted." | |
7cae558b | 47 | echo |
0ea83643 PG |
48 | echo "options:" |
49 | echo " -q quit operation." | |
50 | echo " -c charset charset name for OEM_CHARSET fonts, default: $CHARSET" | |
51 | echo " -t fontdir directory to install the converted fonts in. This" | |
52 | echo " directory should be a known fontdirectory to X, default:" | |
53 | echo " $TARGET"; | |
54 | echo " -b bdftopcf name of the program to call for bdf to pcf conversion," | |
55 | echo " default: $BDFTOPCF"; | |
56 | echo " -f fnt2bdf name of the program to call for winfont to bdf conversion," | |
57 | echo " default: $FC" | |
58 | echo " -p pattern Shell-Pattern of the filenames to look for. By default, the" | |
59 | echo " utility will look for the pattern "$PAT" (case insensitive)." | |
60 | echo " windir base directory to search." | |
61 | exit 1; | |
62 | } | |
63 | ||
64 | ||
65 | while [ "$1" ]; do | |
66 | case $1 in | |
67 | -c ) shift; if [ "$1" ]; then CHARSET=$1; shift; else usage; fi; ;; | |
68 | -t ) shift; if [ "$1" ]; then TARGET=$1; shift; else usage; fi; ;; | |
69 | -b ) shift; if [ "$1" ]; then BDFTOPCF=$1; shift; else usage; fi; ;; | |
70 | -f ) shift; if [ "$1" ]; then FC=$1; shift; else usage; fi; ;; | |
71 | -p ) shift; if [ "$1" ]; then PAT=$1; shift; else usage; fi; ;; | |
72 | -q ) shift; Q=":"; ;; | |
73 | -* ) usage; ;; | |
7cae558b | 74 | * ) if [ "$WIND" ]; then usage; else WIND=$1; shift; fi; ;; |
0ea83643 PG |
75 | esac; |
76 | done; | |
77 | ||
78 | if [ ! "$WIND" ]; then usage; fi; | |
79 | if [ ! -d "$WIND" ]; then $Q echo "$WIND is not a directory"; exit 1; fi; | |
80 | if [ ! -d "$TARGET" ]; then $Q echo "$TARGET is not a directory"; exit 1; fi; | |
81 | type -p $BDFTOPCF 1>/dev/null || { $Q echo "Can 't execute $BDFTOPCF"; exit 1; } | |
82 | type -p $FC 1>/dev/null || { $Q echo "Can't execute $FC"; exit 1; } | |
83 | ||
cd7534e8 JG |
84 | $Q echo -n "looking for bitmap fonts (\"$PAT\") in directory \"$WIND\"... "; |
85 | FONTS=`find $WIND -iname "$PAT" 1>$TFILE 2>/dev/null`; | |
7cae558b | 86 | if [ $? -ne 0 ]; then |
93416cda | 87 | $Q echo "$PAT is an invalid search expression"; exit 1; |
0ea83643 PG |
88 | fi; |
89 | i=0; | |
cd7534e8 | 90 | |
0ea83643 PG |
91 | { while read dummy; do FONTS[$i]="$dummy"; i=$[$i+1]; done; } < $TFILE |
92 | rm $TFILE; | |
93 | $Q echo "done." | |
94 | ||
7cae558b | 95 | if [ -z "$FONTS" ]; then $Q echo "Can't find any fonts in $WIND"; exit 1; fi; |
0ea83643 | 96 | |
8c2e573f | 97 | mkdir "$TMPDIR" |
cd7534e8 | 98 | for i in "${FONTS[@]}"; do cp $i $TMPDIR; done |
8c2e573f | 99 | cd "$TMPDIR" |
0ea83643 | 100 | |
7cae558b | 101 | for i in "${FONTS[@]}"; do |
0ea83643 PG |
102 | FNT=`basename "$i"`; FNT=${FNT%.???}; |
103 | $Q echo "converting $i"; | |
7cae558b | 104 | if [ "$Q" ]; then |
0ea83643 PG |
105 | $FC -c $CHARSET -f $FNT "$i" 2>/dev/null; |
106 | else | |
107 | $FC -c $CHARSET -f $FNT "$i"; | |
108 | fi; | |
109 | done; | |
110 | ||
111 | for i in *.bdf; do | |
4e422766 | 112 | if [ "$i" = "*.bdf" ]; then |
cd7534e8 JG |
113 | echo "No fonts extracted"; rm -rf "$TMPDIR"; exit 0; |
114 | fi; | |
115 | bdftopcf "$i" | gzip -c > ${i%.???}.pcf.gz; | |
116 | $Q echo "installing ${i%.???}.pcfi.gz"; | |
117 | mv "${i%.???}.pcf.gz" $TARGET 2>/dev/null | |
7cae558b | 118 | if [ $? -ne 0 ]; then |
cd7534e8 JG |
119 | $Q echo "Can't install fonts to $TARGET. Try again as the root user."; |
120 | $Q echo "Cleaning up..."; cd "$OLDPWD"; rm -rf "$TMPDIR"; exit 1; | |
121 | fi; | |
0ea83643 PG |
122 | rm "$i"; |
123 | done; | |
124 | ||
125 | cd $TARGET; | |
7cae558b | 126 | $Q echo "running mkfontdir"; |
0ea83643 PG |
127 | if [ "$Q" ]; then |
128 | mkfontdir 1>/dev/null 2>/dev/null; | |
129 | else | |
130 | mkfontdir | |
131 | fi; | |
cd7534e8 | 132 | rm -rf "$TMPDIR" |
0ea83643 PG |
133 | |
134 | if [ "$DISPLAY" ]; then $Q echo "adjusting X font database"; xset fp rehash; fi; |