ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5


2 - The Way of the FONT

Bitmapped fonts can be described in a variety of formats, but on the ebm the FONT structure is used. We don't have to delve into the details of the structure, since to use it we simply need to pass a pointer to the structure wherever a function call requires a FONT *. On every ebm program, the built-in Default font is available without any further programming for ordinary text display (labels and the like), while the System font is used for text such as on button labels and window captioning. All commands that use a FONT pointer can be passed a zero value instead to make use of this default font.
Note that the Default font and the default display font are not necessarily the same. When a program starts up, the program's default font is the one shown here (also called Default); if you then subsequently change it, all program default font references point to the new selection. For instance, you can set the default to the System font with the following line:

SetFont( GUI_GetSystemFont() ); // our default font is now the system font

After SetFont(), all text drawing commands that specify zero for the font pointer will use this new default. However, you can still use other fonts. For example the following line will display a line of text in the System font, regardless of what is the current default setting:

DrawText("This is in System Font", 5,10,GUI_GetSystemFont());

Although there are quite a few commands for working with fonts, the two commands that will likely find the most use are:

GUI_TextWidth(const FONT *font,const char *text,S32 len) - Returns the length in pixels of the specified string. Note that the text doesn't have to be null-terminated as the len value indicates how many characters of the string are used in measuring.

GUI_TruncateText(const FONT *font,const char *text,S16 width,BOOL want_ellipsis) - The reverse of GUI_TextWidth(), this function takes a width in pixels, and returns how many of the characters of the text string will fit. The flag 'want_ellipsis' is used to include the ellipsis char at the end; if true, this character width is taken into consideration when calculating the fit.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice