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