public static int Main(string[] args) { TextWriter writer = Console.Out; string method_name = null; string formatter = null; bool show_help = false; var os = new OptionSet () { { "formatter=", "Source code formatter. Valid values are: 'csharp-coregraphics'", v => formatter = v }, { "out=", "Source code output", v => writer = new StreamWriter (v) }, { "h|?|help", "Displays the help", v => show_help = true }, }; var svg = os.Parse (args); string path = (svg.Count > 1) ? String.Concat (svg) : svg [0]; if (show_help) Usage (os, null); var parser = new SvgPathParser (); switch (formatter) { case "csharp-coregraphics": case "cs-cg": parser.Formatter = new CSharpCoreGraphicsFormatter (writer); break; default: Usage (os, "error: unkown {0} code formatter", formatter); break; } parser.Parse (path, method_name); return 0; }
public override void AwakeFromNib() { base.AwakeFromNib (); SourceCodeOutput.Editable = false; parser = new SvgPathParser (); Convert.Activated += (object sender, EventArgs e) => { using (var tw = new StringWriter ()) { parser.Formatter = GetFormatter (tw); try { parser.Parse (SvgPathInput.StringValue ?? String.Empty, "Unnamed"); SourceCodeOutput.Value = tw.ToString (); } catch { SourceCodeOutput.Value = "Invalid path data. If this looks like a valid path then please " + "file an issue on github: " + Environment.NewLine + BugReport + Environment.NewLine + "and include the offending SVG path: " + Environment.NewLine + SvgPathInput.StringValue; } } }; }
public static int Main(string[] args) { if (args.Length < 1) Usage ("error: Path to FontAwesome directory required"); string font_dir = args [0]; string css_file = Path.Combine (font_dir, "css/font-awesome.css"); if (!File.Exists (css_file)) Usage ("error: Missing '{0}' file.", css_file); string svg_file = Path.Combine (font_dir, "font/fontawesome-webfont.svg"); if (!File.Exists (svg_file)) Usage ("error: Missing '{0}' file.", svg_file); TextWriter writer = (args.Length < 2) ? Console.Out : new StreamWriter (args [1]); writer.WriteLine ("// note: Generated file - do not modify - use convert-font-awesome to regenerate"); writer.WriteLine (); writer.WriteLine ("using MonoTouch.CoreGraphics;"); writer.WriteLine ("using MonoTouch.Dialog;"); writer.WriteLine ("using MonoTouch.Foundation;"); writer.WriteLine ("using MonoTouch.UIKit;"); writer.WriteLine (); writer.WriteLine ("namespace Poupou.Awesome.Demo {"); writer.WriteLine (); writer.WriteLine ("\t[Preserve]"); writer.WriteLine ("\tpublic partial class Elements {"); Dictionary<string,string> names = new Dictionary<string,string> (); foreach (string line in File.ReadLines (css_file)) { if (!line.StartsWith (".icon-", StringComparison.Ordinal)) continue; int p = line.IndexOf (':'); if (p == -1) continue; string name = line.Substring (1, p - 1).Replace ('-', '_'); p = line.IndexOf ("content: \"\\", StringComparison.Ordinal); if (p == -1) continue; string value = line.Substring (p + 11, 4); writer.WriteLine ("\t\t// {0} : {1}", name, value); writer.WriteLine ("\t\tImageStringElement {0}_element = new ImageStringElement (\"{0}\", GetAwesomeIcon ({0}));", name); writer.WriteLine (); names.Add (value, name); } writer.WriteLine ("\t\t// total: {0}", names.Count); writer.WriteLine (); // MonoTouch uses C# and CoreGraphics var code = new CSharpCoreGraphicsFormatter (writer); var parser = new SvgPathParser () { Formatter = code }; foreach (string line in File.ReadLines (svg_file)) { if (!line.StartsWith ("<glyph unicode=\"&#x", StringComparison.Ordinal)) continue; string id = line.Substring (19, 4); string name; if (!names.TryGetValue (id, out name)) continue; int p = line.IndexOf (" d=\"") + 4; int e = line.LastIndexOf ('"'); string data = line.Substring (p, e - p); parser.Parse (data, name); } writer.WriteLine ("\t}"); writer.WriteLine ("}"); writer.Close (); return 0; }
public static int Main(string[] args) { if (args.Length < 1) Usage ("error: Path to FontAwesome directory required"); string font_dir = args [0]; string css_file = Path.Combine (font_dir, "css/font-awesome.css"); if (!File.Exists (css_file)) Usage ("error: Missing '{0}' file.", css_file); string svg_file = Path.Combine (font_dir, "font/fontawesome-webfont.svg"); if (!File.Exists (svg_file)) Usage ("error: Missing '{0}' file.", svg_file); if (args.Length < 2) Usage ("error: Specify formatter"); TextWriter writer = (args.Length < 3) ? Console.Out : new StreamWriter (args [2]); var code = CreateFormatter(args[1], writer); var parser = new SvgPathParser () { Formatter = code }; code.Header(); Console.WriteLine("Parsing icons"); Dictionary<string,string> names = new Dictionary<string,string> (); foreach (string line in File.ReadLines (css_file)) { if (!line.StartsWith (".icon-", StringComparison.Ordinal)) continue; int p = line.IndexOf (':'); if (p == -1) continue; string name = line.Substring (1, p - 1).Replace ('-', '_'); p = line.IndexOf ("content: \"\\", StringComparison.Ordinal); if (p == -1) continue; string value = line.Substring (p + 11, 4); code.NewElement (name, value); names.Add (value, name); } code.ElementStats(names.Count); Console.WriteLine("Parsing glyphs"); foreach (string line in File.ReadLines (svg_file)) { if (!line.StartsWith ("<glyph unicode=\"&#x", StringComparison.Ordinal)) continue; string id = line.Substring (19, 4); string name; if (!names.TryGetValue (id, out name)) continue; int p = line.IndexOf (" d=\"") + 4; int e = line.LastIndexOf ('"'); string data = line.Substring (p, e - p); parser.Parse (data, name); } code.Footer(); return 0; }