コード例 #1
0
        /// <summary>
        /// Registers the font face.
        /// </summary>
        public static XFontSource RegisterFontFace(byte[] fontBytes)
        {
            try
            {
                Lock.EnterFontFactory();
                ulong       key = FontHelper.CalcChecksum(fontBytes);
                XFontSource fontSource;
                if (FontSourcesByKey.TryGetValue(key, out fontSource))
                {
                    throw new InvalidOperationException("Font face already registered.");
                }
                fontSource = XFontSource.GetOrCreateFrom(fontBytes);
                Debug.Assert(FontSourcesByKey.ContainsKey(key));
                Debug.Assert(fontSource.Fontface != null);

                //fontSource.Fontface = new OpenTypeFontface(fontSource);
                //FontSourcesByKey.Add(checksum, fontSource);
                //FontSourcesByFontName.Add(fontSource.FontName, fontSource);

                XGlyphTypeface glyphTypeface = new XGlyphTypeface(fontSource);
                FontSourcesByName.Add(glyphTypeface.Key, fontSource);
                GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface);
                return(fontSource);
            }
            finally { Lock.ExitFontFactory(); }
        }