/// <summary> /// Gets an existing font source or creates a new one. /// A new font source is cached in font factory. /// </summary> public static XFontSource GetOrCreateFrom(byte[] bytes) { ulong key = FontHelper.CalcChecksum(bytes); XFontSource fontSource; if (!FontFactory.TryGetFontSourceByKey(key, out fontSource)) { fontSource = new XFontSource(bytes, key); // Theoretically the font source could be created by a differend thread in the meantime. fontSource = FontFactory.CacheFontSource(fontSource); } return(fontSource); }
public static XFontSource GetOrCreateFrom(string typefaceKey, byte[] fontBytes) { XFontSource fontSource; ulong key = FontHelper.CalcChecksum(fontBytes); if (FontFactory.TryGetFontSourceByKey(key, out fontSource)) { // The font source already exists, but is not yet cached under the specified typeface key. FontFactory.CacheExistingFontSourceWithNewTypefaceKey(typefaceKey, fontSource); } else { // No font source exists. Create new one and cache it. fontSource = new XFontSource(fontBytes, key); FontFactory.CacheNewFontSource(typefaceKey, fontSource); } return(fontSource); }