Norman Vine wrote:
> Here's Mark's example of the command used to generate the sorority.txf
> file: Just change the Font name and the 'glist' to be what you want
>
>   gentexfont \
>     -fn '-sgi-sorority-medium-r-normal--40-*-*-*-p-*--ascii' \

Right, but this only gets you a copy of the X11 bitmap font, which is
ugly and aliased.  My original point was that with only a little work,
you could use ghostscript/FreeType to render a very high (16x)
resolution bitmap of each character and downsample to get a very
nicely antialiased texture to use with the font.  Which would be
great, except for the fact that there are no tools available to do
this, nor documentation to write such tools.

Mark's program generates bitmapped textures from X11 bitmapped fonts.
So, because the X11 bitmap fonts are ugly as sin, the existing plib
fonts leave a lot to be desired*.  But there's nothing in the software
engine that requires that -- it's just a tools issue.

All that being said, I did look through the source code a bit and
think I've puzzled out the format.  Attached is a perl script that
parses a .txf font, prints the metrics information to stdout, and
generates a .pgm file containing the texture.  (Actually, I got the
texture order wrong, so the image is flipped vertically).

I'll see if I can leverage this into some prettier fonts at some point
in the future.

Andy

* There are some other problems, too.  Mark leaves almost no padding
  between the characters in the bitmap, so mipmapping causes the
  characters to "bleed" or "run together" when displayed at small
  sizes.  And some of the metrics are funny -- witness the alignment
  of the characters in the button labels of the property picker, for
  example.

-- 
Andrew J. Ross                NextBus Information Systems
Senior Software Engineer      Emeryville, CA
[EMAIL PROTECTED]              http://www.nextbus.com
"Men go crazy in conflagrations.  They only get better one by one."
 - Sting (misquoted)
#!/usr/bin/perl -w
use strict;

my $file = shift or die;
open TXF, $file or die;

sub getbyte  { my $val; read TXF, $val, 1 or die; return ord $val; }
sub getshort { my $val; read TXF, $val, 2 or die; return unpack "v", $val; }
sub getint   { my $val; read TXF, $val, 4 or die; return unpack "V", $val; }

my $ENDIAN = 0x12345678;

my $magic = sprintf "0x%8.8x", getint();
my $endian = sprintf "0x%8.8x", getint();
my $format = getint();
my $texwid = getint();
my $texhgt = getint();
my $linehgt = getint();
my $unk = getint();
my $nglyph = getint();

printf "Magic $magic Endian $endian Format $format\n", $magic, $endian;
print "Texture: ${texwid}x$texhgt Line: $linehgt Glyphs: $nglyph Unk: $unk\n";

die "Bad magic number ($magic)" if $magic ne "0x667874ff";
die "Bad endianness tag ($endian)" if $endian ne "0x12345678";

for(my $i=0; $i<$nglyph; $i++) {
    print "Glyph $i\n";
    print "   char: ", getshort(), "\n";
    print "  width: ", getbyte(), "\n";
    print " height: ", getbyte(), "\n";
    print "      X: ", getbyte(), "\n";
    print "      Y: ", getbyte(), "\n";
    print "   step: ", getbyte(), "\n";
    print "    unk: ", getbyte(), "\n";
    print "   xoff: ", getshort(), "\n";
    print "   yoff: ", getshort(), "\n";
}

$file =~ s/\.txf$/.pgm/;
open PGM, ">$file" or die;
print PGM "P2\n$texwid $texhgt\n255\n";

if($format == 0) {
    for(my $i=0; $i<($texwid*$texhgt); $i++) { print PGM getbyte(), " "; }
} else {
    for(my $i=0; $i<($texwid*$texhgt/8); $i++) {
        my $byte =  getbyte();
        for(my $j=0; $j<8; $j++) {
            print PGM ($byte & (1<<$j)) ? "255 " : "0 ";
        }
    }
}

Reply via email to