View.cs 2.34 KB
Newer Older
1
2
3
4
5
6
7
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using Svg;
Eric Domke's avatar
Eric Domke committed
8
using System.Diagnostics;
9
10
11
12
13
14
15
16
17
18
19
20

namespace SvgW3CTestRunner
{
    public partial class View : Form
    {
        private const string _svgBasePath = @"..\..\..\W3CTestSuite\svg\";
        private const string _pngBasePath = @"..\..\..\W3CTestSuite\png\";

        public View()
        {
            InitializeComponent();
            // ignore tests pertaining to javascript or xml reading
Eric Domke's avatar
Eric Domke committed
21
22
23
            var passes = File.ReadAllLines(_svgBasePath + @"..\PassingTests.txt").ToDictionary((f) => f, (f) => true);
            var files = (from f in
                             (from g in Directory.GetFiles(_svgBasePath)
24
25
                                    select Path.GetFileName(g))
                         where !f.StartsWith("animate-") && !f.StartsWith("conform-viewer") &&
Eric Domke's avatar
Eric Domke committed
26
27
                            !f.Contains("-dom-") && !f.StartsWith("linking-") && !f.StartsWith("interact-") &&
                            !f.StartsWith("script-")
28
29
                         orderby f
                         select (object)f);
Eric Domke's avatar
Eric Domke committed
30
31
            files = files.Where((f) => !passes.ContainsKey((string)f)).Union(Enumerable.Repeat((object)"## PASSING ##", 1)).Union(files.Where((f) => passes.ContainsKey((string)f)));

32
33
34
35
36
37
            lstFiles.Items.AddRange(files.ToArray());
        }

        private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            var fileName = lstFiles.SelectedItem.ToString();
Eric Domke's avatar
Eric Domke committed
38
            if (fileName.StartsWith("#")) return;
Eric Domke's avatar
Eric Domke committed
39
40
            try
            {
Eric Domke's avatar
Eric Domke committed
41
                Debug.Print(fileName);
Eric Domke's avatar
Eric Domke committed
42
                var doc = SvgDocument.Open(_svgBasePath + fileName);
Eric Domke's avatar
Eric Domke committed
43
44
45
46
47
48
49
50
51
52
                if (fileName.StartsWith("__"))
                {
                    picSvg.Image = doc.Draw(); 
                }
                else
                {
                    var img = new Bitmap(480, 360);
                    doc.Draw(img);
                    picSvg.Image = img; 
                }
Eric Domke's avatar
Eric Domke committed
53
54
55
56
57
58
59
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                picSvg.Image = null;
            }
            
60
61
62
63
64
            var png = Image.FromFile(_pngBasePath + Path.GetFileNameWithoutExtension(fileName) + ".png");
            picPng.Image = png;
        }
    }
}