Example #1
0
        static void Generate(string inputDirectory)
        {
            string outputFile = Path.Combine(inputDirectory, @"src\FontAwesome5\EFontAwesomeIcon.cs");
            var    configFile = Path.Combine(inputDirectory, @"Font-Awesome\metadata\icons.json");

            var fa = new FontAwesomeManager(configFile);

            WriteLine("//------------------------------------------------------------------------------");
            WriteLine("// <auto-generated>");
            WriteLine("//     This code was generated by a tool");
            WriteLine("//");
            WriteLine("//     Changes to this file may cause incorrect behavior and will be lost if");
            WriteLine("//     the code is regenerated.");
            WriteLine("// </auto-generated>");
            WriteLine("//------------------------------------------------------------------------------");

            WriteLine("using System;");
            WriteLine("using System.ComponentModel;");
            WriteLine("namespace FontAwesome5");
            WriteLine("{");
            PushIndent("\t");

            WriteLine("/// <summary>");
            WriteLine("/// FontAwesome by Dave Gandy (@davegandy)");
            WriteLine("///	The iconic SVG, font, and CSS toolkit");
            WriteLine("///	License https://fontawesome.com/license (C#: MIT License)");
            WriteLine("/// </summary>");
            WriteLine("public enum EFontAwesomeStyle");
            WriteLine("{");
            PushIndent("\t");
            WriteSummary("This Style is used as an undefined state.");
            WriteLine("None,");
            WriteLine("");
            foreach (EStyles style in Enum.GetValues(typeof(EStyles)))
            {
                WriteSummary("FontAwesome5 {0} Style", style);
                WriteLine("{0},", style);
                WriteLine("");
            }
            PopIndent();
            WriteLine("}");

            WriteLine("");
            WriteLine("///<summary>FontAwesome5 Icons</summary>");
            WriteLine("public enum EFontAwesomeIcon");
            WriteLine("{");
            PushIndent("\t");
            WriteSummary("Set this value to show no icon.");
            WriteLine("None = 0x0,");
            WriteLine("");

            foreach (EStyles style in Enum.GetValues(typeof(EStyles)))
            {
                foreach (var kvp in fa.Icons.Where(i => i.Value.styles.Contains(style.ToString().ToLower())))
                {
                    WriteSummary(kvp.Value.label);
                    WriteLine("///<see href=\"http://fontawesome.com/icons/{0}?style={1}\" />", kvp.Key, style.ToString().ToLower());
                    WriteLine("[FontAwesomeInformation(\"{0}\", EFontAwesomeStyle.{1}, 0x{2})]", kvp.Value.label, style.ToString(), kvp.Value.unicode);

                    if (kvp.Value.svg.TryGetValue(style.ToString().ToLower(), out var svgInfo))
                    {
                        string path = string.Empty;
                        if (svgInfo.path.Length == 1)
                        {
                            path = $"\"{svgInfo.path[0]}\"";
                        }
                        else
                        {
                            path = svgInfo.path
                                   .Aggregate((current, next) => $"\"{current}\",\"{next}\"");
                        }
                        path = "new[] {" + path + "}";
                        WriteLine("[FontAwesomeSvgInformation({0}, {1}, {2})]", path, svgInfo.width, svgInfo.height);
                    }
                    WriteLine("{0}_{1},", style, fa.Convert(kvp.Key));
                    WriteLine("");
                }
            }

            PopIndent();
            WriteLine("}");

            WriteLine("");
            WriteSummary("FontAwesome Information Attribute");
            WriteLine("public class FontAwesomeInformationAttribute : Attribute");
            WriteLine("{");
            PushIndent("\t");
            WriteSummary("FontAwesome Style");
            WriteLine("public EFontAwesomeStyle Style { get; set; }");
            WriteSummary("FontAwesome Label");
            WriteLine("public string Label { get; set; }");
            WriteSummary("FontAwesome Unicode");
            WriteLine("public int Unicode { get; set; }");
            WriteLine("");
            WriteLine("public FontAwesomeInformationAttribute(string label, EFontAwesomeStyle style, int unicode)");
            WriteLine("{");
            WriteLine("    Label = label;");
            WriteLine("    Style = style;");
            WriteLine("    Unicode = unicode;");
            WriteLine("}");
            PopIndent();
            WriteLine("}");


            WriteLine("");
            WriteSummary("FontAwesome SVG Information Attribute");
            WriteLine("public class FontAwesomeSvgInformationAttribute : Attribute");
            WriteLine("{");
            PushIndent("\t");
            WriteSummary("FontAwesome SVG Path");
            WriteLine("public string[] Path { get; set; }");
            WriteSummary("FontAwesome SVG Width");
            WriteLine("public int Width { get; set; }");
            WriteSummary("FontAwesome SVG Height");
            WriteLine("public int Height { get; set; }");
            WriteLine("");
            WriteLine("public FontAwesomeSvgInformationAttribute(string[] path, int width, int height)");
            WriteLine("{");
            WriteLine("    Path = path;");
            WriteLine("    Width = width;");
            WriteLine("    Height = height;");
            WriteLine("}");
            PopIndent();
            WriteLine("}");

            PopIndent();
            WriteLine("}");

            File.WriteAllText(outputFile, _content.ToString());
        }
