예제 #1
0
        public virtual void StylesOfSvgTagProcessingTest()
        {
            String svg = "<?xml version=\"1.0\" standalone=\"no\"?>\n" + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"
                         + "        \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + "<svg width=\"400\" height=\"200\"\n"
                         + "     viewBox=\"0 0 400 200\" version=\"1.1\"\n" + "     xmlns=\"http://www.w3.org/2000/svg\"\n" +
                         "     xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" + "     xmlns:v=\"http://schemas.microsoft.com/visio/2003/SVGExtensions/\"\n"
                         + "     class=\"st11\">\n" + "    <style type=\"text/css\">\n" + "        .st11 {fill:none;stroke:black;stroke-width:6}\n"
                         + "    </style>\n" + "    <g >\n" + "        <path d=\"M0 100 L0 50 L70 50\"/>\n" + "    </g>\n" + "</svg>";
            JsoupXmlParser         xmlParser    = new JsoupXmlParser();
            IDocumentNode          root         = xmlParser.Parse(svg);
            IBranchSvgNodeRenderer nodeRenderer = (IBranchSvgNodeRenderer) new DefaultSvgProcessor().Process(root).GetRootRenderer
                                                      ();
            PathSvgNodeRenderer pathSvgNodeRenderer = (PathSvgNodeRenderer)((IBranchSvgNodeRenderer)nodeRenderer.GetChildren
                                                                                ()[0]).GetChildren()[0];
            IDictionary <String, String> actual = new Dictionary <String, String>();

            actual.Put("stroke", pathSvgNodeRenderer.GetAttribute("stroke"));
            actual.Put("fill", pathSvgNodeRenderer.GetAttribute("fill"));
            actual.Put("d", pathSvgNodeRenderer.GetAttribute("d"));
            IDictionary <String, String> expected = new Dictionary <String, String>();

            expected.Put("stroke", "black");
            expected.Put("fill", "none");
            expected.Put("d", "M0 100 L0 50 L70 50");
            NUnit.Framework.Assert.AreEqual(expected, actual);
        }
예제 #2
0
        public virtual void StyleTagProcessingTest()
        {
            String svg = "<svg\n" + "   width=\"210mm\"\n" + "   height=\"297mm\"\n" + "   viewBox=\"0 0 210 297\"\n"
                         + "   version=\"1.1\"\n" + "   id=\"svg8\"\n" + "   >\n" + "  <style>\n" + "\tellipse{\n" + "\t\tstroke-width:1.76388889;\n"
                         + "\t\tstroke:#da0000;\n" + "\t\tstroke-opacity:1;\n" + "\t}\n" + "  </style>\n" + "    <ellipse\n" +
                         "       id=\"path3699\"\n" + "       cx=\"96.005951\"\n" + "       cy=\"110.65774\"\n" + "       rx=\"53.672619\"\n"
                         + "       ry=\"53.294643\"\n" + "       style=\"fill:none;stroke-miterlimit:4;stroke-dasharray:none\" />\n"
                         + "</svg>\n";
            JsoupXmlParser         xmlParser    = new JsoupXmlParser();
            IDocumentNode          root         = xmlParser.Parse(svg);
            IBranchSvgNodeRenderer nodeRenderer = (IBranchSvgNodeRenderer) new DefaultSvgProcessor().Process(root).GetRootRenderer
                                                      ();
            IDictionary <String, String> actual = new Dictionary <String, String>();
            //Traverse to ellipse
            ISvgNodeRenderer ellipse = nodeRenderer.GetChildren()[0];

            actual.Put("stroke", ellipse.GetAttribute("stroke"));
            actual.Put("stroke-width", ellipse.GetAttribute("stroke-width"));
            actual.Put("stroke-opacity", ellipse.GetAttribute("stroke-opacity"));
            IDictionary <String, String> expected = new Dictionary <String, String>();

            expected.Put("stroke-width", "1.76388889");
            expected.Put("stroke", "#da0000");
            expected.Put("stroke-opacity", "1");
            NUnit.Framework.Assert.AreEqual(expected, actual);
        }
