Up
Authors
- Ovidiu Predescu (
ovidiu@net-community.com)
-
Date: Generated at 2025-12-03
The font class
Copyright: (C) 1996 Free Software Foundation, Inc.
The NSFont class allows control of the fonts used for
displaying text anywhere on the screen. The primary
methods for getting a particular font are
+fontWithName:matrix:
and
+fontWithName:size:
which take the name and size of a particular font and
return the NSFont object associated with that font. In
addition there are several convenience mathods which
make it easier to get certain types of fonts.
In particular, there are several methods to get the standard
fonts used by the Application to display text for a
partiuclar purpose. See the class methods listed
below for more information. These default fonts can be
set using the user defaults system. The default font names
available are:
-
NSBoldFont Helvetica-Bold (System bold font)
-
NSControlContentFont System font
-
NSFont Helvetica (System Font)
-
NSLabelFont System font
-
NSMenuFont System font
-
NSMenuBarFont System font
-
NSMessageFont System font
-
NSPaletteFont System bold font
-
NSTitleBarFont System bold font
-
NSToolTipsFont System font
-
NSUserFixedPitchFont Courier
-
NSUserFont System font
The default sizes are:
-
NSBoldFontSize (none)
-
NSControlContentFontSize (none)
-
NSFontSize 12 (System Font Size)
-
NSLabelFontSize (none)
-
NSMenuFontSize (none)
-
NSMiniFontSize 8
-
NSMessageFontSize (none)
-
NSPaletteFontSize (none)
-
NSSmallFontSize 10
-
NSTitleBarFontSize (none)
-
NSToolTipsFontSize (none)
-
NSUserFixedPitchFontSize (none)
-
NSUserFontSize (none)
Font sizes list with (none) default to NSFontSize.
- Declared in:
- AppKit/NSFont.h
- Conforms to:
- NSCoding
- NSCopying
Availability: OpenStep
NSFont encapsulates all the information needed to
render text with a specific typeface, size, and style.
It provides comprehensive font creation, measurement, and
glyph manipulation capabilities for text layout and
rendering systems. The font system supports both
screen and printer fonts, with automatic conversion
between them. Fonts can be created by name and size,
or through more advanced methods using font descriptors
and transformation matrices. NSFont provides extensive
metrics information including ascender, descender,
line height, character advancement, and glyph bounding
rectangles. It also supports advanced typography
features like composite glyph positioning and
multi-byte character encoding schemes. The class
integrates with the broader text system through
glyph manipulation methods that support complex text
layout, international text rendering, and precise
typographic control needed for high-quality
document formatting.
NSFont declares 9 Instance Variables
+ (
NSFont*)
boldSystemFontOfSize: (CGFloat)fontSize;
Availability: OpenStep
Returns the bold system font at the specified size.
The bold system font is used for emphasis in user
interface elements and provides consistent bold
text appearance across the system. The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default system
size. Returns a bold variant of the system font at
the specified size.
Returns the default bold font for use in menus
and heading in standard gui components. If
fontSize is <= 0, the default size is
used.
See Also:
+fontWithName:size:
+ (
NSFont*)
controlContentFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used for control content (button
titles, text field content). The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default size.
Returns the standard control content font at the
specified size.
+ (
NSFont*)
fontWithDescriptor: (
NSFontDescriptor*)descriptor
size: (CGFloat)size;
Availability: MacOS-X 10.4.0
Creates a font using a font descriptor
and size. Font descriptors provide a more
flexible way to specify font characteristics
including family, weight, traits, and other
attributes. The descriptor parameter
specifies the desired font characteristics. The
size parameter sets the font
size in points. Returns a font matching
the descriptor at the specified
size.
+ (
NSFont*)
fontWithDescriptor: (
NSFontDescriptor*)descriptor
size: (CGFloat)size
textTransform: (
NSAffineTransform*)transform;
Availability: MacOS-X 10.4.0
Creates a font using a font descriptor,
size, and transformation matrix. This
method provides the most comprehensive font creation
capabilities, combining descriptor-based
selection with size and transformation
control. @param descriptor The font
descriptor specifying the desired font
characteristics. @param size
The font size in points. @param
transform The transformation to apply to
the font. @return A font matching the
descriptor at the specified
size with transformation applied.
+ (
NSFont*)
fontWithDescriptor: (
NSFontDescriptor*)descriptor
textTransform: (
NSAffineTransform*)transform;
Availability: MacOS-X 10.4.0
Creates a font using a font descriptor
and transformation matrix. This method combines
descriptor-based font selection with
custom transformations. The descriptor
parameter specifies the desired font
characteristics. The transform
parameter specifies the transformation to apply
to the font. Returns a font matching the
descriptor with the specified
transformation applied.
+ (
NSFont*)
fontWithName: (
NSString*)aFontName
matrix: (const CGFloat*)fontMatrix;
Availability: OpenStep
Creates a font with the specified PostScript name
and transformation matrix. This method provides the
most control over font creation, allowing custom
transformation matrices for scaling,
rotation, and skewing effects. The
aFontName parameter should contain the
PostScript name of the font (e.g.,
"Helvetica-Bold"). The
fontMatrix parameter should be a 6-element
transformation matrix [a b c d tx ty] for
font transformation. Returns a font object with the
specified name and transformation, or
nil if the font cannot be created.
Returns an autoreleased font with name
aFontName and matrix
fontMatrix.
The fontMatrix is a standard size element
matrix as used in PostScript to describe the
scaling of the font, typically it just includes
the font size as [fontSize 0 0 fontSize 0 0]. You can
use the constant NSFontIdentityMatrix in place of [1
0 0 1 0 0]. If NSFontIdentityMatrix, then the font will
automatically flip itself when set in a
flipped view.
+ (
NSFont*)
fontWithName: (
NSString*)aFontName
size: (CGFloat)fontSize;
Availability: OpenStep
Creates a font with the specified PostScript name
and size. This is the most commonly used font creation
method for standard text rendering. The
aFontName parameter should contain the
PostScript name of the font (e.g.,
"Times-Roman", "Helvetica"). The
fontSize parameter specifies the desired
font size in points. Returns a font object with the
specified name and size, or
nil if
the font cannot be created.
Returns an autoreleased font with name
aFontName and size fontSize.
Fonts created using this method will automatically
flip themselves when set in a flipped view.
+ (
NSFont*)
labelFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used for labels and non-editable
text. The fontSize parameter specifies the
desired font size in points. Use 0.0 for the
default size. Returns the standard label font at
the specified size.
+ (CGFloat)
labelFontSize;
Availability: MacOS-X 10.0.0
Returns the standard font size for labels. Returns
the standard label font size in points.
+ (
NSFont*)
menuBarFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used in the menu bar. The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default size.
Returns the standard menu bar font at the specified
size.
+ (
NSFont*)
menuFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used in menus. The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default size.
Returns the standard menu font at the specified
size.
+ (
NSFont*)
messageFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used for message text in alerts
and dialogs. The fontSize parameter
specifies the desired font size in points. Use
0.0 for the default size. Returns the standard message
font at the specified size.
+ (
NSFont*)
paletteFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used in palette windows and tool
palettes. The fontSize parameter
specifies the desired font size in points. Use
0.0 for the default size. Returns the standard palette
font at the specified size.
+ (
NSArray*)
preferredFontNames;
Availability: OpenStep
Returns the list of preferred font names. The
preferred fonts list determines the fallback
order when a requested font is not available on the
system. Returns an array of NSString objects
containing preferred font names.
Returns an array of the names of preferred fonts.
See Also:
+setPreferredFontNames:
+ (void)
setPreferredFontNames: (
NSArray*)fontNames;
Availability: OpenStep
Sets the list of preferred font names. This
establishes the fallback order for font
selection when requested fonts are not available.
The
fontNames parameter should contain an
array of NSString objects with preferred font names.
Sets an array of the names of preferred fonts to
fontsNames/
See Also:
+preferredFontNames
+ (void)
setUserFixedPitchFont: (
NSFont*)aFont;
Availability: OpenStep
Sets the user's preferred fixed-pitch font. This
establishes the default fixed-pitch font that
will be returned by userFixedPitchFontOfSize: for
subsequent requests. @param aFont The
font to set as the user's preferred fixed-pitch font.
+ (void)
setUserFont: (
NSFont*)aFont;
Availability: OpenStep
Sets the user's preferred proportional font. This
establishes the default proportional font that
will be returned by userFontOfSize: for subsequent
requests. @param aFont The font to set
as the user's preferred proportional font.
+ (CGFloat)
smallSystemFontSize;
Availability: MacOS-X 10.0.0
Returns the standard small system font size.
Returns the standard small system font size in
points.
+ (
NSFont*)
systemFontOfSize: (CGFloat)fontSize;
Availability: OpenStep
Returns the standard system font at the specified
size. The system font is the default font used for
user interface text throughout the system and provides
optimal readability for interface elements. The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default system
size. Returns the system font at the specified size.
Returns the default font for use in menus and
heading in standard gui components. If
fontSize is <= 0, the default size is
used.
See Also:
+boldSystemFontOfSize:
userFontOfSize: userFixedPitchFontOfSize:
+fontWithName:size:
+ (CGFloat)
systemFontSize;
Availability: MacOS-X 10.0.0
Returns the standard system font size. Returns the
standard system font size in points.
+ (CGFloat)
systemFontSizeForControlSize: (
NSControlSize)controlSize;
Availability: MacOS-X 10.0.0
Returns the appropriate system font size for the
given control size. This method provides the correct
font size for different control sizes (regular, small,
mini) to maintain visual consistency. The
controlSize parameter specifies the
control size (NSRegularControlSize,
NSSmallControlSize, NSMiniControlSize).
Returns the appropriate font size for the specified
control size.
+ (
NSFont*)
titleBarFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used in window title bars. The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default size.
Returns the standard title bar font at the
specified size.
+ (
NSFont*)
toolTipsFontOfSize: (CGFloat)fontSize;
Availability: MacOS-X 10.0.0
Returns the font used for tooltip text. The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default size.
Returns the standard tooltip font at the specified
size.
+ (void)
useFont: (
NSString*)aFontName;
Availability: OpenStep
Sets the font for subsequent text drawing operations
by name. This is a legacy method that establishes a font
for text operations by PostScript name. @param
aFontName The PostScript name of the font
to use for text operations.
+ (
NSFont*)
userFixedPitchFontOfSize: (CGFloat)fontSize;
Availability: OpenStep
Returns the user's preferred fixed-pitch font at
the specified size. Fixed-pitch fonts are essential for
code editing, terminal applications, and any context
where character alignment is important. The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default size.
Returns the user's preferred fixed-pitch font at
the specified size.
Returns the default fixed pitch font for use in
locations other than standard gui components.
If fontSize is <= 0, the default size is
used.
See Also:
+setUserFixedPitchFont:
+userFontOfSize:
+boldSystemFontOfSize:
+systemFontOfSize:
+fontWithName:size:
+ (
NSFont*)
userFontOfSize: (CGFloat)fontSize;
Availability: OpenStep
Returns the user's preferred proportional font at
the specified size. This font reflects the user's
personal preference for general text display and
reading, providing a personalized text experience.
The
fontSize parameter specifies the desired
font size in points. Use 0.0 for the default size.
Returns the user's preferred proportional font at
the specified size.
Returns the default font for use in locations
other than standard gui components. If
fontSize is <= 0, the default size is
used.
See Also:
+setUserFont:
+boldSystemFontOfSize:
systemFontOfSize:
userFixedPitchFontOfSize:
+fontWithName:size:
- (
NSSize)
advancementForGlyph: (
NSGlyph)aGlyph;
Availability: OpenStep
Description forthcoming.
- (
NSDictionary*)
afmDictionary;
Availability: OpenStep
Description forthcoming.
- (
NSString*)
afmFileContents;
Availability: OpenStep
This method returns nil in the GNUstep
implementation
- (CGFloat)
ascender;
Availability: OpenStep
Description forthcoming.
- (
NSRect)
boundingRectForFont;
Availability: OpenStep
Description forthcoming.
- (
NSRect)
boundingRectForGlyph: (
NSGlyph)aGlyph;
Availability: OpenStep
Description forthcoming.
- (CGFloat)
capHeight;
Availability: OpenStep
Description forthcoming.
- (
NSCharacterSet*)
coveredCharacterSet;
Availability: MacOS-X 10.0.0
Description forthcoming.
- (CGFloat)
defaultLineHeightForFont;
Availability: OpenStep
Description forthcoming.
- (CGFloat)
descender;
Availability: OpenStep
Description forthcoming.
- (
NSString*)
displayName;
Availability: OpenStep
Description forthcoming.
- (
NSString*)
encodingScheme;
Availability: OpenStep
Description forthcoming.
- (
NSString*)
familyName;
Availability: OpenStep
Description forthcoming.
- (
NSFontDescriptor*)
fontDescriptor;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSString*)
fontName;
Availability: OpenStep
Description forthcoming.
- (void)
getAdvancements: (
NSSizeArray)advancements
forGlyphs: (const
NSGlyph*)glyphs
count: (
NSUInteger)count;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
getAdvancements: (
NSSizeArray)advancements
forPackedGlyphs: (const void*)glyphs
count: (
NSUInteger)count;
Availability: MacOS-X 10.4.0
Not implemented (as of 2025-12-03).
Please help us by producing an implementation of
this and donating it to the GNUstep project.
- (void)
getBoundingRects: (
NSRectArray)bounds
forGlyphs: (const
NSGlyph*)glyphs
count: (
NSUInteger)count;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
glyphIsEncoded: (
NSGlyph)aGlyph;
Availability: OpenStep
Description forthcoming.
- (
NSGlyph)
glyphWithName: (
NSString*)glyphName;
Availability: OpenStep
Description forthcoming.
- (BOOL)
isBaseFont;
Availability: OpenStep
Description forthcoming.
- (BOOL)
isFixedPitch;
Availability: OpenStep
Description forthcoming.
- (CGFloat)
italicAngle;
Availability: OpenStep
Description forthcoming.
- (CGFloat)
leading;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (const CGFloat*)
matrix;
Availability: OpenStep
Description forthcoming.
- (
NSSize)
maximumAdvancement;
Availability: OpenStep
Description forthcoming.
- (
NSSize)
minimumAdvancement;
Availability: OpenStep
Description forthcoming.
- (
NSStringEncoding)
mostCompatibleStringEncoding;
Availability: OpenStep
Description forthcoming.
- (
NSUInteger)
numberOfGlyphs;
Availability: MacOS-X 10.0.0
Description forthcoming.
- (CGFloat)
pointSize;
Availability: OpenStep
Description forthcoming.
- (
NSPoint)
positionOfGlyph: (
NSGlyph)aGlyph
forCharacter: (
unichar)aChar
struckOverRect: (
NSRect)aRect;
Availability: OpenStep
Description forthcoming.
- (
NSPoint)
positionOfGlyph: (
NSGlyph)curGlyph
precededByGlyph: (
NSGlyph)prevGlyph
isNominal: (BOOL*)nominal;
Availability: OpenStep
Description forthcoming.
- (
NSPoint)
positionOfGlyph: (
NSGlyph)aGlyph
struckOverGlyph: (
NSGlyph)baseGlyph
metricsExist: (BOOL*)flag;
Availability: OpenStep
Description forthcoming.
- (
NSPoint)
positionOfGlyph: (
NSGlyph)aGlyph
struckOverRect: (
NSRect)aRect
metricsExist: (BOOL*)flag;
Availability: OpenStep
Description forthcoming.
- (
NSPoint)
positionOfGlyph: (
NSGlyph)aGlyph
withRelation: (
NSGlyphRelation)relation
toBaseGlyph: (
NSGlyph)baseGlyph
totalAdvancement: (
NSSize*)offset
metricsExist: (BOOL*)flag;
Availability: OpenStep
Description forthcoming.
- (int)
positionsForCompositeSequence: (
NSGlyph*)glyphs
numberOfGlyphs: (int)numGlyphs
pointArray: (
NSPoint*)points;
Availability: OpenStep
Description forthcoming.
- (
NSFont*)
printerFont;
Availability: OpenStep
Description forthcoming.
- (
NSFont*)
screenFont;
Availability: OpenStep
Description forthcoming.
- (void)
set;
Availability: OpenStep
Sets this font as the current font for text drawing in
the current graphics context. This method establishes
the font for subsequent text rendering operations,
taking into account the coordinate system and
rendering context.
Sets the receiver as
the font used for text drawing operations. If the
current view is a flipped view, the reciever
automatically flips itself to display
correctly in the flipped view
- (void)
setInContext: (
NSGraphicsContext*)context;
Availability: MacOS-X 10.4.0
Sets this font as the current font in the specified
graphics context. This method provides
more control by allowing the font to be set in a
specific graphics context rather than
the current one. @param context The graphics
context in which to set this font.
- (
NSAffineTransform*)
textTransform;
Availability: MacOS-X 10.4.0
Returns the text transformation matrix for this
font. The transformation matrix defines scaling,
rotation, and skewing applied to the font's
glyphs during rendering. @return The
NSAffineTransform representing the font's
text transformation.
- (CGFloat)
underlinePosition;
Availability: OpenStep
Description forthcoming.
- (CGFloat)
underlineThickness;
Availability: OpenStep
Description forthcoming.
- (CGFloat)
widthOfString: (
NSString*)string;
Availability: OpenStep
Description forthcoming.
- (CGFloat)
xHeight;
Availability: OpenStep
Description forthcoming.
Instance Variables for NSFont Class
@protected void*
_fontRef;
Availability: OpenStep
Warning the underscore at the start of the
name of this instance variable indicates that, even
though it is not technically private, it is
intended for internal use within the package, and
you should not use the variable in other code.
@protected NSFont*
cachedFlippedFont;
Availability: OpenStep
Description forthcoming.
@protected NSFont*
cachedScreenFont;
Availability: OpenStep
Description forthcoming.
@protected id
fontInfo;
Availability: OpenStep
Description forthcoming.
@protected NSString*
fontName;
Availability: OpenStep
Description forthcoming.
@protected CGFloat
matrix;
Availability: OpenStep
Description forthcoming.
@protected BOOL
matrixExplicitlySet;
Availability: OpenStep
Description forthcoming.
@protected int
role;
Availability: OpenStep
Description forthcoming.
@protected BOOL
screenFont;
Availability: OpenStep
Description forthcoming.
- Declared in:
- AppKit/NSFont.h
Availability: MacOS-X 10.0.0
Description forthcoming.
- (GSFontInfo*)
fontInfo;
Availability: MacOS-X 10.0.0
Description forthcoming.
- (void*)
fontRef;
Availability: MacOS-X 10.0.0
Description forthcoming.
Up