Example #2
0
        static void Generate(string inputDirectory)
        {
            var outputFile = Path.Combine(inputDirectory, @"src\FontAwesome5\EFontAwesomeIcon.cs");
            var configFile = Path.Combine(inputDirectory, @"Font-Awesome\metadata\icons.json");

            var fa = new FontAwesomeManager(configFile);

            WriteLine("//------------------------------------------------------------------------------");
            WriteLine("// <auto-generated>");
            WriteLine("//     This code was generated by a tool");
            WriteLine("//");
            WriteLine("//     Changes to this file may cause incorrect behavior and will be lost if");
            WriteLine("//     the code is regenerated.");
            WriteLine("// </auto-generated>");
            WriteLine("//------------------------------------------------------------------------------");

            WriteLine("using System;");
            WriteLine("using System.ComponentModel;");
            WriteLine("namespace FontAwesome5");
            WriteLine("{");
            PushIndent("\t");

            WriteLine("/// <summary>");
            WriteLine("/// FontAwesome by Dave Gandy (@davegandy)");
            WriteLine("///	The iconic SVG, font, and CSS toolkit");
            WriteLine("///	License https://fontawesome.com/license (C#: MIT License)");
            WriteLine("/// </summary>");
            WriteLine("public enum EFontAwesomeStyle");
            WriteLine("{");
            PushIndent("\t");
            WriteSummary("This Style is used as an undefined state.");
            WriteLine("None,");
            WriteLine("");
            foreach (EStyles style in Enum.GetValues(typeof(EStyles)))
            {
                WriteSummary("FontAwesome5 {0} Style", style);
                WriteLine("{0},", style);
                WriteLine("");
            }
            PopIndent();
            WriteLine("}");

            WriteLine("");
            WriteLine("///<summary>FontAwesome5 Icons</summary>");
            WriteLine("public enum EFontAwesomeIcon");
            WriteLine("{");
            PushIndent("\t");
            WriteSummary("Set this value to show no icon.");
            WriteLine("None = 0x0,");
            WriteLine("");

            foreach (EStyles style in Enum.GetValues(typeof(EStyles)))
            {
                foreach (var kvp in fa.Icons.Where(i => i.Value.styles.Contains(style.ToString().ToLower())))
                {
                    WriteSummary(kvp.Value.label);
                    WriteLine("///<see href=\"http://fontawesome.com/icons/{0}?style={1}\" />", kvp.Key, style.ToString().ToLower());
                    WriteLine("{0}_{1},", style, fa.Convert(kvp.Key));
                    WriteLine("");
                }
            }

            PopIndent();
            WriteLine("}");

            PopIndent();
            WriteLine("}");

            File.WriteAllText(outputFile, _content.ToString());

            _content = new StringBuilder();

            WriteLine("//------------------------------------------------------------------------------");
            WriteLine("// <auto-generated>");
            WriteLine("//     This code was generated by a tool");
            WriteLine("//");
            WriteLine("//     Changes to this file may cause incorrect behavior and will be lost if");
            WriteLine("//     the code is regenerated.");
            WriteLine("// </auto-generated>");
            WriteLine("//------------------------------------------------------------------------------");

            WriteLine("using System;");
            WriteLine("using System.Collections.Generic;");
            WriteLine("namespace FontAwesome5");
            WriteLine("{");
            PushIndent("\t");

            WriteLine("internal static class FontAwesomeInternal");
            WriteLine("{");
            PushIndent("\t");
            WriteLine("public static Dictionary<EFontAwesomeIcon, FontAwesomeInformation> Information = new Dictionary<EFontAwesomeIcon, FontAwesomeInformation>() {");
            PushIndent("\t");

            foreach (EStyles style in Enum.GetValues(typeof(EStyles)))
            {
                foreach (var kvp in fa.Icons.Where(i => i.Value.styles.Contains(style.ToString().ToLower())))
                {
                    if (kvp.Value.svg.TryGetValue(style.ToString().ToLower(), out var svgInfo))
                    {
                        WriteLine("{{EFontAwesomeIcon.{0}_{1}, new FontAwesomeInformation(\"{2}\", EFontAwesomeStyle.{0}, \"{3}\", new FontAwesomeSvgInformation(\"{4}\", {5}, {6}))}},",
                                  style, fa.Convert(kvp.Key), kvp.Value.label, char.ConvertFromUtf32(Convert.ToInt32("0x" + kvp.Value.unicode, 16)),
                                  svgInfo.path, svgInfo.width, svgInfo.height);
                    }
                    else
                    {
                        WriteLine("{{EFontAwesomeIcon.{0}_{1}, new FontAwesomeInformation(\"{2}\", EFontAwesomeStyle.{0}, \"{3}\")}},",
                                  style, fa.Convert(kvp.Key), kvp.Value.label, char.ConvertFromUtf32(Convert.ToInt32("0x" + kvp.Value.unicode, 16)));
                    }
                }
            }

            PopIndent();
            WriteLine("};");

            PopIndent();
            WriteLine("};");

            WriteLine("");
            WriteLine("public class FontAwesomeInformation");
            WriteLine("{");
            PushIndent("\t");
            WriteSummary("FontAwesome Label");
            WriteLine("public string Label { get; set; }");
            WriteSummary("FontAwesome Style");
            WriteLine("public EFontAwesomeStyle Style { get; set; }");
            WriteSummary("FontAwesome Unicode");
            WriteLine("public string Unicode { get; set; }");
            WriteSummary("FontAwesome Svg");
            WriteLine("public FontAwesomeSvgInformation Svg { get; set; }");
            WriteLine("");
            WriteLine("public FontAwesomeInformation(string label, EFontAwesomeStyle style, string unicode, FontAwesomeSvgInformation svg = null)");
            WriteLine("{");
            WriteLine("    Label = label;");
            WriteLine("    Style = style;");
            WriteLine("    Unicode = unicode;");
            WriteLine("    Svg = svg;");
            WriteLine("}");
            PopIndent();
            WriteLine("}");
            WriteLine("");
            WriteLine("public class FontAwesomeSvgInformation");
            WriteLine("{");
            PushIndent("\t");
            WriteLine("public string Path { get; set; }");
            WriteLine("public int Width { get; set; }");
            WriteLine("public int Height { get; set; }");
            WriteLine("");
            WriteLine("public FontAwesomeSvgInformation(string path, int width, int height)");
            WriteLine("{");
            WriteLine("    Path = path;");
            WriteLine("    Width = width;");
            WriteLine("    Height = height;");
            WriteLine("}");
            PopIndent();
            WriteLine("}");

            PopIndent();
            WriteLine("}");

            outputFile = Path.Combine(inputDirectory, @"src\FontAwesome5\FontAwesomeInternal.cs");
            File.WriteAllText(outputFile, _content.ToString());
        }