MetafileRenderingTest.cs 1.97 KB
Newer Older
HeinrichAD's avatar
HeinrichAD committed
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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace Svg.UnitTests
{

    /// <summary>
    /// Test Class of rendering SVGs as meterfile.
    /// Based on Issue 210.
    /// </summary>
    /// <remarks>
    /// Test use the following embedded resources:
    ///   - Issue210_Metafile\3DSceneSnapshotBIG.svg
    /// </remarks>
    [TestClass]
    public class MetafileRenderingTest : SvgTestHelper
    {
        protected override string TestResource { get { return GetFullResourceString("Issue210_Metafile.3DSceneSnapshotBIG.svg"); } }
27
        protected override int ExpectedSize { get { return 12500; } } //12896
HeinrichAD's avatar
HeinrichAD committed
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


        [TestMethod]
        [TestProperty(name: "speed", value: "slow")]
        public void TestMetafileRendering()
        {
            LoadSvg(GetXMLDocFromResource());
        }


        protected override Image DrawSvg(SvgDocument svgDoc)
        {
            // GDI+
            Metafile metafile;
            using (var stream = new MemoryStream())
            using (var img = new Bitmap((int)svgDoc.Width.Value, (int)svgDoc.Height.Value)) // Not necessary if you use Control.CreateGraphics().
            using (Graphics ctrlGraphics = Graphics.FromImage(img)) // Control.CreateGraphics()
            {
                IntPtr handle = ctrlGraphics.GetHdc();

                var rect = new RectangleF(0, 0, svgDoc.Width, svgDoc.Height);
                metafile = new Metafile(stream,
                    handle,
                    rect,
                    MetafileFrameUnit.Pixel,
                    EmfType.EmfPlusOnly);

                using (Graphics ig = Graphics.FromImage(metafile))
                {
                    svgDoc.Draw(ig);
                }

                ctrlGraphics.ReleaseHdc(handle);
            }

            return metafile;
        }
    }
}