[GRASS-dev] fonts and character encoding

Glynn Clements glynn at gclements.plus.com
Sat May 12 17:08:46 EDT 2007

Michael Barton wrote:

> > So, I think that the GUI should probably set GRASS_FT_ENCODING to the
> > locale's encoding (e.g. from "locale charmap").
> You mean instead of having the user set it?



Tcl and Python both use Unicode internally, and automatically convert
to the locale's encoding when calling system functions. So if the user
types a value for e.g. "d.text text=..." into the GUI, the sequence of
bytes which end up in the corresponding argv[] will be in the locale's

At least, that's the default. With Tcl, you can change the default
encoding with "encoding system <name>", where <name> is one of the
values returned by "encoding names". Also, when reading/writing
streams (files or pipes), you can change the encoding for that
particular stream with "fconfigure $fh -encoding ...".

But, in general, the GUI should probably stick with the locale's
encoding, as that's what external commands will normally be expecting.

> How do I access locale charmap from TclTk or wxPython?

	set encoding [exec locale charmap]
	encoding = Popen(["locale", "charmap"], stdout=PIPE).communicate()[0].strip()

AFAICT, the resulting value will be valid for iconv(), and thus for

Needless to say, this won't work on Windows. You can get the Windows
codepage by parsing the output from "mode con cp /status", although
there might be better solutions. iconv appears to accept cp??? for
most of the common ones (e.g. cp437 = US, cp850 = western Europe,

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list