[GRASSLIST:9846] Re: Learning to use freetype fonts

Hamish hamish_nospam at yahoo.com
Sun Jan 15 18:42:21 EST 2006


> > I recently compiled GRASS with freetype support and I am trying to
> > learn to use it. When I follow the following sequence to define a
> > default font, it fails:
> >
> > GRASS 6.1.cvs (WASPN_NAD83):~ > locate bitstream | grep 'Vera'
..
> > /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf
..
> > GRASS 6.1.cvs (WASPN_NAD83):~ > d.font.freetype \
> >   font=/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf
..
> > GRASS 6.1.cvs (WASPN_NAD83):~ > d.text.freetype -n text="Hello"
> > east=20,20 ERROR: No font selected
> >
> > But, if I call the font directly in the command it works:
> >
> > GRASS 6.1.cvs (WASPN_NAD83):~ > d.text.freetype -n text="Hello" \
> >   east=20,20
> >   path=/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf
> >
> > (successfully draws on the monitor)
> >
> > Without d.text.freetype working, I can't see text in legends or map
> > titles. What's the secret to getting this working?


Some history:

First there were GRASS fonts* which you selected with d.font. These
fonts were used by d.text, d.legend, d.vect, d.labels, d.barscale, 
d.graph, etc.

[*] cyrilc,gothgbt,gothgrt,gothitt,greekc,greekcs,greekp,
    greeks,italicc,italiccs,italict,romanc,romancs,romand,
    romans,romant,scriptc,scripts

Maybe if you were Greek you could make use of these for some text, but
for non-english it wasn't very good. And for english results could be 
ugly. Many people used a graphics program to add text to exported
maps instead of using the build in fonts.

So Huidae Cho wrote d.text.freetype to draw text to the screen using
a local FreeType (or TrueType) font. This was great for everyone, but 
wasn't a general & automatic solution for the above modules.

Time passed & the i18n of GRASS came to be. The FOSS4G team (AFAIK)
created the infrastructure and the d.font.freetype module so the main
GRASS font (romans et al) could be over-ridden by d.font.freetype and 
so d.vect, d.legend, etc could now use FreeType fonts as the default.

Thus the d.text.freetype module is independent of the d.font.freetype
module, but the d.text module does observe the d.font.freetype setting.

In hind-sight this is pretty confusing, & I apologise if the help pages
do not make this clear. Please point out where improvements could be made.

Perhaps d.text.freetype could "pick" the font set by d.font.freetype 
from the GRASS display driver if the font isn't explicitly given, instead 
of an error somehow. Not sure how to extract that from the driver, maybe
d.font.freetype needs to set/update a new g.gisenv variable?

ps.map is another (confusing) story....


> That is, without d.font.freetype, I can't get legend text, etc...

this doesn't work?

G> d.font.freetype font=""   # turns off freetype support
G> d.font font=romans
G> echo "`g.version`" | d.text


Also, I have this in my ~/.grass.bashrc file:
alias d.font.vera='d.font.freetype /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf'

which I find useful.


Hamish




More information about the grass-user mailing list