Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSFontManagerMBS class.

NSFontManagerMBS.addCollection(collectionName as String, Options as Integer = 0) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 17.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Adds a specified font collection to the font manager with a given set of options.

collectionName: The collection to add.
Options: Pass NSFontCollectionApplicationOnlyMask to make the collection available only to the application.
Return true if the font collection was successfully added; otherwise, false.

NSFontManagerMBS.addFontDescriptorsToCollection(descriptors() as NSFontDescriptorMBS, collectionName as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 17.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Adds an array of font descriptors to the specified font collection.
Example
dim fontManager as NSFontManagerMBS = NSFontManagerMBS.sharedFontManager

dim collectionNames() as string = fontManager.collectionNames
dim collectionName as string = collectionNames(collectionNames.Ubound) // get last one

dim fonts() as NSFontDescriptorMBS = fontManager.fontDescriptorsInCollection(collectionName)

// add Helvetica to this collection

dim font as NSFontMBS = NSFontMBS.fontWithName("Helvetica", 12)
dim fontDescriptor as NSFontDescriptorMBS = font.fontDescriptor

fontManager.addFontDescriptorsToCollection(array(fontDescriptor), collectionName)

dim fonts2() as NSFontDescriptorMBS = fontManager.fontDescriptorsInCollection(collectionName)

// fonts2 should have one more entry than fonts
Break

descriptors: The font descriptors to add.
collectionName: The font collection to which descriptors are added.

NSFontManagerMBS.availableFontFamilies as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the names of the font families available in the system.
Example
dim n as new NSFontManagerMBS
dim names() as string = n.availableFontFamilies

MsgBox Join(names,EndOfLine)

These fonts are in various system font directories.

Some examples using this method:

NSFontManagerMBS.availableFontNamesMatchingFontDescriptor(descriptor as NSFontDescriptorMBS) as String()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 17.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the names of the fonts that match the attributes in the given font descriptor.
Example
// ask for monospace font trait
Dim traitsAttributes As New Dictionary
traitsAttributes.Value(NSFontDescriptorMBS.NSFontSymbolicTrait) = NSFontDescriptorMBS.NSFontMonoSpaceTrait

// ask for traits
Dim fontAttributes As New Dictionary
fontAttributes.Value(NSFontDescriptorMBS.NSFontTraitsAttribute) = traitsAttributes

// now make a font descriptor for this
Dim fd As NSFontDescriptorMBS = NSFontDescriptorMBS.fontDescriptorWithFontAttributes(fontAttributes)

// and ask font manager for matching fonts
Dim fontManager As New NSFontManagerMBS
Dim fonts() As String = fontManager.availableFontNamesMatchingFontDescriptor(fd)

// finds e.g. AndaleMono, CourierNewPSMT, CourierNewPS-ItalicMT, CourierNewPS-BoldMT, CourierNewPS-BoldItalicMT,
// FZLTXHB--B51-0, FZLTZHB--B51-0, FZLTTHB--B51-0, Menlo-Regular, Menlo-Italic, Menlo-Bold, Menlo-BoldItalic,
// Monaco, Osaka-Mono, JCsmPC, PTMono-Regular, PTMono-Bold

NSFontManagerMBS.availableFontNamesWithTraits(traits as Integer) as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 12.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the names of the fonts available in the system whose traits are described exactly by the given font trait mask (not the NSFont objects themselves).
Example
dim n as new NSFontManagerMBS
dim names() as string = n.availableFontNamesWithTraits(n.NSBoldFontMask)

MsgBox str(UBound(names)+1)+" fonts: "+Join(names,", ")

traits: The font traits for which to return font names. You specify the desired traits by combining the font trait mask values described in Constants using the bitwiseor operator.

Returns the names of the corresponding fonts.

These fonts are in various system font directories.

If fontTraitMask is 0, this method returns all fonts that are neither italic nor bold. This result is the same one you'd get if fontTraitMask were NSUnitalicFontMask | NSUnboldFontMask.

NSFontManagerMBS.availableFonts as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the names of the fonts available in the system (not the NSFont objects themselves).
Example
dim n as new NSFontManagerMBS
dim names() as string = n.availableFonts

MsgBox Join(names,EndOfLine)

These fonts are in various system font directories.

Some examples using this method:

NSFontManagerMBS.availableMembersOfFontFamily(FontFamily as string) as Variant()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns an array with one entry for each available member of a font family.
Example
dim n as new NSFontManagerMBS
dim members() as Variant = n.availableMembersOfFontFamily("Times")

for each m as Variant in members
dim member() as Variant = m

MsgBox "Postscript name: "+member(0)+EndOfLine+"Suffix: "+member(1)+EndOfLine+"Font weight: "+member(2)+EndOfLine+"Font trait: "+member(3)
next

family: The name of a font family, like one that availableFontFamilies returns.

Returns the available members of family.

Each entry of the returned variant array is another variant array with four members, as follows:

0.The PostScript font name, as a string.
1.The part of the font name used in the font panel that's not the font name, as a string. This value is not localized—for example, "Roman", "Italic", or "Bold".
2.The font's weight, as a double.
3.The font's traits, as a double.

The members of the family are arranged in the font panel order (narrowest to widest, lightest to boldest, plain to italic).

Some examples using this method:

NSFontManagerMBS.collectionNames as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the names of the currently loaded font collections.
Example
dim n as new NSFontManagerMBS
dim names() as string = n.collectionNames

MsgBox Join(names,EndOfLine)

The names of the current font collections.

NSFontManagerMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Initializes the object with the shared instance of the font manager for the application, creating it if necessary.

NSFontManagerMBS.convertAttributes(dic as dictionary) as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Converts attributes in response to an object initiating an attribute change, typically the Font panel or Font menu.

NSFontManagerMBS.convertFont(font as NSFontMBS) as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Converts the given font according to the object that initiated a font change, typically the Font panel or Font menu.

NSFontManagerMBS.convertFontToFace(font as NSFontMBS, face as string) as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a font whose traits are as similar as possible to those of the given font except for the typeface, which is changed to the given typeface.
Example
dim fontManager as new NSFontManagerMBS
// you have a font
dim font as NSFontMBS = NSFontMBS.fontWithName("Helvetica", 12)

// change font face
font = fontManager.convertFontToFace(font, "Helvetica-BoldOblique")

MsgBox font.fontName // shows Helvetica-BoldOblique

Font: The font whose traits are matched.
face: The new typeface; a fully specified family-face name, such as Helvetica-BoldOblique or Times-Roman.

Returns a font with matching traits and the given typeface, or aFont if it can't be converted.

This method attempts to match the weight and posture of aFont as closely as possible. Italic is mapped to Oblique, for example. Weights are mapped based on an approximate numeric scale of 0 to 15.

NSFontManagerMBS.convertFontToFamily(font as NSFontMBS, family as string) as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a font whose traits are as similar as possible to those of the given font except for the font family, which is changed to the given family.
Example
dim fontManager as new NSFontManagerMBS
// you have a font
dim font as NSFontMBS = NSFontMBS.fontWithName("Helvetica", 12)

// change font family
font = fontManager.convertFontToFamily(font, "Arial")

MsgBox font.fontName // shows ArialMT

Font: The font whose traits are matched.
family: The new font famliy; a generic font name, such as Helvetica or Times.

Returns a font with matching traits and the given family, or aFont if it can't be converted.

This method attempts to match the weight and posture of aFont as closely as possible. Italic is mapped to Oblique, for example. Weights are mapped based on an approximate numeric scale of 0 to 15.

NSFontManagerMBS.convertFontToHaveTrait(font as NSFontMBS, trait as Integer) as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 12.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a font whose traits are the same as those of the given font, except that the traits are changed to include the single specified trait.
Example
dim n as new NSFontManagerMBS
dim f as NSFontMBS = NSFontMBS.fontWithName("Times", 12.0)
dim g as NSFontMBS = n.convertFontToHaveTrait(f, n.NSBoldFontMask)

MsgBox g.fontName // Times-Bold

Font: The font whose traits are matched.
Trait: The new trait; may be any one of the traits described in Constants. Using NSUnboldFontMask or NSUnitalicFontMask removes the bold or italic trait, respectively.

Returns a font with matching traits including the given trait, or font if it can't be converted.
Using NSUnboldFontMask or NSUnitalicFontMask removes the bold or italic trait, respectively.

NSFontManagerMBS.convertFontToNotHaveTrait(font as NSFontMBS, trait as Integer) as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 12.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns an NSFont object with the same traits as the given font, except for the traits in the given font trait mask, which are removed.
Example
dim n as new NSFontManagerMBS
dim f as NSFontMBS = NSFontMBS.fontWithName("Times-Bold", 12.0)
dim g as NSFontMBS = n.convertFontToHaveTrait(f, n.NSUnBoldFontMask)

MsgBox g.fontName // Times-Roman

Font: The font whose traits are matched.
trait: The mask for the traits to remove, created using the bitwiseOr operator to combine the traits described in Constants. Using NSUnboldFontMask or NSUnitalicFontMask removes the bold or italic trait, respectively.
Returns a font with matching traits minus the given traits, or font if it can't be converted.

NSFontManagerMBS.convertFontToSize(font as NSFontMBS, size as Double) as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns an NSFont object whose traits are the same as those of the given font, except for the size, which is changed to the given size.
Example
dim fontManager as new NSFontManagerMBS
// you have a font
dim font as NSFontMBS = NSFontMBS.fontWithName("Helvetica", 12)

// change font size
font = fontManager.convertFontToSize(font, 20)

MsgBox str(font.pointSize)

Font: The font whose traits are matched.
size: The new font size.

Returns a font with matching traits except in the new size, or aFont if it can't be converted.

NSFontManagerMBS.convertFontTraits(traits as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 12.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Converts font traits to a new traits mask value.

traits: The current font traits.

Returns the new traits mask value to be used by convertFont:.

This method is intended to be invoked to query the font traits while the action message (usually changeFont:) is being invoked when the current font action is either NSAddTraitFontAction or NSRemoveTraitFontAction.

Available in Mac OS X v10.5 and later.

NSFontManagerMBS.convertWeightOfFont(font as NSFontMBS, up as boolean) as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 12.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns an NSFont object whose weight is greater or lesser than that of the given font, if possible.
Example
dim n as new NSFontManagerMBS
dim f as NSFontMBS = NSFontMBS.fontWithName("Times", 12.0)
dim g as NSFontMBS = n.convertWeightOfFont(f, true)

MsgBox g.fontName // Times-Bold

up: If true, a heavier font is returned; if it's false, a lighter font is returned.
Font: The font whose weight is increased or decreased.

Returns a font with matching traits except for the new weight, or font if it can't be converted.

NSFontManagerMBS.Enabled as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Whether the font conversion system's user interface items (the Font panel and Font menu items) are enabled.

True if the font conversion system's user interface items (the Font panel and Font menu items) are enabled; false if they're not.
(Read and Write computed property)

NSFontManagerMBS.fontDescriptorsInCollection(collectionName as String) as NSFontDescriptorMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 17.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns an array of the font descriptors in the collection specified by the given collection name.
Example
dim fontManager as NSFontManagerMBS = NSFontManagerMBS.sharedFontManager
dim collectionNames() as string = fontManager.collectionNames
dim collectionName as string = collectionNames(collectionNames.Ubound) // get last one
dim fonts() as NSFontDescriptorMBS = fontManager.fontDescriptorsInCollection(collectionName)
Break

NSFontManagerMBS.fontHasTraits(fontName as string, Traits as Integer) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 13.2 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Indicates whether the given font has all the specified traits.
Example
dim n as NSFontMBS = NSFontMBS.boldSystemFontOfSize(12)
dim m as new NSFontManagerMBS

dim isBold as Boolean = m.fontHasTraits(n.fontName, m.NSBoldFontMask)
dim isItalic as Boolean = m.fontHasTraits(n.fontName, m.NSItalicFontMask)

MsgBox "is bold: "+str(isBold)+_
EndOfLine+"is italic: "+str(isItalic)

typeface: The name of the font.
fontTraitMask: The font traits to test, specified by combining the font trait mask values described in Constants using the bitwiseOR operation.

Returns true if the font named typeface has all the traits specified in fontTraitMask; false if it doesn't.

Using NSUnboldFontMask returns true if the font is not bold, false otherwise. Using NSUnitalicFontMask returns true if the font is not italic, false otherwise.

NSFontManagerMBS.isMultiple as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Indicates whether the last font selection recorded has multiple fonts.

Returns true if the last font selection recorded has multiple fonts; false if it's a single font.

NSFontManagerMBS.orderFrontFontPanel

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
This action method opens the Font panel by sending it an orderFront message, creating the Font panel if necessary.

NSFontManagerMBS.orderFrontStylesPanel

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
This action method opens the Font styles panel.

NSFontManagerMBS.removeCollection(collectionName as String) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 17.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Removes the specified font collection.

Returns true on success and false on failure.

NSFontManagerMBS.removeFontDescriptorFromCollection(descriptor as NSFontDescriptorMBS, collectionName as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 17.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Removes the specified font descriptor from the specified collection.

descriptor: The font descriptor to remove.
collection: The font collection from which to remove the descriptor.

NSFontManagerMBS.selectedFont as NSFontMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the last font recorded.

NSFontManagerMBS.setSelectedAttributes(dic as dictionary, isMultiple as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Informs the paragraph and character formatting panels when text in a selection has changed attributes.

dic: The new attributes.
isMultiple: If true, informs the panel that multiple fonts or attributes are enclosed within the selection.

This method is used primarily by NSTextView.
Available in Mac OS X v10.3 and later.

NSFontManagerMBS.setSelectedFont(font as NSFontMBS, isMultiple as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Records the given font as the currently selected font and updates the Font panel to reflect this.

font: The font to set as selected.
isMultiple: If true, the Font panel indicates that more than one font is contained in the selection; if false, it does not.

An object that manipulates fonts should invoke this method whenever it becomes first responder and whenever its selection changes. It shouldn't invoke this method in the process of handling a changeFont message, as this causes the font manager to lose the information necessary to effect the change. After all fonts have been converted, the font manager itself records the new selected font.

NSFontManagerMBS.traitsOfFont(font as NSFontMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 13.2 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the traits of the given font.
Example
dim n as NSFontMBS = NSFontMBS.boldSystemFontOfSize(12)
dim m as new NSFontManagerMBS

// shows 2 which is m.NSBoldFontMask
MsgBox str(m.traitsOfFont(n))

Font: The font whose traits are returned.
Returns the font traits, returned as a mask created by combining values listed in Constants with the bitwiseOR operation.

NSFontManagerMBS.weightOfFont(font as NSFontMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacCocoa Plugin 13.2 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a rough numeric measure the weight of the given font.
Example
dim n as NSFontMBS = NSFontMBS.boldSystemFontOfSize(12)
dim m as new NSFontManagerMBS

MsgBox str(m.weightOfFont(n))

Font: The font whose weight is returned.

A rough numeric measure the weight of the given font, where 0 indicates the lightest possible weight, 5 indicates a normal or book weight, and 9 or more indicates a bold or heavier weight.

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...