-
Notifications
You must be signed in to change notification settings - Fork 111
font_spec
Homeworld Font Format Specification:
\
The Homeworld font format will be optimised for 3D graphics systems which use direct color. To that end, the fonts will be composed as a single 2D texture with u/v coordinates for the individual font characters. Since many graphics systems impose limitations on the possible dimensions of textures, we will have to be able to specify the dimensions of this texture. For example, they may be the most efficient exponent of 2.
\
The fonts will be stored in the file with a palette. Because the sizes of fonts is rather negligible compared to most other graphics, we will use 8 bit per pixel. The palette will have color information if the bitmap is a color bitmap, and alpha information if the font has anti-aliased edges or is transparent.
\
The font file will have 5 main sections arranged in the following order:
-
Header. This will contain information about the font and how it will appear
-
Character map (actually part of the header). This will be a list of pointer to the individual characters. Unused characters will be NULL. This list will be 256 pointers.
-
Character header information. This will be the u/v coordinates and size of the character.
-
Character image. This will be the 8-bit bitmap with all the font characters crammed in.
-
Palette. This will be the palette of colors and alpha for the following character image
\
Following is a more detailed description of the individual sections.
\
Name
Type and length
Usage
Ident. string
8 bytes
Compared to “Orannge” to verify this is a font file.
Version
16-bit word
Low byte minor version number high byte major version number.
Flags
16-bit word
Flags for the font*.
Ncharacters
32-bit word
Number of characters in file.
Spacing
32-bit word
Spacing between characters in this font.
Height
32-bit word
Full height of font (from top of tallest character bottom of lowest hanging character).
Ybaseline
32-bit word
Pixels from top of font to baseline of font (not full height if hanging characters).
Name
32-bit offset
Fixed up to optional name pointer.
Widthimage
32-bit word
Width of the full font image.
Heightimage
32-bit word
Height of the font image.
Ncolors
32-bit word
Number of colors in the font. Must be at least 2.
Ppalette
32-bit offset
Fixed up to a pointer to the palette.
Pimage
32-bit offset
Fixed up to a pointer to the font image.
reserved
16 bytes
Reserved for future font formats.
Characters
256 32-bit character offsets
Offsets (fixed up to pointers) to characters for each font. A NULL pointer means character not represented. The first entry is always NULL
\
* Bit-field flags for the font file header:
-
Color font. Monochrome is the default
-
Alpha enable. By default, no anti-aliasing will be applied to fonts.
\
There will be between zero and 255 character headers for a font. Each header will have the following format:
Name
Type and Length
Usage
u
16-bit word (pixel coords)
Left extreme of character image in font image.
v
16-bit word (pixel coords)
Top extreme of character.
width
16-bit word
Width of this character.
height
16-bit word
Height of this character.
OffsetX
16-bit word (screen coords)
x offset of bitmap on screen.*
Offsety
16-bit word (screen coords)
y offset of bitmap on screen.*
\
* The offset values are to permit efficient packing of characters such as comma and lower-case ‘o’ which would not take nearly the full extent of the maximum character height. This will reduce the size of our fonts at a minimum of additional run-time expense.
\
This will be an 8-bit image of a width and height defined in the file header. It will index the palette which follows.
\
The palette will be a list of 32-bit RGBA values. There will be
Ncolors entries in this list. This will describe the colors and
transparency of the characters, if it is a color font or just the
transparency, if it is a monochrome font. The simplest palette will be 2
colors : (0, 0, 0, 0) for the first (transparent) color and (0, 0, 0, 1)
for the second (solid) color. The color for a monochrome font needn’t be
specified here, as it comes from the function calls which render it.
There will be a maximum of 256 colors.