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
Var fontManager as NSFontManagerMBS = NSFontManagerMBS.sharedFontManager

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

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

// add Helvetica to this collection

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

fontManager.addFontDescriptorsToCollection(array(fontDescriptor), collectionName)

Var 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
Var n as new NSFontManagerMBS
Var 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
Var traitsAttributes As New Dictionary
traitsAttributes.Value(NSFontDescriptorMBS.NSFontSymbolicTrait) = NSFontDescriptorMBS.NSFontMonoSpaceTrait

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

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

// and ask font manager for matching fonts
Var fontManager As New NSFontManagerMBS
Var 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
Var n as new NSFontManagerMBS
Var 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
Var n as new NSFontManagerMBS
Var 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
Var n as new NSFontManagerMBS
Var members() as Variant = n.availableMembersOfFontFamily("Times")

for each m as Variant in members
Var 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.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
Var fontManager as NSFontManagerMBS = NSFontManagerMBS.sharedFontManager
Var collectionNames() as string = fontManager.collectionNames
Var collectionName as string = collectionNames(collectionNames.Ubound) // get last one
Var 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
Var n as NSFontMBS = NSFontMBS.boldSystemFontOfSize(12)
Var m as new NSFontManagerMBS

Var isBold as Boolean = m.fontHasTraits(n.fontName, m.NSBoldFontMask)
Var 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
Var n as NSFontMBS = NSFontMBS.boldSystemFontOfSize(12)
Var 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
Var n as NSFontMBS = NSFontMBS.boldSystemFontOfSize(12)
Var 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...