[GRASS-dev] using system fonts?

Perhaps this is a silly question, but is there any way to use system fonts in GRASS. Currently, we either need to use a stroke font (the default, ugly) or specify a path to a Truetype font.

It is quite easy to get system font information (family, name, style, size, color, etc) from a standard system font dialog in wxPython (and in TclTk too). Is there some way to pass that information to GRASS so that it will be the display font. Or could there be a flag/GRASS environmental variable, to make the default system font the default GRASS font? Then the default could be changed as desired. Imagine Helvetica/Lucida Grand/Arial as the default font for legends, bar scales, and the likeā€¦

Michael


Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Michael Barton wrote:

Perhaps this is a silly question, but is there any way to use system fonts
in GRASS. Currently, we either need to use a stroke font (the default, ugly)
or specify a path to a Truetype font.

It is quite easy to get system font information (family, name, style, size,
color, etc) from a standard system font dialog in wxPython (and in TclTk
too). Is there some way to pass that information to GRASS so that it will be
the display font. Or could there be a flag/GRASS environmental variable, to
make the default system font the default GRASS font? Then the default could
be changed as desired. Imagine Helvetica/Lucida Grand/Arial as the default
font for legends, bar scales, and the like...

Adding support for bitmap fonts would be reasonably straightforward,
but getting those fonts without using X might be a different matter
(bear in mind that there might not be any font files on the local
system. X can get its fonts from a font server).

Personally, I would have thought that the Freetype support would be
sufficient. If it isn't, I can look into either stealing the
PCF-reading code from X, or writing an X-based font-dumping utility.
Obviously, I don't want to make the PNG/PS drivers link directly
against Xlib.

BTW, the term "default system font" isn't clear-cut. Different
toolkits may have different ideas as to the default font. Xt uses X
resources. Tcl/Tk manually parses certain X resource files (but not in
the same that Xt does), so it might use the same font as Xt-based
applications or it might not. GTK and Qt have their own mechanisms,
and can vary depending upon whether they are being used under Gnome or
KDE.

--
Glynn Clements <glynn@gclements.plus.com>

I guess, I'm thinking of my Mac-centric world (thought similar for Windows
too), where bringing up a font selection dialog lets me access the fonts
installed on my system and send their specifications to a display app. I
don't have to go searching for them. These are the bitmapped fonts, in
general I guess.

It would simply be nice to be able to make a consistent font selection
interface across GRASS. I don't use Linux enough to know where a
font-selection dialog created by wxPython, for example, gets its fonts.

Maybe it's more a matter of specifying fonts. Currently, we have to give a
TT font file path. Could it accept a bitmapped font description too (font
name, style, color, size)?

Michael

On 4/23/07 11:44 AM, "Glynn Clements" <glynn@gclements.plus.com> wrote:

Michael Barton wrote:

Perhaps this is a silly question, but is there any way to use system fonts
in GRASS. Currently, we either need to use a stroke font (the default, ugly)
or specify a path to a Truetype font.

It is quite easy to get system font information (family, name, style, size,
color, etc) from a standard system font dialog in wxPython (and in TclTk
too). Is there some way to pass that information to GRASS so that it will be
the display font. Or could there be a flag/GRASS environmental variable, to
make the default system font the default GRASS font? Then the default could
be changed as desired. Imagine Helvetica/Lucida Grand/Arial as the default
font for legends, bar scales, and the like...

Adding support for bitmap fonts would be reasonably straightforward,
but getting those fonts without using X might be a different matter
(bear in mind that there might not be any font files on the local
system. X can get its fonts from a font server).

Personally, I would have thought that the Freetype support would be
sufficient. If it isn't, I can look into either stealing the
PCF-reading code from X, or writing an X-based font-dumping utility.
Obviously, I don't want to make the PNG/PS drivers link directly
against Xlib.

