[GRASS-dev] figureing out fonts - part 3 correction

if uname -s can differentiate Debian from other systems, it's easy enough to
make /usr/share/fonts/freetype as the initial directory for those systems.

Michael

On 4/30/07 1:16 AM, "Hamish" <hamish_nospam@yahoo.com> wrote:

Michael Barton wrote:

I've done a font selection dialog for the GUI that helps set default
display fonts. Let me know if it works OK with your system. Does it
start you out at /usr/lib/xll/fonts?

if I choose TrueType, it goes to /usr/X11R6/lib/X11/fonts (that's where
/usr/lib/xll/fonts symlinks to). I then need to manually navigate to
/usr/share/fonts/freetype, but Debian may well be doing its own thing
there and can+will patch as needed (without complaint).

stroke fonts need the path and extension stripped off of them to work.
e.g. remove .ppm extension: (from NVIZ)

if { [string compare [file extension $fname] ".ppm"] == 0 } then {
    set fname [file rootname $fname]
}

from here:
  File Operations

you need to do [file tail $filename] as well as rootname.

the font setting works, but doesn't survive a restart of gis.m.

(still, good progress!)

Hamish

ps- catch needed for open/close of text files or just execs?

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

if uname -s can differentiate Debian from other systems, it's easy enough to
make /usr/share/fonts/freetype as the initial directory for those systems.

I suggest parsing etc/freetypecap, and either using the directory part
of the path for the first font in that file, or the directory used by
most fonts (the former is easier, the latter is probably more useful).

E.g.

cat $GISBASE/etc/freetypecap | awk -F: '{print $2}' | sed 's!/[^/]*$!!' | uniq -c | sort -nr | head -n 1 | cut -c 9-

Alternatively, you could replicate the logic of mkftcap (formerly
d.freetypecap), i.e. scan a list of candidate directories and settle
for the first one which exists.

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

This is logical. Any suggestion on how to figure out the directory used by
most fonts?

Michael

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

Michael Barton wrote:

if uname -s can differentiate Debian from other systems, it's easy enough to
make /usr/share/fonts/freetype as the initial directory for those systems.

I suggest parsing etc/freetypecap, and either using the directory part
of the path for the first font in that file, or the directory used by
most fonts (the former is easier, the latter is probably more useful).

E.g.

cat $GISBASE/etc/freetypecap | awk -F: '{print $2}' | sed 's!/[^/]*$!!' | uniq
-c | sort -nr | head -n 1 | cut -c 9-

Alternatively, you could replicate the logic of mkftcap (formerly
d.freetypecap), i.e. scan a list of candidate directories and settle
for the first one which exists.

__________________________________________
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

On 30.04.2007 17:32, Michael Barton wrote:

if uname -s can differentiate Debian from other systems, it's easy enough to
make /usr/share/fonts/freetype as the initial directory for those systems.

No it doesn't. In my system (which is Debian) uname -s returns Linux,
but you can identify Debian by the presence of the file /etc/debian_version

--Wolf

--

