Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.


Inherits From: NSObject

Conforms To: NSCoding, NSCopying NSObject (NSObject)

Declared In: AppKit/NSFont.h

Class Description

The NSFont class declares the programmatic interface to objects that correspond to fonts. NSFont is in principle an abstract class that represents fonts in general, not just PostScript fonts. In practice, at this time, NSFont objects represent PostScript fonts. Each NSFont object records a font's name, size, style, and matrix. When an NSFont object receives a set message, it establishes its font as the current font in the PostScript Server's current graphics state.

For a given application, only one NSFont object is created for a particular PostScript font/size or font/matrix combination. That isif you ask for 24-point Optima, a new font object is created for 24-point Optima if such an object doesn't exist already. When the NSFont class object receives a message to create a new object for a particular font, it first checks whether an object has already been created for that font. If so, the the NSFont class object returns the existing font object; otherwise, the the NSFont class object creates a new font object and returns it.

This sharing of NSFont objects minimizes the number of distinct font objects created. It also implies that no one object in your application can know whether it has the only reference to a particular NSFont object. Thus, NSFont objects shouldn't be deallocated, but should be treated like auto-released Foundation class objects.

Where matrix is used, it refers to a PostScript-style six-element array of numbers that indicate transformations to be applied to a font. An NSFontIdentityMatrix identifies a font matrix used for fonts created by specifying a size.

The size of a font in the method definitions is defined in points, which in currently accepted practice, are actually PostScript unitsa PostScript unit being defined as 1/72 of an inch, or 0.0139 of an inch. In metric equivalents, a PostScript unit is 0.3528 millimetres. PostScript points are minimally different from printer's points, so for all intents and purposes you can think of PostScript units and points as interchangeable.

In general, you instantiate an NSFont object by sending one of the methods listed in Creating a Font Object to the NSFont class object. The methods with system and user in their names obtain special pre-determined fonts defined at the system level and the application level, respectively. In general, you would use the fontWithName:size: and fontWithName:matrix: methods to obtain a named font.

A variety of methods are available for querying a font object. In particular, AFM (Adobe Font Metrics) data can be obtained by invoking afmDictionary or afmFileContents .

Methods whose descriptions state Returns1/4and matrix NSFontIdentityMatrix actually return an NSFontIdentityMatrix whose first and fourth elements are multiplied by the current size of the font.


Methods listed in Creating a Font Object can all raise a NSFontUnavailableException if the requested font can't be constructed.

Creating a Font Object

Setting the Font

Querying the Font

Manipulating Glyphs