Пример #1
0
        public async Task Png96Dpi()
        {
            var fileName = Path.Combine(_artifacts, "png96.sprite");
            var imgFile  = fileName + ".jpg";
            var lessFile = fileName + ".less";

            try
            {
                var doc = await SpriteDocument.FromFile(fileName);

                await _generator.Generate(doc);

                using (var image = Image.FromFile(imgFile))
                {
                    Assert.AreEqual(56, image.Height); // 16 + padding
                    Assert.AreEqual(236, image.Width); // 16 * 6 + padding
                }

                string less = File.ReadAllText(lessFile);
                Assert.IsTrue(less.Contains(".png96-a()"), "Sprite \"a.png\" not generated");
                Assert.IsTrue(less.Contains("url('png96.sprite.jpg')"), "Incorrect url value");
                Assert.IsTrue(less.Contains("margin: 0"), "Incorrect custom style");
            }
            finally
            {
                File.Delete(imgFile);
                File.Delete(lessFile);
            }
        }
Пример #2
0
 public static async Task GenerateSpriteAsync(SpriteDocument doc)
 {
     try
     {
         await _generator.Generate(doc);
     }
     catch (FileNotFoundException ex)
     {
         MessageBox.Show(ex.Message, Vsix.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
         ProjectHelpers.DTE.ItemOperations.OpenFile(doc.FileName);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
Пример #3
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            var _artifacts = new DirectoryInfo(".\\").FullName;

            var spritesDirName = "Sprites";

            if (!Directory.Exists(spritesDirName))
            {
                Directory.CreateDirectory(spritesDirName);
            }

            var _fileName = Path.Combine(_artifacts, spritesDirName, $"{txtSpriteName.Text}.sprite");

            var images = new List <string>();

            foreach (FileInfoDisplayName f in lbTarget.Items)
            {
                images.Add(f.File.FullName);
            }

            var document = new SpriteDocument(_fileName, images);

            document.Orientation             = ImageSprites.Orientation.Horizontal;
            document.Padding                 = 20;
            document.Output                  = ImageType.Png;
            document.Stylesheet              = Stylesheet.Css;
            document.CustomStyles["display"] = "block";
            document.CustomStyles.Add("margin", "0");

            var task = Task.Run(() => _generator.Generate(document));

            task.Wait();

            var documentTask = Task.Run(() => document.Save());

            documentTask.Wait();
        }