[GRASS-dev] d.font: font name checking?

I see that d.font doesn't do any validation of the font name:

GRASS 6.4.svn (eth_utm32):~ > d.font romans
GRASS 6.4.svn (eth_utm32):~ > d.font paul
GRASS 6.4.svn (eth_utm32):~ > d.font glynn
GRASS 6.4.svn (eth_utm32):~ >

Is there a way to add that?

thanks
Markus

Markus Neteler wrote:

I see that d.font doesn't do any validation of the font name:

GRASS 6.4.svn (eth_utm32):~ > d.font romans
GRASS 6.4.svn (eth_utm32):~ > d.font paul
GRASS 6.4.svn (eth_utm32):~ > d.font glynn
GRASS 6.4.svn (eth_utm32):~ >

Is there a way to add that?

The code to read the font list is already there for the -l/-L
switches, so you can just read the list and check that the font is in
that list. However, note that the argument to font= can also be an
absolute path to a .ttf file, which needn't exist in the fontcap file.

This issue affects any module which accepts font names, e.g. d.text.

At present, R_font() doesn't return a result. R_font() itself doesn't
care whether the font exists; the font isn't actually loaded until you
try to draw something with it.

[Part of the reason for this is so that, when using direct rendering,
modules don't waste time loading the default "romans" font when they
aren't going to use it.]

Similarly, there's no check that $GRASS_FONT is valid; the value is
just passed to R_font(), and validity only becomes an issue when you
try to draw text.

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

On Fri, May 23, 2008 at 11:07 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

I see that d.font doesn't do any validation of the font name:

GRASS 6.4.svn (eth_utm32):~ > d.font romans
GRASS 6.4.svn (eth_utm32):~ > d.font paul
GRASS 6.4.svn (eth_utm32):~ > d.font glynn
GRASS 6.4.svn (eth_utm32):~ >

Is there a way to add that?

The code to read the font list is already there for the -l/-L
switches, so you can just read the list and check that the font is in
that list.

Well.. re "just": when it comes to C strings, I am routinely lost.

However, note that the argument to font= can also be an
absolute path to a .ttf file, which needn't exist in the fontcap file.

Maybe, if / or \ is present, do a different check.

This issue affects any module which accepts font names, e.g. d.text.

At present, R_font() doesn't return a result. R_font() itself doesn't
care whether the font exists; the font isn't actually loaded until you
try to draw something with it.

I see.

[Part of the reason for this is so that, when using direct rendering,
modules don't waste time loading the default "romans" font when they
aren't going to use it.]

Similarly, there's no check that $GRASS_FONT is valid; the value is
just passed to R_font(), and validity only becomes an issue when you
try to draw text.

But *then* it should spit an error if the font isn't there... anyway, in
d.font would be nicer.

Markus