Java Code Examples for sun.font.FontManagerFactory#getInstance()

The following examples show how to use sun.font.FontManagerFactory#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Font.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example 2
Source File: Font.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example 3
Source File: Font.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example 4
Source File: Font.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example 5
Source File: Font.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Font(AttributeValues values, String oldName, int oldStyle,
             boolean created, Font2DHandle handle) {

    this.createdFont = created;
    if (created) {
        this.font2DHandle = handle;

        String newName = null;
        if (oldName != null) {
            newName = values.getFamily();
            if (oldName.equals(newName)) newName = null;
        }
        int newStyle = 0;
        if (oldStyle == -1) {
            newStyle = -1;
        } else {
            if (values.getWeight() >= 2f)   newStyle  = BOLD;
            if (values.getPosture() >= .2f) newStyle |= ITALIC;
            if (oldStyle == newStyle)       newStyle  = -1;
        }
        if (handle.font2D instanceof CompositeFont) {
            if (newStyle != -1 || newName != null) {
                FontManager fm = FontManagerFactory.getInstance();
                this.font2DHandle =
                    fm.getNewComposite(newName, newStyle, handle);
            }
        } else if (newName != null) {
            this.createdFont = false;
            this.font2DHandle = null;
        }
    }
    initFromValues(values);
}
 
Example 6
Source File: Font.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private Font(AttributeValues values, String oldName, int oldStyle,
             boolean created, Font2DHandle handle) {

    this.createdFont = created;
    if (created) {
        this.font2DHandle = handle;

        String newName = null;
        if (oldName != null) {
            newName = values.getFamily();
            if (oldName.equals(newName)) newName = null;
        }
        int newStyle = 0;
        if (oldStyle == -1) {
            newStyle = -1;
        } else {
            if (values.getWeight() >= 2f)   newStyle  = BOLD;
            if (values.getPosture() >= .2f) newStyle |= ITALIC;
            if (oldStyle == newStyle)       newStyle  = -1;
        }
        if (handle.font2D instanceof CompositeFont) {
            if (newStyle != -1 || newName != null) {
                FontManager fm = FontManagerFactory.getInstance();
                this.font2DHandle =
                    fm.getNewComposite(newName, newStyle, handle);
            }
        } else if (newName != null) {
            this.createdFont = false;
            this.font2DHandle = null;
        }
    }
    initFromValues(values);
}
 
Example 7
Source File: WToolkit.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FontMetrics getFontMetrics(Font font) {
    // This is an unsupported hack, but left in for a customer.
    // Do not remove.
    FontManager fm = FontManagerFactory.getInstance();
    if (fm instanceof SunFontManager
        && ((SunFontManager) fm).usePlatformFontMetrics()) {
        return WFontMetrics.getFontMetrics(font);
    }
    return super.getFontMetrics(font);
}
 
Example 8
Source File: WToolkit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FontMetrics getFontMetrics(Font font) {
    // This is an unsupported hack, but left in for a customer.
    // Do not remove.
    FontManager fm = FontManagerFactory.getInstance();
    if (fm instanceof SunFontManager
        && ((SunFontManager) fm).usePlatformFontMetrics()) {
        return WFontMetrics.getFontMetrics(font);
    }
    return super.getFontMetrics(font);
}
 
Example 9
Source File: Font.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Font(AttributeValues values, String oldName, int oldStyle,
             boolean created, Font2DHandle handle) {

    this.createdFont = created;
    if (created) {
        this.font2DHandle = handle;

        String newName = null;
        if (oldName != null) {
            newName = values.getFamily();
            if (oldName.equals(newName)) newName = null;
        }
        int newStyle = 0;
        if (oldStyle == -1) {
            newStyle = -1;
        } else {
            if (values.getWeight() >= 2f)   newStyle  = BOLD;
            if (values.getPosture() >= .2f) newStyle |= ITALIC;
            if (oldStyle == newStyle)       newStyle  = -1;
        }
        if (handle.font2D instanceof CompositeFont) {
            if (newStyle != -1 || newName != null) {
                FontManager fm = FontManagerFactory.getInstance();
                this.font2DHandle =
                    fm.getNewComposite(newName, newStyle, handle);
            }
        } else if (newName != null) {
            this.createdFont = false;
            this.font2DHandle = null;
        }
    }
    initFromValues(values);
}
 
Example 10
Source File: WToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FontMetrics getFontMetrics(Font font) {
    // This is an unsupported hack, but left in for a customer.
    // Do not remove.
    FontManager fm = FontManagerFactory.getInstance();
    if (fm instanceof SunFontManager
        && ((SunFontManager) fm).usePlatformFontMetrics()) {
        return WFontMetrics.getFontMetrics(font);
    }
    return super.getFontMetrics(font);
}
 
