Beispiel #1
0
        public override IPath GetPath()
        {
            PathBuilder pb = new PathBuilder();

            pb.AddBezier(P1, P2, P3);
            return(pb.Build().GenerateOutline(Width));
        }
Beispiel #2
0
        public static void isTest0()
        {
            System.IO.Directory.CreateDirectory("output");
            using (Image <Rgba32> img = new Image <Rgba32>(1500, 500))
            {
                PathBuilder pathBuilder = new PathBuilder();
                pathBuilder.SetOrigin(new PointF(500, 0));
                pathBuilder.AddBezier(new PointF(50, 450), new PointF(200, 50), new PointF(300, 50), new PointF(450, 450));
                // add more complex paths and shapes here.

                IPath path = pathBuilder.Build();

                // For production application we would recomend you create a FontCollection
                // singleton and manually install the ttf fonts yourself as using SystemFonts
                // can be expensive and you risk font existing or not existing on a deployment
                // by deployment basis.
                var font = SystemFonts.CreateFont("Arial", 39, FontStyle.Regular);

                string text = "Hello World Hello World Hello World Hello World Hello World";
                img.Mutate(ctx => ctx
                           .Fill(Rgba32.White)                                                     // white background image
                           .Draw(Rgba32.Gray, 3, path)                                             // draw the path so we can see what the text is supposed to be following
                           .DrawText(text, font, Rgba32.Black, path, new TextGraphicsOptions(true) // draw the text along the path wrapping at the end of the line
                {
                    WrapTextWidth = path.Length
                }));

                img.Save("output/wordart.png");
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            System.IO.Directory.CreateDirectory("output");
            using (Image <Rgba32> img = new Image <Rgba32>(1500, 500))
            {
                PathBuilder pathBuilder = new PathBuilder();
                pathBuilder.SetOrigin(new PointF(500, 0));
                pathBuilder.AddBezier(new PointF(50, 450), new PointF(200, 50), new PointF(300, 50), new PointF(450, 450));
                // add more complex paths and shapes here.

                IPath path = pathBuilder.Build();

                SixLabors.Fonts.FontCollection fontCollection = new FontCollection();
                SixLabors.Fonts.Font           carlitoFont    = fontCollection.Install(Directory.GetCurrentDirectory() + "/font/Carlito-Regular.ttf")
                                                                .CreateFont(14, FontStyle.Regular);

                string text = "Hello World Hello World Hello World Hello World Hello World";
                var    textGraphicsOptions = new TextGraphicsOptions(true) // draw the text along the path wrapping at the end of the line
                {
                    WrapTextWidth = path.Length
                };

                var point = new PointF(100, 100);
                img.Mutate(ctx => ctx
                           .Fill(Rgba32.White)         // white background image
                           .Draw(Rgba32.Gray, 3, path) // draw the path so we can see what the text is supposed to be following
                           .DrawText(textGraphicsOptions, text, carlitoFont, Rgba32.Black, point));

                img.Save("output/path.png");
            }
        }
        public void DrawPath(Point start, IList <IPathCommand> commands, double thickness, bool fill = false)
        {
            // Not supported
            var builder = new PathBuilder();

            builder.SetOrigin(new PointF((float)start.X, (float)start.Y));
            builder.StartFigure();
            PointF currentPoint = new PointF();

            foreach (var c in commands)
            {
                switch (c)
                {
                case LineTo line:
                {
                    builder.AddLine(currentPoint, line.End.ToPointF());
                    break;
                }

                case CurveTo curve:
                {
                    builder.AddBezier(currentPoint, curve.ControlStart.ToPointF(), curve.ControlEnd.ToPointF(), curve.End.ToPointF());
                    break;
                }

                case MoveTo move:
                {
                    builder.StartFigure();
                    break;
                }

                case QuadraticBeizerCurveTo curve:
                {
                    builder.AddBezier(currentPoint, curve.Control.ToPointF(), curve.End.ToPointF());
                    break;
                }

                case ClosePath close:
                {
                    builder.CloseFigure();
                    break;
                }
                }
                currentPoint = c.End.ToPointF();
            }
            image.Mutate(ctx => ctx.Draw(Black, 2.0f, builder.Build()));
        }
        public void AddBezier()
        {
            var builder = new PathBuilder();

            builder.AddBezier(new Vector2(10, 10), new Vector2(20, 20), new Vector2(20, 30), new Vector2(10, 40));

            Assert.IsType <Path>(builder.Build());
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            System.IO.Directory.CreateDirectory("output");
            using (Image img = new Image <Rgba32>(1500, 500))
            {
                PathBuilder pathBuilder = new PathBuilder();
                pathBuilder.SetOrigin(new PointF(500, 0));
                pathBuilder.AddBezier(new PointF(50, 450), new PointF(200, 50), new PointF(300, 50), new PointF(450, 450));
                // add more complex paths and shapes here.

                IPath path = pathBuilder.Build();

                // For production application we would recomend you create a FontCollection
                // singleton and manually install the ttf fonts yourself as using SystemFonts
                // can be expensive and you risk font existing or not existing on a deployment
                // by deployment basis.
                var font = SystemFonts.CreateFont("Arial", 39, FontStyle.Regular);

                string text = "Hello World Hello World Hello World Hello World Hello World";
                var    textGraphicsOptions = new TextGraphicsOptions() // draw the text along the path wrapping at the end of the line
                {
                    TextOptions =
                    {
                        WrapTextWidth = path.Length
                    }
                };

                // lets generate the text as a set of vectors drawn along the path


                var glyphs = TextBuilder.GenerateGlyphs(text, path, new RendererOptions(font, textGraphicsOptions.TextOptions.DpiX, textGraphicsOptions.TextOptions.DpiY)
                {
                    HorizontalAlignment = textGraphicsOptions.TextOptions.HorizontalAlignment,
                    TabWidth            = textGraphicsOptions.TextOptions.TabWidth,
                    VerticalAlignment   = textGraphicsOptions.TextOptions.VerticalAlignment,
                    WrappingWidth       = textGraphicsOptions.TextOptions.WrapTextWidth,
                    ApplyKerning        = textGraphicsOptions.TextOptions.ApplyKerning
                });

                img.Mutate(ctx => ctx
                           .Fill(Color.White)         // white background image
                           .Draw(Color.Gray, 3, path) // draw the path so we can see what the text is supposed to be following
                           .Fill(Color.Black, glyphs));

                img.Save("output/wordart.png");
            }
        }
Beispiel #7
0
        /// <summary>
        /// takes in a parsed path and returns a list of points that can be used to draw the path
        /// </summary>
        /// <returns>The drawing points.</returns>
        /// <param name="segments">Segments.</param>
        public Vector2[] getDrawingPoints(List <SvgPathSegment> segments, float flatness = 3)
        {
            var path = new PathBuilder();

            for (var j = 0; j < segments.Count; j++)
            {
                var segment = segments[j];
                if (segment is SvgMoveToSegment)
                {
                    path.AddPoint(segment.start);
                }
                else if (segment is SvgCubicCurveSegment)
                {
                    var cubicSegment = segment as SvgCubicCurveSegment;

                    path.AddBezier(segment.start, cubicSegment.firstCtrlPoint, cubicSegment.secondCtrlPoint, segment.end);
                }
                else if (segment is SvgClosePathSegment)
                {
                    if (path.Count > 0 && !path.Buffer[0].Equals(path.Buffer[path.Count - 1]))
                    {
                        path.ClosePath();
                    }
                }
                else if (segment is SvgLineSegment)
                {
                    path.AddPoint(segment.start);
                    path.AddPoint(segment.end);
                }
                else if (segment is SvgQuadraticCurveSegment)
                {
                    var quadSegment = segment as SvgQuadraticCurveSegment;

                    var segmentArray = new Vector2[] { segment.end, quadSegment.secondCtrlPoint, quadSegment.firstCtrlPoint, segment.end };

                    path.AddBeziers(segmentArray, BezierType.Quadratic);
                }
                else
                {
                    Debug.warn("unknown type in getDrawingPoints");
                }
            }

            return(path.Buffer);
        }
        public void GradientsWithTransparencyOnExistingBackground <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            provider.VerifyOperation(
                image =>
            {
                image.Mutate(i => i.Fill(Color.Red));
                image.Mutate(ApplyGloss);
            });

            void ApplyGloss(IImageProcessingContext ctx)
            {
                Size            size            = ctx.GetCurrentSize();
                IPathCollection glossPath       = BuildGloss(size.Width, size.Height);
                var             graphicsOptions = new GraphicsOptions
                {
                    Antialias            = true,
                    ColorBlendingMode    = PixelColorBlendingMode.Normal,
                    AlphaCompositionMode = PixelAlphaCompositionMode.SrcAtop
                };
                var linearGradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, size.Height / 2), GradientRepetitionMode.Repeat, new ColorStop(0, Color.White.WithAlpha(0.5f)), new ColorStop(1, Color.White.WithAlpha(0.25f)));

                ctx.SetGraphicsOptions(graphicsOptions).Fill(linearGradientBrush, glossPath);
            }

            IPathCollection BuildGloss(int imageWidth, int imageHeight)
            {
                var pathBuilder = new PathBuilder();

                pathBuilder.AddLine(new PointF(0, 0), new PointF(imageWidth, 0));
                pathBuilder.AddLine(new PointF(imageWidth, 0), new PointF(imageWidth, imageHeight * 0.4f));
                pathBuilder.AddBezier(new PointF(imageWidth, imageHeight * 0.4f), new PointF(imageWidth / 2, imageHeight * 0.6f), new PointF(0, imageHeight * 0.4f));
                pathBuilder.CloseFigure();
                return(new PathCollection(pathBuilder.Build()));
            }
        }
Beispiel #9
0
 /// <summary>
 /// Draws a cubic bezier from the current point  to the <paramref name="point"/>
 /// </summary>
 /// <param name="secondControlPoint">The second control point.</param>
 /// <param name="thirdControlPoint">The third control point.</param>
 /// <param name="point">The point.</param>
 void IGlyphRenderer.CubicBezierTo(PointF secondControlPoint, PointF thirdControlPoint, PointF point)
 {
     Builder.AddBezier(_currentPoint, secondControlPoint, thirdControlPoint, point);
     _currentPoint = point;
 }
 void IGlyphRenderer.CubicBezierTo(Vector2 secondControlPoint, Vector2 thirdControlPoint, Vector2 point)
 {
     builder.AddBezier(currentPoint, secondControlPoint, thirdControlPoint, point);
     currentPoint = point;
 }