-
Notifications
You must be signed in to change notification settings - Fork 0
FV0000
The-Nice-One edited this page Feb 4, 2026
·
4 revisions
The header section uses a total of 8 bytes.
- The first 3 bytes are the magic bytes which are:
116 105 70. - The first bit in the 4th byte represents if the font letters should alligned by height (0), or by width (1). If font letters are alligned by height than each letter has the same height, and vice-versa. The following 3 bits are ignored. The last 4 bits define the format version. The current format version is
0000. - Afterwards the next byte is used to store the height or width (depending on above) of all the letter in the font. The width/height must be a unsigned single byte integer.
- Finally are 3 bytes which store a simple checksum to verify integrity of file. Example checksum function can be found in (spf.rs)[https://github.com/The-Nice-One/spf.rs/blob/main/src%2Fbyte.rs#L29-L38].
After the 8 initial bytes you can start defining each letter in your font as follows:
- The first 1-4 (as per the UTF-8 bit Distribution Table) bytes store the character (that is utf-8 encoded) to define.
- Secondly the next byte is the custom height or width of the letter. (will be opposite of choice in first bit)
- Lastly to define the character bitmap do the following:
- Begin by figuring out how many bytes the character bitmap needs. For this you can
bytes = ceilling( ( customHeightorWidth * constantHeightorWidth ) / 8 )Note: the reason we use ceiling is to make sure we dont miss out on bitmap data, as a result this leads to possible waated bytes. (ex. character needs 36 bits, we will need to use 5 bytes even though 4 of those bits will be unused) - Now that you know how many bytes your character bitmap needs, you can define it as a series of 0 (empty pixel), or 1. (used pixel) Starting from the top left corner in the first row, this represents the first bit. One to the right would represent the second bit, then the third, and so on until the customWidth or constantWidth (depending on setup) are greater than the current bit. Now this bit will represent the first bit in the second row. This pattern continues until the current bit is greater than the
customWidthorHeight * constantWidthorHeight. IfcustomWidthorHeight * constantWidthorHeightis perfectly dividable by 8 you can skip the point below, otherwise:- If the number of bits your character bitmap needs is not perfectly dividable by 8, you must close off the unfinished byte by appending the remainder of bits to the end of the last byte. These remainder bits will be completely ignored (see issues)
- You may repeat step 3 for every single character in your font.
- Begin by figuring out how many bytes the character bitmap needs. For this you can