0

I have this bitmap font (BDF) (https://github.com/lucy/tewi-font) and I need to parse it into arrays of pixels per character, or at least a way to draw a char into a Bitmap image without antialiasing.

Non platform specific classes if possible.

Ale32bit
  • 39
  • 4
  • For the latter: Note sure about Core but for the winforms way see [here](https://stackoverflow.com/questions/49554126/image-getting-blurred-when-enlarging-picture-box/49556218#49556218) – TaW Jan 12 '21 at 08:45
  • @TaW I'm looking for functions specific to the BDF format, which is basically a text file – Ale32bit Jan 12 '21 at 08:48
  • Honestly doesn't seem hard at all to make your own parser for it. Opening one of these files, the actual data can be decoded just by converting it to binary. – Nyerguds Jan 14 '21 at 14:51

1 Answers1

-1

I had the same problem and wrote a small parser: BdfFontParser (Nuget: BdfFontParser). The library parses the bdf file into a BdfFont object with all the properties.

Usage:

With the helper class GetMapOfString you will get your needed two-dimensional array for one character or a whole string:

using BdfFontParser;
using System.Text;

var font = new BdfFont("fonts/7x13B.bdf");

var map = bdfFont.GetMapOfString("Hello World");
var width = map.GetLength(0);
var height = map.GetLength(1);

var sb = new StringBuilder();

// draw line by line
for (int line = 0; line < height; line++)
{
    // iterate through every bit
    for (int bit = 0; bit < width; bit++)
    {
        sb.Append(map[bit,line] ? '#' : ' ');
    }    
        
    sb.AppendLine();
}

Console.WriteLine(sb.ToString());

To visualize the a bdf font character and what the parser does the following hexdraw image from this wiki article is helpful:

00 00000000 --------
00 00000000 --------
00 00000000 --------
00 00000000 --------
18 00011000 ---██---
24 00100100 --█--█--
24 00100100 --█--█--
42 01000010 -█----█-
42 01000010 -█----█-
7E 01111110 -██████-
42 01000010 -█----█-
42 01000010 -█----█-
42 01000010 -█----█-
42 01000010 -█----█-
00 00000000 --------
00 00000000 --------
Marco G
  • 102
  • 5