Ejemplo n.º 1
0
        private static bool SaveFont()
        {
            try
            {
                string tempPath    = Path.GetTempPath();
                string tempPngFile = Path.Combine(tempPath, "temptexture.png");
                string tempDdsFile = Path.Combine(tempPath, "temptexture.dds");

                const string filename    = "lyrics.dds";
                string       ddsFilename = filename;
                string       pngFilename = filename;
                bool         keepPngFile = false;

                if (filename.EndsWith(".dds"))
                {
                    pngFilename = Path.ChangeExtension(filename, ".png");
                }
                else
                {
                    ddsFilename = Path.ChangeExtension(filename, ".dds");
                    keepPngFile = true;
                }

                string definitionFilename = Path.ChangeExtension(filename, ".glyphs.xml");

                GlyphDefinitions.Save(definitionFilename, FontGenerator);
                BitmapFunctions.SaveImage(FontCanvas, tempPngFile, TextureWidth, TextureHeight);

                using (Process nvdxtProcess = new Process())
                {
                    nvdxtProcess.StartInfo.UseShellExecute = false;
                    nvdxtProcess.StartInfo.CreateNoWindow  = true;
                    nvdxtProcess.StartInfo.FileName        = "nvdxt.exe";
                    nvdxtProcess.StartInfo.Arguments       = $"-file \"{tempPngFile}\" -output \"{tempDdsFile}\" -quality_highest -dxt5 -nomipmap -overwrite -forcewrite";

                    nvdxtProcess.Start();
                    nvdxtProcess.WaitForExit();
                }

                File.Delete(ddsFilename);
                File.Move(tempDdsFile, ddsFilename);

                if (keepPngFile)
                {
                    File.Delete(pngFilename);
                    File.Move(tempPngFile, pngFilename);
                }
                else
                {
                    File.Delete(tempPngFile);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error saving texture file.\n" + ex.Message);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static void Save(string filename, RS2014FontGenerator fontGenerator)
        {
            int textureWidth  = fontGenerator.TextureWidth;
            int textureHeight = fontGenerator.TextureHeight;
            Dictionary <string, Rect> outerRects = fontGenerator.OuterRects;
            Dictionary <string, Rect> innerRects = fontGenerator.InnerRects;

            GlyphDefinitions definitionFile = new GlyphDefinitions
            {
                TextureHeight = textureHeight,
                TextureWidth  = textureWidth,
                Glyphs        = new List <GlyphDefinition>(fontGenerator.Glyphs.Count)
            };

            foreach (string glyph in fontGenerator.Glyphs)
            {
                Rect innerRect = innerRects[glyph];
                Rect outerRect = outerRects[glyph];

                definitionFile.Glyphs.Add(
                    new GlyphDefinition
                {
                    Symbol = glyph,

                    InnerXMin = (float)(innerRect.Left / textureWidth),
                    InnerXMax = (float)(innerRect.Right / textureWidth),
                    InnerYMin = (float)(innerRect.Top / textureHeight),
                    InnerYMax = (float)(innerRect.Bottom / textureHeight),

                    OuterXMin = (float)(outerRect.Left / textureWidth),
                    OuterXMax = (float)(outerRect.Right / textureWidth),
                    OuterYMin = (float)(outerRect.Top / textureHeight),
                    OuterYMax = (float)(outerRect.Bottom / textureHeight)
                });
            }

            XmlHelper.Serialize(filename, definitionFile);
        }