Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        static XFontSource GetOrCreateFrom(string typefaceKey, byte[] fontBytes)
        {
            ulong 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);
        }