Esempio n. 1
0
        public void Run(string[] args)
        {
            // Print the exe header
            PrintHeader();

            // Parse the command line
            if (!ParseCommandLine(args))
            {
                Environment.Exit(-1);
            }

            // Loads the description
            var filePath = Path.Combine(Environment.CurrentDirectory, XmlFontFile);

            var fontDescription = FontDescription.Load(XmlFontFile);

            var defaultOutputFile = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));

            // Compiles to SpriteData
            OutputFile = OutputFile ?? defaultOutputFile;

            string dependencyFile = null;

            if (CompileOnlyIfNewer)
            {
                dependencyFile = Path.Combine(OutputDependencyDirectory, FileDependencyList.GetDependencyFileNameFromSourcePath(Path.GetFileName(filePath)));
            }

            bool forceCompilation = (DebugOutputSpriteSheet != null && !File.Exists(DebugOutputSpriteSheet));

            var result = FontCompiler.CompileAndSave(filePath, OutputFile, dependencyFile);

            if (result.IsContentGenerated || forceCompilation)
            {
                Console.WriteLine("Writing [{0}] ({1} format)", OutputFile, fontDescription.Format);

                // Save output files.
                if (!string.IsNullOrEmpty(DebugOutputSpriteSheet))
                {
                    Console.WriteLine("Saving debug output spritesheet {0}", DebugOutputSpriteSheet);

                    var spriteFontData = SpriteFontData.Load(OutputFile);

                    if (spriteFontData.Bitmaps.Length > 0 && spriteFontData.Bitmaps[0].Data is SpriteFontData.BitmapData)
                    {
                        var bitmapData = (SpriteFontData.BitmapData)spriteFontData.Bitmaps[0].Data;
                        using (var image = Image.New2D(bitmapData.Width, bitmapData.Height, 1, bitmapData.PixelFormat))
                        {
                            Utilities.Write(image.DataPointer, bitmapData.Data, 0, bitmapData.Data.Length);
                            image.Save(DebugOutputSpriteSheet, ImageFileType.Dds);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No need to write [{0}]. File is up-to-date from XML description", OutputFile);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads an <see cref="EffectData"/> from the specified stream.
        /// </summary>
        /// <param name="device">The graphics device</param>
        /// <param name="stream">The stream.</param>
        /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param>
        /// <returns>An <see cref="EffectData"/>. Null if the stream is not a serialized <see cref="EffectData"/>.</returns>
        /// <remarks>
        /// </remarks>
        public static SpriteFont Load(GraphicsDevice device, Stream stream, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null)
        {
            var spriteFontData = SpriteFontData.Load(stream, bitmapDataLoader);

            if (spriteFontData == null)
            {
                return(null);
            }
            return(New(device, spriteFontData));
        }
Esempio n. 3
0
        /// <summary>
        /// Compiles the specified font description into a <see cref="SpriteFontData"/> object.
        /// </summary>
        /// <param name="fontDescription">The font description.</param>
        /// <returns>A SpriteFontData object.</returns>
        public static SpriteFontData Compile(FontDescription fontDescription)
        {
            // We are using a MemoryStream, this is not efficient
            // but this was a quickiest way to use existing from MakeSpriteFont from DirectXTk
            var stream = new MemoryStream();

            MakeSpriteFont(fontDescription, stream);
            stream.Position = 0;
            return(SpriteFontData.Load(stream));
        }
Esempio n. 4
0
        /// <summary>
        /// Loads an <see cref="EffectData"/> from the specified stream.
        /// </summary>
        /// <param name="device">The graphics device</param>
        /// <param name="stream">The stream.</param>
        /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param>
        /// <returns>An <see cref="EffectData"/>. Null if the stream is not a serialized <see cref="EffectData"/>.</returns>
        /// <remarks>
        /// </remarks>
        public static SpriteFont Load(GraphicsDevice device, Stream stream, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null)
        {
            var spriteFontData = SpriteFontData.Load(stream, bitmapDataLoader);

            if (spriteFontData == null)
            {
                return(null);
            }
            // the SpriteFontData is loaded here and will be used only in the current SpriteFont instance
            // therefore it is safe to dispose it's Texture2D instances, if any.
            return(New(device, spriteFontData, true));
        }
Esempio n. 5
0
        protected override SpriteFont ReadContent(IContentManager readerManager, GraphicsDevice device, ref ContentReaderParameters parameters)
        {
            SpriteFont spriteFont = null;
            var        assetPath  = Path.GetDirectoryName(parameters.AssetName);

            // Load the sprite font data
            var spriteFontData = SpriteFontData.Load(parameters.Stream, name => readerManager.Load <Texture2D>(Path.Combine(assetPath ?? string.Empty, name)));

            // If sprite font was fine, then instantiate SpriteFont graphics object.
            if (spriteFontData != null)
            {
                spriteFont = SpriteFont.New(device, spriteFontData);
            }

            return(spriteFont);
        }
Esempio n. 6
0
 public object ReadContent(IContentManager readerManager, string assetName, Stream stream, out bool keepStreamOpen, object options)
 {
     keepStreamOpen = false;
     return(SpriteFontData.Load(stream));
 }
Esempio n. 7
0
 public object ReadContent(IContentManager readerManager, ref ContentReaderParameters parameters)
 {
     parameters.KeepStreamOpen = false;
     return(SpriteFontData.Load(parameters.Stream));
 }