Exemplo n.º 1
1
        public LinesModule()
        {
            Get["/examples/w3schools/lines/1"] = _ =>
            {
                var svg = new Svg(500,210);

                svg
                    .Line(0, 0, 200, 200)
                    .WithStroke(255, 0, 0)
                    .WithStrokeWidth(2);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 2
0
        public PolylinesModule()
        {
            Get["/examples/w3schools/polylines/1"] = _ =>
            {
                var svg = new Svg(500, 200);

                svg
                .Polyline(20, 20, 40, 25, 60, 40, 80, 120, 120, 140, 200, 180)
                .WithFill("none")
                .WithStroke("black")
                .WithStrokeWidth(3);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polylines/2"] = _ =>
            {
                var svg = new Svg(500, 180);

                svg
                .Polyline(0, 40, 40, 40, 40, 80, 80, 80, 80, 120, 120, 120, 120, 160)
                .WithFill("white")
                .WithStroke("red")
                .WithStrokeWidth(4);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 3
0
        public PolylinesModule()
        {
            Get["/examples/w3schools/polylines/1"] = _ =>
            {
                var svg = new Svg(500,200);

                svg
                    .Polyline(20, 20, 40, 25, 60, 40, 80, 120, 120, 140, 200, 180)
                    .WithFill("none")
                    .WithStroke("black")
                    .WithStrokeWidth(3);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polylines/2"] = _ =>
            {
                var svg = new Svg(500,180);

                svg
                    .Polyline(0, 40, 40, 40, 40, 80, 80, 80, 80, 120, 120, 120, 120, 160)
                    .WithFill("white")
                    .WithStroke("red")
                    .WithStrokeWidth(4);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 4
0
        public RectanglesModule()
        {
            Get["/examples/w3schools/rectangles/1"] = _ =>
            {
                var svg = new Svg(400, 110);

                svg
                .Rectangle(0, 0, 300, 100)
                .WithFill(0, 0, 255)
                .WithStrokeWidth(3)
                .WithStroke(0, 0, 0);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/rectangles/2"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                .WithFill("blue")
                .WithStroke("pink")
                .WithStrokeWidth(5)
                .WithFillOpacity(0.1)
                .WithStrokeOpacity(0.9);

                return(Response.AsText(svg.ToString()).WithContentType("image/svg+xml"));
            };

            Get["/examples/w3schools/rectangles/3"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                .WithFill("blue")
                .WithStroke("pink")
                .WithStrokeWidth(5)
                .WithOpacity(0.5);

                return(Response.AsText(svg.ToString()).WithContentType("image/svg+xml"));
            };

            Get["/examples/w3schools/rectangles/4"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                .WithRoundedCorners(20, 20)
                .WithFill("red")
                .WithStroke("black")
                .WithStrokeWidth(5)
                .WithOpacity(0.5);

                return(Response.AsText(svg.ToString()).WithContentType("image/svg+xml"));
            };
        }
Exemplo n.º 5
0
        public PolygonsModule()
        {
            Get["/examples/w3schools/polygons/1"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Polygon(200, 10, 250, 190, 160, 210)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(1);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polygons/2"] = _ =>
            {
                var svg = new Svg(500, 250);

                svg
                .Polygon(220, 10, 300, 210, 170, 250, 123, 234)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(1);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polygons/3"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(5)
                .WithFillRule(FillRule.NonZero);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/polygons/4"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                .WithFill("lime")
                .WithStroke("purple")
                .WithStrokeWidth(5)
                .WithFillRule(FillRule.EvenOdd);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 6
0
        public RectanglesModule()
        {
            Get["/examples/w3schools/rectangles/1"] = _ =>
            {
                var svg = new Svg(400, 110);

                svg
                    .Rectangle(0, 0, 300, 100)
                    .WithFill(0, 0, 255)
                    .WithStrokeWidth(3)
                    .WithStroke(0, 0, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/rectangles/2"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                    .WithFill("blue")
                    .WithStroke("pink")
                    .WithStrokeWidth(5)
                    .WithFillOpacity(0.1)
                    .WithStrokeOpacity(0.9);

                return Response.AsText(svg.ToString()).WithContentType("image/svg+xml");
            };

            Get["/examples/w3schools/rectangles/3"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                    .WithFill("blue")
                    .WithStroke("pink")
                    .WithStrokeWidth(5)
                    .WithOpacity(0.5);

                return Response.AsText(svg.ToString()).WithContentType("image/svg+xml");
            };

            Get["/examples/w3schools/rectangles/4"] = _ =>
            {
                var svg = new Svg(400, 180);

                svg.Rectangle(50, 20, 150, 150)
                    .WithRoundedCorners(20, 20)
                    .WithFill("red")
                    .WithStroke("black")
                    .WithStrokeWidth(5)
                    .WithOpacity(0.5);

                return Response.AsText(svg.ToString()).WithContentType("image/svg+xml");
            };
        }
Exemplo n.º 7
0
        public PolygonsModule()
        {
            Get["/examples/w3schools/polygons/1"] = _ =>
            {
                var svg = new Svg(500,210);

                svg
                    .Polygon(200, 10, 250, 190, 160, 210)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(1);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polygons/2"] = _ =>
            {
                var svg = new Svg(500,250);

                svg
                    .Polygon(220, 10, 300, 210, 170, 250, 123, 234)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(1);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polygons/3"] = _ =>
            {
                var svg = new Svg(500,210);

                svg
                    .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(5)
                    .WithFillRule(FillRule.NonZero);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/polygons/4"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                    .Polygon(100, 10, 40, 198, 190, 78, 10, 78, 160, 198)
                    .WithFill("lime")
                    .WithStroke("purple")
                    .WithStrokeWidth(5)
                    .WithFillRule(FillRule.EvenOdd);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 8
0
        public void Blur_WithFiftyPercent_CanAddFilter()
        {
            var originalSvg = "<svg width=\"100\" height=\"200\"><rect width=\"90\" height=\"90\" fill=\"green\" /></svg>";
            var svgElement  = XElement.Parse(originalSvg);
            var svg         = new Svg(svgElement);

            svg.ApplyEffect(new Blur(50));

            var result = svg.ToString();
        }
Exemplo n.º 9
0
        public LinesModule()
        {
            Get["/examples/w3schools/lines/1"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Line(0, 0, 200, 200)
                .WithStroke(255, 0, 0)
                .WithStrokeWidth(2);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 10
0
        public TextModule()
        {
            Get["/examples/w3schools/text/1"] = _ =>
            {
                var svg = new Svg(200, 30);

                svg
                .Text(0, 15, "I love SVG!")
                .WithFill("red")
                .WithFontSize(12);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/text/2"] = _ => {
                var svg = new Svg(200, 60);

                svg
                .Text(0, 15, "I love SVG!")
                .WithFill("red")
                .WithFontSize(12)
                .WithTransformRotate(30, 20, 40);


                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/text/3"] = _ => {
                var svg = new Svg(200, 90);

                var text = svg
                           .Text(10, 20, "Several lines:")
                           .WithFill("red")
                           .WithFontSize(12);
                text.AddSpan(10, 45, "First line.");
                text.AddSpan(10, 70, "Second line.");


                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/text/4"] = _ => {
                var svg = new Svg(200, 30);

                var anchor = svg.Anchor("http://www.w3schools.com/svg", "_blank");
                anchor.Text(0, 15, "I love SVG!").WithFill("red");

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 11
0
        public CirclesModule()
        {
            Get["/examples/w3schools/circles/1"] = _ =>
            {
                var svg = new Svg(100, 100);

                svg
                .Circle(50, 50, 40)
                .WithStroke("black")
                .WithStrokeWidth(3)
                .WithFill("red");

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 12
0
        public CirclesModule()
        {
            Get["/examples/w3schools/circles/1"] = _ =>
            {
                var svg = new Svg(100, 100);

                svg
                    .Circle(50, 50, 40)
                    .WithStroke("black")
                    .WithStrokeWidth(3)
                    .WithFill("red");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 13
0
        public TextModule()
        {
            Get["/examples/w3schools/text/1"] = _ =>
            {
                var svg = new Svg(200, 30);

                svg
                    .Text(0, 15, "I love SVG!")
                    .WithFill("red")
                    .WithFontSize(12);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/text/2"] = _ => {
                var svg = new Svg(200, 60);

                svg
                    .Text(0, 15, "I love SVG!")
                    .WithFill("red")
                    .WithFontSize(12)
                    .WithTransformRotate(30, 20, 40);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/text/3"] = _ => {
                var svg = new Svg(200, 90);

                var text = svg
                    .Text(10, 20, "Several lines:")
                    .WithFill("red")
                    .WithFontSize(12);
                text.AddSpan(10, 45, "First line.");
                text.AddSpan(10, 70, "Second line.");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/text/4"] = _ => {
                var svg = new Svg(200,30);

                var anchor = svg.Anchor("http://www.w3schools.com/svg", "_blank");
                anchor.Text(0, 15, "I love SVG!").WithFill("red");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 14
0
        public BlurEffectsModule()
        {
            Get["/examples/w3schools/blur-effects/1"] = _ =>
            {
                var svg = new Svg(110, 110);

                var f1 = svg.Defs.AddFilter();
                f1.GaussianBlur(15, FilterInput.SourceGraphic);

                svg
                    .Rectangle(0, 0, 90, 90)
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("yellow")
                    .WithFilter(f1);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 15
0
        public BlurEffectsModule()
        {
            Get["/examples/w3schools/blur-effects/1"] = _ =>
            {
                var svg = new Svg(110, 110);

                var f1 = svg.Defs.AddFilter();
                f1.GaussianBlur(15, FilterInput.SourceGraphic);

                svg
                .Rectangle(0, 0, 90, 90)
                .WithStroke("green")
                .WithStrokeWidth(3)
                .WithFill("yellow")
                .WithFilter(f1);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 16
0
        public void Zoom_WithTwoHundredPercent_DoublesWidthAndHeightValues()
        {
            var originalWidth  = 100;
            var originalHeight = 150;

            var originalSvg = $"<svg width=\"{originalWidth}\" height=\"{originalHeight}\"></svg>";
            var svgElement  = XElement.Parse(originalSvg);
            var svg         = new Svg(svgElement);

            var zoom = new Zoom(2);

            zoom.Apply(svg);

            var modifiedSvg = svg.ToString();

            var expectedSvg = new Svg(
                XElement.Parse($"<svg width=\"{originalWidth * zoom.Percentage}\" height=\"{originalHeight * zoom.Percentage}\"></svg>"))
                              .ToString();

            Assert.Equal(new MinifiedString(expectedSvg), new MinifiedString(modifiedSvg));
        }
Exemplo n.º 17
0
        public EllipsesModule()
        {
            Get["/examples/w3schools/ellipses/1"] = _ =>
            {
                var svg = new Svg(500, 140);

                svg
                    .Ellipse(200, 80, 100, 50)
                    .WithFill("yellow")
                    .WithStroke("purple")
                    .WithStrokeWidth(2);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/ellipses/2"] = _ =>
            {
                var svg = new Svg(500, 150);

                svg.Ellipse(240, 100, 220, 30).WithFill("purple");
                svg.Ellipse(220, 70, 190, 20).WithFill("lime");
                svg.Ellipse(210, 45, 170, 15).WithFill("yellow");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/ellipses/3"] = _ =>
            {
                var svg = new Svg(500, 150);

                svg.Ellipse(250, 50, 220, 30).WithFill("yellow");
                svg.Ellipse(220, 50, 190, 20).WithFill("white");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 18
0
        public EllipsesModule()
        {
            Get["/examples/w3schools/ellipses/1"] = _ =>
            {
                var svg = new Svg(500, 140);

                svg
                .Ellipse(200, 80, 100, 50)
                .WithFill("yellow")
                .WithStroke("purple")
                .WithStrokeWidth(2);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/ellipses/2"] = _ =>
            {
                var svg = new Svg(500, 150);

                svg.Ellipse(240, 100, 220, 30).WithFill("purple");
                svg.Ellipse(220, 70, 190, 20).WithFill("lime");
                svg.Ellipse(210, 45, 170, 15).WithFill("yellow");

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/ellipses/3"] = _ =>
            {
                var svg = new Svg(500, 150);

                svg.Ellipse(250, 50, 220, 30).WithFill("yellow");
                svg.Ellipse(220, 50, 190, 20).WithFill("white");

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 19
0
        public StrokingModule()
        {
            Get["/examples/w3schools/stroking/1"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                            .Group()
                            .WithFill("none");
                group
                .Path()
                .WithStroke("red")
                .MoveTo(5, 20)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStroke("blue")
                .MoveTo(5, 40)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStroke("black")
                .MoveTo(5, 60)
                .LineToRelative(215, 0);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/stroking/2"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                            .Group()
                            .WithFill("none")
                            .WithStroke("black");
                group
                .Path()
                .WithStrokeWidth(2)
                .MoveTo(5, 20)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStrokeWidth(4)
                .MoveTo(5, 40)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStrokeWidth(6)
                .MoveTo(5, 60)
                .LineToRelative(215, 0);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/stroking/3"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                            .Group()
                            .WithFill("none")
                            .WithStroke("black")
                            .WithStrokeWidth(6);
                group
                .Path()
                .WithStrokeLinecap(StrokeLinecap.Butt)
                .MoveTo(5, 20)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStrokeLinecap(StrokeLinecap.Round)
                .MoveTo(5, 40)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStrokeLinecap(StrokeLinecap.Square)
                .MoveTo(5, 60)
                .LineToRelative(215, 0);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/stroking/4"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                            .Group()
                            .WithFill("none")
                            .WithStroke("black")
                            .WithStrokeWidth(4);
                group
                .Path()
                .WithStrokeDasharray(5, 5)
                .MoveTo(5, 20)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStrokeDasharray(10, 10)
                .MoveTo(5, 40)
                .LineToRelative(215, 0);
                group
                .Path()
                .WithStrokeDasharray(20, 10, 5, 5, 5, 10)
                .MoveTo(5, 60)
                .LineToRelative(215, 0);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 20
0
 public string SvgString()
 {
     return(Svg.ToString());
 }
Exemplo n.º 21
0
        public PathsModule()
        {
            Get["/examples/w3schools/paths/1"] = _ =>
            {
                var svg = new Svg(400, 210);

                svg.Path()
                    .MoveTo(150, 0)
                    .LineTo(75, 200)
                    .LineTo(225, 200)
                    .ClosePath();

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/paths/2"] = _ =>
            {
                var svg = new Svg(450, 400);

                svg.Path()
                    .MoveTo(100, 350)
                    .LineToRelative(150, -300)
                    .ClosePath()
                    .WithStroke("red")
                    .WithStrokeWidth(3)
                    .WithFill("none");
                svg.Path()
                    .MoveTo(250, 50)
                    .LineToRelative(150, 300)
                    .ClosePath()
                    .WithStroke("red")
                    .WithStrokeWidth(3)
                    .WithFill("none");
                svg.Path()
                    .MoveTo(175, 200)
                    .LineToRelative(150, 0)
                    .ClosePath()
                    .WithStroke("green")
                    .WithStrokeWidth(3)
                    .WithFill("none");

                svg.Path()
                    .MoveTo(100, 350)
                    .QuadraticBezierRelative(150, -300, 300, 000)
                    .WithStroke("blue")
                    .WithStrokeWidth(5)
                    .WithFill("none");

                // Mark relevant points
                var relevantPoints = svg.Group()
                    .WithStrokeWidth(3)
                    .WithFill("black");
                relevantPoints.Circle(100, 350, 3);
                relevantPoints.Circle(250, 50, 3);
                relevantPoints.Circle(400, 350, 3);

                // Label the points
                var labels = svg.Group()
                    .WithFontSize(30)
                    .WithFontFamily("sans-serif")
                    .WithFill("black")
                    .WithStroke("none")
                    .WithTextAnchor(TextAnchor.Middle);
                labels.Text(100, 350, "A").WithDx(-30);
                labels.Text(250, 50, "B").WithDy(-10);
                labels.Text(400, 350, "C").WithDx(30);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemplo n.º 22
0
        public PathsModule()
        {
            Get["/examples/w3schools/paths/1"] = _ =>
            {
                var svg = new Svg(400, 210);

                svg.Path()
                .MoveTo(150, 0)
                .LineTo(75, 200)
                .LineTo(225, 200)
                .ClosePath();

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };

            Get["/examples/w3schools/paths/2"] = _ =>
            {
                var svg = new Svg(450, 400);

                svg.Path()
                .MoveTo(100, 350)
                .LineToRelative(150, -300)
                .ClosePath()
                .WithStroke("red")
                .WithStrokeWidth(3)
                .WithFill("none");
                svg.Path()
                .MoveTo(250, 50)
                .LineToRelative(150, 300)
                .ClosePath()
                .WithStroke("red")
                .WithStrokeWidth(3)
                .WithFill("none");
                svg.Path()
                .MoveTo(175, 200)
                .LineToRelative(150, 0)
                .ClosePath()
                .WithStroke("green")
                .WithStrokeWidth(3)
                .WithFill("none");

                svg.Path()
                .MoveTo(100, 350)
                .QuadraticBezierRelative(150, -300, 300, 000)
                .WithStroke("blue")
                .WithStrokeWidth(5)
                .WithFill("none");

                // Mark relevant points
                var relevantPoints = svg.Group()
                                     .WithStrokeWidth(3)
                                     .WithFill("black");
                relevantPoints.Circle(100, 350, 3);
                relevantPoints.Circle(250, 50, 3);
                relevantPoints.Circle(400, 350, 3);

                // Label the points
                var labels = svg.Group()
                             .WithFontSize(30)
                             .WithFontFamily("sans-serif")
                             .WithFill("black")
                             .WithStroke("none")
                             .WithTextAnchor(TextAnchor.Middle);
                labels.Text(100, 350, "A").WithDx(-30);
                labels.Text(250, 50, "B").WithDy(-10);
                labels.Text(400, 350, "C").WithDx(30);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemplo n.º 23
0
 public static Response AsSvg(this IResponseFormatter formatter, Svg svg)
 {
     return(formatter.AsText(svg.ToString(), "image/svg+xml"));
 }
Exemplo n.º 24
0
 public static Response AsSvg(this IResponseFormatter formatter, Svg svg)
 {
     return formatter.AsText(svg.ToString(), "image/svg+xml");
 }
Exemplo n.º 25
0
        public StrokingModule()
        {
            Get["/examples/w3schools/stroking/1"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none");
                group
                    .Path()
                    .WithStroke("red")
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStroke("blue")
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStroke("black")
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/stroking/2"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none")
                    .WithStroke("black");
                group
                    .Path()
                    .WithStrokeWidth(2)
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeWidth(4)
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeWidth(6)
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/stroking/3"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none")
                    .WithStroke("black")
                    .WithStrokeWidth(6);
                group
                    .Path()
                    .WithStrokeLinecap(StrokeLinecap.Butt)
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeLinecap(StrokeLinecap.Round)
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeLinecap(StrokeLinecap.Square)
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };

            Get["/examples/w3schools/stroking/4"] = _ =>
            {
                var svg = new Svg(300, 80);

                var group = svg
                    .Group()
                    .WithFill("none")
                    .WithStroke("black")
                    .WithStrokeWidth(4);
                group
                    .Path()
                    .WithStrokeDasharray(5, 5)
                    .MoveTo(5, 20)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeDasharray(10,10)
                    .MoveTo(5, 40)
                    .LineToRelative(215, 0);
                group
                    .Path()
                    .WithStrokeDasharray(20,10,5,5,5,10)
                    .MoveTo(5, 60)
                    .LineToRelative(215, 0);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }