| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.3 and later. |
| Companion guide | |
| Declared in | NSFontDescriptor.h |
NSFontDescriptor objects provide a mechanism to describe a font with a dictionary of attributes. This font descriptor can be used later to create or modify an NSFont object. Mac OS X v10.4 and later provides a font matching capability, so that you can partially describe a font by creating a font descriptor with, for example, just a family name. You can then find all the available fonts on the system with a matching family name using matchingFontDescriptorsWithMandatoryKeys:.
There are several ways to create a new NSFontDescriptor object. You can use alloc and initWithFontAttributes:, fontDescriptorWithFontAttributes:, fontDescriptorWithName:matrix:, or fontDescriptorWithName:size:. to create a font descriptor based on either your custom attributes dictionary or on a specific font’s name and size. Alternatively you can use one of the fontDescriptor… instance methods (such as fontDescriptorWithFace:) to create a modified version of an existing descriptor. The latter methods are useful if you have an existing descriptor and simply want to change one aspect.
All attributes in the attributes dictionary are optional.
+ fontDescriptorWithFontAttributes:
+ fontDescriptorWithName:matrix:
+ fontDescriptorWithName:size:
– fontDescriptorByAddingAttributes:
– fontDescriptorWithFace:
– fontDescriptorWithFamily:
– fontDescriptorWithMatrix:
– fontDescriptorWithSize:
– fontDescriptorWithSymbolicTraits:
Returns a font descriptor with a dictionary of attributes.
+ (NSFontDescriptor *)fontDescriptorWithFontAttributes:(NSDictionary *)attributes
The attributes for the font descriptor. If nil, the font descriptor’s dictionary will be empty.
The new font descriptor.
NSFontDescriptor.hReturns a font descriptor with the NSFontNameAttribute and NSFontMatrixAttribute dictionary attributes set to the given values.
+ (NSFontDescriptor *)fontDescriptorWithName:(NSString *)fontName matrix:(NSAffineTransform *)matrix
The value for NSFontNameAttribute.
The value for NSFontMatrixAttribute.
The new font descriptor.
NSFontDescriptor.hReturns a font descriptor with the NSFontNameAttribute and NSFontSizeAttribute dictionary attributes set to the given values.
+ (NSFontDescriptor *)fontDescriptorWithName:(NSString *)fontName size:(CGFloat)size
The value for NSFontNameAttribute.
The value for NSFontSizeAttribute.
The new font descriptor.
NSFontDescriptor.hReturns the receiver’s dictionary of attributes.
- (NSDictionary *)fontAttributes
The attribute dictionary.
NSFontDescriptor.hReturns a new font descriptor that is the same as the receiver but with the specified attributes taking precedence over the existing ones.
- (NSFontDescriptor *)fontDescriptorByAddingAttributes:(NSDictionary *)attributes
The new attributes.
The new font descriptor.
NSFontDescriptor.hReturns a new font descriptor that is the same as the receiver but with the specified face.
- (NSFontDescriptor *)fontDescriptorWithFace:(NSString *)newFace
The new font face.
The new font descriptor.
NSFontDescriptor.hReturns a new font descriptor whose attributes are the same as the receiver but from the specified family.
- (NSFontDescriptor *)fontDescriptorWithFamily:(NSString *)newFamily
The new font family.
The new font descriptor.
NSFontDescriptor.hReturns a new font descriptor that is the same as the receiver but with the specified matrix.
- (NSFontDescriptor *)fontDescriptorWithMatrix:(NSAffineTransform *)matrix
The new font matrix.
The new font descriptor.
NSFontDescriptor.hReturns a new font descriptor that is the same as the receiver but with the specified point size.
- (NSFontDescriptor *)fontDescriptorWithSize:(CGFloat)newPointSize
The new point size.
The new font descriptor.
NSFontDescriptor.hReturns a new font descriptor that is the same as the receiver but with the specified symbolic traits taking precedence over the existing ones.
- (NSFontDescriptor *)fontDescriptorWithSymbolicTraits:(NSFontSymbolicTraits)symbolicTraits
The new symbolic traits.
The new font descriptor.
NSFontDescriptor.hInitializes and returns a new font descriptor with the specified attributes.
- (id)initWithFontAttributes:(NSDictionary *)attributes
The attributes for the new font descriptor. If nil, the font descriptor’s attribute dictionary will be empty.
The new font descriptor.
NSFontDescriptor.hReturns all the fonts available on the system whose specified attributes match those of the receiver.
- (NSArray *)matchingFontDescriptorsWithMandatoryKeys:(NSSet *)mandatoryKeys
Keys that must be identical to be matched. Can be nil.
The matching font descriptors.
For example, suppose there are two versions of a given font installed that differ in the number of glyphs covered (the new version has more glyphs). If you explicitly specify NSFontNameAttribute as the only mandatory key, then a font descriptor that specifies a font name and character set by default matches both versions, since the character set attribute is not used for matching. If you specify that font name and character set keys are mandatory, the returned array contains only the font that matches both keys.
NSFontDescriptor.hReturns a normalized font descriptor whose specified attributes match those of the receiver.
- (NSFontDescriptor *)matchingFontDescriptorWithMandatoryKeys:(NSSet *)mandatoryKeys
Keys that must be identical to be matched. Can be nil.
The matching font descriptor.
The returned font descriptor is the first element returned from matchingFontDescriptorsWithMandatoryKeys:.
NSFontDescriptor.hReturns the current transform matrix of the receiver.
- (NSAffineTransform *)matrix
The transform matrix.
NSFontDescriptor.hReturns the font attribute specified by the given key.
- (id)objectForKey:(NSString *)anAttribute
The font attribute key.
The font attribute corresponding to anAttribute. For valid values of anAttribute, see “Font attributes”.
NSFontDescriptor.hReturns the point size of the receiver.
- (CGFloat)pointSize
The receiver’s point size.
NSFontDescriptor.hReturns the PostScript name of the receiver.
- (NSString *)postscriptName
The receiver’s Postscript name.
NSFontDescriptor.hReturns a bit mask that describes the traits of the receiver.
- (NSFontSymbolicTraits)symbolicTraits
The receiver’s font traits.
The traits describe the font’s characteristics—see NSFontSymbolicTraits.
NSFontDescriptor.hThese font attributes are defined by NSFontDescriptor.
NSString *NSFontFamilyAttribute; NSString *NSFontNameAttribute; NSString *NSFontFaceAttribute; NSString *NSFontSizeAttribute; NSString *NSFontVisibleNameAttribute; NSString *NSFontColorAttribute; NSString *NSFontMatrixAttribute; NSString *NSFontVariationAttribute; NSString *NSFontCharacterSetAttribute; NSString *NSFontCascadeListAttribute; NSString *NSFontTraitsAttribute; NSString *NSFontFixedAdvanceAttribute; NSString *NSFontFeatureSettingsAttribute
NSFontFamilyAttributeAn optional NSString object that specifies the font family.
Available in Mac OS X v10.3 and later.
Declared in NSFontDescriptor.h.
NSFontNameAttributeAn optional NSString object that specifies the font name.
Available in Mac OS X v10.3 and later.
Declared in NSFontDescriptor.h.
NSFontFaceAttributeAn optional NSString object that specifies the font face.
Available in Mac OS X v10.3 and later.
Declared in NSFontDescriptor.h.
NSFontSizeAttributeAn optional NSString object, containing a float value, that specifies the font size.
Available in Mac OS X v10.3 and later.
Declared in NSFontDescriptor.h.
NSFontVisibleNameAttributeAn optional NSString object that specifies the font’s visible name.
Available in Mac OS X v10.3 and later.
Declared in NSFontDescriptor.h.
NSFontColorAttributeAn optional NSData object that specifies the font color. (Deprecated. Use NSForegroundColorAttributeName instead.)
Available in Mac OS X v10.3 and later.
Deprecated in Mac OS X v10.4.
Declared in NSFontDescriptor.h.
NSFontMatrixAttributeAn NSAffineTransform instance that specifies the font’s transformation matrix.
The default value is the identity matrix.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontVariationAttributeAn NSDictionary instance that describes the font’s variation axis.
The default value is supplied by the font. See “Font variation axis dictionary keys” for dictionary keys.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontCharacterSetAttributeAn NSCharacterSet instance that represents the set of Unicode characters covered by the font.
The default value is supplied by the font.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontCascadeListAttributeAn NSArray instance—each member of the array is a sub-descriptor.
The default value is the system default cascading list for user's locale.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontTraitsAttributeAn NSDictionary instance instance fully describing font traits.
The default value is supplied by the font. See “Font traits dictionary keys” for dictionary keys.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontFixedAdvanceAttributeAn NSNumber instance containing a float value that overrides the glyph advancement specified by the font.
The default value is 0.0.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontFeatureSettingsAttributeAn array of dictionaries representing non-default font feature settings.
Each dictionary contains NSFontFeatureTypeIdentifierKey and NSFontFeatureSelectorIdentifierKey.
Available in Mac OS X v10.5 and later.
Declared in NSFontDescriptor.h.
You can retrieve the values for these attributes using objectForKey:.
NSFontDescriptor.hThe following constants can be used as keys to retrieve information about a font descriptor from its trait dictionary.
NSString *NSFontSymbolicTrait; NSString *NSFontWeightTrait; NSString *NSFontWidthTrait; NSString *NSFontSlantTrait;
NSFontSymbolicTraitThe symbolic traits value as an NSNumber object.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontWeightTraitThe normalized weight value as an NSNumber object.
The valid value range is from -1.0 to 1.0. The value of 0.0 corresponds to the regular or medium font weight.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontWidthTraitThe relative inter-glyph spacing value as an NSNumber object.
The valid value range is from -1.0 to 1.0. The value of 0.0 corresponds to the regular glyph spacing.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontSlantTraitThe relative slant angle value as an NSNumber object.
The valid value range is from -1.0 to 1.0. The value of 0.0 corresponds to 0 degree clockwise rotation from the vertical and 1.0 corresponds to 30 degrees clockwise rotation.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
These keys are used with NSFontTraitsAttribute.
NSFontDescriptor.hThe following constants can be used as keys to retrieve information about a font descriptor from its variation axis dictionary.
NSString *NSFontVariationAxisIdentifierKey; NSString *NSFontVariationAxisMinimumValueKey; NSString *NSFontVariationAxisMaximumValueKey; NSString *NSFontVariationAxisDefaultValueKey; NSString *NSFontVariationAxisNameKey;
NSFontVariationAxisIdentifierKeyThe axis identifier value as an NSNumber object.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontVariationAxisMinimumValueKeyThe minimum axis value as an NSNumber object.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontVariationAxisMaximumValueKeyThe maximum axis value as an NSNumber object.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontVariationAxisDefaultValueKeyThe default axis value as an NSNumber object.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontVariationAxisNameKeyThe localized variation axis name.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
These keys are used with NSFontVariationAttribute.
NSFontDescriptor.hThe following constants can be used as keys to retrieve information about a font descriptor from its feature dictionary.
NSString *NSFontFeatureTypeIdentifierKey; NSString *NSFontFeatureSelectorIdentifierKey;
NSFontFeatureTypeIdentifierKey An NSNumber object specifying a font feature type such as ligature, character shape, and so on. See “Font Features“ in ATSUI Programming Guide for predefined feature types.
Available in Mac OS X v10.5 and later.
Declared in NSFontDescriptor.h.
NSFontFeatureSelectorIdentifierKeyAn NSNumber object specifying a font feature selector such as common ligature off, traditional character shape, and so on. See “Font Features“ in ATSUI Programming Guide for predefined feature selectors.
Available in Mac OS X v10.5 and later.
Declared in NSFontDescriptor.h.
These keys are used with NSFontFeatureSettingsAttribute.
NSFontDescriptor.hNSFontSymbolicTraits symbolically describes stylistic aspects of a font.
typedef uint32_t NSFontSymbolicTraits;
The upper 16 bits is used to describe appearance of the font (see NSFontFamilyClass) whereas the lower 16 bits is used for typeface information (see Typeface information). The font appearance information represented by the upper 16 bits can be used for stylistic font matching. The symbolic traits supersede the existing NSFontTraitMask type used by NSFontManager. The corresponding values are kept compatible between NSFontTraitMask and NSFontSymbolicTraits.
NSFontDescriptor.hThese constants classify certain stylistic qualities of the font. These values correspond closely to the font class values in the OpenType OS/2 table. The class values are bundled in the upper four bits of the NSFontSymbolicTraits and can be accessed via NSFontFamilyClassMask. For more information about the specific meaning of each identifier, refer to the OpenType specification.
enum {
NSFontUnknownClass = 0 << 28,
NSFontOldStyleSerifsClass = 1 << 28,
NSFontTransitionalSerifsClass = 2 << 28,
NSFontModernSerifsClass = 3 << 28,
NSFontClarendonSerifsClass = 4 << 28,
NSFontSlabSerifsClass = 5 << 28,
NSFontFreeformSerifsClass = 7 << 28,
NSFontSansSerifClass = 8 << 28,
NSFontOrnamentalsClass = 9 << 28,
NSFontScriptsClass = 10 << 28,
NSFontSymbolicClass = 12 << 28
};
typedef uint32_t NSFontFamilyClass;
NSFontUnknownClassThe font has no design classification.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontOldStyleSerifsClassThe font’s style is based on the Latin printing style of the 15th to 17th century.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontTransitionalSerifsClassThe font’s style is based on the Latin printing style of the 18th to 19th century.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontModernSerifsClassThe font’s style is based on the Latin printing style of the 20th century.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontClarendonSerifsClassThe font’s style is a variation of the Oldstyle Serifs and the Transitional Serifs.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontSlabSerifsClassThe font’s style is characterized by serifs with a square transition between the strokes and the serifs (no brackets).
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontFreeformSerifsClassThe font’s style includes serifs, but it expresses a design freedom that does not generally fit within the other serif design classifications.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontSansSerifClassThe font’s style includes most basic letter forms (excluding Scripts and Ornamentals) that do not have serifs on the strokes.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontOrnamentalsClassThe font’s style includes highly decorated or stylized character shapes such as those typically used in headlines.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontScriptsClassThe font’s style is among those typefaces designed to simulate handwriting.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontSymbolicClassThe font’s style is generally design independent, making it suitable for special characters (icons, dingbats, technical symbols, and so on) that may be used equally well with any font.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontDescriptor.hThis constant is used to access NSFontFamilyClass values in the upper four bits of NSFontSymbolicTraits.
enum {
NSFontFamilyClassMask = 0xF0000000
};
NSFontFamilyClassMaskThe font family class mask used to access NSFontFamilyClass values.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
Typeface information is specified by the lower 16 bits of NSFontSymbolicTraits using the following constants.
enum {
NSFontItalicTrait = (1 << 0),
NSFontBoldTrait = (1 << 1),
NSFontExpandedTrait = (1 << 5),
NSFontCondensedTrait = (1 << 6),
NSFontMonoSpaceTrait = (1 << 10),
NSFontVerticalTrait = (1 << 11),
NSFontUIOptimizedTrait = (1 << 12)
};
NSFontItalicTraitThe font’s typestyle is italic.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontBoldTraitThe font’s typestyle is boldface.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontExpandedTraitThe font’s typestyle is expanded. Expanded and condensed traits are mutually exclusive.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontCondensedTraitThe font’s typestyle is condensed. Expanded and condensed traits are mutually exclusive.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontMonoSpaceTraitThe font uses fixed-pitch glyphs if available. The font may have multiple glyph advances (many CJK glyphs contain two spaces).
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontVerticalTraitThe font uses vertical glyph variants and metrics.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontUIOptimizedTraitThe font synthesizes appropriate attributes for user interface rendering, such as control titles, if necessary.
Available in Mac OS X v10.4 and later.
Declared in NSFontDescriptor.h.
NSFontDescriptor.hLast updated: 2009-11-13