static XFontSource GetOrCreateFrom(string typefaceKey, byte[] fontBytes, string fontName) { 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); // Name is necessary for reading TTC files if (fontSource.FontName == null) { fontSource._fontName = fontName; } FontFactory.CacheNewFontSource(typefaceKey, fontSource); } return(fontSource); }
/// <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); if (!FontFactory.TryGetFontSourceByKey(key, out XFontSource 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); }
static XFontSource GetOrCreateFrom(string typefaceKey, byte[] fontBytes) { var key = FontHelper.CalcChecksum(fontBytes); if (FontFactory.TryGetFontSourceByKey(key, out XFontSource 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); }