java.awt.font.FontRenderContext#equals ( )源码实例Demo

下面列出了java.awt.font.FontRenderContext#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码2 项目: TencentKona-8   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码3 项目: jdk8u60   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码4 项目: openjdk-jdk8u   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码6 项目: Bytecoder   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.usingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码7 项目: openjdk-jdk9   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码8 项目: jdk8u-jdk   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码9 项目: hottub   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码10 项目: openjdk-8-source   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码11 项目: openjdk-8   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码12 项目: jdk8u_jdk   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码13 项目: jdk8u-jdk   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}
 
源代码14 项目: jdk8u-dev-jdk   文件: FontDesignMetrics.java
public static FontDesignMetrics getMetrics(Font font,
                                           FontRenderContext frc) {


    /* When using alternate composites, can't cache based just on
     * the java.awt.Font. Since this is rarely used and we can still
     * cache the physical fonts, its not a problem to just return a
     * new instance in this case.
     * Note that currently Swing native L&F composites are not handled
     * by this code as they use the metrics of the physical anyway.
     */
    SunFontManager fm = SunFontManager.getInstance();
    if (fm.maybeUsingAlternateCompositeFonts() &&
        FontUtilities.getFont2D(font) instanceof CompositeFont) {
        return new FontDesignMetrics(font, frc);
    }

    FontDesignMetrics m = null;
    KeyReference r;

    /* There are 2 possible keys used to perform lookups in metricsCache.
     * If the FRC is set to all defaults, we just use the font as the key.
     * If the FRC is non-default in any way, we construct a hybrid key
     * that combines the font and FRC.
     */
    boolean usefontkey = frc.equals(getDefaultFrc());

    if (usefontkey) {
        r = metricsCache.get(font);
    } else /* use hybrid key */ {
        // NB synchronization is not needed here because of updates to
        // the metrics cache but is needed for the shared key.
        synchronized (MetricsKey.class) {
            MetricsKey.key.init(font, frc);
            r = metricsCache.get(MetricsKey.key);
        }
    }

    if (r != null) {
        m = (FontDesignMetrics)r.get();
    }

    if (m == null) {
        /* either there was no reference, or it was cleared. Need a new
         * metrics instance. The key to use in the map is a new
         * MetricsKey instance when we've determined the FRC is
         * non-default. Its constructed from local vars so we are
         * thread-safe - no need to worry about the shared key changing.
         */
        m = new FontDesignMetrics(font, frc);
        if (usefontkey) {
            metricsCache.put(font, new KeyReference(font, m));
        } else /* use hybrid key */ {
            MetricsKey newKey = new MetricsKey(font, frc);
            metricsCache.put(newKey, new KeyReference(newKey, m));
        }
    }

    /* Here's where we keep the recent metrics */
    for (int i=0; i<recentMetrics.length; i++) {
        if (recentMetrics[i]==m) {
            return m;
        }
    }

    synchronized (recentMetrics) {
        recentMetrics[recentIndex++] = m;
        if (recentIndex == MAXRECENT) {
            recentIndex = 0;
        }
    }
    return m;
}