Example 11
Source File: Font.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Font(AttributeValues values, String oldName, int oldStyle,
             boolean created, Font2DHandle handle) {

    this.createdFont = created;
    if (created) {
        this.font2DHandle = handle;

        String newName = null;
        if (oldName != null) {
            newName = values.getFamily();
            if (oldName.equals(newName)) newName = null;
        }
        int newStyle = 0;
        if (oldStyle == -1) {
            newStyle = -1;
        } else {
            if (values.getWeight() >= 2f)   newStyle  = BOLD;
            if (values.getPosture() >= .2f) newStyle |= ITALIC;
            if (oldStyle == newStyle)       newStyle  = -1;
        }
        if (handle.font2D instanceof CompositeFont) {
            if (newStyle != -1 || newName != null) {
                FontManager fm = FontManagerFactory.getInstance();
                this.font2DHandle =
                    fm.getNewComposite(newName, newStyle, handle);
            }
        } else if (newName != null) {
            this.createdFont = false;
            this.font2DHandle = null;
        }
    }
    initFromValues(values);
}
 
Example 12
Source File: Font.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private Font(AttributeValues values, String oldName, int oldStyle,
             boolean created, Font2DHandle handle) {

    this.createdFont = created;
    if (created) {
        this.font2DHandle = handle;

        String newName = null;
        if (oldName != null) {
            newName = values.getFamily();
            if (oldName.equals(newName)) newName = null;
        }
        int newStyle = 0;
        if (oldStyle == -1) {
            newStyle = -1;
        } else {
            if (values.getWeight() >= 2f)   newStyle  = BOLD;
            if (values.getPosture() >= .2f) newStyle |= ITALIC;
            if (oldStyle == newStyle)       newStyle  = -1;
        }
        if (handle.font2D instanceof CompositeFont) {
            if (newStyle != -1 || newName != null) {
                FontManager fm = FontManagerFactory.getInstance();
                this.font2DHandle =
                    fm.getNewComposite(newName, newStyle, handle);
            }
        } else if (newName != null) {
            this.createdFont = false;
            this.font2DHandle = null;
        }
    }
    initFromValues(values);
}
 
Example 13
Source File: Font.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Font(File fontFile, int fontFormat,
             boolean isCopy, CreatedFontTracker tracker)
    throws FontFormatException {
    this.createdFont = true;
    /* Font2D instances created by this method track their font file
     * so that when the Font2D is GC'd it can also remove the file.
     */
    FontManager fm = FontManagerFactory.getInstance();
    this.font2DHandle = fm.createFont2D(fontFile, fontFormat, isCopy,
                                        tracker).handle;
    this.name = this.font2DHandle.font2D.getFontName(Locale.getDefault());
    this.style = Font.PLAIN;
    this.size = 1;
    this.pointSize = 1f;
}
 
Example 14
Source File: WToolkit.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FontMetrics getFontMetrics(Font font) {
    // This is an unsupported hack, but left in for a customer.
    // Do not remove.
    FontManager fm = FontManagerFactory.getInstance();
    if (fm instanceof SunFontManager
        && ((SunFontManager) fm).usePlatformFontMetrics()) {
        return WFontMetrics.getFontMetrics(font);
    }
    return super.getFontMetrics(font);
}
 
Example 15
Source File: SunGraphicsEnvironment.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static FontManagerForSGE getFontManagerForSGE() {
    FontManager fm = FontManagerFactory.getInstance();
    return (FontManagerForSGE) fm;
}
 
