LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Converting classic Slackware fonts (.fnt) to TrueType fonts? (https://www.linuxquestions.org/questions/slackware-14/converting-classic-slackware-fonts-fnt-to-truetype-fonts-4175536834/)

jeremya 03-15-2015 08:27 PM

Converting classic Slackware fonts (.fnt) to TrueType fonts?
 
Back in Slackware 3.5 I fell in love with the rl.fnt font:
http://imgur.com/KfB2YQj.png

I recently re-discovered it while playing around with a LIVE CD archive I found online...

Nowadays I spend most of my time in Windows, but I'm falling back in love with Linux and I'd really like have this font... everywhere (Windows, Raspbian, Slackware 14+, etc).

So, I'd love to convert it (or be pointed to a conversion that's already been done...) to a monospace TrueType font. The crux of the issues is that I can't find an online converter anywhere that understands the .fnt format. Most websites even claim it's an archaic Windows bitmap font format (Windows doesn't recognize it anymore). I've verified that Windows recognizes .fon bitmap font files, but not .fnt (if it ever did...).

Any clue on how to get this to happen?

Caveats:
According to http://www.techrepublic.com/blog/win...ommand-prompt/, in order for the font to be recognized in Windows:

Code:

In addition to the monospaced criteria, Microsoft also specifies that the font for the Command Prompt:
  1. Cannot be an italic font

  2. Cannot have a negative A or C space

  3. Must be FF_MODERN if it is a TrueType font

  4. Must be OEM_CHARSET if it is not a TrueType font


Of course, I also want to use the font in Raspbian. I figure once I get it converted to a TTF, it should be trivial to get it working over there...

So, I'd also love to know how I can guarantee criteria 2 and 3. (1 and 4 are irrelevant).

Thanks in advance for the help!

About me:
I'm a developer who is getting "back into Linux" after a 20 year hiatus. Back in my college days (mid-90s) I spent most of my time in Slackware 3.5 (and, admittedly I spent most of that time in a telnet client playing MUDs, shell scripting, and abusing the university's dial-up access with auto-re-dialer scripts my roommate and I hacked together...). I dual-booted to Windows 95 when I wanted to play games. ;-)

Didier Spaier 03-16-2015 11:51 AM

I don't think that will be easy. In case you didn't find it already the spec is here.

I tried to open it in fontforge but it does not recognize it:
Code:

This does not appear to be a Windows FNT for FON file
I downloaded it from this link. Not sure it's the same as yours but it was shipped in Slackware 2.1 and "setfont rl.fnt" works here (Slackware 14.1).

jeremya 03-16-2015 12:32 PM

Thank you!

Excellent find on the Classic Windows FNT spec.

The older RL.FNT seems to be identical to the newer one. Same size, same hash:

Code:

C:\Users\Jeremy\Desktop> Get-FileHash .\2.1.rl.fnt

Algorithm      Hash                                                                  Path
---------      ----                                                                  ----
SHA256          9F089C1EB1000D44CE100DDB60262574C388AB391150BE0530AC2FCCDE211989      C:\Users\Jeremy\Desktop\2.1.rl.fnt


C:\Users\Jeremy\Desktop> Get-FileHash rl.fnt

Algorithm      Hash                                                                  Path
---------      ----                                                                  ----
SHA256          9F089C1EB1000D44CE100DDB60262574C388AB391150BE0530AC2FCCDE211989      C:\Users\Jeremy\Desktop\rl.fnt

Now all I need is a classic Slackware FNT spec and perhaps I can build a converter to the Windows .FNT format... which may still work "out-of-the-box" as a Raster/Bitmap-type font. Either way, once the RL.FNT is translated into a "proper" .FNT, most of the online converters should be able to translate it into a TTF...

So, any idea where to find the file format definition for the "classic" Slackware .FNT format? :)

Didier Spaier 03-16-2015 01:33 PM

Found some interesting stuff (I think):

The README that explains where the fonts come from
The source zipped archive vfont2.zip
The script used to extract the fonts from the archive

EDIT. First link fixed, thanks bassmadrigal.

PS the man page included in vfont2.zip states that this font was created in 1989 for OS/2 ;)

bassmadrigal 03-16-2015 01:42 PM

