Draws bitmap fonts and manages font meta information.
The Font class is provided for the purpose of bitmap font rendering and querying font meta information. It supports styles such as bold, italic and underlined text, along with extra features such as adjustable spacing and word alignment. Fixed-point bitmap fonts are supported through the Windows .fon file format. Truetype fonts are not supported (refer to the VectorText class for this feature).
Bitmap fonts must be stored in the fonts:fixed/
directory in order to be recognised. The process of font installation and file management is managed by functions supplied in the Font module.
The Font class includes full support for the unicode character set through its support for UTF-8. This gives you the added benefit of being able to support international character sets with ease, but you must be careful not to use character codes above #127 without being sure that they follow UTF-8 guidelines. Find out more about UTF-8 at this web page.
Initialisation of a new font object can be as simple as declaring its Point size and Face name. Font objects can be difficult to alter post-initialisation, so all style and graphical selections must be defined on creation. For example, it is not possible to change styling from regular to bold format dynamically. To support multiple styles of the same font, create a font object for every style that requires support. Basic settings such as colour, the font string and text positioning are not affected by these limitations.
To draw a font string to a Bitmap object, start by setting the Bitmap and String fields. The X and Y fields determine string positioning and you can also use the Align field to position a string to the right or center of the surface area.
To clarify the terminology used in this documentation, please note the definitions for the following terms:
Please note that in the majority of cases the VectorText class should be used for drawing strings because the Font class is not integrated with the display's 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. | |||||||||||||||||||
Use this field to set the alignment of a font string within its surface area. This is an abstract means of positioning in comparison to setting the X and Y fields directly.
| |||||||||||||||||||||
AlignHeight | INT | The height to use when aligning the font string. | |||||||||||||||||||
AlignWidth | INT | The width to use when aligning the font string. | |||||||||||||||||||
Ascent | INT | The total number of pixels above the baseline. | |||||||||||||||||||
The Ascent value reflects the total number of pixels above the baseline, including the Leading value. | |||||||||||||||||||||
Bitmap | *Bitmap | The destination Bitmap to use when drawing a font. | |||||||||||||||||||
Bold | INT | Set to true to enable bold styling. | |||||||||||||||||||
Setting the Bold field to | |||||||||||||||||||||
Colour | RGB8 | The font colour in RGB8 format. | |||||||||||||||||||
EndX | INT | Indicates the final horizontal coordinate after completing a draw operation. | |||||||||||||||||||
EndY | INT | Indicates the final vertical coordinate after completing a draw operation. | |||||||||||||||||||
Face | STRING | The name of a font face that is to be loaded on initialisation. | |||||||||||||||||||
The name of an installed font face must be specified here for initialisation. If this field is undefined then the initialisation process will use the user's preferred face. A list of available faces can be obtained from the GetList() function. For convenience, the face string can also be extended with extra parameters so that the point size and style are defined at the same time. Extra parameters are delimited with the colon character and must follow a set order defined as Here are some examples: Noto Sans:12:Bold Italic:#ff0000 Courier:10.6 Charter:120%::255,128,255 Multiple font faces can be specified in CSV format, e.g. | |||||||||||||||||||||
FixedWidth | INT | Forces a fixed pixel width to use for all glyphs. | |||||||||||||||||||
The FixedWidth value imposes a preset pixel width for all glyphs in the font. It is important to note that if the fixed width value is less than the widest glyph, the glyphs will overlap each other. | |||||||||||||||||||||
Flags | FTF | Optional flags. | |||||||||||||||||||
GlyphSpacing | DOUBLE | Adjusts the amount of spacing between each character. | |||||||||||||||||||
This field adjusts the horizontal spacing between each glyph, technically known as kerning between each font character. The value is expressed as a multiplier of the width of each character, and defaults to 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. | |||||||||||||||||||
This field reflects the 'external leading' value (also known as the 'gutter'), measured in pixels. | |||||||||||||||||||||
Height | INT | The point size of the font, expressed in pixels. | |||||||||||||||||||
The point size of the font is expressed in this field as a pixel measurement. It does not not include the leading value (refer to Ascent if leading is required). The height is calculated on initialisation and can be read at any time. | |||||||||||||||||||||
Italic | INT | Set to true to enable italic styling. | |||||||||||||||||||
Setting the Italic field to | |||||||||||||||||||||
Leading | INT | 'Internal leading' measured in pixels. Applies to fixed fonts only. | |||||||||||||||||||
LineCount | INT | The total number of lines in a font string. | |||||||||||||||||||
This field indicates the number of lines that are present in a #font's String field. If word wrapping is enabled, this will be taken into account in the resulting figure. | |||||||||||||||||||||
LineSpacing | INT | The amount of spacing between each line. | |||||||||||||||||||
This field defines the amount of space between each line that is printed with a font object. It is set automatically during initialisation to reflect the recommended distance between each line. The client can increase or decrease this value to make finer adjustments to the line spacing. If negative, the text will be printed in a reverse vertical direction with each new line. If set prior to initialisation, the value will be added to the font's normal line-spacing instead of over-riding 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. | |||||||||||||||||||
This field reflects the maximum possible pixel height per character, covering the entire character set at the current point size. | |||||||||||||||||||||
Opacity | DOUBLE | Determines the level of translucency applied to a font. | |||||||||||||||||||
This field determines the translucency level of a font graphic. The default setting is 100%, which means that the font will not be translucent. Any other value set here will alter the impact of a font's graphic over the destination Bitmap. High values will retain the boldness of the font, while low values can render it close to invisible. 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. | |||||||||||||||||||
An outline can be drawn around a font by setting the Outline field to an RGB8 colour. The outline can be turned off by writing this field with a | |||||||||||||||||||||
Path | STRING | The path to a font file. | |||||||||||||||||||
This field can be defined prior to initialisation. It can be used to refer to the exact location of a font data file, in opposition to the normal practice of loading fonts that are installed on the host system. This feature is ideal for use when distributing custom fonts with an application. | |||||||||||||||||||||
Point | DOUBLE | The point size of a font. | |||||||||||||||||||
The point size defines the size of a font in point units, at a ratio of 1:72 DPI. 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 in order to draw text with a font object. A string must consist of a valid sequence of UTF-8 characters. Line feeds are allowed (whenever a line feed is reached, the Draw() action will start printing on the next line). Drawing will stop when the null termination character is reached. 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. | |||||||||||||||||||
The style of a font can be selected by setting the Style field. This comes into effect only if the font actually supports the specified style as part of its graphics set. If the style is unsupported, the regular styling of the face will be used on initialisation. 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. | |||||||||||||||||||
The TabSize value controls the interval between tabs, measured in characters. The default tab size is 8 and the TabSize only comes into effect when tab characters are used in the font String. | |||||||||||||||||||||
Underline | RGB8 | Enables font underlining when set. | |||||||||||||||||||
To underline a font string, set the Underline field to the colour that should be used to draw the underline. Underlining can be turned off by writing this field with a | |||||||||||||||||||||
Width | INT | Returns the pixel width of a string. | |||||||||||||||||||
Read this virtual field to obtain the pixel width of a font string. You must have already set a string in the font for this to work, or a width of zero will be returned. | |||||||||||||||||||||
WrapEdge | INT | Enables word wrapping at a given boundary. | |||||||||||||||||||
Word wrapping is enabled by setting the WrapEdge field to a value greater than zero. Wrapping occurs whenever the right-most edge of any word in the font string extends past the coordinate indicated by the WrapEdge. | |||||||||||||||||||||
X | INT | The starting horizontal position when drawing the font string. | |||||||||||||||||||
When drawing font strings, the X and Y fields define the position that the string will be drawn to in the target surface. The default coordinates are | |||||||||||||||||||||
Y | INT | The starting vertical position when drawing the font string. | |||||||||||||||||||
When drawing font strings, the X and Y fields define the position that the string will be drawn to in the target surface. The default coordinates are | |||||||||||||||||||||
YOffset | INT | Additional offset value that is added to vertically aligned fonts. | |||||||||||||||||||
Fonts that are aligned vertically (either in the center or bottom edge of the drawing area) will have a vertical offset value. Reading that value from this field and adding it to the Y field will give you an accurate reading of where the string will be drawn. |
The following actions are currently supported:
Name | Comment | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
Result flags for the SelectFont() function.
Name | Description |
---|---|
FMETA::HIDDEN | The font should not appear in any named list shown to the user. |
FMETA::HINT_INTERNAL | The Freetype hinter should be used. |
FMETA::HINT_LIGHT | The light version of the Freetype hinter should be used. |
FMETA::HINT_NORMAL | The hinting information provided by the font should be given preference. |
FMETA::SCALED | The font is scalable (assume fixed otherwise). |
FMETA::VARIABLE | This is a scalable font featuring variable metrics. |
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). |
For GetList(), describes a system font.
Field | Type | Description |
---|---|---|
Next | struct FontList * | Pointer to the next entry in the list. |
Name | STRING | The name of the font face. |
Alias | STRING | Reference to another font Name if this is an alias. |
Points | LONG * | Pointer to an array of fixed point sizes supported by the font. |
Styles | STRING | Supported styles are listed here in CSV format. |
Axes | STRING | For variable fonts, lists all supported axis codes in CSV format |
Scalable | BYTE | TRUE if the font is scalable. |
Variable | BYTE | TRUE if the font has variable metrics. |
Hinting | HINT | Hinting options |
Hidden | BYTE | TRUE if the font should be hidden from user font lists. |
8-bit RGB colour value.
Field | Type | Description |
---|---|---|
Red | UBYTE | Red component value |
Green | UBYTE | Green component value |
Blue | UBYTE | Blue component value |
Alpha | UBYTE | Alpha component value |
Class Info | |
---|---|
ID | ID_FONT |
Category | Graphics |
Include | modules/font.h |
Version | 1 |