BTW, the term "default system font" isn't clear-cut. Different
toolkits may have different ideas as to the default font. Xt uses X
resources. Tcl/Tk manually parses certain X resource files (but not in
the same that Xt does), so it might use the same font as Xt-based
applications or it might not. GTK and Qt have their own mechanisms,
and can vary depending upon whether they are being used under Gnome or
KDE.

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Michael Barton wrote:

I guess, I'm thinking of my Mac-centric world (thought similar for Windows
too), where bringing up a font selection dialog lets me access the fonts
installed on my system and send their specifications to a display app. I
don't have to go searching for them. These are the bitmapped fonts, in
general I guess.

That would surprise me; TrueType fonts seem to be the norm nowadays.
Bear in mind that TTF files can contain pre-rendered bitmaps for
common sizes; the FreeType library will use these automatically if
they are found.

It would simply be nice to be able to make a consistent font selection
interface across GRASS. I don't use Linux enough to know where a
font-selection dialog created by wxPython, for example, gets its fonts.

That depends upon the toolkit which wx uses, and the options it was
built with (e.g. whether it uses Xft).

Maybe it's more a matter of specifying fonts. Currently, we have to give a
TT font file path. Could it accept a bitmapped font description too (font
name, style, color, size)?

In general, no.

X applications can tell the X server to use a font by name. The X
server knows where to get the fonts from via the FontPath settings in
the xorg.conf file (previously XF86Config).

Non-X applications won't easily be able to find whatever fonts X is
using; they may not even be available from the system on which the
client is running (other than by "dumping" them, i.e. drawing text
into a pixmap then grabbing the pixmap contents from the server; for
TrueType fonts, this will get you pre-rendered bitmaps rather than the
outlines).

Every application which wants to do something with fonts other than
render them via X has the same issues; even X applications which need
to get at the actual fonts to e.g. embed them in a PDF file.

--
Glynn Clements <glynn@gclements.plus.com>

I wonder if [wx]Python has a general font handling API that taps into the platform font/type API - for both selecting and drawing fonts.

Especially on OSX, probably Windows, available fonts are not just what's "installed". There are 3rd party utilities that 'activate' fonts outside the normal font folders, using the system API.

On Apr 23, 2007, at 8:02 PM, Michael Barton wrote:

I guess, I'm thinking of my Mac-centric world (thought similar for Windows
too), where bringing up a font selection dialog lets me access the fonts
installed on my system and send their specifications to a display app. I
don't have to go searching for them. These are the bitmapped fonts, in
general I guess.

It would simply be nice to be able to make a consistent font selection
interface across GRASS. I don't use Linux enough to know where a
font-selection dialog created by wxPython, for example, gets its fonts.

Maybe it's more a matter of specifying fonts. Currently, we have to give a
TT font file path. Could it accept a bitmapped font description too (font
name, style, color, size)?

Michael

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

[Trillian] What are you supposed to do WITH a maniacally depressed robot?

[Marvin] You think you have problems? What are you supposed to do if you ARE a maniacally depressed robot? No, don't try and answer, I'm 50,000 times more intelligent than you and even I don't know the answer...

- HitchHiker's Guide to the Galaxy

William Kyngesburye wrote:

I wonder if [wx]Python has a general font handling API that taps into
the platform font/type API - for both selecting and drawing fonts.

Yes. But that doesn't help us at all, as it won't actually tell you
where to find the .ttf file so that the display drivers can use it.

--
Glynn Clements <glynn@gclements.plus.com>

Ah, I was thinking of font rendering with Python, not directly in a GRASS display module or driver. Even so, the Python font API (whatever it may be) might have some method of obtaining the font file path?

On Apr 23, 2007, at 9:14 PM, Glynn Clements wrote:

William Kyngesburye wrote:

I wonder if [wx]Python has a general font handling API that taps into
the platform font/type API - for both selecting and drawing fonts.

Yes. But that doesn't help us at all, as it won't actually tell you
where to find the .ttf file so that the display drivers can use it.

--
Glynn Clements <glynn@gclements.plus.com>

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

"Time is an illusion - lunchtime doubly so."

