public virtual void ParseAndProcessSuccessTest()
        {
            String     name = "minimal";
            FileStream fis  = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
            IDictionary <String, ISvgNodeRenderer> map = new Dictionary <String, ISvgNodeRenderer>();
            RectangleSvgNodeRenderer rect = new RectangleSvgNodeRenderer();

            rect.SetAttribute("fill", "none");
            rect.SetAttribute("stroke", "black");
            rect.SetAttribute("width", "500");
            rect.SetAttribute("height", "400");
            ISvgNodeRenderer root = new SvgTagSvgNodeRenderer();

            root.SetAttribute("xmlns", "http://www.w3.org/2000/svg");
            root.SetAttribute("version", "1.1");
            root.SetAttribute("width", "500");
            root.SetAttribute("height", "400");
            ISvgProcessorResult expected = new SvgProcessorResult(map, root, new FontProvider(), new FontSet());
            ISvgProcessorResult actual   = SvgConverter.ParseAndProcess(fis);

            //TODO(RND-868): remove below checks
            NUnit.Framework.Assert.AreEqual(typeof(SvgTagSvgNodeRenderer), actual.GetRootRenderer().GetType());
            NUnit.Framework.Assert.AreEqual(0, actual.GetNamedObjects().Count);
            NUnit.Framework.Assert.AreEqual("500", actual.GetRootRenderer().GetAttribute("width"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an
        /// <see cref="iText.Kernel.Pdf.Xobject.PdfFormXObject"/>
        /// tied to the passed
        /// <c>PdfDocument</c>
        /// using the SVG processing result.
        /// </summary>
        /// <param name="result">Processing result containing the SVG information</param>
        /// <param name="pdfDocument">pdf that shall contain the image</param>
        /// <returns>PdfFormXObject instance</returns>
        public virtual PdfFormXObject CreateXObjectFromProcessingResult(ISvgProcessorResult result, PdfDocument pdfDocument
                                                                        )
        {
            ISvgNodeRenderer topSvgRenderer = result.GetRootRenderer();
            float            width;
            float            height;

            float[] wh = SvgConverter.ExtractWidthAndHeight(topSvgRenderer);
            width  = wh[0];
            height = wh[1];
            PdfFormXObject   pdfForm      = new PdfFormXObject(new Rectangle(0, 0, width, height));
            PdfCanvas        canvas       = new PdfCanvas(pdfForm, pdfDocument);
            ResourceResolver tempResolver = new ResourceResolver(null, resourceResolver.GetRetriever());
            // TODO DEVSIX-4107 pass the resourceResolver variable (not tempResolver variable) to the
            //  SvgDrawContext constructor so that the SVG inside the SVG is processed.
            SvgDrawContext context = new SvgDrawContext(tempResolver, result.GetFontProvider(), result.GetRootRenderer
                                                            ());

            context.AddNamedObjects(result.GetNamedObjects());
            context.PushCanvas(canvas);
            ISvgNodeRenderer root = new PdfRootSvgNodeRenderer(topSvgRenderer);

            root.Draw(context);
            return(pdfForm);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create an
        /// <see cref="iText.Kernel.Pdf.Xobject.PdfFormXObject"/>
        /// tied to the passed
        /// <c>PdfDocument</c>
        /// using the SVG processing result.
        /// </summary>
        /// <param name="result">Processing result containing the SVG information</param>
        /// <param name="pdfDocument">pdf that shall contain the image</param>
        /// <returns>PdfFormXObject instance</returns>
        public virtual PdfFormXObject CreateXObjectFromProcessingResult(ISvgProcessorResult result, PdfDocument pdfDocument
                                                                        )
        {
            ISvgNodeRenderer topSvgRenderer = result.GetRootRenderer();
            float            width;
            float            height;

            float[] wh = SvgConverter.ExtractWidthAndHeight(topSvgRenderer);
            width  = wh[0];
            height = wh[1];
            PdfFormXObject pdfForm = new PdfFormXObject(new Rectangle(0, 0, width, height));
            PdfCanvas      canvas  = new PdfCanvas(pdfForm, pdfDocument);
            SvgDrawContext context = new SvgDrawContext(null, result.GetFontProvider());

            context.AddNamedObjects(result.GetNamedObjects());
            context.PushCanvas(canvas);
            ISvgNodeRenderer root = new PdfRootSvgNodeRenderer(topSvgRenderer);

            root.Draw(context);
            return(pdfForm);
        }