Draws bitmap fonts and manages font meta information.
The Font class renders fixed-size bitmap fonts to a Bitmap and exposes metrics for the selected font face. It supports bold, italic and underlined text, as well as adjustable glyph spacing, line spacing, tab width and alignment. Bitmap fonts are loaded from Windows .fon files. Scalable TrueType rendering is provided by VectorText instead.
Bitmap fonts must be stored in the fonts:fixed/ directory to be recognised during font database refreshes. Use the Font module's query and refresh functions to inspect or rebuild the installed font list.
Font strings are interpreted as UTF-8, allowing Unicode text to be supplied through the String field. Do not insert arbitrary byte values above 127 unless they are valid UTF-8 sequences. Invalid or unsupported glyphs fall back to the font's default character.
Initialisation of a new Font object can be as simple as declaring its Point size and Face name. Font face, size and style selections should be set before initialisation because the loaded bitmap data is cached for that combination. To use multiple styles of the same face, create one Font object for each required style. Runtime drawing properties such as colour, String, X, Y and alignment can still be changed between draw operations.
To draw a string, set Bitmap and String, then call Draw(). The X and Y fields set the starting position. Use Align together with AlignWidth and AlignHeight when text needs to be positioned within a larger surface area.
This documentation uses the following font terminology:
Point is the requested size of the font. It is relative to other point sizes of the same face; two faces at the
same point size are not necessarily the same pixel height.Height is the vertical bearing of the font expressed in pixels. It excludes top leading and the gutter used by
descending glyphs.Gutter is the space below the baseline used by descending glyphs such as g and y. It is also known as the
external leading or descent.LineSpacing is the recommended pixel distance from one baseline to the next.Glyph is a single rendered character image.Use VectorText for most display text. The Font class draws directly to a Bitmap and is not integrated with the display vector scene graph.
The Font class consists of the following fields:
Access | Name | Type | Comment | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Align | ALIGN | Sets the position of a font string to an abstract alignment. | |||||||||||||||||||
Sets the alignment of the font string within the AlignWidth and AlignHeight area. This is used in addition to the X and Y drawing coordinates.
| |||||||||||||||||||||
| AlignHeight | INT | The height to use when aligning the font string. | |||||||||||||||||||
Defines the height of the area used for vertical alignment. If this field is | |||||||||||||||||||||
| AlignWidth | INT | The width to use when aligning the font string. | |||||||||||||||||||
Defines the width of the area used for horizontal alignment. If this field is | |||||||||||||||||||||
| Ascent | INT | The total number of pixels above the baseline. | |||||||||||||||||||
Reflects the total number of pixels above the baseline, including Leading. | |||||||||||||||||||||
| Bitmap | *Bitmap | The destination Bitmap to use when drawing a font. | |||||||||||||||||||
| Bold | INT | Set to true to enable bold styling. | |||||||||||||||||||
| Colour | RGB8 | The font colour in RGB8 format. | |||||||||||||||||||
| EndX | INT | Indicates the final horizontal coordinate after completing a draw operation. | |||||||||||||||||||
Reflects the final horizontal coordinate reached by the most recent Draw() operation. | |||||||||||||||||||||
| EndY | INT | Indicates the final vertical coordinate after completing a draw operation. | |||||||||||||||||||
Reflects the final vertical coordinate reached by the most recent Draw() operation. | |||||||||||||||||||||
| Face | STRING | The name of a font face that is to be loaded on initialisation. | |||||||||||||||||||
| FixedWidth | INT | Forces a fixed pixel width to use for all glyphs. | |||||||||||||||||||
Forces all glyphs to advance by the specified pixel width. If the value is less than the widest glyph, rendered glyphs can overlap. | |||||||||||||||||||||
| Flags | FTF | Optional flags. | |||||||||||||||||||
| GlyphSpacing | DOUBLE | Adjusts the amount of spacing between each character. | |||||||||||||||||||
Adjusts horizontal glyph advance as a multiplier of each glyph's normal width. The default value is Using negative values is valid, and can lead to text being printed backwards. | |||||||||||||||||||||
| Gutter | INT | The 'external leading' value, measured in pixels. Applies to fixed fonts only. | |||||||||||||||||||
Reflects the external leading, or descent area, below the baseline. | |||||||||||||||||||||
| Height | INT | The point size of the font, expressed in pixels. | |||||||||||||||||||
| Italic | INT | Set to true to enable italic styling. | |||||||||||||||||||
| Leading | INT | 'Internal leading' measured in pixels. Applies to fixed fonts only. | |||||||||||||||||||
| LineCount | INT | The total number of lines in a font string. | |||||||||||||||||||
| LineSpacing | INT | The amount of spacing between each line. | |||||||||||||||||||
Defines the vertical distance from one line baseline to the next. It is initialised from the selected font and can be increased or decreased to adjust line spacing. If negative, later lines are drawn upward. If set before initialisation, the value is added to the font's normal line spacing instead of replacing it. For instance, setting the LineSpacing to 2 will result in an extra 2 pixels being added to the font's spacing. | |||||||||||||||||||||
| MaxHeight | INT | The maximum possible pixel height per character. | |||||||||||||||||||
Reflects the maximum bitmap height for the selected font at the current point size. | |||||||||||||||||||||
| Opacity | DOUBLE | Determines the level of translucency applied to a font. | |||||||||||||||||||
Determines the translucency level of the font fill colour. The default setting is Please note that the use of translucency will always have an impact on the time it normally takes to draw a font. | |||||||||||||||||||||
| Outline | RGB8 | Defines the outline colour around a font. | |||||||||||||||||||
Draws a one-pixel outline around bitmap glyphs when set to an RGB8 colour with a non-zero alpha component. Set the field to | |||||||||||||||||||||
| Path | STRING | The path to a font file. | |||||||||||||||||||
Defines the exact font file to load before initialisation. This bypasses normal face-name resolution through the font database. This feature is ideal for use when distributing custom fonts with an application. | |||||||||||||||||||||
| Point | DOUBLE | The point size of a font. | |||||||||||||||||||
Defines the requested font size in points. When setting the point size of a bitmap font, the system will try and find the closest matching value for the requested point size. For instance, if you request a fixed font at point 11 and the closest size is point 8, the system will drop the font to point 8. | |||||||||||||||||||||
| String | STRING | The string to use when drawing a Font. | |||||||||||||||||||
The String field must be defined to draw text with a Font object. It must contain valid UTF-8. Line feed characters start a new line during Draw(). If a string contains characters that are not supported by a font, those characters will be printed using a default character from the font. | |||||||||||||||||||||
| Style | STRING | Determines font styling. | |||||||||||||||||||
Selects the preferred style for initialisation. If the selected face does not provide that style, regular styling or the first registered style is used. Bitmap fonts are a special case if a bold or italic style is selected. In this situation the system can automatically convert the font to that style even if the correct graphics set does not exist. Conventional font styles are | |||||||||||||||||||||
| TabSize | INT | Defines the tab size to use when drawing and manipulating a font string. | |||||||||||||||||||
Controls the tab interval, measured in character columns. The default tab size is | |||||||||||||||||||||
| Underline | RGB8 | Enables font underlining when set. | |||||||||||||||||||
Draws an underline using the supplied RGB8 colour. Set the field to | |||||||||||||||||||||
| Width | INT | Returns the pixel width of a string. | |||||||||||||||||||
| WrapEdge | INT | Enables word wrapping at a given boundary. | |||||||||||||||||||
Enables word wrapping when set to a value greater than zero. Wrapping occurs when a word extends beyond this X coordinate. | |||||||||||||||||||||
| X | INT | The starting horizontal position when drawing the font string. | |||||||||||||||||||
Defines the starting horizontal coordinate for Draw(). The default coordinate is | |||||||||||||||||||||
| Y | INT | The starting vertical position when drawing the font string. | |||||||||||||||||||
Defines the starting vertical coordinate for Draw(). The default coordinate is | |||||||||||||||||||||
| YOffset | INT | Additional offset value that is added to vertically aligned fonts. | |||||||||||||||||||
Returns the vertical offset applied by | |||||||||||||||||||||
The following actions are currently supported:
| Draw | Draws a font to a Bitmap. | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ERR acDraw(*Object, DOUBLE X, DOUBLE Y, DOUBLE Width, DOUBLE Height)
| ||||||||||||
Universal values for alignment of graphics and text
| Name | Description |
|---|---|
| ALIGN::BOTTOM | Align to bottom |
| ALIGN::CENTER | Synonym for HORIZONTAL | VERTICAL |
| ALIGN::HORIZONTAL | Align to horizontal center |
| ALIGN::LEFT | Align to left |
| ALIGN::MIDDLE | Synonym for HORIZONTAL | VERTICAL |
| ALIGN::RIGHT | Align to right |
| ALIGN::TOP | Align to top |
| ALIGN::VERTICAL | Align to vertical center |
Font flags
| Name | Description |
|---|---|
| FTF::BASE_LINE | The Font's Y coordinate is the base line. |
| FTF::BOLD | Font is described as having a bold weight (read only). |
| FTF::HEAVY_LINE | Underline the font with a double-sized line, using the colour defined in Underline. |
| FTF::ITALIC | Font is described as using italics (read only). |
8-bit RGB colour value.
| Field | Type | Description |
|---|---|---|
| Red | UINT8 | Red component value |
| Green | UINT8 | Green component value |
| Blue | UINT8 | Blue component value |
| Alpha | UINT8 | Alpha component value |