Font.SourceIdentifier Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne l’ID unique des données de police source.
public int SourceIdentifier { [Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)] get; }
[<get: Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)>]
member this.SourceIdentifier : int
Valeur de propriété
identificateur unique pour les données de la source de police.
- Attributs
Remarques
Retourne l’ID unique des données de police source.
Vous pouvez utiliser cet identificateur comme clé du cache ou vérifier si deux polices peuvent être interpolées avec les paramètres de variante de police.
<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>
Voici un exemple de mise en cache d’un objet de police qui a
<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>
Java documentation pour android.graphics.fonts.Font.getSourceIdentifier().
Les parties de cette page sont des modifications basées sur le travail créé et partagé par Android Open Source et utilisées en fonction des termes décrits dans la Creative Commons 2.5 Attribution License.