[GRASS-dev] How to change fonts in gis manager?

Glynn,

I’ve created a nice TclTk panel for d.text.new in the GIS Manager. It works fine. Now I’d like to be able to change the fonts it uses. Currently, it only seems to use romans.

I’ve taken out the hard coded d.font romans from the gis.m display routine as it seems to be no longer needed with the new drivers.

But still, when I run d.font (which requires an x.mon to run) and d.font.freetype, it has no effects on d.text.new. I want to embed font selection in the d.text.new panel but want to make sure it works and see what format of fonts definitions it will accept.

Do you have any idea why changing the fonts doesn’t have any effects on d.text.new?

Thanks
Michael


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

Michael Barton wrote:

I¹ve created a nice TclTk panel for d.text.new in the GIS Manager. It works
fine. Now I¹d like to be able to change the fonts it uses. Currently, it
only seems to use romans.

I¹ve taken out the hard coded d.font romans from the gis.m display routine
as it seems to be no longer needed with the new drivers.

But still, when I run d.font (which requires an x.mon to run) and
d.font.freetype, it has no effects on d.text.new. I want to embed font
selection in the d.text.new panel but want to make sure it works and see
what format of fonts definitions it will accept.

Do you have any idea why changing the fonts doesn¹t have any effects on
d.text.new?

d.font and d.font.freetype don't work with direct rendering, as there
is no monitor process to retain state between d.* commands; each d.*
command runs as if with a freshly-started monitor. Similarly, d.frame
and d.save don't work, for the same reason.

To set the default font for direct rendering, you have to use the
environment variables:

  GRASS_FT_FONT
  GRASS_FT_ENCODING
  GRASS_FONT

Note that GRASS_FONT accepts either FreeType or stroke fonts, while
GRASS_FT_FONT only accepts FreeType fonts. If both are set,
GRASS_FT_FONT takes precedence over GRASS_FONT. If neither are set,
"romans" is used.

For GRASS_FONT, the value is passed directly to R_font(), and should
be one of:

1. The full path to a stroke font, beginning with $GISBASE/fonts.
2. The full path to a FreeType font (.ttf file).
3. The name of a FreeType font from the freetypecap file.
4. The name of a stroke font in the $GISBASE/fonts directory.

If the value begins with a "/", it's a full path. If it begins with
(the expansion of) $GISBASE/fonts, it's assumed to be a stroke font,
otherwise a freetype font.

If the value doesn't begin with a "/", it's first searched for in the
freetypecap file; if it isn't found, it's assumed to be the name of a
stroke font.

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

Glynn,

Thanks. I can do something to implement these. I have a related question.
TclTk (and wxPython) have built-in utilities to allow the user to select a
"system" font of some kind (e.g., {timeroman 12 bold}). Is there any way
that GRASS can recognize these?

Michael
__________________________________________
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

From: Glynn Clements <glynn@gclements.plus.com>
Date: Mon, 6 Nov 2006 14:40:34 +0000
To: Michael Barton <michael.barton@asu.edu>
Cc: grass-dev <grass-dev@grass.itc.it>
Subject: Re: [GRASS-dev] How to change fonts in gis manager?

For GRASS_FONT, the value is passed directly to R_font(), and should
be one of:

1. The full path to a stroke font, beginning with $GISBASE/fonts.
2. The full path to a FreeType font (.ttf file).
3. The name of a FreeType font from the freetypecap file.
4. The name of a stroke font in the $GISBASE/fonts directory.

Michael Barton wrote:

I¹ve created a nice TclTk panel for d.text.new in the GIS Manager.

we should probably pick a better name than "d.text.new", it tells you
nothing about what the module does vs other d.text modules and will
become an anachronism before very long.

thanks,
Hamish

Michael Barton wrote:

Thanks. I can do something to implement these. I have a related question.
TclTk (and wxPython) have built-in utilities to allow the user to select a
"system" font of some kind (e.g., {timeroman 12 bold}). Is there any way
that GRASS can recognize these?

No.

At least, not without adding code to use whatever interface(s)
Tk/wxPython use. AFAICT, Tk doesn't use any standard interface (at
least not on X), so we would have to either take the code which Tk
uses and add it to lib/driver, or make lib/driver depend upon Tk.

Even that might not be sufficient; Tk just needs to get a reference to
the font which it can pass to the window system; GRASS needs the
actual glyph bitmaps.

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

Hamish wrote:

> I¹ve created a nice TclTk panel for d.text.new in the GIS Manager.

we should probably pick a better name than "d.text.new", it tells you
nothing about what the module does vs other d.text modules and will
become an anachronism before very long.

If it's deemed to be work adequately, it should supersede d.text (i.e.
change PGM to d.text in display/d.text.new/Makefile and remove d.text
from SUBDIRS in display/Makefile).

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

IMHO, it should simply replace d.text. It has all d.text features and more.

Michael
__________________________________________
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

