public void AddAlignmentLines()
        {
            SvgGroupElement alinmentLinesGroup = new SvgGroupElement("AlignmentLines");

            alinmentLinesGroup.Style = s_AlignmentLineStyle;

            SvgLineElement line1 = new SvgLineElement(
                GetSvgLength(this.Origin.X), GetSvgLength(0),
                GetSvgLength(this.Origin.X), GetSvgLength(this.Page.Width));

            alinmentLinesGroup.AddChild(line1);

            SvgLineElement line2 = new SvgLineElement(
                GetSvgLength(0), GetSvgLength(this.Origin.Y),
                GetSvgLength(this.Page.Width), GetSvgLength(this.Origin.Y));

            alinmentLinesGroup.AddChild(line2);

            float             radius       = 65;
            SvgEllipseElement cutOutCircle = new SvgEllipseElement(
                GetSvgLength(this.Origin.X), GetSvgLength(this.Origin.Y),
                GetSvgLength(radius), GetSvgLength(radius));

            alinmentLinesGroup.AddChild(cutOutCircle);

            this.Root.AddChild(alinmentLinesGroup);
        }
        public Geometry CreateGeometry(SvgEllipseElement element)
        {
            double _cx = Math.Round(element.Cx.AnimVal.Value, 4);
            double _cy = Math.Round(element.Cy.AnimVal.Value, 4);
            double _rx = Math.Round(element.Rx.AnimVal.Value, 4);
            double _ry = Math.Round(element.Ry.AnimVal.Value, 4);

            if (_rx <= 0 || _ry <= 0)
            {
                return(null);
            }

            /*if (_cx <= 1 && _cy <= 1 && _rx <= 1 && _ry <= 1)
             * {
             *  gp.AddEllipse(_cx-_rx, _cy-_ry, _rx*2, _ry*2);
             * }
             * else
             * {
             *  gp.AddEllipse(_cx-_rx, _cy-_ry, _rx*2 - 1, _ry*2 - 1);
             * }*/
            //gp.AddEllipse(_cx - _rx, _cy - _ry, _rx * 2, _ry * 2);

            EllipseGeometry geometry = new EllipseGeometry(new Point(_cx, _cy),
                                                           _rx, _ry);

            return(geometry);
        }
        private void AddCenteredCircle(SvgGroupElement group, float radius)
        {
            SvgEllipseElement circleElement = new SvgEllipseElement(
                0, 0,
                radius, radius);

            group.AddChild(circleElement);
        }
Exemple #4
0
        internal static SvgEllipseElement CreateCenteredCircle(double radius, SvgStyle style)
        {
            SvgEllipseElement circleElement = new SvgEllipseElement(
                0, 0,
                (float)radius, (float)radius);

            circleElement.Style = style;
            return(circleElement);
        }
        public override SvgPathSegList VisitEllipseElement(SvgEllipseElement element)
        {
            var cx = element.Cx?.Value ?? 0;
            var cy = element.Cy?.Value ?? 0;
            var rx = element.Rx?.Value ?? 0;
            var ry = element.Ry?.Value ?? 0;

            return(CreateEllipsePaths(cx, cy, ry, rx));
        }
Exemple #6
0
        protected override void RenderEllipse(CanvasDrawingSession session, SvgEllipseElement element)
        {
            var centerX = this.LengthConverter.ConvertX(element.CenterX);
            var centerY = this.LengthConverter.ConvertY(element.CenterY);
            var radiusX = this.LengthConverter.ConvertX(element.RadiusX);
            var radiusY = this.LengthConverter.ConvertY(element.RadiusY);

            using (var geometry = CanvasGeometry.CreateEllipse(this.ResourceCreator, centerX, centerY, radiusX, radiusY))
            {
                this.RenderGeometory(session, geometry, element.Transform.Result, element.Style);
            }
        }
Exemple #7
0
        public static SvgEllipseElement CreateCircle(Point center, double radius, SvgStyle style)
        {
            SvgEllipseElement circleElement = new SvgEllipseElement(
                center.X, center.Y,
                radius, radius);

            if (style != null)
            {
                circleElement.Style = style;
            }
            return(circleElement);
        }
        private IEnumerable <SvgStyledTransformedElement> GetCircles(float distance)
        {
            float maxRadius = (float)Math.Sqrt(this.Page.Width * this.Page.Width / 4 + (this.Page.Height - this.Origin.Y) * (this.Page.Height - this.Origin.Y));
            int   count     = (int)(maxRadius / distance);

            for (int i = 0; i <= count; i++)
            {
                float             radius        = i * distance;
                SvgEllipseElement circleElement = new SvgEllipseElement(
                    GetSvgLength(this.Origin.X), GetSvgLength(this.Origin.Y),
                    GetSvgLength(radius), GetSvgLength(radius));

                yield return(circleElement);
            }
        }
        public static GraphicsPath CreatePath(SvgEllipseElement element)
        {
            GraphicsPath gp  = new GraphicsPath();
            float        _cx = (float)element.Cx.AnimVal.Value;
            float        _cy = (float)element.Cy.AnimVal.Value;
            float        _rx = (float)element.Rx.AnimVal.Value;
            float        _ry = (float)element.Ry.AnimVal.Value;

            if (_rx <= 0 || _ry <= 0)
            {
                return(null);
            }

            gp.AddEllipse(_cx - _rx, _cy - _ry, _rx * 2, _ry * 2);

            return(gp);
        }
