Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 1 | #! /bin/bash |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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 |
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | # |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 19 | |
| 20 | # default settings |
| 21 | TMPDIR=/tmp/fconv.$$; |
| 22 | TFILE=`tempfile`; |
| 23 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 24 | # Where the fnt2bdf utility resides |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 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=""; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 32 | OLDPWD=`pwd`; |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 33 | |
| 34 | usage () { |
| 35 | echo "usage: "`basename $0`" [-q] [-c charset] [-t fontdir] [-b bdftopcf] [-f fnt2bdf]" |
| 36 | echo " [-p pattern] windir" |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 37 | echo |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 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." |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 41 | echo |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 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; |
| 56 | } |
| 57 | |
| 58 | |
| 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; ;; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 68 | * ) if [ "$WIND" ]; then usage; else WIND=$1; shift; fi; ;; |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 69 | esac; |
| 70 | done; |
| 71 | |
| 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; } |
| 77 | |
| 78 | $Q echo -n "looking for bitmap fonts... " |
| 79 | FONTS=`find "$WIND" -iname $PAT 1>$TFILE 2>/dev/null`; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 80 | if [ $? -ne 0 ]; then |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 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." |
| 87 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 88 | if [ -z "$FONTS" ]; then $Q echo "Can't find any fonts in $WIND"; exit 1; fi; |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 89 | |
Andreas Mohr | 8c2e573 | 2001-11-25 00:51:36 +0000 | [diff] [blame] | 90 | mkdir "$TMPDIR" |
| 91 | cd "$TMPDIR" |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 92 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 93 | for i in "${FONTS[@]}"; do |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 94 | FNT=`basename "$i"`; FNT=${FNT%.???}; |
| 95 | $Q echo "converting $i"; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 96 | if [ "$Q" ]; then |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 97 | $FC -c $CHARSET -f $FNT "$i" 2>/dev/null; |
| 98 | else |
| 99 | $FC -c $CHARSET -f $FNT "$i"; |
| 100 | fi; |
| 101 | done; |
| 102 | |
| 103 | for i in *.bdf; do |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 104 | if [ "$i" == "*.bdf" ]; then echo "No fonts extracted"; exit 0; fi; |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 105 | bdftopcf -o "${i%.???}.pcf" "$i"; |
| 106 | $Q echo "installing ${i%.???}.pcf"; |
| 107 | mv "${i%.???}.pcf" $TARGET 2>/dev/null |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 108 | if [ $? -ne 0 ]; then |
Andreas Mohr | 8c2e573 | 2001-11-25 00:51:36 +0000 | [diff] [blame] | 109 | $Q echo "Can't install fonts to $TARGET. Are your root?"; cd "$OLDPWD"; rm -rf "$TMPDIR"; exit 1; fi; |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 110 | rm "$i"; |
| 111 | done; |
| 112 | |
| 113 | cd $TARGET; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 114 | $Q echo "running mkfontdir"; |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 115 | if [ "$Q" ]; then |
| 116 | mkfontdir 1>/dev/null 2>/dev/null; |
| 117 | else |
| 118 | mkfontdir |
| 119 | fi; |
Andreas Mohr | 8c2e573 | 2001-11-25 00:51:36 +0000 | [diff] [blame] | 120 | rmdir "$TMPDIR" |
Peter Ganten | 0ea8364 | 2000-05-30 20:49:07 +0000 | [diff] [blame] | 121 | |
| 122 | if [ "$DISPLAY" ]; then $Q echo "adjusting X font database"; xset fp rehash; fi; |