Пример #1
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);
        }
Пример #2
0
        static int Main(string[] args)
        {
            string filename;

            if (args.Length == 1)
            {
                filename = args[0];
                if (!File.Exists(filename))
                {
                    Console.WriteLine("File not found: " + filename);
                    return(1);
                }
            }
            else
            {
                Console.WriteLine("Give a filename as a command line argument.");
                return(1);
            }

            CreateCanvas();

            FontGenerator = new RS2014FontGenerator(FontCanvas, new Canvas());

            if (filename.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) && !LoadXMLFile(filename))
            {
                return(1);
            }

            if (filename.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) && !LoadTextFile(filename))
            {
                return(1);
            }

            FontGenerator.SetFont(new TextBlock().FontFamily, FontWeights.Bold, Defaults.FontSize, Defaults.KanjiFontSize);

            switch (FontGenerator.TryGenerateFont())
            {
            case GenerationResult.Success:
                FontCanvas.Width  = TextureWidth = FontGenerator.TextureWidth;
                FontCanvas.Height = TextureHeight = FontGenerator.TextureHeight;
                FontCanvas.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                FontCanvas.Arrange(new Rect(FontCanvas.DesiredSize));

                Console.WriteLine("Font generated.");
                break;

            case GenerationResult.DidNotFitIntoMaxSize:
                Console.WriteLine("The glyphs did not fit into the maximum size texture.");
                return(1);

            case GenerationResult.UserCanceled:
                break;

            default:
                Debug.Print("Unexpected generation result!");
                break;
            }

            if (!SaveFont())
            {
                return(1);
            }

            return(0);
        }