Internal Font Format

Overview

The internal font format is a binary format generated by the Font Generator. This is a pixelated format: each character is encoded as a grayscale bitmap image (on 1, 2, 4 or 8 bits per pixel). It does not need runtime memory allocation when loading the font or when drawing a string: the Graphics Engine’s software algorithms directly read the bitmap image from the memory.

Characteristics

The binary files hold font properties:

  • Font height and width, in pixels. A font has a fixed height. This height includes the white pixels at the top and bottom of each character, simulating line spacing in paragraphs. A monospace font is a font where all characters have the same width; for example, a ‘!’ representation has the same width as a ‘w’. In a proportional font, ‘w’ will be wider than a ‘!’. No width is specified for a proportional font.

    Font Height

    Font Height

  • Baseline, in pixels. All characters have the same baseline, which is an imaginary line on top of which the characters seem to stand. Characters can be partly under the line, for example ‘g’ or ‘}’. The number of pixels specified is the number of pixels above the baseline.

    Font baseline

    Font baseline

  • Space character size, in pixels. For proportional fonts, the Space character (0x20) is a specific character because it has no filled pixels, and so its width must be specified. For monospace, the space size is equal to the font width (and hence the same as all other characters).

  • Styles: A font holds either a combination of these styles: BOLD, ITALIC, or is said to be PLAIN.

  • When the selected font does not have a graphical representation of the required character, the first character in font is drawn instead.

Pixel Transparency

The Graphics Engine’s software algorithms render the font according to the value stored for each pixel. If the value is 0, the pixel is not rendered. If the value is the maximum value (for example the value 3 for 2 bits-per-pixel), the pixel is rendered using the current foreground color, completely overwriting the current value of the destination pixel. For other values, the pixel is rendered by blending the selected foreground color with the current color of the destination.

If n is the number of bits-per-pixel, then the maximum value of a pixel (pmax) is 2^n 1. The value of each color component of the final pixel is equal to:

\[foreground * pixelValue / pmax + background * (pmax - pixelValue) / pmax\]

Languages

Supported Languages

The Graphics Engine’s software algorithms manage the Unicode basic multilingual alphabet, whose characters are encoded on 16 bits, i.e. Unicode characters ranging from 0x0000 to 0xFFFF (Surrogates characters are allowed). It allows to render left-to-right or right-to-left writing systems: Latin (English, etc.), Arabic, Chinese, etc. are some supported languages. However, the rendering is always performed left-to-right, even if the string is written right-to-left. There is no support for top-to-bottom writing systems.

Complex Layout

Some languages require diacritics, contextual letters, specific character ordering, etc. and the Graphics Engine’s software algorithms do not handle these specificities at runtime. To manage the complex layouts, use either of these solutions:

  • Use the offline tool Native Language Support to automatically convert the translation messages in a characters array compatible with the Graphics Engine’s software algorithms.

  • Implement a complex layouter in the Abstract Layer API (see Font Renderer) to convert the application’s strings in a character array which format is compatible with the Graphics Engine’s software algorithms and call the Graphics Engine’s software algorithms to draw them.