示例#1
0
        public virtual void CalculateNestedViewportDifferentFromParentTest()
        {
            Rectangle      expected = new Rectangle(0, 0, 500, 500);
            SvgDrawContext context  = new SvgDrawContext(null, null);
            PdfDocument    document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
                                                                        (0)));

            document.AddNewPage();
            PdfFormXObject pdfForm = new PdfFormXObject(expected);
            PdfCanvas      canvas  = new PdfCanvas(pdfForm, document);

            context.PushCanvas(canvas);
            context.AddViewPort(expected);
            SvgTagSvgNodeRenderer        parent   = new SvgTagSvgNodeRenderer();
            SvgTagSvgNodeRenderer        renderer = new SvgTagSvgNodeRenderer();
            PdfRootSvgNodeRenderer       root     = new PdfRootSvgNodeRenderer(parent);
            IDictionary <String, String> styles   = new Dictionary <String, String>();

            styles.Put("width", "500");
            styles.Put("height", "500");
            renderer.SetAttributesAndStyles(styles);
            renderer.SetParent(parent);
            Rectangle actual = root.CalculateViewPort(context);

            NUnit.Framework.Assert.IsTrue(expected.EqualsWithEpsilon(actual));
        }
        public virtual void Draw(SvgDrawContext context)
        {
            //Set viewport and transformation for pdf-context
            context.AddViewPort(this.CalculateViewPort(context));
            PdfCanvas currentCanvas = context.GetCurrentCanvas();

            currentCanvas.ConcatMatrix(this.CalculateTransformation(context));
            currentCanvas.WriteLiteral("% svg root\n");
            subTreeRoot.Draw(context);
        }
        internal override void PreDraw(SvgDrawContext context)
        {
            base.PreDraw(context);
            float[]   markerWidthHeight = GetMarkerWidthHeightValues();
            float     markerWidth       = markerWidthHeight[0];
            float     markerHeight      = markerWidthHeight[1];
            Rectangle markerViewport    = new Rectangle(CssUtils.ParseAbsoluteLength(this.GetAttribute(SvgConstants.Attributes
                                                                                                       .X)), CssUtils.ParseAbsoluteLength(this.GetAttribute(SvgConstants.Attributes.Y)), markerWidth, markerHeight
                                                        );

            context.AddViewPort(markerViewport);
        }
示例#4
0
        internal override void PreDraw(SvgDrawContext context)
        {
            base.PreDraw(context);
            float[] markerWidthHeight = GetMarkerWidthHeightValues();
            float   markerWidth       = markerWidthHeight[0];
            float   markerHeight      = markerWidthHeight[1];
            String  xAttribute        = this.GetAttribute(SvgConstants.Attributes.X);
            String  yAttribute        = this.GetAttribute(SvgConstants.Attributes.Y);
            float   x = xAttribute != null?CssUtils.ParseAbsoluteLength(xAttribute) : 0f;

            float y = yAttribute != null?CssUtils.ParseAbsoluteLength(yAttribute) : 0f;

            Rectangle markerViewport = new Rectangle(x, y, markerWidth, markerHeight);

            context.AddViewPort(markerViewport);
        }
        private void ProcessAspectRatioPositionAndCompare(String alignValue, AffineTransform cmpTransform)
        {
            SvgDrawContext context = new SvgDrawContext(null, null);

            // topmost viewport has default page size values for bounding rectangle
            context.AddViewPort(VIEWPORT_VALUE);
            float[] viewboxValues = VIEWBOX_VALUES;
            float   scaleWidth    = 1.0f;
            float   scaleHeight   = 1.0f;
            AbstractBranchSvgNodeRenderer renderer            = new SvgTagSvgNodeRenderer();
            IDictionary <String, String>  attributesAndStyles = new Dictionary <String, String>();

            renderer.SetAttributesAndStyles(attributesAndStyles);
            AffineTransform outTransform = renderer.ProcessAspectRatioPosition(context, viewboxValues, alignValue, scaleWidth
                                                                               , scaleHeight);

            NUnit.Framework.Assert.IsTrue(cmpTransform.Equals(outTransform));
        }
示例#6
0
        public virtual void CalculateOutermostTransformation()
        {
            AffineTransform expected = new AffineTransform(1d, 0d, 0d, -1d, 0d, 600d);
            SvgDrawContext  context  = new SvgDrawContext(null, null);
            PdfDocument     document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
                                                                         (0)));

            document.AddNewPage();
            PdfFormXObject pdfForm = new PdfFormXObject(new Rectangle(0, 0, 600, 600));
            PdfCanvas      canvas  = new PdfCanvas(pdfForm, document);

            context.PushCanvas(canvas);
            SvgTagSvgNodeRenderer  renderer = new SvgTagSvgNodeRenderer();
            PdfRootSvgNodeRenderer root     = new PdfRootSvgNodeRenderer(renderer);

            context.AddViewPort(root.CalculateViewPort(context));
            AffineTransform actual = root.CalculateTransformation(context);

            NUnit.Framework.Assert.AreEqual(expected, actual);
        }
        public virtual void CalculateNestedViewportSameAsParentTest()
        {
            Rectangle      expected = new Rectangle(0, 0, 600, 600);
            SvgDrawContext context  = new SvgDrawContext(null, null);
            PdfDocument    document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
                                                                        (0)));

            document.AddNewPage();
            PdfFormXObject pdfForm = new PdfFormXObject(expected);
            PdfCanvas      canvas  = new PdfCanvas(pdfForm, document);

            context.PushCanvas(canvas);
            context.AddViewPort(expected);
            SvgTagSvgNodeRenderer parent   = new SvgTagSvgNodeRenderer();
            SvgTagSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();

            renderer.SetParent(parent);
            Rectangle actual = renderer.CalculateViewPort(context);

            NUnit.Framework.Assert.IsTrue(expected.EqualsWithEpsilon(actual));
        }
示例#8
0
 protected internal override void DoDraw(SvgDrawContext context)
 {
     context.AddViewPort(this.CalculateViewPort(context));
     base.DoDraw(context);
 }