[GRASS-dev] thinking about font variables

Glynn Clements glynn at gclements.plus.com
Thu Apr 26 04:27:14 EDT 2007


Michael Barton wrote:

> >> FWIW, I simply have this line in my .grass.bashrc file:  (GRASS 6.3)
> >>  alias d.font.vera='d.font
> >> path=/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf'
> >> 
> >> or for GRASS 6.2:
> >>  alias d.font.vera='d.font.freetype
> >> /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf'
> >> 
> >> then I run d.font.vera whenever I want that.
> > 
> > If you put e.g.:
> > 
> > vera:/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf:iso-8859-1:
> > 
> > into $GISBASE/etc/freetypecap, you can use "d.font vera" to get the
> > same result.
> > 
> > At present, the freetypecap file is copied from scripts/d.text.freetype.
> > We can probably improve upon that, e.g. looking for .ttf files in
> > likely font directories (e.g. /usr/share/fonts, /usr/lib/X11/fonts,
> > etc; suggestions for additional directories are welcome).
> > 
> > Even if we have an environment variable for a font path, the
> > freetypecap file has the advantage that you can specify a more useful
> > name (a lot of TTF files still use DOS 8.3 filenames).
> 
> This works if you type d.font vera from the command line and follow it with
> a d.* command. 
> 
> However, it will do nothing if you run d.font vera and then run a d.*
> command from the GUI into a TclTk (or wxPython) canvas, because these run in
> direct rendering mode. The only way to set fonts there is to set GRASS_FONT
> immediately prior to rendering. This can be done with a file browse dialog
> to find a font file and set it to a variable that can be used in the
> GRASS_FONT= statement.

Note that either a font name (from freetypecap) or a complete path can
be used for GRASS_FONT (essentially, R_font() accepts either form, and
thus so does anything which sets a font). You can use "d.font -l" to
get a list of valid names (both stroke and FreeType fonts).

> However, with the d.font from the command line or setting GRASS_FONT from
> within the GUI, the setting does not persist beyond the current GRASS
> session. That is, unless you want the default (ugly) stroke font, you must
> set the font at least for each session and (depending on what you do) for
> each command. 

You can set GRASS_FONT (etc) in e.g. ~/.grass.bashrc. mon.select uses
those variables when selecting a monitor, and direct rendering also
uses them.

> My suggestion is to have an optional font setting in the form of a variable
> in the .grassrc6 file that would persist past the current session. That is,
> to let the user replace the Romans stroke font with something else as the
> default GRASS font for every GRASS session unless it is explicitly
> overridden (e.g., in a d.text command). From the user standpoint, it would
> be great if this could be done by a flag in d.font (like the new flag for
> g.region that lets it set a new default WIND).

I'm not convinced that a GRASS variable is a good idea here. At a
minimum, the environment variables would have to take precedence (for
the GUI, and so that the setting can be overriden on a per-command
basis).

> The other suggestion is for a GRASS_FONTPATH environmental variable that
> would let a user substitute $GRASS_FONTPATH/Vera.ttf for typing (or browsing
> for) /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf. This is only a
> convenience, but a helpful one, along the lines of the GRASS_PROJSHARE
> variable.

Again, this would probably want to be a fallback, with the freetypecap
file being used first. Also, it would really need to be a path rather
than a single directory.

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




More information about the grass-dev mailing list