<:3 )---- Wolf Bergenheim ----( 8:>

Michael Barton wrote:

>> if uname -s can differentiate Debian from other systems, it's easy enough to
>> make /usr/share/fonts/freetype as the initial directory for those systems.
>
> I suggest parsing etc/freetypecap, and either using the directory part
> of the path for the first font in that file, or the directory used by
> most fonts (the former is easier, the latter is probably more useful).
>
> E.g.
>
> cat $GISBASE/etc/freetypecap | awk -F: '{print $2}' | sed 's!/[^/]*$!!' | uniq
> -c | sort -nr | head -n 1 | cut -c 9-
>
> Alternatively, you could replicate the logic of mkftcap (formerly
> d.freetypecap), i.e. scan a list of candidate directories and settle
> for the first one which exists.

This is logical. Any suggestion on how to figure out the directory used by
most fonts?

cat $GISBASE/etc/freetypecap | awk -F: '{print $2}' | sed 's!/[^/]*$!!' | uniq -c | sort -nr | head -n 1 | cut -c 9-

Actually, it should check for $GRASS_FT_CAP, and only use
$GISBASE/etc/freetypecap as a fallback.

If you wanted to bypass freetypecap altogether and scan the
directories yourself:

for dir in ... ; do
    if [ -d "$dir" ] ; then
        find "$dir" -type f -iname '*.ttf' -print
    fi
done | sed 's!/[^/]*$!!' | uniq -c | sort -nr | head -n 1 | cut -c 9-

If you wanted to do it entirely in Tcl, you would need to perform
directory traversal, as the actual font files will frequently be in
subdirectories of the standard font directories.

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

Thanks for the ideas. To clarify, will the fonts be listed in $GRAS_FT_CAP
such that I can just parse this?

Michael

On 4/30/07 12:27 PM, "Glynn Clements" <glynn@gclements.plus.com> wrote:

Michael Barton wrote:

if uname -s can differentiate Debian from other systems, it's easy enough
to
make /usr/share/fonts/freetype as the initial directory for those systems.

I suggest parsing etc/freetypecap, and either using the directory part
of the path for the first font in that file, or the directory used by
most fonts (the former is easier, the latter is probably more useful).

E.g.

cat $GISBASE/etc/freetypecap | awk -F: '{print $2}' | sed 's!/[^/]*$!!' |
uniq
-c | sort -nr | head -n 1 | cut -c 9-

Alternatively, you could replicate the logic of mkftcap (formerly
d.freetypecap), i.e. scan a list of candidate directories and settle
for the first one which exists.

This is logical. Any suggestion on how to figure out the directory used by
most fonts?

cat $GISBASE/etc/freetypecap | awk -F: '{print $2}' | sed 's!/[^/]*$!!' | uniq
-c | sort -nr | head -n 1 | cut -c 9-

Actually, it should check for $GRASS_FT_CAP, and only use
$GISBASE/etc/freetypecap as a fallback.

If you wanted to bypass freetypecap altogether and scan the
directories yourself:

for dir in ... ; do
    if [ -d "$dir" ] ; then
        find "$dir" -type f -iname '*.ttf' -print
    fi
done | sed 's!/[^/]*$!!' | uniq -c | sort -nr | head -n 1 | cut -c 9-

If you wanted to do it entirely in Tcl, you would need to perform
directory traversal, as the actual font files will frequently be in
subdirectories of the standard font directories.

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

Thanks for the ideas. To clarify, will the fonts be listed in $GRAS_FT_CAP
such that I can just parse this?

The mkftcap script will generate a freetypecap file containing all
.ttf files found in its hard-coded list of directories. The user may
subsequently edit the file.

For binary distributions, the mkftcap script will need to be run on
the target system after installation, or the user will need to create
the file by other means.

Any fonts which are added after the freetypecap file is created won't
appear until the file is explicitly updated.

IOW, there can be fonts which are installed but which aren't listed in
the freetypecap file. This may be an explicit choice on the user's
part, or it may be an oversight. If you could guarantee that all fonts
were listed in that file, there wouldn't be any need to support
specifying fonts by an absolute path.

One reason why the freetypecap file may not list all available fonts
is that some users may have a lot of fonts, and don't want an
excessively-long list of options for any font= parameters.

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

Michael Barton wrote:

if uname -s can differentiate Debian from other systems, it's easy
enough to make /usr/share/fonts/freetype as the initial directory for
those systems.

No, it can't. It just gives "Linux" or "Darwin" or whatever.
(the OS kernel is distinct from the distribution (Linux vs GNU; Debian
can run using Hurd or *BSD instead of Linux))

Don't worry too much about accommodating special changes for Debian.
It's more a question of what's now commonly used industry-wide.

Hamish

Glynn Clements wrote:

The mkftcap script will generate a freetypecap file containing all
.ttf files found in its hard-coded list of directories. The user may
subsequently edit the file.

patch attached, for your consideration.
(run without needing a fake mapset, add copyright and file header)

Can "^*" be added to promote a consistent non-romans default font (if
found)? eg. Helvetica, Vera, or something common (sans).

How well does it deal with spaces in font path names?

For binary distributions, the mkftcap script will need to be run on
the target system after installation, or the user will need to create
the file by other means.

shall we add the running of the script to this part of lib/init/init.sh
  # First time user - GISRC is defined in the GRASS script
  if [ ! -f "$GISRC" ] ; then
    ...

and add a rescan button to Michael's new GUI default font picker tool?

Any fonts which are added after the freetypecap file is created won't
appear until the file is explicitly updated.

for this we could add a hint in the d.font help page to run
"$GISBASE/etc/mkftcap" from the GRASS prompt.

IOW, there can be fonts which are installed but which aren't listed in
the freetypecap file. This may be an explicit choice on the user's
part, or it may be an oversight. If you could guarantee that all fonts
were listed in that file, there wouldn't be any need to support
specifying fonts by an absolute path.

so Michael's new GUI font picker tool could have three entries:

//////////////////
// <> stoke font [pulldown list of the usual suspects]
// <> (registered) TTF [pulldown list parsed from freetypecap] [Rescan]
// <> Browse filesystem for TTF file
//
// Selected font: [____] [Set as Default]
/////////////////

Hamish

(attachments)

mkftcap.diff (1.07 KB)

Hamish wrote:

> The mkftcap script will generate a freetypecap file containing all
> .ttf files found in its hard-coded list of directories. The user may
> subsequently edit the file.

patch attached, for your consideration.
(run without needing a fake mapset, add copyright and file header)

The $GISBASE test was needed when it wrote to
$GISBASE/etc/freetypecap, but is no longer required.

Can "^*" be added to promote a consistent non-romans default font (if
found)? eg. Helvetica, Vera, or something common (sans).

I would rather leave it to the user to set GRASS_FONT in their
~/.grass.bashrc etc.

How well does it deal with spaces in font path names?

It seems to work okay. Certainly, it handles spaces in the filenames;
I don't have any fonts in directories which have spaces.

> For binary distributions, the mkftcap script will need to be run on
> the target system after installation, or the user will need to create
> the file by other means.

shall we add the running of the script to this part of lib/init/init.sh
  # First time user - GISRC is defined in the GRASS script
  if [ ! -f "$GISRC" ] ; then
    ...

and add a rescan button to Michael's new GUI default font picker tool?

The user may not be able to modify the system-wide freetypecap file
due to filesystem permissions.

The "right" place to generate the global freetypecap file is either at
build time (when building from source) or from a post-install script
(when installing a binary package).

Also, I consider the freetypecap file to be a configuration file.
Auto-generation is useful for a quick start, but once the file exists,
it should only be modified by the user.

> Any fonts which are added after the freetypecap file is created won't
> appear until the file is explicitly updated.

for this we could add a hint in the d.font help page to run
"$GISBASE/etc/mkftcap" from the GRASS prompt.

It's actually in the scripts directory at the moment.

> IOW, there can be fonts which are installed but which aren't listed in
> the freetypecap file. This may be an explicit choice on the user's
> part, or it may be an oversight. If you could guarantee that all fonts
> were listed in that file, there wouldn't be any need to support
> specifying fonts by an absolute path.

so Michael's new GUI font picker tool could have three entries:

//////////////////
// <> stoke font [pulldown list of the usual suspects]
// <> (registered) TTF [pulldown list parsed from freetypecap] [Rescan]
// <> Browse filesystem for TTF file
//
// Selected font: [____] [Set as Default]
/////////////////

Sounds reasonable.

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