OO-Snippets: Display the available fonts

Commons

KeywordsgetFontDescriptors, Font, FontDescriptor, getContainerWindow
LanguageOOBasic
ApplicationOffice
AuthorsAndrew Pitonyak (initial)
Supported Versions
Supported OS
Question How can I list the fonts available to a document?
Answer

The available fonts are known by the container window. The getFontDescriptors() method returns an array of awt FontDescriptor structures that contain a lot of information about the font. The font descriptor can be passed to the getFont() method, which returns an object that supports the awt XFont interface. The XFont interface provides methods to determine font metrics, and the width of an individual character or an entire string of characters.

Taken from Andrew's Macro Document at http://www.pitonyak.org

Code-Snippet-Listing (snippet-source)

Sub ListFonts
  Dim oWindow    'The container window supports the awt XDevice interface.
  Dim oDescript  'Array of awt FontDescriptor structures
  Dim s$         'Temporary string variable to hold all of the string names.
  Dim i%         'General index variable

  oWindow = ThisComponent.getCurrentController().getFrame().getContainerWindow()
  oDescript = oWindow.getFontDescriptors()
  s = ""

  For i = LBound(oDescript) to UBound(oDescript)
    s = s & oDescript(i).Name & ", "
  Next
  MsgBox s
End Sub

Changelog

DateUserModification
2004-06-28pitonyakInitial version

and