- Ford Prefect

If there is a way to get the path from the multitude of font information I
CAN get, I can't find it. Everything but.

What I'd like to get away from is for everyone to have to search for their
fonts to use in GRASS. On the Mac, most are in /Library/fonts. However, some
are also in the X11RC directory. On different Linux systems they are in
other places, and for Windows I have no idea where they live.

This means that there is no way to design a generic font picker for GRASS
that will simply list available fonts. I CAN get a generic font picker from
a GUI package, but at least with wxPython and TclTk, it provides lots of
information about font DESCRIPTION, but nothing (that I can find) about font
LOCATION and file name.

Maybe it's just not possible to specify font description for GRASS display
(or more trouble than it's worth for one reason or another). But it would be
nice.

The other thing that makes this more complicated is that, if I understand it
correctly, font settings do not persist past a single display event. This
provides greater flexibility in creating displays with different fonts, but
it makes it harder to set a default font for all GRASS unless you want to
change it.

This is all doable and possible to have nice displays in GRASS. It's just
complicated to code into a GUI. I'll stop whining now.

Michael

On 4/23/07 7:56 PM, "William Kyngesburye" <woklist@kyngchaos.com> wrote:

Ah, I was thinking of font rendering with Python, not directly in a
GRASS display module or driver. Even so, the Python font API
(whatever it may be) might have some method of obtaining the font
file path?

On Apr 23, 2007, at 9:14 PM, Glynn Clements wrote:

William Kyngesburye wrote:

I wonder if [wx]Python has a general font handling API that taps into
the platform font/type API - for both selecting and drawing fonts.

Yes. But that doesn't help us at all, as it won't actually tell you
where to find the .ttf file so that the display drivers can use it.

--
Glynn Clements <glynn@gclements.plus.com>

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

"Time is an illusion - lunchtime doubly so."

- Ford Prefect

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

William Kyngesburye wrote:

Ah, I was thinking of font rendering with Python, not directly in a
GRASS display module or driver. Even so, the Python font API
(whatever it may be) might have some method of obtaining the font
file path?

Nope; that information simply isn't available.

The way that fonts work in a GUI is that the GUI (usually) provides
some way to obtain a list of names, and (invariably) provides some way
to select a font using a name.

As for paths: there may not be any paths. The X server can get its
fonts from a font server; as for where the font server gets those
fonts from, not even the X server knows. And even if it did, that
doesn't help if it can't access the filesystem on the box which is
running the font server.

And even if the X server gets those fonts from files, those files may
not be accessible to the X client.

I do all of my GRASS development on my Linux box. When I say "on", I
mean that's where the shell is running, that's where make, gcc etc
run, that's where GRASS programs are run.

The Linux box doesn't have a monitor. The Windows box has a monitor,
and that's where the X server runs, and that's where all of my windows
(XEmacs, xterm, XDRIVER, gis.m etc) show up. The X server is using the
fonts on the Windows box (i.e. /usr/X11R6/lib/X11/fonts/* in Cygwin,
or C:\cygwin\usr\X11R6\lib\X11\fonts in Windows). Those paths simply
aren't accessible to gis.m or other programs running on the Linux box.

Now, I do have a reasonable set of fonts available on the Linux box,
in /usr/share/fonts/*. But there is absolutely no standard API
function (whether in C or Tk or Python or anything else) which is
going to reveal this fact to the PNG driver. It *has* to be told.

--
Glynn Clements <glynn@gclements.plus.com>

Michael Barton wrote:

If there is a way to get the path from the multitude of font information I
CAN get, I can't find it. Everything but.

What I'd like to get away from is for everyone to have to search for their
fonts to use in GRASS. On the Mac, most are in /Library/fonts. However, some
are also in the X11RC directory. On different Linux systems they are in
other places, and for Windows I have no idea where they live.

This means that there is no way to design a generic font picker for GRASS
that will simply list available fonts. I CAN get a generic font picker from
a GUI package, but at least with wxPython and TclTk, it provides lots of
information about font DESCRIPTION, but nothing (that I can find) about font
LOCATION and file name.

Maybe it's just not possible to specify font description for GRASS display
(or more trouble than it's worth for one reason or another). But it would be
nice.

At a minimum, it requires that the renderer knows where the fonts are,
and can get at them.

The other thing that makes this more complicated is that, if I understand it
correctly, font settings do not persist past a single display event. This
provides greater flexibility in creating displays with different fonts, but
it makes it harder to set a default font for all GRASS unless you want to
change it.

For direct rendering, the font is set from environment variables. That
means that they can only be changed by an ancestor of any d.* commands
(e.g. the shell, gis.m, gism.py etc), and not by a sibling (the way
that d.font works).

The font could easily be set from a GRASS variable, but that's
basically a bad idea. It doesn't make it any easier for a GUI (setting
an environment variable is no harder than running d.font), and causes
problems due to statefulness, i.e. the order in which you execute the
display commands matters, you can't run multiple display commands
concurrently, etc.

In general, global state is bad. Its use in GRASS is due to its CLI
origins, where having to specify the database, location, mapset,
region, monitor, font, etc as explicit parameters for each command
would be a nuisance. Mostly, you want those parameters to be the same
for successive commands until you say otherwise, so you use global
state to eliminate the need to keep typing them.

For a GUI, this isn't an issue; the GUI can keep track of the state.
Moreover, if you want to change a parameter for an individual command,
you don't have to modify global state, run the command, change the
state back, and hope that the modification didn't interfere with
anything else which was running concurrently.

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

Nope; that information simply isn't available.

The way that fonts work in a GUI is that the GUI (usually) provides
some way to obtain a list of names, and (invariably) provides some way
to select a font using a name.

perhaps add a script to the GUI Config menu to search the system for
.ttf fonts and dump to a .grass fontcap file?

eg for {`uname -s` = "Darwin"} look in wherever Mac dumps fonts, for
Windows use a .bat file that looks in C:\Windows\fonts\*.ttf (or
wherever), and for Linux /usr/X11R6/lib/X11/fonts/* or other common
dumping grounds.

if any files are on that list you get an easy picker, if not you can
always select the <file broswer>.

??,
Hamish

This is what I was thinking of with a GRASS_FONTPATH variable. It could
either set these as reasonable defaults or read what is specifically set in
a configuration file (e.g., .grassrc6 or .profile).

Michael

On 4/23/07 10:57 PM, "Hamish" <hamish_nospam@yahoo.com> wrote:

Glynn Clements wrote:

Nope; that information simply isn't available.

The way that fonts work in a GUI is that the GUI (usually) provides
some way to obtain a list of names, and (invariably) provides some way
to select a font using a name.

perhaps add a script to the GUI Config menu to search the system for
.ttf fonts and dump to a .grass fontcap file?

eg for {`uname -s` = "Darwin"} look in wherever Mac dumps fonts, for
Windows use a .bat file that looks in C:\Windows\fonts\*.ttf (or
wherever), and for Linux /usr/X11R6/lib/X11/fonts/* or other common
dumping grounds.

if any files are on that list you get an easy picker, if not you can
always select the <file broswer>.

??,
Hamish

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

This is what I'm trying to think about and maybe try something. I can
certainly create a file browser that would let a user find and select a True
Type font. I'm just trying to think of a way that a user doesn't have to try
to figure out where the fonts are stored--or at the very least give them a
reasonable hint to start with. Maybe everyone using Linux knows the path to
the fonts, but I'd wager that most people using Mac's and Windows don't know
this.

Michael

On 4/23/07 10:18 PM, "Glynn Clements" <glynn@gclements.plus.com> wrote:

For a GUI, this isn't an issue; the GUI can keep track of the state.
Moreover, if you want to change a parameter for an individual command,
you don't have to modify global state, run the command, change the
state back, and hope that the modification didn't interfere with
anything else which was running concurrently.

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton