当前位置: 首页>>代码示例>>Java>>正文


Java FontRenderContext.equals方法代码示例

本文整理汇总了Java中java.awt.font.FontRenderContext.equals方法的典型用法代码示例。如果您正苦于以下问题:Java FontRenderContext.equals方法的具体用法?Java FontRenderContext.equals怎么用?Java FontRenderContext.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.font.FontRenderContext的用法示例。


在下文中一共展示了FontRenderContext.equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMetrics

import java.awt.font.FontRenderContext; //导入方法依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:74,代码来源:FontDesignMetrics.java


注:本文中的java.awt.font.FontRenderContext.equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。