DeskLib 2.90a:Font2.h


Contents


Introduction and Overview

The Font Manager doesn't automatically update fonts when you change between modes with different pixel to OS unit ratios. This can lead to font handles referring to fonts which do not appear the same size as those you claimed.

The functions declared by this header allow you to claim a font and have it automatically updated when the mode changes, so that you always have a handle for the font at the size you wanted.

It works by registering for user messages with Event_Claim and detecting a mode change, then updating the handles in its list. Make sure you call Event_Initialise (or equivalent) before using this library.

Font2 also frees all font handles you have claimed through it when your application exits, by registering an atexit() handler.


Functions


Font2_ClaimFont

os_error * Font2_ClaimFont(font2_block **font2, const char *name, int sizex, int sizey);

'name' should be the name of the font you wish to use (eg. "Trinity.Medium"). The font size is specified in 1/16ths of a point (eg. 12*16 for 12pt).

(*font2) will be filled with a pointer to a font2_block containing the information about the given font.

By always referring to the handle and information in this block you will always have up-to-date data.

This function returns NULL if there is no error.


Font2_ReclaimFont

os_error * Font2_ReclaimFont(font2_block **font2, const char *name, int xsize, int ysize);

This releases a claim on an previously claimed font if *font2 is not NULL, and then updates *font2 with a claim on the font with name 'name' and the specified size in 1/16ths of a point.


Font2_ReleaseFont

void Font2_ReleaseFont(font2_block **font2);

This releases a claim on the font claimed with Font2_Claim (if *font2 is not NULL) and then sets *font2 to NULL.


Font2_Initialise

void Font2_Initialise(void );

This sets up the Font2 system and registers a claim with Event_Claim so that it can detect mode changes.

It is called automatically as necessary by Font2, so you never have to call this yourself.


Type


struct font2_block

font2_block

typedef struct font2_block
{
font_handle handle;
font_info info;

} font2_block;

This is the form in which your program can access always up-to-date font handles and font information through Font2.

The font_info block is supplied as you will usually want the know the bounding box at some point, and this cuts down on calls to Font_ReadInfo and means it only has to be stored once for all uses of the same font in the app.