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); } }
/// <summary> /// Compiles an XML font file description to a file. Optionally output dependency file. /// </summary> /// <param name="sourceXmlFile">The source XML file.</param> /// <param name="outputFile">The output file.</param> /// <param name="dependencyFile">The dependency file.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public static ContentCompilerResult CompileAndSave(string sourceXmlFile, string outputFile, string dependencyFile = null) { var logger = new Logger(); var result = new ContentCompilerResult { Logger = logger }; try { var fontDescription = FontDescription.Load(sourceXmlFile); var defaultOutputFile = Path.GetFileNameWithoutExtension(sourceXmlFile); // Compiles to SpriteData outputFile = outputFile ?? defaultOutputFile; result.IsContentGenerated = true; if (dependencyFile != null) { if (!FileDependencyList.CheckForChanges(dependencyFile)) { result.IsContentGenerated = false; } } if (result.IsContentGenerated) { // Make sure that directory name doesn't collide with filename var directoryName = Path.GetDirectoryName(outputFile + ".tmp"); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } using (var stream = new NativeFileStream(outputFile, NativeFileMode.Create, NativeFileAccess.Write)) { Compile(fontDescription, stream); if (dependencyFile != null) { var dependencies = new FileDependencyList(); dependencies.AddDefaultDependencies(); dependencies.AddDependencyPath(sourceXmlFile); dependencies.Save(dependencyFile); } } } } catch (FontException ex) { logger.Error(ex.Message); } catch (Exception ex) { logger.Error(ex.ToString()); } return(result); }