Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceFontLoader"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        public ResourceFontLoader(Factory factory)
        {
            _factory = factory;
            foreach (var name in typeof(ResourceFontLoader).Assembly.GetManifestResourceNames())
            {
                if (name.EndsWith(".ttf"))
                {
                    var fontBytes = Utilities.ReadStream(typeof (ResourceFontLoader).Assembly.GetManifestResourceStream(name));
                    var stream = new DataStream(fontBytes.Length, true, true);
                    stream.Write(fontBytes, 0, fontBytes.Length);
                    stream.Position = 0;
                    _fontStreams.Add(new ResourceFontFileStream(stream));
                }
            }

            // Build a Key storage that stores the index of the font
            _keyStream = new DataStream(sizeof(int) * _fontStreams.Count, true, true);
            for (int i = 0; i < _fontStreams.Count; i++ )
                _keyStream.Write((int)i);
            _keyStream.Position = 0;

            // Register the 
            _factory.RegisterFontFileLoader(this);
            _factory.RegisterFontCollectionLoader(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PrivateFontLoader"/> class.
        /// This does not load any font resources for right now.
        /// </summary>
        /// <param name="factory">The factory.</param>
        public PrivateFontLoader(Factory factory)
        {
            _factory = factory;

            // Build a Key storage that stores the index of the font
            _keyStream = new DataStream(sizeof(int) * _fontStreams.Count, true, true);
            for (int i = 0; i < _fontStreams.Count; i++)
                _keyStream.Write((int)i);
            _keyStream.Position = 0;

            // Register the 
            _factory.RegisterFontFileLoader(this);
            _factory.RegisterFontCollectionLoader(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FileFontLoader"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="fontFilePath">The relative path and file name.</param>
        public FileFontLoader(Factory factory, string fontFilePath)
        {
            this.factory = factory;

            var fontBytes = Utilities.ReadStream(CCContentManager.SharedContentManager.GetAssetStream(fontFilePath));
            var stream = new DataStream(fontBytes.Length, true, true);
            stream.Write(fontBytes, 0, fontBytes.Length);
            stream.Position = 0;

            fontStreams.Add(new FileFontFileStream(stream));

            // Build a Key storage that stores the index of the font
            keyStream = new DataStream(sizeof(int) * fontStreams.Count, true, true);
            for (int i = 0; i < fontStreams.Count; i++)
                keyStream.Write((int)i);
            keyStream.Position = 0;

            // Register the 
            factory.RegisterFontFileLoader(this);
            factory.RegisterFontCollectionLoader(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceFontLoader"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        public ResourceFontCollectionLoader(Factory factory)
        {
            _factory = factory;

            var resources = from assembly in AppDomain.CurrentDomain.GetAssemblies()
                            from name in assembly.GetManifestResourceNames()
                            where name.EndsWith(".ttf")
                            select assembly.GetManifestResourceStream(name);

            foreach (Stream stream in resources) {
                DataStream dxstream = new DataStream((int)stream.Length, true, true);
                dxstream.Write(Utilities.ReadStream(stream), 0, (int)stream.Length);
                dxstream.Position = 0;
                _fontStreams.Add(new ResourceFontFileStream(dxstream));
            }

            /*
            foreach (var name in System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceNames())
            {
                if (name.EndsWith(".ttf"))
                {
                    var fontBytes = Utilities.ReadStream(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream(name));
                    var stream = new DataStream(fontBytes.Length, true, true);
                    stream.Write(fontBytes, 0, fontBytes.Length);
                    stream.Position = 0;
                    _fontStreams.Add(new ResourceFontFileStream(stream));
                }
            }
             */

            // Build a Key storage that stores the index of the font
            _keyStream = new DataStream(sizeof(int) * _fontStreams.Count, true, true);
            for (int i = 0; i < _fontStreams.Count; i++ )
                _keyStream.Write((int)i);
            _keyStream.Position = 0;

            // Register the loader
            _factory.RegisterFontFileLoader(this);
            _factory.RegisterFontCollectionLoader(this);
        }