Exemple #10
0
        public Geometry CreateGeometry(SvgEllipseElement element)
        {
            double _cx = Math.Round(element.Cx.AnimVal.Value, 4);
            double _cy = Math.Round(element.Cy.AnimVal.Value, 4);
            double _rx = Math.Round(element.Rx.AnimVal.Value, 4);
            double _ry = Math.Round(element.Ry.AnimVal.Value, 4);

            if (_rx <= 0 || _ry <= 0)
            {
                return(null);
            }

            EllipseGeometry geometry = new EllipseGeometry(new Point(_cx, _cy),
                                                           _rx, _ry);

            return(geometry);
        }
Exemple #11
0
        public static GraphicsPath CreatePath(SvgEllipseElement element)
        {
            GraphicsPath gp  = new GraphicsPath();
            float        _cx = (float)element.Cx.AnimVal.Value;
            float        _cy = (float)element.Cy.AnimVal.Value;
            float        _rx = (float)element.Rx.AnimVal.Value;
            float        _ry = (float)element.Ry.AnimVal.Value;

            /*if (_cx <= 1 && _cy <= 1 && _rx <= 1 && _ry <= 1)
             * {
             *  gp.AddEllipse(_cx-_rx, _cy-_ry, _rx*2, _ry*2);
             * }
             * else
             * {
             *  gp.AddEllipse(_cx-_rx, _cy-_ry, _rx*2 - 1, _ry*2 - 1);
             * }*/
            gp.AddEllipse(_cx - _rx, _cy - _ry, _rx * 2, _ry * 2);

            return(gp);
        }
Exemple #12
0
        public Geometry CreateGeometry(SvgEllipseElement element)
        {
            double _cx = Math.Round(element.Cx.AnimVal.Value, 4);
            double _cy = Math.Round(element.Cy.AnimVal.Value, 4);
            double _rx = Math.Round(element.Rx.AnimVal.Value, 4);
            double _ry = Math.Round(element.Ry.AnimVal.Value, 4);

            // New in SVG 2. The auto value for rx and ry was added to allow consistent parsing of these properties for both ellipses and rectangles.
            // Previously, if either rx or ry was unspecified, the ellipse would not render.
            double r = Math.Max(_rx, _ry);

            if (_rx <= 0 || _ry <= 0)
            {
                if (r <= 0)
                {
                    return(null);
                }
                else
                {
                    if (_rx <= 0 && !element.HasAttribute("rx"))
                    {
                        _rx = r;
                    }
                    else if (_ry <= 0 && !element.HasAttribute("ry"))
                    {
                        _ry = r;
                    }
                }
                if (_rx <= 0 || _ry <= 0)
                {
                    return(null);
                }
            }

            EllipseGeometry geometry = new EllipseGeometry(new Point(_cx, _cy), _rx, _ry);

            return(geometry);
        }
Exemple #13
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            var root = new SvgSvgElement("4in", "4in", "-10,-10 250,250");

            //adding multiple children

            root.AddChildren(
                new SvgRectElement(5, 5, 5, 5),
                new SvgEllipseElement(20, 20, 8, 12)
            {
                Style = "fill:yellow;stroke:red"
            },

                new SvgAElement("https://github.com/managed-commons/SvgNet").AddChildren(
                    new SvgTextElement("Textastic!", 30, 20)
            {
                Style = "fill:midnightblue;stroke:navy;stroke-width:1px;font-size:30px;font-family:Calibri"
            })
                );

            //group and path

            var grp = new SvgGroupElement("green_group")
            {
                Style = "fill:green;stroke:black;"
            };

            grp.AddChild(new SvgRectElement(30, 30, 5, 20));

            var ell = new SvgEllipseElement
            {
                CX = 50,
                CY = 50,
                RX = 10,
                RY = 20
            };

            var pathy = new SvgPathElement
            {
                D     = "M 20,80 C 20,90 30,80 70,100 C 70,100 40,60 50,60 z",
                Style = ell.Style
            };

            root.AddChild(grp);

            //cloning and style arithmetic

            grp.AddChildren(ell, pathy);

            grp.Style.Set("fill", "blue");

            var grp2 = (SvgGroupElement)SvgFactory.CloneElement(grp);

            grp2.Id = "cloned_red_group";

            grp2.Style.Set("fill", "red");

            grp2.Style += "opacity:0.5";

            grp2.Transform = "scale (1.2, 1.2)  translate(10)";

            root.AddChild(grp2);

            //output

            string s = root.WriteSVGString(true);

            tbOut.Text = s;

            string tempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");

            using (var tw = new StreamWriter(tempFile, false))
                tw.Write(s);

            svgOut.Navigate(new Uri(tempFile));
            svgOut.Refresh(WebBrowserRefreshOption.Completely);
        }
