Mar 272001
 

Customizing Console Fonts

Written by Troy Bowman

After playing with slackware for a while I got pretty excited about some interesting fonts that they have to replace the very boring and generic console font. A couple of the fonts I liked were "t" (technical) font and the unorthodox "scrawl" font.

Instantly, I remembered the ability to change the console font in freebsd, but that those console fonts were just international fonts, and didn’t change the way the fonts on the console looked much at all. I wondered if the .fnt.gz files that slackware uses were compatible with freebsd’s font files and if I could just copy one over and instigate it. My reflex was to go ask the people in #freebsd on undernet (as I often do). They didn’t know, but said "there’s only one way to find out!" So, I thought I’d give it a shot. When I told them it worked a few minutes later, Lazarus told me to send what I did in, so here it is.

Getting the Console Font you Want

I simply unzipped the fonts I wanted from slackware and dumped them into the /usr/share/syscons/fonts directory. The two fonts I liked were mentioned above, the "t" and "scrawl" fonts, t.fnt.gz and scrawl_w.fnt.gz, respectively.

After that, read the vidcontrol manpage a little I tried issuing the command that would change the font. It worked instantly! I issued this command:

# vidcontrol -f 8x16 t

Since t.fnt was in the directory it was supposed to be, it found it automatically. I tried it with a font in my home directory, specifying the full path, and that worked too, of course.

Aaah, my console already looked a TON nicer. I once again had the warm fuzzy feeling that comes from using an open operating system, and I no longer had to have those evil lingering connotations of MS-DOS that come with the standard textmode font.

It was easy to make my computer boot up with this font, since FreeBSD already has an rc mechanism to allow for font selection. For example, to add my "t.fnt" to rc.conf, I’d simply add the line:

font8x16="t"

Tada!

Font Editing

After all that, I wasn’t satisfied. I wanted more. I liked the scrawl font a lot more than the technical font because it was so wacky looking that the clueless would probably think my video card went bad or bewitched or something. I had one peeve about the scrawl font. The "a" letter looked more like an "e" to me, and because of that, I’d get short brain-farts looking at the letter trying to realize what it was. I thought there must be a font editor, so I typed "font" on my console and pressed the awesome "tab" button and it expectedly filled out "fontedit" for me! (tab works for bash, but often for tcsh or csh, tab is not enough. For csh and its derivatives, you have to press control-D to get it to list possible stuff that you haven’t written yet.)

I tried to start to use that program, but it didn’t work. After reading the manpage, I noticed that it may have been written for those select people who own a Sun Keyboard with keys like "Help", "F13", "Select" and so on. I thought there had to be a better way.

I noticed there was a fontedit in the ports (/usr/ports/sysutils), and wondered if that was any different. Well, it was. It provides two programs: "fontdump", which dumps the whole font to a file that is "readable by humans" and "fontmake", which takes an edited dump file and converts it back to a binary .fnt file. Editing the font with a text editor was a piece of cake, and within minutes I had a new scrawl.fnt that didn’t have a wacky "a". 

  One Response to “Customizing Console Fonts”

  1. (posted by Dan Langille)

    I was very excited to read the Customizing Console Fonts item, because I
    thought it would help me with my own desire to mix characters from two
    different fonts. I knew how to change the font used, via vidcontrol, but
    not about the handy fontedit port.

    [font project: including CP437 graphic characters into an ISO-8859-1 font.
    I "enhanced" cdplay to use graphics characters instead of +,| etc., but
    don’t like the CP437 letters.]

    Unfortunately, fontdump can’t read FreeBSD’s proprietary encoded format. So
    I looked into how vidcontrol deals with them, and found decode.c. I rewrote
    it as a standalone program – fontdecode.c – which can be used to convert a
    FreeBSD .fnt file into one that fontdump will accept, i.e. a standard VGA
    font file.

    The code is here:
    ========= fontdecode.c ===========
    <PRE>
    #include &lt;stdio.h&gt;
    #include &lt;string.h&gt;

    int main()
    {
    int n, pos = 0;
    char *p;
    char temp[128];
    char buffer[4096];

    #define DEC(c) (((c) – ‘ ‘) & 0x3f)

    do {
    if (!fgets(temp, sizeof(temp), stdin))
    return(0);
    } while (strncmp(temp, "begin ", 6));
    sscanf(temp, "begin %o %s", &n, temp);
    for (;;) {
    if (!fgets(p = temp, sizeof(temp), stdin))
    return(0);
    if ((n = DEC(*p)) <= 0)
    break;
    for (++p; n > 0; p += 4, n -= 3)
    if (n >= 3) {
    buffer[pos++] = DEC(p[0])<<2 | DEC(p[1])>>4;
    buffer[pos++] = DEC(p[1])<<4 | DEC(p[2])>>2;
    buffer[pos++] = DEC(p[2])<<6 | DEC(p[3]);
    }
    else {
    if (n >= 1) {
    buffer[pos++] =
    DEC(p[0])<<2 | DEC(p[1])>>4;
    }
    if (n >= 2) {
    buffer[pos++] =
    DEC(p[1])<<4 | DEC(p[2])>>2;
    }
    if (n >= 3) {
    buffer[pos++] =
    DEC(p[2])<<6 | DEC(p[3]);
    }
    }
    }
    if (!fgets(temp, sizeof(temp), stdin) || strcmp(temp, "end\n"))
    return(0);
    for (n = 0; n < pos; n++)
    putchar(buffer[n]);
    return(pos);
    }
    </PRE>
    =========================================
    [The credit for this code goes to Soren. I just adapted it. I guess I
    should have left the copyright notice in there. See vidcontrol/decode.c]