예제 #3
0
        public virtual void TestXmlDeclarationAndComment()
        {
            String        xml    = "<?xml version=\"1.0\" standalone=\"no\"?>\n" + "<!-- just declaration and comment -->";
            Stream        stream = new MemoryStream(xml.GetBytes());
            IDocumentNode node   = new JsoupXmlParser().Parse(stream, "UTF-8");

            // only text (whitespace) child node shall be fetched.
            NUnit.Framework.Assert.AreEqual(1, node.ChildNodes().Count);
        }
        public virtual void NamedObjectRectangleTest()
        {
            String              svgFile                   = sourceFolder + "namedObjectRectangleTest.svg";
            Stream              svg                       = new FileStream(svgFile, FileMode.Open, FileAccess.Read);
            JsoupXmlParser      xmlParser                 = new JsoupXmlParser();
            IDocumentNode       root                      = xmlParser.Parse(svg, null);
            ISvgProcessorResult processorResult           = new DefaultSvgProcessor().Process(root);
            IDictionary <String, ISvgNodeRenderer> actual = processorResult.GetNamedObjects();

            NUnit.Framework.Assert.AreEqual(1, actual.Count);
            NUnit.Framework.Assert.IsTrue(actual.ContainsKey("MyRect"));
        }
        public virtual void DefaultBehaviourTest()
        {
            String                 svgFile   = sourceFolder + "RedCircle.svg";
            Stream                 svg       = new FileStream(svgFile, FileMode.Open, FileAccess.Read);
            JsoupXmlParser         xmlParser = new JsoupXmlParser();
            IDocumentNode          root      = xmlParser.Parse(svg, null);
            IBranchSvgNodeRenderer actual    = (IBranchSvgNodeRenderer) new DefaultSvgProcessor().Process(root).GetRootRenderer
                                                   ();
            IBranchSvgNodeRenderer       expected                  = new SvgTagSvgNodeRenderer();
            ISvgNodeRenderer             expectedEllipse           = new EllipseSvgNodeRenderer();
            IDictionary <String, String> expectedEllipseAttributes = new Dictionary <String, String>();

            expectedEllipse.SetAttributesAndStyles(expectedEllipseAttributes);
            expected.AddChild(expectedEllipse);
            //1 child
            NUnit.Framework.Assert.AreEqual(expected.GetChildren().Count, actual.GetChildren().Count);
        }
        public virtual void SmoothCurveTest3()
        {
            String      filename = "smoothCurveTest3.pdf";
            PdfDocument doc      = new PdfDocument(new PdfWriter(destinationFolder + filename));

            doc.AddNewPage();
            String                 svgFilename = "smoothCurveTest3.svg";
            Stream                 xmlStream   = new FileStream(sourceFolder + svgFilename, FileMode.Open, FileAccess.Read);
            IElementNode           rootTag     = new JsoupXmlParser().Parse(xmlStream, "ISO-8859-1");
            DefaultSvgProcessor    processor   = new DefaultSvgProcessor();
            IBranchSvgNodeRenderer root        = (IBranchSvgNodeRenderer)processor.Process(rootTag, null).GetRootRenderer();
            SvgDrawContext         context     = new SvgDrawContext(null, null);
            PdfCanvas              cv          = new PdfCanvas(doc, 1);

            context.PushCanvas(cv);
            NUnit.Framework.Assert.IsTrue(root.GetChildren()[0] is PathSvgNodeRenderer);
            root.GetChildren()[0].Draw(context);
            doc.Close();
        }
예제 #7
0
        public virtual void DefaultBehaviourTest()
        {
            String                 svgFile   = sourceFolder + "RedCircle.svg";
            Stream                 svg       = new FileStream(svgFile, FileMode.Open, FileAccess.Read);
            JsoupXmlParser         xmlParser = new JsoupXmlParser();
            IDocumentNode          root      = xmlParser.Parse(svg, null);
            IBranchSvgNodeRenderer actual    = (IBranchSvgNodeRenderer) new DefaultSvgProcessor().Process(root, null).GetRootRenderer
                                                   ();
            //Attribute comparison from the known RedCircle.svg
            IDictionary <String, String> attrs = actual.GetChildren()[0].GetAttributeMapCopy();

            NUnit.Framework.Assert.AreEqual(11, attrs.Keys.Count, "Number of parsed attributes is wrong");
            NUnit.Framework.Assert.AreEqual("1", attrs.Get("stroke-opacity"), "The stroke-opacity attribute doesn't correspond it's value"
                                            );
            NUnit.Framework.Assert.AreEqual("1.76388889", attrs.Get("stroke-width"), "The stroke-width attribute doesn't correspond it's value"
                                            );
            NUnit.Framework.Assert.AreEqual("path3699", attrs.Get("id"), "The id attribute doesn't correspond it's value"
                                            );
            NUnit.Framework.Assert.AreEqual("none", attrs.Get("stroke-dasharray"), "The stroke-dasharray attribute doesn't correspond it's value"
                                            );
        }