Applied patch from Marcelo E. Magallon <marcelo.magallon@bigfoot.com>
[wmaker-crm.git] / util / wsetfont
blobaab254773d02e1c892521d1a660c2008028b2ef5
1 #!/bin/sh
3 # language/font setting script for Window Maker
5 # by MANOME Tomonori <manome@itlb.te.noda.sut.ac.jp>
6 # (rewriten slightly by judas@hell on Jan 27 2001
7 # -argument --nodef tries to change only font coding (limited!)
8 # -much easier to add new font codings
9 # -much harder to read code...
10 # -argument --auto gets locale by itself, but does not override if some
11 # coding is also given
12 # -argument --locale=?? takes locale code (ja, sk, ...)
13 # )
15 # [Special Thanks To]
16 # Korean fontset info from:
17 # Byeong-Chan, Kim <redhands@linux.sarang.net>
18 # Chae-yong Chong <cychong@metro.telecom.samsung.co.kr>
19 # Latin2 fontset info from:
20 # Piotr Dembinski <pdemb@aurora.put.poznan.pl>
21 # Toni Bilic <root@toni.hr.tel.hr>
22 # Greek fontset info from:
23 # Nikolaos Papagrigoriou <papanikos@usa.net>
24 # Quote bug fix info from:
25 # Luke Kendall <luke@research.canon.com.au>
26 # Bug fix info for Korean font section from:
27 # CHOI Junho <junker@jazz.snu.ac.kr>
29 VERSION="Version 0.5 1998/12/07"
31 WDWRITE="wdwrite"
32 WDREAD="wdread"
33 PROGRAM=`basename $0`
35 help_msg() {
36 cat >/dev/stderr <<EOF
37 $PROGRAM - font/language setting utility for Window Maker
39 Usage: $VERSION
40 $PROGRAM [--nodef] [--auto] <font_family>
41 -----------------------------------------------------------------------
42 [font_fam] [Fontset] [Font Information]
43 default helvetica
44 latin1 helvetica(iso8859-1)
45 latin2 helvetica(iso8859-2) See *Note1.
46 greek helvetica(iso8859-7) See *Note1.
47 japanese helvetica/-*-fixed(jisx02XX) Included in X11R6/XFree86("fnon" pkg)
48 korean helvetica/-*-kodig(ksc5601) See *Note1.
49 korean2 helvetica/daewoo(ksc5601) Included in X11R6/XFree86("fnon" pkg)
50 russian helvetica(koi8-r) Included in X11R6/XFree86("fcyr" pkg)
51 turkish unknown See *Note2.
52 -----------------------------------------------------------------------
53 Latin1 Languages: Danish/Dutch/English/Finnish/French/Galician/German/
54 Italian/Norwegian/Portuguese/Spanish/Swedish/...
55 Latin2 Languages: Croatian/Czech/Polish/Romanian/Slovenian/...
57 *Note1: Not included in X11R6/XFree86. You can download them from ...
58 Latin2 X fonts packages: http://sizif.mf.uni-lj.si/linux/cee/iso8859-2.html
59 Greek X fonts packages: ftp://argeas.argos.hol.gr/pub/unix/linux/GREEK/fonts/
60 ftp://ftp.ntua.gr/pub/fonts/X11/
61 Korean X fonts packages: ftp://linux.sarang.net (Linux RPM)
62 ftp://ftp.kaist.ac.kr/pub/hangul/fonts
63 *Note2: please let me know appropriate font setting for WMGLOBAL/WindowMaker,
64 and the fonts' URL to download. mail-to: manome@itlb.te.noda.sut.ac.jp
65 EOF
66 exit
69 nodef=""
70 auto=""
71 family=""
72 for i in $*; do
73 case $i in
74 "--nodef")
75 nodef="YES";;
76 "--auto")
77 auto="YES";;
78 --locale=*)
79 new_locale=`echo $i |sed -e "s|--locale=||" -`;;
81 if [ -z $family ]; then
82 family=$i
83 else
84 help_msg
85 fi;;
86 esac
87 done
88 if [ -z "$family" ] && [ -z "$new_locale" ] && [ -z "$auto" ]; then
89 help_msg
92 ################################################################################
93 # You should make changes only in this area
94 # (or it is not what I wanted it to be...)
98 # For --auto and --locale= switch...
100 all_codings="latin1 latin2 greek japanese korean2 russian"
101 latin1="ca da de gl nl fi fr de is it no pt es sv se"
102 latin2="hr cz cs hu pl ro sk sl"
103 greek="el"
104 japanese="ja"
105 korean2="ko"
106 russian="ru bg"
109 # These are lists of all domains and keys we're gonna change...
111 DomainNames="WMGLOBAL WindowMaker"
112 DomainWMGLOBAL="SystemFont BoldSystemFont MultiByteText"
113 DomainWindowMaker="WindowTitleFont MenuTitleFont MenuTextFont IconTitleFont ClipTitleFont DisplayFont"
115 for i in $DomainNames; do
116 tmp="Domain$i"
117 eval AllKeys="\"$AllKeys \$${tmp}\""
118 done
121 # Items that don't need to have coding string appended ( = not fonts).
123 NotFont="MultiByteText"
126 # Elements of $NodefUnable will always have fonts set to defaults, while those
127 # of $NonedefAble will have changed only coding part of font name (if --nodef
128 # command line argument is used).
130 NodefAble="default latin1 latin2 greek russian"
131 NodefUnable="japanese korean korean2"
132 Supported="$NodefAble $NodefUnable"
134 defaultCoding="*-*"
135 latin1Coding="iso8859-1"
136 latin2Coding="iso8859-2"
137 greekCoding="iso8859-7"
138 russianCoding="koi8-r"
140 defaultMultiByteText="AUTO"
141 latin1MultiByteText="NO"
142 latin2MultiByteText="YES"
143 greekMultiByteText="YES"
144 russianMultiByteText="YES"
147 # Default WindowMaker fonts for NodefAble font families (part telling us
148 # the font coding will be added automaticly from *Coding).
150 DefaultSystemFont="-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-"
151 DefaultBoldSystemFont="-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-"
152 DefaultWindowTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-"
153 DefaultMenuTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-"
154 DefaultMenuTextFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-"
155 DefaultIconTitleFont="-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-"
156 DefaultClipTitleFont="-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-"
157 DefaultDisplayFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-"
158 DefaultMultiByteText="AUTO"
161 # NodefUnable have to give full font descriptions...
163 japaneseSystemFont=\"-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-%d-*,-*-*-medium-r-normal-*-*-*\"
164 japaneseBoldSystemFont=\"-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-%d-*,-*-*-medium-r-normal-*-*-*\"
165 japaneseWindowTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
166 japaneseMenuTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
167 japaneseMenuTextFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
168 japaneseIconTitleFont=\"-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-12-*,-*-*-medium-r-normal-*-*-*\"
169 japaneseClipTitleFont=\"-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-12-*,-*-*-medium-r-normal-*-*-*\"
170 japaneseDisplayFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
171 japaneseMultiByteText="YES"
173 koreanSystemFont=\"-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--%d-*-*-*-*-*-*-*,*-*-medium-r-normal-*-%d-*-*-*-*-*-*-*,*-*-*-*-*--%d-*-*-*-*-*-*-*,*\"
174 koreanBoldSystemFont=\"-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-kodig-bold-r-normal--%d-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--%d-*-*-*-*-*-*-*,*-*-bold-r-normal-*-%d-*-*-*-*-*-*-*,*-*-*-*-*--%d-*-*-*-*-*-*-*,*\"
175 koreanWindowTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--12-*-*-*-*-*-*-*,-*-*-medium-r-normal--12-*-*-*-*-*-*-*,-*-*-medium-r-normal--*-*-*-*-*-*-*-*,-*-*-*-r-normal--*-*-*-*-*-*-*-*,-*-*-*-*-*--*-*-*-*-*-*-*-*,*\"
176 koreanMenuTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--14-*-*-*-*-*-*-*,-*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
177 koreanMenuTextFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--14-*-*-*-*-*-*-*,*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
178 koreanIconTitleFont=\"-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
179 koreanClipTitleFont=\"-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
180 koreanDisplayFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
181 koreanMultiByteText="YES"
183 korean2SystemFont=\"-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-medium-r-normal-*-%d-*,-*-medium-r-normal-*\"
184 korean2BoldSystemFont=\"-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-medium-r-normal-*-%d-*,-*-medium-r-normal-*\"
185 korean2WindowTitleFont=\"7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
186 korean2MenuTitleFont=\"7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
187 korean2MenuTextFont=\"7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
188 korean2IconTitleFont=\"-*-helvetica-medium-r-normal-*-10-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-12-*-*-*-*-*-ksc5601.1987-*\"
189 korean2ClipTitleFont=\"-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-12-*-*-*-*-*-ksc5601.1987-*\"
190 korean2DisplayFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
191 korean2MultiByteText="YES"
194 # End of area meant to hold everything you could need to modify...
195 ################################################################################
198 # Get current locale automaticaly (--auto).
200 if [ -z "$family" ]; then
201 if [ -n "$new_locale" ]; then
202 locale="$new_locale"
203 else
204 locale=$LANG
205 if [ -z "$locale" ]; then
206 locale=$LC_ALL
210 if [ -z "$locale" ]; then
211 family="default"
212 else
213 for i in $all_codings; do
214 eval _i="\$$i"
215 for j in ${_i}; do
216 if [ "$j" = "${locale%_*}" ]; then
217 family="$i"
218 break 2
220 done
221 done
226 # Do we recognize passed coding?
228 is_supported=""
229 for i in $Supported; do
230 if test "$family" = "$i"; then
231 is_supported="YES"
232 break
234 done
235 if test -z "$is_supported"; then # unknown coding
236 cat >/dev/stderr <<EOT
237 Sorry, font coding $family or locale $locale not recognized.
238 Type $PROGRAM with no arguments for list of supported font codings...
240 exit 1
244 # Nodef is supported only for elements of $NodefAble.
246 is_nodef_unable=""
247 for i in $NodefUnable; do
248 if test "$family" = "$i"; then
249 if test -n "$nodef"; then # --nodef with one from $NodefUnable
250 cat >/dev/stderr <<-EOT
251 Sorry, --nodef argument is not allowed for these font codings:
252 $NodefUnable
253 Run $PROGRAM without --nodef argument to set default fonts for your
254 font coding.
256 exit 1
257 else
258 is_nodef_unable="YES"
259 break
262 done
265 # The real work...
267 if test -z "$nodef"; then
268 for i in $AllKeys; do
269 if test -n "$is_nodef_unable"; then # japanese,... defaults
270 tmp="$family$i"
271 eval $i="\$${tmp}"
272 else # rest, load defaults
273 not_font=""
274 for j in $NotFont; do
275 if test "$i" = "$j"; then
276 not_font="YES"
277 break
279 done
280 if test -n "$not_font"; then # don't append coding (not default!)
281 tmp="${family}$i"
282 eval $i="\$${tmp}"
283 else # append coding
284 tmp="Default$i"
285 tmp1="${family}Coding"
286 eval $i="\$${tmp}\$${tmp1}"
289 done
290 else
291 cat >/dev/stderr <<EOT
292 You used --nodef command line argument. You should note, that this
293 works with these font codings only:
294 $NodefAble
295 You should not use it to change fonts from other font codings than
296 those listed above. If your WindowMaker does not appear to find fonts,
297 you should run $PROGRAM once again without --nodef argument.
302 # Ok, in the following, `i' will be the domain file name,
303 # `j' is the actual key in that file we try to change...
305 for i in $DomainNames; do
306 echo
307 echo "Setting up $i domain file..."
308 tmp="Domain$i"
309 eval _tmp="\$${tmp}"
310 for j in ${_tmp}; do
311 if test -n "$nodef"; then # --nodef, change coding only
312 not_font=""
313 for k in $NotFont; do
314 if test "$k" = "$j"; then
315 not_font="YES"
316 break;
318 done
319 if test -n "$not_font"; then # don't append coding
320 tmp1="${family}$j"
321 eval $j="\$${tmp1}"
322 else # append coding
323 #TODO:make this funny sed script a lot smarter to let us make changes in font
324 # lists, etc... (then we can enable --nodef for NodefUnable codings)
325 #TODO:better (or at least any) check, whether wmaker is installed...
326 tmp1="${family}Coding"
327 eval _tmp1="\$${tmp1}"
328 eval $j=`$WDREAD $i $j | sed -e "s/\(^-.*-\).*-.*$/\1${_tmp1}/g"`
329 eval _j="\$$j"
330 if test -z "${_j}"; then # failed, load default
331 tmp2="Default$j"
332 eval $j="\$${tmp2}"
336 tmp1="$j=\"`eval echo '${'$j'}'`\"" # cosmetic length workaround
337 echo '<<<<'
338 if [ ${#tmp1} -lt 80 ]; then
339 tmp1=`echo $tmp1 | sed -e 's/^\(.\{1,76\}\).*/\1/'`
341 eval _j="\$$j"
342 echo $j="${_j}"
343 $WDWRITE $i $j \"${_j}\"
344 done
345 done
346 echo