Exemple #14
0
 protected abstract void RenderEllipse(TSession session, SvgEllipseElement element);
Exemple #15
0
 public override void VisitEllipseElement(SvgEllipseElement element)
 {
     this.RenderShapeToCanvas(element, new EllipsePolygon(element.Cx.Value.Value, element.Cy.Value.Value, element.Rx.Value.Value * 2, element.Ry.Value.Value * 2));
 }
Exemple #16
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            SvgSvgElement root = new SvgSvgElement("4in", "4in", "0,0 100,100");

            //adding multiple children

            root.AddChildren(
                new SvgRectElement(5, 5, 5, 5),
                new SvgEllipseElement(30, 10, 8, 12),
                new SvgTextElement("Textastic!", 3, 20)
                );

            //group and path

            SvgGroupElement grp = new SvgGroupElement("green_group")
            {
                Style = "fill:green;stroke:black;"
            };

            SvgEllipseElement ell = new SvgEllipseElement {
                CX = 50,
                CY = 50,
                RX = 10,
                RY = 20
            };

            SvgPathElement pathy = new SvgPathElement {
                D     = "M 20,80 C 20,90 30,80 70,100 C 70,100 40,60 50,60 z",
                Style = ell.Style
            };

            root.AddChild(grp);

            //cloning and style arithmetic

            grp.AddChildren(ell, pathy);

            grp.Style.Set("fill", "blue");

            SvgGroupElement grp2 = (SvgGroupElement)SvgFactory.CloneElement(grp);

            grp2.Id = "cloned_red_group";

            grp2.Style.Set("fill", "red");

            grp2.Style += "opacity:0.5";

            grp2.Transform = "scale (1.2, 1.2)  translate(10)";

            root.AddChild(grp2);

            //output

            string s = root.WriteSVGString(true);

            tbOut.Text = s;

            string tempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");

            StreamWriter tw = new StreamWriter(tempFile, false);

            tw.Write(s);

            tw.Close();

            svgOut.Navigate(new Uri(tempFile));
            svgOut.Refresh(WebBrowserRefreshOption.Completely);
        }
Exemple #17
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            SvgSvgElement root = new SvgSvgElement("4in", "4in", "0,0 100,100");


            //adding multiple children

            root.AddChildren(
                new SvgRectElement(5, 5, 5, 5),
                new SvgEllipseElement(30, 10, 8, 12),
                new SvgTextElement("Textastic!", 3, 20)
                );


            //group and path

            SvgGroupElement grp = new SvgGroupElement("green_group");

            grp.Style = "fill:green;stroke:black;";

            SvgEllipseElement ell = new SvgEllipseElement();

            ell.CX = 50;
            ell.CY = 50;
            ell.RX = 10;
            ell.RY = 20;

            SvgPathElement pathy = new SvgPathElement();

            pathy.D     = "M 20,80 C 20,90 30,80 70,100 C 70,100 40,60 50,60 z";
            pathy.Style = ell.Style;

            root.AddChild(grp);


            //cloning and style arithmetic

            grp.AddChildren(ell, pathy);

            grp.Style.Set("fill", "blue");

            SvgGroupElement grp2 = (SvgGroupElement)SvgFactory.CloneElement(grp);

            grp2.Id = "cloned_red_group";

            grp2.Style.Set("fill", "red");

            grp2.Style += "opacity:0.5";

            grp2.Transform = "scale (1.2, 1.2)  translate(10)";

            root.AddChild(grp2);


            //output

            string s = root.WriteSVGString(true);

            tbOut.Text = s;

            StreamWriter tw = new StreamWriter("c:\\temp\\foo.svg", false);

            tw.Write(s);

            tw.Close();

            svgOut.SRC = "c:\\temp\\foo.svg";
        }
 public virtual void VisitEllipseElement(SvgEllipseElement element)
 => DefaultVisit(element);
 public override void VisitEllipseElement(SvgEllipseElement element)
 => VisitPathSegList(element, element.ConvertToPathSegList());