Bug 156775 Allow fonts to benefit from ResourceManager
Eclipse 3.x added a lot of features for manipulating ImageDescriptors and managing them through ResourceManager. Currently, it is cumbersome to do the same thing with Fonts, so most people are still using global Font registry. This enhancement requests that we add features to make Fonts as easy to manage as Images are. - FontDescriptors are provided globally - FontDescriptors are easy to manipulate - Concrete fonts are obtained from the FontDescriptors via a ResourceManager as needed - Fonts benefit from reference-counted shared allocations just like Images do. The attached patch adds the following enhancements for Font management. New Features: 1. (feature) Add helper methods to FontDescriptor to allow font size and style to be set without packing and unpacking the FontData. 2. (performance) Add a getFontData() method to FontDescriptor, to make it possible to manipulate font descriptors without creating a concrete Fonts. 3. (cleanup) Remove NamedFontDescriptor, and replace it with (the more general) ArrayFontDescriptor. 4. (performance) Refactor FontRegistry to use the ResourceManager tree in order to benefit from shared allocations (like Images currently do). 5. (feature) Wherever there is a prominent method that returns a global Font, provide a version that returns a FontDescriptor. Refactor where necessary such that a concrete Font won't be allocated as long as clients are only calling the descriptor version.
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java
* Calculates the default font and returns the result
     */
    Font calculateDefaultFont() {
        Display current = Display.getCurrent();
        if (current == null) {
            Shell shell = new Shell();
            Font font = new Font(null, shell.getFont().getFontData());
            shell.dispose();
            return font;
        }
		return new Font(current, current.getSystemFont().getFontData());
    }
    /**
     * Returns the default font data.  Creates it if necessary.
     * @return Font
     */
    public Font defaultFont() {
        return defaultFontRecord().getBaseFont();
    }
    /**
     * Returns the default font record.
     */
    private FontRecord defaultFontRecord() {
        FontRecord record = (FontRecord) stringToFontRecord
                .get(JFaceResources.DEFAULT_FONT);
        if (record == null) {
            Font defaultFont = calculateDefaultFont();
            record = createFont(JFaceResources.DEFAULT_FONT, defaultFont
                    .getFontData());
            stringToFontRecord.put(JFaceResources.DEFAULT_FONT, record);