typedef object font;
font newfont(char *family_name, int style, int size); void del(font f); int getwidth(font f); /* average width of font */ int getheight(font f); /* line height of font */ int getascent(font f); /* size above baseline */ int getdescent(font f); /* size below baseline */ int strwidth(font f, char *s); /* pixel width of string */ point strsize(font f, char *s); /* pixel width and height */ rect strrect(font f, char *s); /* pixel width and height */ void setfont(font f); /* change to new font */ font currentfont(void); /* return current font */
extern font SystemFont; /* system font */ extern font FixedFont; /* fixed-width font */ extern font Times; /* times roman 12 serif */ extern font Helvetica; /* helvetica 12 sans-serif */ extern font Courier; /* courier 12 fixed-width */ #define Plain 0x0000 #define Bold 0x0001 #define Italic 0x0002 #define BoldItalic 0x0003 #define SansSerif 0x0004 #define FixedWidth 0x0008 #define Wide 0x0010 #define Narrow 0x0020
A font is a typeface of a certain size and style.
A font can be obtained using newfont. The family name parameter is a string like "Times" or "Courier", while the style is a bit-field composed of any of the styles Plain, Bold, Italic, SansSerif, FixedWidth, Wide or Narrow. Use plus or bitwise-or operators to combine these styles. The size field can be either a positive number, which specifies a pixel-height for the font, or a negative number to indicate a point-size.
Hence newfont("Times", Bold, -12) returns a bold Times 12-point font, while newfont("Courier", Italic+Wide, 14) returns a wide italicised Courier font with an on-screen height of 14 pixels. (NB: one point is defined as one 72nd of an inch, hence 12 points = one 6th of an inch.) The function may return NULL if it cannot find a suitable font.
The del function releases the memory used by a font. In general this function does not need to be used unless memory is critical, as fonts will automatically be released from memory.
The getwidth function returns the average pixel width of a character in the given font, while getheight returns the distance in pixels from the top of one line of text to the top of the next. The getascent and getdescent functions return the pixel distances above and below the font's baseline that the font characters actually extend. The height of a font will be equal to the ascent plus the descent, plus any inter-line spacing distance.
The strwidth function reports the pixel width of the given string in the supplied font. The strsize function returns a point structure which reports the pixel width and height of the given string in the supplied font. The width will be reported as the x-coordinate, while the y-coordinate reports the height of the string. The strrect function returns the string's pixel width and height in the returned rectangle's width and height fields. The rectangle's x and y values are left at zero.
The current font can be set using the setfont function. The currentfont returns which font is currently being used in text drawing functions.
Five fonts are automatically supplied to the user: SystemFont, FixedFont, Times, Helvetica, Courier. The SystemFont is the default system font, the FixedFont is a fixed-width font, while Times, Helvetica and Courier are each 12-point fonts of the respective typeface.