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"); }; }
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")); }; }
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"); }; }
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")); }; }
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")); }; }
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"); }; }
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"); }; }
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(); }
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")); }; }
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")); }; }
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")); }; }
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"); }; }
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"); }; }
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"); }; }
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")); }; }
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)); }
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"); }; }
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")); }; }
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")); }; }
public string SvgString() { return(Svg.ToString()); }
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"); }; }
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")); }; }
public static Response AsSvg(this IResponseFormatter formatter, Svg svg) { return(formatter.AsText(svg.ToString(), "image/svg+xml")); }
public static Response AsSvg(this IResponseFormatter formatter, Svg svg) { return formatter.AsText(svg.ToString(), "image/svg+xml"); }
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"); }; }