GetFNum
GetFNum
Obtain font number associated with a font name Str255 fontName ; address of Pascal-style string of font name short *fontNum ; receives the matching font number
GetFNum obtains the font number matching a given font name. fontName is the address of a pascal-style length-prefixed string containing
the name of the font whose number you wish to obtain. Uppercase and
lowercase is not significant.
fontNum is the address of a short. Upon return, it contains the number of the
font corresponding with fontName.
If font fontName cannot be found, fontNum gets set to 0. Be warned
that 0 is a valid font number (of the system font, Chicago), so
we must do further error checking. See the example below for the
recommended way to do this.
Notes: If a user were to type in the name of a font, you could use this
to obtain the font number (which is needed for all subsequent
Some programmers have found it advantageous to use font names, stored in
a 'TEXT' or 'STR ' resource, and use GetFNum at run-time rather than hard-coding font numbers into the applications. This is because font
your system currently uses the expected font numbers for standard fonts.
The GetFontName function performs the inverse operation; it looks up a font name, given its font number. The RealFont function returns a Boolean indicating whether a particular font and size exist.
Example
#include <Fonts.h>
Boolean GetFontNumber( Str255 fontName, short *fontNum ) {
if ( *fontNum == 0) {
/* Either we didn't find the font, or we were looking for the system
* font. */
}
else
}