Font.SourceIdentifier Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce l'ID univoco dei dati del tipo di carattere di origine.
public int SourceIdentifier { [Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)] get; }
[<get: Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)>]
member this.SourceIdentifier : int
Valore della proprietà
identificatore univoco per i dati dell'origine del tipo di carattere.
- Attributi
Commenti
Restituisce l'ID univoco dei dati del tipo di carattere di origine.
È possibile usare questo identificatore come chiave della cache o controllare se due tipi di carattere possono essere interpolati con le impostazioni di variazione del carattere.
<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>
Di seguito è riportato un esempio di memorizzazione nella cache dell'oggetto carattere con
<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>
per android.graphics.fonts.Font.getSourceIdentifier().
Le parti di questa pagina sono modifiche basate sul lavoro creato e condiviso dalla e usati in base ai termini descritti in Creative License 2.5 Attribution License.