forgot this
[wmaker-crm.git] / util / wsetfont
blobb7854efd4d9305b6bb6a4d34a46d4b36f278c2f0
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>
28 # Ukrainian fontset info from:
29 # Bohdan Vlasyuk <bohdan@vstu.edu.ua>
31 VERSION="Version 0.6 2002/01/12"
33 WDWRITE="wdwrite"
34 WDREAD="wdread"
35 PROGRAM=`basename $0`
37 help_msg() {
38 cat >/dev/stderr <<EOF
39 $PROGRAM - font/language setting utility for Window Maker
41 Usage: $VERSION
42 $PROGRAM [--nodef] [--auto] <font_family>
43 -----------------------------------------------------------------------
44 [font_fam] [Fontset] [Font Information]
45 default helvetica
46 latin1 helvetica(iso8859-1)
47 latin2 helvetica(iso8859-2) See *Note1.
48 greek helvetica(iso8859-7) See *Note1.
49 japanese helvetica/-*-fixed(jisx02XX) Included in X11R6/XFree86("fnon" pkg)
50 korean helvetica/-*-kodig(ksc5601) See *Note1.
51 korean2 helvetica/daewoo(ksc5601) Included in X11R6/XFree86("fnon" pkg)
52 russian helvetica(koi8-r) Included in X11R6/XFree86("fcyr" pkg)
53 ukrainian helvetica(koi8-u) See *Note1.
54 turkish unknown See *Note2.
55 -----------------------------------------------------------------------
56 Latin1 Languages: Danish/Dutch/English/Finnish/French/Galician/German/
57 Italian/Norwegian/Portuguese/Spanish/Swedish/...
58 Latin2 Languages: Croatian/Czech/Polish/Romanian/Slovenian/...
60 *Note1: Not included in X11R6/XFree86. You can download them from ...
61 Latin2 X fonts packages: http://sizif.mf.uni-lj.si/linux/cee/iso8859-2.html
62 Greek X fonts packages: ftp://argeas.argos.hol.gr/pub/unix/linux/GREEK/fonts/
63 ftp://ftp.ntua.gr/pub/fonts/X11/
64 Korean X fonts packages: ftp://linux.sarang.net (Linux RPM)
65 ftp://ftp.kaist.ac.kr/pub/hangul/fonts
66 Ukrainian X fonts packages: http://www.inp.nsk.su/~bolkhov/files/fonts/cyr-rfx/
67 *Note2: please let me know appropriate font setting for WMGLOBAL/WindowMaker,
68 and the fonts' URL to download. mail-to: manome@itlb.te.noda.sut.ac.jp
69 EOF
70 exit
73 nodef=""
74 auto=""
75 family=""
76 for i in $*; do
77 case $i in
78 "--nodef")
79 nodef="YES";;
80 "--auto")
81 auto="YES";;
82 --locale=*)
83 new_locale=`echo $i |sed -e "s|--locale=||" -`;;
85 if [ -z $family ]; then
86 family=$i
87 else
88 help_msg
89 fi;;
90 esac
91 done
92 if [ -z "$family" ] && [ -z "$new_locale" ] && [ -z "$auto" ]; then
93 help_msg
96 ################################################################################
97 # You should make changes only in this area
98 # (or it is not what I wanted it to be...)
102 # For --auto and --locale= switch...
104 all_codings="latin1 latin2 greek japanese korean2 russian ukrainian"
105 latin1="ca da de gl nl fi fr de is it no pt es sv se"
106 latin2="hr cz cs hu pl ro sk sl"
107 greek="el"
108 japanese="ja"
109 korean2="ko"
110 russian="ru bg"
111 ukrainian="uk" # note that it's really uk, not ua.
114 # These are lists of all domains and keys we're gonna change...
116 DomainNames="WMGLOBAL WindowMaker"
117 DomainWMGLOBAL="SystemFont BoldSystemFont MultiByteText"
118 DomainWindowMaker="WindowTitleFont MenuTitleFont MenuTextFont IconTitleFont ClipTitleFont DisplayFont"
120 for i in $DomainNames; do
121 tmp="Domain$i"
122 eval AllKeys="\"$AllKeys \$${tmp}\""
123 done
126 # Items that don't need to have coding string appended ( = not fonts).
128 NotFont="MultiByteText"
131 # Elements of $NodefUnable will always have fonts set to defaults, while those
132 # of $NonedefAble will have changed only coding part of font name (if --nodef
133 # command line argument is used).
135 NodefAble="default latin1 latin2 greek russian ukrainian"
136 NodefUnable="japanese korean korean2"
137 Supported="$NodefAble $NodefUnable"
139 defaultCoding="*-*"
140 latin1Coding="iso8859-1"
141 latin2Coding="iso8859-2"
142 greekCoding="iso8859-7"
143 russianCoding="koi8-r"
144 ukrainianCoding="koi8-u"
146 defaultMultiByteText="AUTO"
147 latin1MultiByteText="NO"
148 latin2MultiByteText="YES"
149 greekMultiByteText="YES"
150 russianMultiByteText="YES"
151 ukrainianMultiByteText="YES"
155 # Default WindowMaker fonts for NodefAble font families (part telling us
156 # the font coding will be added automaticly from *Coding).
158 DefaultSystemFont="-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-"
159 DefaultBoldSystemFont="-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-"
160 DefaultWindowTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-"
161 DefaultMenuTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-"
162 DefaultMenuTextFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-"
163 DefaultIconTitleFont="-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-"
164 DefaultClipTitleFont="-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-"
165 DefaultDisplayFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-"
166 DefaultMultiByteText="AUTO"
169 # NodefUnable have to give full font descriptions...
171 japaneseSystemFont="-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-%d-*,-*-*-medium-r-normal-*-*-*"
172 japaneseBoldSystemFont="-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-%d-*,-*-*-medium-r-normal-*-*-*"
173 japaneseWindowTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*"
174 japaneseMenuTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*"
175 japaneseMenuTextFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*"
176 japaneseIconTitleFont="-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-12-*,-*-*-medium-r-normal-*-*-*"
177 japaneseClipTitleFont="-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-12-*,-*-*-medium-r-normal-*-*-*"
178 japaneseDisplayFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*"
179 japaneseMultiByteText="YES"
181 koreanSystemFont="-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--%d-*-*-*-*-*-*-*,*-*-medium-r-normal-*-%d-*-*-*-*-*-*-*,*-*-*-*-*--%d-*-*-*-*-*-*-*,*"
182 koreanBoldSystemFont="-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-kodig-bold-r-normal--%d-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--%d-*-*-*-*-*-*-*,*-*-bold-r-normal-*-%d-*-*-*-*-*-*-*,*-*-*-*-*--%d-*-*-*-*-*-*-*,*"
183 koreanWindowTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--12-*-*-*-*-*-*-*,-*-*-medium-r-normal--12-*-*-*-*-*-*-*,-*-*-medium-r-normal--*-*-*-*-*-*-*-*,-*-*-*-r-normal--*-*-*-*-*-*-*-*,-*-*-*-*-*--*-*-*-*-*-*-*-*,*"
184 koreanMenuTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--14-*-*-*-*-*-*-*,-*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*"
185 koreanMenuTextFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--14-*-*-*-*-*-*-*,*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*"
186 koreanIconTitleFont="-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*"
187 koreanClipTitleFont="-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*"
188 koreanDisplayFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*"
189 koreanMultiByteText="YES"
191 korean2SystemFont="-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-medium-r-normal-*-%d-*,-*-medium-r-normal-*"
192 korean2BoldSystemFont="-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-medium-r-normal-*-%d-*,-*-medium-r-normal-*"
193 korean2WindowTitleFont="7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*"
194 korean2MenuTitleFont="7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*"
195 korean2MenuTextFont="7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*"
196 korean2IconTitleFont="-*-helvetica-medium-r-normal-*-10-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-12-*-*-*-*-*-ksc5601.1987-*"
197 korean2ClipTitleFont="-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-12-*-*-*-*-*-ksc5601.1987-*"
198 korean2DisplayFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*"
199 korean2MultiByteText="YES"
202 # End of area meant to hold everything you could need to modify...
203 ################################################################################
206 # Get current locale automaticaly (--auto).
208 if [ -z "$family" ]; then
209 if [ -n "$new_locale" ]; then
210 locale="$new_locale"
211 else
212 locale=$LANG
213 if [ -z "$locale" ]; then
214 locale=$LC_ALL
218 if [ -z "$locale" ]; then
219 family="default"
220 else
221 for i in $all_codings; do
222 eval _i="\$$i"
223 for j in ${_i}; do
224 if [ "$j" = "${locale%_*}" ]; then
225 family="$i"
226 break 2
228 done
229 done
234 # Do we recognize passed coding?
236 is_supported=""
237 for i in $Supported; do
238 if test "$family" = "$i"; then
239 is_supported="YES"
240 break
242 done
243 if test -z "$is_supported"; then # unknown coding
244 cat >/dev/stderr <<EOT
245 Sorry, font coding $family or locale $locale not recognized.
246 Type $PROGRAM with no arguments for list of supported font codings...
248 exit 1
252 # Nodef is supported only for elements of $NodefAble.
254 is_nodef_unable=""
255 for i in $NodefUnable; do
256 if test "$family" = "$i"; then
257 if test -n "$nodef"; then # --nodef with one from $NodefUnable
258 cat >/dev/stderr <<-EOT
259 Sorry, --nodef argument is not allowed for these font codings:
260 $NodefUnable
261 Run $PROGRAM without --nodef argument to set default fonts for your
262 font coding.
264 exit 1
265 else
266 is_nodef_unable="YES"
267 break
270 done
273 # The real work...
275 if test -z "$nodef"; then
276 for i in $AllKeys; do
277 if test -n "$is_nodef_unable"; then # japanese,... defaults
278 tmp="$family$i"
279 eval $i="\$${tmp}"
280 else # rest, load defaults
281 not_font=""
282 for j in $NotFont; do
283 if test "$i" = "$j"; then
284 not_font="YES"
285 break
287 done
288 if test -n "$not_font"; then # don't append coding (not default!)
289 tmp="${family}$i"
290 eval $i="\$${tmp}"
291 else # append coding
292 tmp="Default$i"
293 tmp1="${family}Coding"
294 eval $i="\$${tmp}\$${tmp1}"
297 done
298 else
299 cat >/dev/stderr <<EOT
300 You used --nodef command line argument. You should note, that this
301 works with these font codings only:
302 $NodefAble
303 You should not use it to change fonts from other font codings than
304 those listed above. If your WindowMaker does not appear to find fonts,
305 you should run $PROGRAM once again without --nodef argument.
310 # Ok, in the following, `i' will be the domain file name,
311 # `j' is the actual key in that file we try to change...
313 for i in $DomainNames; do
314 echo
315 echo "Setting up $i domain file..."
316 tmp="Domain$i"
317 eval _tmp="\$${tmp}"
318 for j in ${_tmp}; do
319 if test -n "$nodef"; then # --nodef, change coding only
320 not_font=""
321 for k in $NotFont; do
322 if test "$k" = "$j"; then
323 not_font="YES"
324 break;
326 done
327 if test -n "$not_font"; then # don't append coding
328 tmp1="${family}$j"
329 eval $j="\$${tmp1}"
330 else # append coding
331 #TODO:make this funny sed script a lot smarter to let us make changes in font
332 # lists, etc... (then we can enable --nodef for NodefUnable codings)
333 #TODO:better (or at least any) check, whether wmaker is installed...
334 tmp1="${family}Coding"
335 eval _tmp1="\$${tmp1}"
336 eval $j=`$WDREAD $i $j | sed -e "s/\(^-.*-\).*-.*$/\1${_tmp1}/g"`
337 eval _j="\$$j"
338 if test -z "${_j}"; then # failed, load default
339 tmp2="Default$j"
340 eval $j="\$${tmp2}"
344 tmp1="$j=\"`eval echo '${'$j'}'`\"" # cosmetic length workaround
345 echo '<<<<'
346 if [ ${#tmp1} -lt 80 ]; then
347 tmp1=`echo $tmp1 | sed -e 's/^\(.\{1,76\}\).*/\1/'`
349 eval _j="\$$j"
350 echo $j="${_j}"
351 $WDWRITE $i $j \"${_j}\"
352 done
353 done
354 echo