Search code examples
graphicstextdrawing

Byte codes for pixel maps for Ascii characters?


Anyone who ever had to draw text in a graphics application for pre-windows operating systems (i.e. Dos) will know what I'm asking for.

Each ASCII character can be represented by an 8x8 pixel matrix. Each matrix can be represented by an 8 byte code (each byte used as a bit mask for each line of the matrix, 1 bit representing a white pixel, each 0 a black pixel).

Does anyone know where I can find the byte codes for the basic ASCII characters?

Thanks,
BW


Solution

  • Self answering because user P i hasn't (they posted it in a comment on the question).

    This github repo is exactly what I was looking for

    dhepper/font8x8

    From the read me . . .


    8x8 monochrome bitmap font for rendering

    A collection of header files containing a 8x8 bitmap font.

    font8x8.h contains all available characters font8x8_basic.h contains unicode points U+0000 - U+007F font8x8_latin.h contains unicode points U+0000 - U+00FF

    Author: Daniel Hepper [email protected] License: Public Domain

    Encoding

    Every character in the font is encoded row-wise in 8 bytes.

    The least significant bit of each byte corresponds to the first pixel in a row.

    The character 'A' (0x41 / 65) is encoded as { 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}

    0x0C => 0000 1100 => ..XX....
    0X1E => 0001 1110 => .XXXX...
    0x33 => 0011 0011 => XX..XX..
    0x33 => 0011 0011 => XX..XX..
    0x3F => 0011 1111 => xxxxxx..
    0x33 => 0011 0011 => XX..XX..
    0x33 => 0011 0011 => XX..XX..
    0x00 => 0000 0000 => ........
    

    To access the nth pixel in a row, right-shift by n.

                         . . X X . . . .
                         | | | | | | | |
    (0x0C >> 0) & 1 == 0-+ | | | | | | |
    (0x0C >> 1) & 1 == 0---+ | | | | | |
    (0x0C >> 2) & 1 == 1-----+ | | | | |
    (0x0C >> 3) & 1 == 1-------+ | | | |
    (0x0C >> 4) & 1 == 0---------+ | | |
    (0x0C >> 5) & 1 == 0-----------+ | |
    (0x0C >> 6) & 1 == 0-------------+ |
    (0x0C >> 7) & 1 == 0---------------+