54 lines
3.2 KiB
Markdown
54 lines
3.2 KiB
Markdown
# Font Bitmap
|
|
|
|
## Introduction
|
|
|
|
Font Bitmap (FBM) is the custom font format used by the Blastproof bootloader. It has been designed to be simple and support a selected set of features useful and simple to render from a bare metal environnement. This font format is generated by the `fontgen` utility. In this file, we describe how they are structured, not how they are generated, rendered or used. Please take note that this format has been designed for the x86-64 architecture and for little endian usage. More precisely, all multibytes integer are little endian, except codepoint encoding (see below).
|
|
|
|
## Header
|
|
|
|
Each FBM font start with the following 10 bytes header:
|
|
- Signature: 3 bytes that are set to `FBM` in ASCII
|
|
- Encoding: 1 byte. Reserved encoding are 0x01 for ASCII, 0x08 for UTF-8 and 0x10 for UTF-16
|
|
- Entries count: 4 bytes, indicate the number of glyph inside the file
|
|
- Width: 1 byte, the width in pixel of a glyph
|
|
- Height: 1 byte, the heigth in pixel of a glyph
|
|
|
|
Please note that the provided font in Vystem are only tested for ASCII encoding.
|
|
|
|
## Glyphs table
|
|
|
|
Each glyph occupies `4+width*height` bytes.
|
|
|
|
### Codepoint
|
|
|
|
The 4 first byte are for the codepoint. The codepoint is encoded as detailled below, **no matter the endianness**:
|
|
- ASCII: the first byte of the codepoint is the ASCII code, the next 3 are set to 0
|
|
- UTF-8: if `N` is the amount of byte the UTF-8 code take, then the first `N` are to be set to the UTF-8 code bytes, and the next `4-N` bytes are set to 0
|
|
- UTF-16: if 2 bytes are used, the two first bytes of the UTF-16 code are set into the first two bytes of the codepoint. If 4 bytes are used, use all codepoint bytes
|
|
|
|
In all cases, the useful bytes are always left-aligned and the unused bytes are set to 0. The codepoint `0xFFFFFFFF` is reserved for the replacement character in case of missing character in the font.
|
|
|
|
### Pixel encoding
|
|
|
|
Each pixel is encoded with two values in mind:
|
|
- a boolean indicating if the pixel is on or off
|
|
- a 4 bit value indicating the shading of the pixel, ranging from 0 (background color) to 15 (text full color)
|
|
|
|
Each pixel is encoded on one byte with the following scheme:
|
|
- Bit 0 (MSB): shading bit 0 (MSB of the shading value)
|
|
- Bit 1: second bit of the first byte of the codepoint
|
|
- Bit 2: shading bit 1
|
|
- Bit 3: fourth bit of the second byte of the codepoint
|
|
- Bit 4: shading bit 2
|
|
- Bit 5: sixth bit of the third byte of the codepoint
|
|
- Bit 6: shading bit 3 (LSB of the shading value)
|
|
- Bit 7: on/off bit
|
|
|
|
Note: above, when we provide a bit index, it starting from left to rigth. It apply to pixel byte, shading value and bit index for corruption detection.
|
|
|
|
When rendering the font, the renderer will take two values: background color and text color. It will create a scale ranging from 0 to 15 using linear interpolation and apply the expected color to each pixel using this scale and the shading value. The bit 1, 3 and 5 of each pixel is set to bits found in the codepoint to detect corruption. The pixels are stored in a grid, line by line, from top to bottom.
|
|
|
|
## Provided font
|
|
|
|
Vystem provide a basic font named `bitra`, with 12 pixels as width and 20 as height, only supporting ASCII characters. This font is stored in the file `bitra-medium-ascii.fbm`.
|