Fl_Font

The type passed to Fl_Widget::label_font() and other parts of fltk is a typedef defined like this, pointing at a structure Fl_Font_:

To draw text in a font you use fl_font(Fl_Font,size) to select a font and scale, and then fl_draw(const char*) to draw letters. See the documentaion on drawing functions.

The following Fl_Font values are predefined:

Methods

Fl_Font_* Fl_Font_::bold();
Fl_Font_* Fl_Font_::italic();

Pointers to the bold and italic versions of this font. FL_HELVETICA->bold() is the same as FL_HELVETICA_BOLD, FL_TIMES->bold()->italic() is the same as FL_TIMES_BOLD_ITALIC.

These are never null. If this font has no bold or italic version then these are circular pointers. Thus FL_TIMES_BOLD->bold() is the same as FL_TIMES_BOLD and FL_SYMBOL->bold() is the same as FL_SYMBOL.

const char* Fl_Font_::system_name()

Returns a string that identifies the font in a system-specific manner. About all that can be said about it is that it is different for every font (two different fonts may return the same name()). This string is not portable, even between different machines running the same operating system.

const char* Fl_Font_::name(int* attributes = 0)

Returns the name of the font. The return value points to a static buffer that is overwritten each call (so copy the string if you want to keep it).

The integer pointed to by attributes is set to zero, FL_BOLD or FL_ITALIC or FL_BOLD|FL_ITALIC. If this pointer is null then the attributes are indicated by adding a space and "bold" or "italic" to the name.

int Fl_Font_::encodings(const char** &array) const;

Sets array to point at a list of encoding names. The return value is the length of this array. Each string identifies an "encoding" that is supported by this font. These strings may be passed to the fl_encoding() to select what characters the first 256 codes print. A zero length array may be returned, this indicates that the font will print the same no matter what encoding is set.

int Fl_Font_::sizes(int *&array) const;

Sets array to point at a list of sizes. The return value is the length of this array. The sizes are sorted from smallest to largest and indicate what sizes can be given to fl_font() that will be matched exactly (fl_font() will pick the closest size for other sizes). A zero in the first location of the array indicates a scalable font, where any size works, although the array may list sizes that work "better" than others. The returned array points at a static buffer that is overwritten each call, so you want to copy it if you plan to keep it.

Fl_Font fl_find_font(const char* name, int attributes = 0);

Find a font with the given "nice" name. You can get bold and italic by adding a space and "bold" or "italic" (or both) to the name, or by passing them as the attributes. Case is ignored and fltk will accept some variations in the font name.

The current implementation calls fl_list_fonts() and then does a binary search for the font in it. This can make the first call pretty slow, especially on X.

int fl_list_fonts(Fl_Font*& arrayp);

This allocates and fills in an array containing every font on the server. The location arrayp is set to a pointer to this array, and the length of the array is the return value. Each entry is a "base" font, there may be bold, italic, and bold+italic version of each font pointed to by bold() or italic().

Subsequent calls to this function returns the same array again. Currently there is no way to update the list from any changes to the set of fonts on the server.