Example 16
Source File: GraphicsEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Registers a <i>created</i> <code>Font</code>in this
 * <code>GraphicsEnvironment</code>.
 * A created font is one that was returned from calling
 * {@link Font#createFont}, or derived from a created font by
 * calling {@link Font#deriveFont}.
 * After calling this method for such a font, it is available to
 * be used in constructing new <code>Font</code>s by name or family name,
 * and is enumerated by {@link #getAvailableFontFamilyNames} and
 * {@link #getAllFonts} within the execution context of this
 * application or applet. This means applets cannot register fonts in
 * a way that they are visible to other applets.
 * <p>
 * Reasons that this method might not register the font and therefore
 * return <code>false</code> are:
 * <ul>
 * <li>The font is not a <i>created</i> <code>Font</code>.
 * <li>The font conflicts with a non-created <code>Font</code> already
 * in this <code>GraphicsEnvironment</code>. For example if the name
 * is that of a system font, or a logical font as described in the
 * documentation of the {@link Font} class. It is implementation dependent
 * whether a font may also conflict if it has the same family name
 * as a system font.
 * <p>Notice that an application can supersede the registration
 * of an earlier created font with a new one.
 * </ul>
 * @return true if the <code>font</code> is successfully
 * registered in this <code>GraphicsEnvironment</code>.
 * @throws NullPointerException if <code>font</code> is null
 * @since 1.6
 */
public boolean registerFont(Font font) {
    if (font == null) {
        throw new NullPointerException("font cannot be null.");
    }
    FontManager fm = FontManagerFactory.getInstance();
    return fm.registerFont(font);
}
 
Example 17
Source File: GraphicsEnvironment.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Indicates a preference for locale-specific fonts in the mapping of
 * logical fonts to physical fonts. Calling this method indicates that font
 * rendering should primarily use fonts specific to the primary writing
 * system (the one indicated by the default encoding and the initial
 * default locale). For example, if the primary writing system is
 * Japanese, then characters should be rendered using a Japanese font
 * if possible, and other fonts should only be used for characters for
 * which the Japanese font doesn't have glyphs.
 * <p>
 * The actual change in font rendering behavior resulting from a call
 * to this method is implementation dependent; it may have no effect at
 * all, or the requested behavior may already match the default behavior.
 * The behavior may differ between font rendering in lightweight
 * and peered components.  Since calling this method requests a
 * different font, clients should expect different metrics, and may need
 * to recalculate window sizes and layout. Therefore this method should
 * be called before user interface initialisation.
 * @since 1.5
 */
public void preferLocaleFonts() {
    FontManager fm = FontManagerFactory.getInstance();
    fm.preferLocaleFonts();
}
 
Example 18
Source File: GraphicsEnvironment.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Indicates a preference for proportional over non-proportional (e.g.
 * dual-spaced CJK fonts) fonts in the mapping of logical fonts to
 * physical fonts. If the default mapping contains fonts for which
 * proportional and non-proportional variants exist, then calling
 * this method indicates the mapping should use a proportional variant.
 * <p>
 * The actual change in font rendering behavior resulting from a call to
 * this method is implementation dependent; it may have no effect at all.
 * The behavior may differ between font rendering in lightweight and
 * peered components. Since calling this method requests a
 * different font, clients should expect different metrics, and may need
 * to recalculate window sizes and layout. Therefore this method should
 * be called before user interface initialisation.
 * @since 1.5
 */
public void preferProportionalFonts() {
    FontManager fm = FontManagerFactory.getInstance();
    fm.preferProportionalFonts();
}
 
Example 19
Source File: GraphicsEnvironment.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Indicates a preference for locale-specific fonts in the mapping of
 * logical fonts to physical fonts. Calling this method indicates that font
 * rendering should primarily use fonts specific to the primary writing
 * system (the one indicated by the default encoding and the initial
 * default locale). For example, if the primary writing system is
 * Japanese, then characters should be rendered using a Japanese font
 * if possible, and other fonts should only be used for characters for
 * which the Japanese font doesn't have glyphs.
 * <p>
 * The actual change in font rendering behavior resulting from a call
 * to this method is implementation dependent; it may have no effect at
 * all, or the requested behavior may already match the default behavior.
 * The behavior may differ between font rendering in lightweight
 * and peered components.  Since calling this method requests a
 * different font, clients should expect different metrics, and may need
 * to recalculate window sizes and layout. Therefore this method should
 * be called before user interface initialisation.
 * @since 1.5
 */
public void preferLocaleFonts() {
    FontManager fm = FontManagerFactory.getInstance();
    fm.preferLocaleFonts();
}
 
Example 20
Source File: GraphicsEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Indicates a preference for locale-specific fonts in the mapping of
 * logical fonts to physical fonts. Calling this method indicates that font
 * rendering should primarily use fonts specific to the primary writing
 * system (the one indicated by the default encoding and the initial
 * default locale). For example, if the primary writing system is
 * Japanese, then characters should be rendered using a Japanese font
 * if possible, and other fonts should only be used for characters for
 * which the Japanese font doesn't have glyphs.
 * <p>
 * The actual change in font rendering behavior resulting from a call
 * to this method is implementation dependent; it may have no effect at
 * all, or the requested behavior may already match the default behavior.
 * The behavior may differ between font rendering in lightweight
 * and peered components.  Since calling this method requests a
 * different font, clients should expect different metrics, and may need
 * to recalculate window sizes and layout. Therefore this method should
 * be called before user interface initialisation.
 * @since 1.5
 */
public void preferLocaleFonts() {
    FontManager fm = FontManagerFactory.getInstance();
    fm.preferLocaleFonts();
}