From: Hamish <hamish_nospam@yahoo.com>
Date: Tue, 7 Nov 2006 16:25:04 +1300
To: Michael Barton <michael.barton@asu.edu>
Cc: <glynn@gclements.plus.com>, <grass-dev@grass.itc.it>
Subject: Re: [GRASS-dev] How to change fonts in gis manager?

Michael Barton wrote:

I¹ve created a nice TclTk panel for d.text.new in the GIS Manager.

we should probably pick a better name than "d.text.new", it tells you
nothing about what the module does vs other d.text modules and will
become an anachronism before very long.

thanks,
Hamish

Too bad.

It is easy enough to make an interface that will pull up GRASS fonts and the
few TrueType fonts that live in the X11 directory, and offer a browser to
let the users pick others. I've done that now. However, it would be nice if
GRASS could somehow easily recognize all the standard system fonts on
different OS's.

Michael
__________________________________________
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

From: Glynn Clements <glynn@gclements.plus.com>
Date: Tue, 7 Nov 2006 05:34:34 +0000
To: Michael Barton <michael.barton@asu.edu>
Cc: grass-dev <grass-dev@grass.itc.it>
Subject: Re: [GRASS-dev] How to change fonts in gis manager?

Michael Barton wrote:

Thanks. I can do something to implement these. I have a related question.
TclTk (and wxPython) have built-in utilities to allow the user to select a
"system" font of some kind (e.g., {timeroman 12 bold}). Is there any way
that GRASS can recognize these?

No.

At least, not without adding code to use whatever interface(s)
Tk/wxPython use. AFAICT, Tk doesn't use any standard interface (at
least not on X), so we would have to either take the code which Tk
uses and add it to lib/driver, or make lib/driver depend upon Tk.

Even that might not be sufficient; Tk just needs to get a reference to
the font which it can pass to the window system; GRASS needs the
actual glyph bitmaps.

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

Patton, Eric wrote:

Disregard my last email, I found out that I needed to place the
GRASS_FT_FONT definition in .grass.bashrc, not grassrc6.

GRASS_FT_FONT etc aren't intended for the user, but for applications
which direct rendering (currently gis.m).

Presumably you are setting it as a workaround for gis.m not providing
a mechanism to set the default font?

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

Glynn,

Thanks for noting this. Currently, there are menu entries for d.font and
d.font.freetype. But these don't work anymore in this context.

So I guess there needs to be a little TclTk dialog written that replaces
these. It would work kind of like the font selection part of the text layer
panel to set GRASS_FONT.

Michael
__________________________________________
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

From: Glynn Clements <glynn@gclements.plus.com>
Date: Thu, 23 Nov 2006 16:35:43 +0000
To: "Patton, Eric" <epatton@nrcan.gc.ca>
Cc: Michael Barton <michael.barton@asu.edu>, grass-dev
<grass-dev@grass.itc.it>
Subject: RE: [GRASS-dev] How to change fonts in gis manager?

Patton, Eric wrote:

Disregard my last email, I found out that I needed to place the
GRASS_FT_FONT definition in .grass.bashrc, not grassrc6.

GRASS_FT_FONT etc aren't intended for the user, but for applications
which direct rendering (currently gis.m).

Presumably you are setting it as a workaround for gis.m not providing
a mechanism to set the default font?

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

Michael Barton wrote:

Thanks for noting this. Currently, there are menu entries for d.font
and d.font.freetype. But these don't work anymore in this context.

So I guess there needs to be a little TclTk dialog written that
replaces these. It would work kind of like the font selection part of
the text layer panel to set GRASS_FONT.

It is a nice ability to change the font for different d.* commands, so
any solution should allow "cmd" display layers containing a d.font.*
command. e.g. use a different font for grid labels and city name labels.
(vs 1 font for all rendering in that display window)

Hamish

Michael Barton wrote:

>> Disregard my last email, I found out that I needed to place the
>> GRASS_FT_FONT definition in .grass.bashrc, not grassrc6.
>
> GRASS_FT_FONT etc aren't intended for the user, but for applications
> which direct rendering (currently gis.m).
>
> Presumably you are setting it as a workaround for gis.m not providing
> a mechanism to set the default font?

Thanks for noting this. Currently, there are menu entries for d.font and
d.font.freetype. But these don't work anymore in this context.

So I guess there needs to be a little TclTk dialog written that replaces
these. It would work kind of like the font selection part of the text layer
panel to set GRASS_FONT.

Ideally, it should be possible to set the font/encoding globally, for
a specific display, and for a specific command.

If want to allow the user to choose fonts from a list, you can list
the FreeType fonts with "d.font.freetype -l"[1], and the stroke fonts
by enumerating the $GISBASE/fonts directory. Also, $GRASS_FONT can be
the absolute path to a .ttf file, so a "Browse" option might be
useful.

[1] With the -l switch, d.font.freetype never gets as far as calling
R_open_driver(), so it doesn't require a driver or for any of the
PNG-driver environment variables to be set

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