public DiaIconFinder() { icons = new DiaIcons(); objecticons = new Dictionary <string, string> (); objectsheets = new Dictionary <string, string> (); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("sheets"); foreach (System.IO.FileInfo f in dir.GetFiles("*.sheet")) { string sheet = f.Name.Replace(".sheet", ""); XPathDocument document = new XPathDocument(f.FullName); XPathNavigator nav = document.CreateNavigator(); XmlNamespaceManager manager = new XmlNamespaceManager(nav.NameTable); manager.AddNamespace("dia", "http://www.lysator.liu.se/~alla/dia/dia-sheet-ns"); XPathExpression query = nav.Compile("/dia:sheet/dia:contents/dia:object"); query.SetContext(manager); XPathNodeIterator links = nav.Select(query); while (links.MoveNext()) { try { string objectname = links.Current.GetAttribute("name", ""); string iconpath = DiaIconFinder.GetPathFromNode(sheet, objectname, nav); if ("" != iconpath) { objecticons.Add(objectname, iconpath); } objectsheets.Add(objectname, sheet); } catch { } } } System.IO.DirectoryInfo sdir = new System.IO.DirectoryInfo("shapes"); foreach (System.IO.DirectoryInfo idir in sdir.GetDirectories()) { GetShapesInDir(idir); foreach (System.IO.DirectoryInfo jdir in idir.GetDirectories()) { GetShapesInDir(jdir); } } }
public static void Main(string[]args) { if ((args.Length == 1 && ("-h" == args[0] || "--help" == args[0])) || args.Length > 2) { Console.Error.WriteLine ("USAGE: shapes2sprite [Options]"); Console.Error.WriteLine ("Options:"); Console.Error.WriteLine ("--montage Output montage command line"); Console.Error.WriteLine ("--datadir=datadir Path where sheets and shapes reside"); Console.Error.WriteLine ("-h, --help Display help and exit"); Console.Error.WriteLine ("-v, --version Display version and exit"); return; } if (1 == args.Length && ("-v" == args[0] || "--version" == args[0])) { Console.Error.WriteLine ("shapes2sprite 0.2.2"); Console.Error.WriteLine ("Copyright (c) 2011 - 2013 Steffen Macke"); return; } bool montage = false; for (int i = 0; i < args.Length; i++) { if (10 < args[i].Length && "--datadir=" == args[i].Substring (0, 10)) Directory.SetCurrentDirectory (args[i].Substring (10)); if ("--montage" == args[i]) montage = true; } string montagecmd = "montage -geometry +0+0 -tile "; int objectcount = 0; string files = ""; int x = 0, y = 0; if (!montage) Console.WriteLine (".icon { width: 22px; height: 22px; }"); DiaIcons diaicons = new DiaIcons (); foreach (KeyValuePair < string, string > icon in diaicons.icons) { if (DiaIcons.SHEET_SPECIFIC == icon.Value) continue; files += icon.Value + " "; objectcount++; if (!montage) Console.WriteLine (".d" + icon.Key.Replace (".png", "") + " {background: transparent url(s.png) -" + x + "px -" + y + "px no-repeat;}"); x += 22; if (2200 <= x) { x = 0; y += 22; } } montagecmd += "100x" + Math.Ceiling ((decimal) objectcount / 100) + " " + files + " s.png"; if (montage) Console.WriteLine (montagecmd); }
public static void Main(string[] args) { if ((args.Length == 1 && ("-h" == args[0] || "--help" == args[0])) || args.Length > 2) { Console.Error.WriteLine("USAGE: shapes2sprite [Options]"); Console.Error.WriteLine("Options:"); Console.Error.WriteLine ("--montage Output montage command line"); Console.Error.WriteLine ("--datadir=datadir Path where sheets and shapes reside"); Console.Error.WriteLine ("-h, --help Display help and exit"); Console.Error.WriteLine ("-v, --version Display version and exit"); return; } if (1 == args.Length && ("-v" == args[0] || "--version" == args[0])) { Console.Error.WriteLine("shapes2sprite 0.2.2"); Console.Error.WriteLine("Copyright (c) 2011 - 2013 Steffen Macke"); return; } bool montage = false; for (int i = 0; i < args.Length; i++) { if (10 < args[i].Length && "--datadir=" == args[i].Substring(0, 10)) { Directory.SetCurrentDirectory(args[i].Substring(10)); } if ("--montage" == args[i]) { montage = true; } } string montagecmd = "montage -geometry +0+0 -tile "; int objectcount = 0; string files = ""; int x = 0, y = 0; if (!montage) { Console.WriteLine(".icon { width: 22px; height: 22px; }"); } DiaIcons diaicons = new DiaIcons(); foreach (KeyValuePair <string, string> icon in diaicons.icons) { if (DiaIcons.SHEET_SPECIFIC == icon.Value) { continue; } files += icon.Value + " "; objectcount++; if (!montage) { Console.WriteLine(".d" + icon.Key.Replace(".png", "") + " {background: transparent url(s.png) -" + x + "px -" + y + "px no-repeat;}"); } x += 22; if (2200 <= x) { x = 0; y += 22; } } montagecmd += "100x" + Math.Ceiling((decimal)objectcount / 100) + " " + files + " s.png"; if (montage) { Console.WriteLine(montagecmd); } }
public DiaIconFinder() { icons = new DiaIcons (); objecticons = new Dictionary < string, string > (); objectsheets = new Dictionary < string, string > (); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo ("sheets"); foreach (System.IO.FileInfo f in dir.GetFiles ("*.sheet")) { string sheet = f.Name.Replace (".sheet", ""); XPathDocument document = new XPathDocument (f.FullName); XPathNavigator nav = document.CreateNavigator (); XmlNamespaceManager manager = new XmlNamespaceManager (nav.NameTable); manager.AddNamespace ("dia", "http://www.lysator.liu.se/~alla/dia/dia-sheet-ns"); XPathExpression query = nav.Compile ("/dia:sheet/dia:contents/dia:object"); query.SetContext (manager); XPathNodeIterator links = nav.Select (query); while (links.MoveNext ()) { try { string objectname = links.Current.GetAttribute ("name", ""); string iconpath = DiaIconFinder.GetPathFromNode (sheet, objectname, nav); if ("" != iconpath) objecticons.Add (objectname, iconpath); objectsheets.Add (objectname, sheet); } catch { } } } System.IO.DirectoryInfo sdir = new System.IO.DirectoryInfo ("shapes"); foreach (System.IO.DirectoryInfo idir in sdir.GetDirectories ()) { GetShapesInDir (idir); foreach (System.IO.DirectoryInfo jdir in idir.GetDirectories ()) { GetShapesInDir (jdir); } } }