c5ef77056ce9a1e7de8877203860babc7ae25020
[wmaker-crm.git] / util / wsetfont
blobc5ef77056ce9a1e7de8877203860babc7ae25020
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 echo -e "\n"\
37 "$PROGRAM - font/language setting utility for Window Maker\n"\
38 "\n"\
39 "Usage: $VERSION\n"\
40 " $PROGRAM [--nodef] [--auto] <font_family>" >/dev/stderr
41 cat >/dev/stderr <<EOF
42 -----------------------------------------------------------------------
43 [font_fam] [Fontset] [Font Information]
44 default helvetica
45 latin1 helvetica(iso8859-1)
46 latin2 helvetica(iso8859-2) See *Note1.
47 greek helvetica(iso8859-7) See *Note1.
48 japanese helvetica/-*-fixed(jisx02XX) Included in X11R6/XFree86("fnon" pkg)
49 korean helvetica/-*-kodig(ksc5601) See *Note1.
50 korean2 helvetica/daewoo(ksc5601) Included in X11R6/XFree86("fnon" pkg)
51 russian helvetica(koi8-r) Included in X11R6/XFree86("fcyr" pkg)
52 turkish unknown See *Note2.
53 -----------------------------------------------------------------------
54 Latin1 Languages: Danish/Dutch/English/Finnish/French/Galician/German/
55 Italian/Norwegian/Portuguese/Spanish/Swedish/...
56 Latin2 Languages: Croatian/Czech/Polish/Romanian/Slovenian/...
58 *Note1: Not included in X11R6/XFree86. You can download them from ...
59 Latin2 X fonts packages: http://sizif.mf.uni-lj.si/linux/cee/iso8859-2.html
60 Greek X fonts packages: ftp://argeas.argos.hol.gr/pub/unix/linux/GREEK/fonts/
61 ftp://ftp.ntua.gr/pub/fonts/X11/
62 Korean X fonts packages: ftp://linux.sarang.net (Linux RPM)
63 ftp://ftp.kaist.ac.kr/pub/hangul/fonts
64 *Note2: please let me know appropriate font setting for WMGLOBAL/WindowMaker,
65 and the fonts' URL to download. mail-to: manome@itlb.te.noda.sut.ac.jp
66 EOF
67 exit
70 nodef=""
71 auto=""
72 family=""
73 for i in $*; do
74 case $i in
75 "--nodef")
76 nodef="YES";;
77 "--auto")
78 auto="YES";;
80 if echo $i |grep "^--locale=" >/dev/null 2>&1; then
81 new_locale=$(echo $i |sed -e "s|--locale=||")
82 elif [ -z $family ]; then
83 family=$i
84 else
85 help_msg
86 fi;;
87 esac
88 done
89 if [ -z "$family" ] && [ -z "$new_locale" ] && [ -z "$auto" ]; then
90 help_msg
93 ################################################################################
94 # You should make changes only in this area
95 # (or it is not what I wanted it to be...)
99 # For --auto and --locale= switch...
101 all_codings="latin1 latin2 greek japanese korean2 russian"
102 latin1="ca da de gl nl fi fr de is it no pt es sv se"
103 latin2="hr cz cs hu pl ro sk sl"
104 greek="el"
105 japanese="ja"
106 korean2="ko"
107 russian="ru bg"
110 # These are lists of all domains and keys we're gonna change...
112 DomainNames="WMGLOBAL WindowMaker"
113 DomainWMGLOBAL="SystemFont BoldSystemFont MultiByteText"
114 DomainWindowMaker="WindowTitleFont MenuTitleFont MenuTextFont IconTitleFont ClipTitleFont DisplayFont"
116 for i in $DomainNames; do
117 tmp="Domain$i"
118 eval AllKeys="\"$AllKeys \$${tmp}\""
119 done
122 # Items that don't need to have coding string appended ( = not fonts).
124 NotFont="MultiByteText"
127 # Elements of $NodefUnable will always have fonts set to defaults, while those
128 # of $NonedefAble will have changed only coding part of font name (if --nodef
129 # command line argument is used).
131 NodefAble="default latin1 latin2 greek russian"
132 NodefUnable="japanese korean korean2"
133 Supported="$NodefAble $NodefUnable"
135 defaultCoding="*-*"
136 latin1Coding="iso8859-1"
137 latin2Coding="iso8859-2"
138 greekCoding="iso8859-7"
139 russianCoding="koi8-r"
141 defaultMultiByteText="AUTO"
142 latin1MultiByteText="NO"
143 latin2MultiByteText="YES"
144 greekMultiByteText="YES"
145 russianMultiByteText="YES"
148 # Default WindowMaker fonts for NodefAble font families (part telling us
149 # the font coding will be added automaticly from *Coding).
151 DefaultSystemFont="-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-"
152 DefaultBoldSystemFont="-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-"
153 DefaultWindowTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-"
154 DefaultMenuTitleFont="-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-"
155 DefaultMenuTextFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-"
156 DefaultIconTitleFont="-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-"
157 DefaultClipTitleFont="-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-"
158 DefaultDisplayFont="-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-"
159 DefaultMultiByteText="AUTO"
162 # NodefUnable have to give full font descriptions...
164 japaneseSystemFont=\"-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-%d-*,-*-*-medium-r-normal-*-*-*\"
165 japaneseBoldSystemFont=\"-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-%d-*,-*-*-medium-r-normal-*-*-*\"
166 japaneseWindowTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
167 japaneseMenuTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
168 japaneseMenuTextFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
169 japaneseIconTitleFont=\"-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-12-*,-*-*-medium-r-normal-*-*-*\"
170 japaneseClipTitleFont=\"-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-12-*,-*-*-medium-r-normal-*-*-*\"
171 japaneseDisplayFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-14-*,-*-*-medium-r-normal-*-*-*\"
172 japaneseMultiByteText="YES"
174 koreanSystemFont=\"-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--%d-*-*-*-*-*-*-*,*-*-medium-r-normal-*-%d-*-*-*-*-*-*-*,*-*-*-*-*--%d-*-*-*-*-*-*-*,*\"
175 koreanBoldSystemFont=\"-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-kodig-bold-r-normal--%d-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--%d-*-*-*-*-*-*-*,*-*-bold-r-normal-*-%d-*-*-*-*-*-*-*,*-*-*-*-*--%d-*-*-*-*-*-*-*,*\"
176 koreanWindowTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--12-*-*-*-*-*-*-*,-*-*-medium-r-normal--12-*-*-*-*-*-*-*,-*-*-medium-r-normal--*-*-*-*-*-*-*-*,-*-*-*-r-normal--*-*-*-*-*-*-*-*,-*-*-*-*-*--*-*-*-*-*-*-*-*,*\"
177 koreanMenuTitleFont=\"-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--14-*-*-*-*-*-*-*,-*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
178 koreanMenuTextFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--14-*-*-*-*-*-*-*,*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
179 koreanIconTitleFont=\"-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
180 koreanClipTitleFont=\"-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--10-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
181 koreanDisplayFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-kodig-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--12-*-*-*-*-*-*-*,*-*-medium-r-normal--*-*-*-*-*-*-*-*,*-*-*-r-normal--*-*-*-*-*-*-*-*,*\"
182 koreanMultiByteText="YES"
184 korean2SystemFont=\"-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-medium-r-normal-*-%d-*,-*-medium-r-normal-*\"
185 korean2BoldSystemFont=\"-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-medium-r-normal-*-%d-*,-*-medium-r-normal-*\"
186 korean2WindowTitleFont=\"7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
187 korean2MenuTitleFont=\"7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
188 korean2MenuTextFont=\"7x14,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
189 korean2IconTitleFont=\"-*-helvetica-medium-r-normal-*-10-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-12-*-*-*-*-*-ksc5601.1987-*\"
190 korean2ClipTitleFont=\"-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-12-*-*-*-*-*-ksc5601.1987-*\"
191 korean2DisplayFont=\"-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*,-*-gothic-medium-r-normal-*-16-*-*-*-*-*-ksc5601.1987-*\"
192 korean2MultiByteText="YES"
195 # End of area meant to hold everything you could need to modify...
196 ################################################################################
199 # Get current locale automaticaly (--auto).
201 if [ -z "$family" ]; then
202 if [ -n "$new_locale" ]; then
203 locale="$new_locale"
204 else
205 locale=$LANG
206 if [ -z "$locale" ]; then
207 locale=$LC_ALL
211 if [ -z "$locale" ]; then
212 family="default"
213 else
214 for i in $all_codings; do
215 eval _i="\$$i"
216 for j in ${_i}; do
217 if [ "$j" = "${locale%_*}" ]; then
218 family="$i"
219 break 2
221 done
222 done
227 # Do we recognize passed coding?
229 is_supported=""
230 for i in $Supported; do
231 if test "$family" = "$i"; then
232 is_supported="YES"
233 break
235 done
236 if test -z "$is_supported"; then # unknown coding
237 echo -e "\n"\
238 "Sorry, font coding $family or locale $locale not recognized.\n"\
239 "Type $PROGRAM with no arguments for list of supported font codings...\n"\
240 "" >/dev/stderr
241 exit 1
245 # Nodef is supported only for elements of $NodefAble.
247 is_nodef_unable=""
248 for i in $NodefUnable; do
249 if test "$family" = "$i"; then
250 if test -n "$nodef"; then # --nodef with one from $NodefUnable
251 echo -e "\n"\
252 "Sorry, --nodef argument is not allowed for these font codings:\n"\
253 " $NodefUnable\n"\
254 "Run $PROGRAM without --nodef argument to set default fonts for your\n"\
255 "font coding.\n"\
256 "" >/dev/stderr
257 exit 1
258 else
259 is_nodef_unable="YES"
260 break
263 done
266 # The real work...
268 if test -z "$nodef"; then
269 for i in $AllKeys; do
270 if test -n "$is_nodef_unable"; then # japanese,... defaults
271 tmp="$family$i"
272 eval $i="\$${tmp}"
273 else # rest, load defaults
274 not_font=""
275 for j in $NotFont; do
276 if test "$i" = "$j"; then
277 not_font="YES"
278 break
280 done
281 if test -n "$not_font"; then # don't append coding (not default!)
282 tmp="${family}$i"
283 eval $i="\$${tmp}"
284 else # append coding
285 tmp="Default$i"
286 tmp1="${family}Coding"
287 eval $i="\$${tmp}\$${tmp1}"
290 done
291 else
292 echo -e "\n"\
293 "You used --nodef command line argument. You should note, that this\n"\
294 "works with these font codings only:\n"\
295 " $NodefAble\n"\
296 "You should not use it to change fonts from other font codings than\n"\
297 "those listed above. If your WindowMaker does not appear to find fonts,\n"\
298 "you should run $PROGRAM once again without --nodef argument." >/dev/stderr
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