1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
//
// shapes2sprite.cs: Convert dia shapes into CSS sprites
//
// Author:
// Steffen Macke (sdteffen@sdteffen.de)
//
// Copyright (C) 2007, 2009 - 2013 Steffen Macke (http://dia-installer.de)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
using System;
using System.Xml.XPath;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.IO;
// CSS classes for all shapes and objects
public class Shapes2Sprite
{
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);
}
}
|