當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。