Quote:

Originally Posted by Didier Spaier (Post 5333016)
The README that explains where the fonts come from

Looks like you forgot the http:// at the beginning of the link, so it now shows http://www.linuxquestions.org/questions/mirrors.slackware.com instead of pointing to the correct link: README

Didier Spaier 03-16-2015 02:12 PM

...hit Quote instead of Edit, sorry...

jeremya 03-16-2015 02:13 PM

Thank you again!

It certainly explains the pedigree (I did see the SCRIPT before but realized it wasn't doing much but copying 4k chunks from another file).

However, it doesn't provide insight into the actual binary .FNT format being used... at least not in an actionable way.

I suppose whatever font processing & display code Slackware is using could give some hints. I'd rather not reverse-engineer the format from the code, but if I get bored/motivated enough I suppose I could resort to that.

Diantre 03-16-2015 02:41 PM

Quote:

Originally Posted by jeremya (Post 5332668)
So, I'd love to convert it (or be pointed to a conversion that's already been done...) to a monospace TrueType font. The crux of the issues is that I can't find an online converter anywhere that understands the .fnt format. Most websites even claim it's an archaic Windows bitmap font format (Windows doesn't recognize it anymore). I've verified that Windows recognizes .fon bitmap font files, but not .fnt (if it ever did...).

Any clue on how to get this to happen?

I tried to convert rl.fnt to another format, but fontforge is unable to open this fnt file (Didier already mentioned this). It turns out that rl.fnt is a raw font!

Code:

$ file rl.fnt
rl.fnt: data

From the setfont manpage:

Code:

FONT FORMATS
      The standard Linux font format is the PSF font.  It has a header describing font  proper‐
      ties like character size, followed by the glyph bitmaps, optionally followed by a Unicode
      mapping table giving the Unicode value for each glyph.  Several  other  (obsolete)  font
      formats  are  recognized.  If  the input file has code page format (probably with suffix
      .cp), containing three fonts with sizes e.g. 8x8, 8x14 and 8x16, then one of the  options
      -8  or  -14  or  -16 must be used to select one.  Raw font files are binary files of size
      256*N bytes, containing bit images for each of 256 characters, one byte  per  scan  line,
      and N bytes per character (0 < N <= 32).
  Most fonts have a width of 8 bits, but with the
      framebuffer device (fb) other widths can be used.

To perform the conversion you'll need psftools:

Code:

$ raw2psf rl.fnt rl.psf
$ file rl.psf
rl.psf: Linux/i386 PC Screen Font v2 data, 256 characters, no directory, 16x8

However, fontforge is unable to open this psf file. Luckily psftools has more conversion utilities:

Code:

$ psf2[TAB]
psf2bbc  psf2bsd  psf2inc  psf2raw  psf2wof  psf2xbm 
psf2bdf  psf2fnt  psf2pbms  psf2txt  psf2wyse  psf2zx

I tried converting rl.psf to bdf:

Code:

$ psf2bdf rl.psf rl.bdf
$ file rl.bdf
rl.bdf: X11 BDF font, ASCII text

Now this rl.bdf file can be opened with fontforge, and from there it can be manipulated and saved to different formats, including TTF. I'm no expert with fontforge, so I have no clue about the steps necessary to convert a bitmap font to another format. Here's some info from the fontforge website.

Hope that helps.

jeremya 03-16-2015 11:58 PM

Thank you very much, Diantre!

This should be most helpful... I'll report back once I make some progress. :)

[edit]:

Made some early progress just hacking around the .FNT file given the spec hint in the setfont MAN page you referenced...

I'm able to tease the glyphs out easily with a little script I wrote. Result sample:

Code:

----816:
       
       
       
       
  0000 
 0  00
    0 
    0 
  000 
    00
    00
    00
    00 
 000   
       
       


...
---1184:
       
       
  0000
    00 
    00 
    00 
    00 
    00 
    00 
    00 
    00 
    00 
    00 
    0 
0000   
       


---1200:

And the code I whipped up to do the conversion (my Windows environment is still way more friendly for me, so I used Powershell):

Code:

param($font = "RO.FNT")
$f = [System.IO.File]::ReadAllBytes($font)
$sb = New-Object System.Text.StringBuilder
$charSize = $f.Length / 256

for($i = 0; $i -lt $f.Length; $i += $charSize) {
    write-host -f DarkGray $(("{0}:" -f $i).PadLeft(8,'-'))
    for($j = 0; $j -lt $charSize; $j++) {
        # convert byte at offset to binary string and pad with 0s
        $buf = [Convert]::ToString($f[$i + $j],2).PadLeft(8,'0')

        # convert 0s to space and 1s to 0 for easier viewing
        $buf = $buf -replace "0"," "
        $buf = $buf -replace "1","0"

        $sb.Append($buf) > $null
        $sb.AppendLine() > $null
    }

    write-host $sb.ToString()
    $sb.Clear() > $null
}

It's far from the end goal, but being able to read the bitmaps is a huge first step! Thanks again, everyone!

1337_powerslacker 03-17-2015 10:16 AM

2 Attachment(s)
Quote:

Originally Posted by jeremya (Post 5332668)
Back in Slackware 3.5 I fell in love with the rl.fnt font:
http://imgur.com/KfB2YQj.png

Jeremy, your post stirred up some nostalgia on my part so, armed with information others have posted on this thread, I decided to embark on an effort to utilize the old font in Konsole.The result of my effort is posted below.

For those interested, I have attached the file itself. Due to the restrictions of LQ, I've had to add the .txt extension to get it to upload, but once you've downloaded, do the following:

Code:

mv rl.otf.txt rl.otf
sudo cp rl.otf /usr/share/fonts/OTF/
cd /usr/share/fonts/OTF/
sudo mkfontdir .
sudo mkfontscale .
sudo fc-cache -f

Happy Slacking!

Regards,

Matt

P.S. The font option displayed in Konsole's font selection dialog box is 'psf', for a reason I have yet to fathom. Probably someone who is more familiar with fonts could post why this is happening.

jeremya 03-17-2015 06:44 PM

Very cool.

Might I inquire as to how you made the jump from fnt (or bdf, etc) to otf?

1337_powerslacker 03-17-2015 07:48 PM

Quote:

Originally Posted by jeremya (Post 5333701)
Very cool.

Might I inquire as to how you made the jump from fnt (or bdf, etc) to otf?

You may. I used the command:
Code:


raw2psf rl.fnt rl.psf

to convert the raw font to a psf file via the psftools package per Diantre's suggestions.
Then I used the command:
Code:

psf2bdf rl.psf rl.bdf
to convert it from a .psf file to a file .bdf file, one that fontforge could open.

In fontforge, I opened the file, went to Element --> Font Info, clicked on 'General' on the left side, change 'Em size' to a power of 2; in this case, 2^10, or 1024, then clicked OK.

To save, I went to File --> Generate Font. Where it says 'No Outline Font', I clicked on the drop-down menu and selected Open Type (CFF), renamed the file above the selection box to reflect the new extension, and clicked 'Generate'. Viola! an OpenType font I could drop right into /usr/share/fonts/OTF. Ran the commands to register the new font, and configured Konsole to use the font. Retro goodness!

jeremya 03-17-2015 09:38 PM

Awesome. Thank you very much for the blow-by-blow... and for sharing the OTF!

1337_powerslacker 03-18-2015 07:49 AM

Converting classic Slackware fonts (.fnt) to TrueType fonts?
 
You're welcome. I most certainly enjoyed the challenge. It's why I run Slackware in the first place. Keeps the mind sharp, especially as I am getting older and forgetting things. :(

jeremya 09-14-2020 11:21 PM

1 Attachment(s)
Quote:

Originally Posted by 1337_powerslacker (Post 5334015)
You're welcome. I most certainly enjoyed the challenge. It's why I run Slackware in the first place. Keeps the mind sharp, especially as I am getting older and forgetting things. :(

Well, I figured I'd circle back around after all these years because I tried to use the .OTF you labored over on Windows 10 and for some odd reason it doesn't like it. No errors, it just renders every glyph as completely transparent (no positive or negative space whatsoever)... so we may be missing something.

Here's a snapshot of what it looks like in FontForge:

Attachment 34077

Any idea on what else we can try?


All times are GMT -5. The time now is 07:51 AM.