Пример #1
0
        public void TestRenderWImage()
        {
            var builder = new SvgBuilder();
            var doc     = builder.Open(new MemoryStream(TestingSources.WithImage));

            SaveBitmap(doc.Draw(), "TestRenderWImage.png");
        }
Пример #2
0
        public void TestAllChildren()
        {
            var doc = new SvgBuilder().Open(Encoding.UTF8.GetString(TestingSources.Basic_Shapes));

            Assert.AreEqual(1, doc.Children.Count);
            Assert.AreEqual(7, doc.AllChildren().Count());
        }
Пример #3
0
        public void TestScale()
        {
            var doc = new SvgBuilder().Open(Encoding.UTF8.GetString(TestingSources.Basic_Shapes));

            SaveBitmap(doc.Draw(), "before.png");
            doc.EditScale(2);
            SaveBitmap(doc.Draw(), "after.png");
        }
Пример #4
0
        public void TestRenderRect()
        {
            var doc = new SvgBuilder().OpenPath("rect.svg");

            using (var bmp = new Bitmap(800, 800))
            {
                var render = SvgRenderer.FromImage(bmp);
                doc.RenderElement(render);
            }
        }
Пример #5
0
        static SvgBuilder()
        {
            AvailableElements = new Dictionary <string, ElementInfo>();
            var svgTypes = from t in typeof(SvgDocument).Assembly.GetExportedTypes()
                           where t.GetCustomAttributes(typeof(SvgElementAttribute), true).Length > 0 &&
                           t.IsSubclassOf(typeof(SvgElement))
                           select new ElementInfo {
                ElementName = ((SvgElementAttribute)t.GetCustomAttributes(typeof(SvgElementAttribute), true)[0]).ElementName, ElementType = t
            };

            foreach (var type in svgTypes)
            {
                AvailableElements[type.ElementName] = type;
            }
            AvailableElements["svg"] = new ElementInfo("svg", typeof(SvgDocument));
            Default = new SvgBuilder();
        }
Пример #6
0
        public void TestRenderCustomFont()
        {
            var builder = new SvgBuilder();

            builder.FontFamilyLookup += TestRenderCustomFont_FontFamilyLookup;
            var doc = new SvgDocument {
                SvgBuilder = builder
            };
            var text = new SvgText("Hello World")
            {
                SvgBuilder = builder
            };

            doc.Children.Add(text);
            text.Font     = NASALIZA;
            text.FontSize = new SvgUnit(22);
            text.Y        = new SvgUnit(100);
            Assert.AreEqual(text.Font, NASALIZA);
            SaveBitmap(doc.Draw(), "TestRenderCustomFont.png");
        }
Пример #7
0
 /// <summary>
 /// Given the SVG/XML fragment return a fully populated SVG node.  The returned nodes are not added to this document
 /// </summary>
 /// <param name="fragment">The SVG/XML formatted string to parse</param>
 /// <param name="entities">Optional dictionary to resolve entities. May be null.</param>
 /// <returns></returns>
 public SvgElement[] ParseFragment(string fragment, Dictionary <string, string> entities = null)
 {
     return(SvgBuilder.ParseFragment(this, fragment, entities));
 }
Пример #8
0
        /// <summary>
        /// Opens an SVG document from the specified <see cref="Stream"/> and adds the specified entities.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> containing the SVG document to open.</param>
        /// <param name="entities">Custom entity definitions.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="stream"/> parameter cannot be <c>null</c>.</exception>
        public static T Open <T>(Stream stream, Dictionary <string, string> entities) where T : SvgDocument, new()
        {
            var builder = new SvgBuilder(Activator.CreateInstance <T>);

            return((T)builder.Open(stream, entities));
        }
Пример #9
0
 public void TestEmptyPath()
 {
     var b = new SvgBuilder().Open(TestingSources.SvgEmptyPath).Bounds;
 }
Пример #10
0
 /// <summary>
 /// Gets the FontFamily object for the current FontFamily
 /// </summary>
 /// <returns></returns>
 public System.Drawing.FontFamily GetFontFamily()
 {
     return(SvgBuilder.GetFontFamily(_fontFamily));
 }