Font.SourceIdentifier プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ソース フォント データの一意の ID を返します。
public int SourceIdentifier { [Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)] get; }
[<get: Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)>]
member this.SourceIdentifier : int
プロパティ値
フォント ソース データの一意識別子。
- 属性
注釈
ソース フォント データの一意の ID を返します。
この識別子をキャッシュのキーとして使用するか、フォント バリエーション設定で 2 つのフォントを補間できるかどうかを確認できます。
<code>
// Following three Fonts, fontA, fontB, fontC have the same identifier.
Font fontA = new Font.Builder("/path/to/font").build();
Font fontB = new Font.Builder(fontA).setTtcIndex(1).build();
Font fontC = new Font.Builder(fontB).setFontVariationSettings("'wght' 700).build();
// Following fontD has the different identifier from above three.
Font fontD = new Font.Builder("/path/to/another/font").build();
// Following fontE has different identifier from above four even the font path is the same.
// To get the same identifier, please create new Font instance from existing fonts.
Font fontE = new Font.Builder("/path/to/font").build();
</code>
を持つフォント オブジェクトをキャッシュする例を次に示します。
<code>
private LongSparseArray<SparseArray<Font>> mCache = new LongSparseArray<>();
private Font getFontWeightVariation(Font font, int weight) {
// Different collection index is treated as different font.
long key = ((long) font.getSourceIdentifier()) << 32 | (long) font.getTtcIndex();
SparseArray<Font> weightCache = mCache.get(key);
if (weightCache == null) {
weightCache = new SparseArray<>();
mCache.put(key, weightCache);
}
Font cachedFont = weightCache.get(weight);
if (cachedFont != null) {
return cachedFont;
}
Font newFont = new Font.Builder(cachedFont)
.setFontVariationSettings("'wght' " + weight);
.build();
weightCache.put(weight, newFont);
return newFont;
}
</code>
の android.graphics.fonts.Font.getSourceIdentifier()
Java ドキュメント。
このページの一部は、によって作成および共有された作業に基づく変更であり、に記載されている条件に従って使用されます。