Esempio n. 1
0
        /// <summary>
        /// Creates a <see cref="StreamGeometry"/> from a string.
        /// </summary>
        /// <param name="s">The string.</param>
        /// <returns>A <see cref="StreamGeometry"/>.</returns>
        public static StreamGeometry Parse(string s)
        {
            StreamGeometry result = new StreamGeometry();

            using (StreamGeometryContext ctx = result.Open())
            {
                PathMarkupParser parser = new PathMarkupParser(result, ctx);
                parser.Parse(s);
                return result;
            }
        }
Esempio n. 2
0
        public Form1()
        {
            InitializeComponent();

            _render = new PlatformRenderInterface();
            PerspexLocator.CurrentMutable.Bind<IPlatformRenderInterface>().ToConstant(_render);
            _geometry =  new StreamGeometry();
            _rbitmap = new RenderTargetBitmap(50, 50);
            _renderTarget = _render.CreateRenderer(new PlatformHandle(Handle, "HWND"), ClientSize.Width,
                ClientSize.Height);
            var timer = new Timer() {Interval = 20};
            timer.Tick += delegate { Invalidate(); };
            timer.Start();
            components.Add(timer);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            using (var ctx = _geometry.Open())
            {
                ctx.BeginFigure(new Point(10,10), true);
                ctx.LineTo(new Point(40,25));
                ctx.BezierTo(new Point(50, 45), new Point(43, 48), new Point(20, 90));
                ctx.LineTo(new Point(10, 60));
                ctx.EndFigure(true);
            }

            _text =
                new FormattedText(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
                    "Arial", 25, FontStyle.Normal, TextAlignment.Left, FontWeight.Normal);

            _text.Constraint = new Size(400, double.PositiveInfinity);

            using (var ctx = _rbitmap.CreateDrawingContext())
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Aqua)), new Rect(10, 10, 30, 30), 5);

            _bitmap = new Bitmap(@"C:\Users\keks\Desktop\phoenix.png");
        }
Esempio n. 3
0
        public override void DrawPolygon(RBrush brush, RPoint[] points)
        {
            if (points != null && points.Length > 0)
            {
                var g = new StreamGeometry();
                using (var context = g.Open())
                {
                    context.BeginFigure(Util.Convert(points[0]), true);
                    for (int i = 1; i < points.Length; i++)
                        context.LineTo(Util.Convert(points[i]));
                    context.EndFigure(false);
                }

                _g.DrawGeometry(((BrushAdapter)brush).Brush, null, g);
            }
        }
Esempio n. 4
0
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     this.geometry = geometry;
     this.context  = context;
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PathMarkupParser"/> class.
 /// </summary>
 /// <param name="geometry">The geometry in which the path should be stored.</param>
 /// <param name="context">The context for <paramref name="geometry"/>.</param>
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     _geometry = geometry;
     _context  = context;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xpg"></param>
        /// <returns></returns>
        public static StreamGeometry ToStreamGeometry(this XPathGeometry xpg)
        {
            var sg = new StreamGeometry();
            var sgc = sg.Open();

            var previous = default(XPoint);

            foreach (var xpf in xpg.Figures)
            {
                sgc.BeginFigure(
                    new Point(xpf.StartPoint.X, xpf.StartPoint.Y),
                    xpf.IsFilled);

                previous = xpf.StartPoint;

                foreach (var segment in xpf.Segments)
                {
                    if (segment is XArcSegment)
                    {
                        var arcSegment = segment as XArcSegment;
                        sgc.ArcTo(
                            new Point(arcSegment.Point.X, arcSegment.Point.Y),
                            new Size(arcSegment.Size.Width, arcSegment.Size.Height),
                            arcSegment.RotationAngle,
                            arcSegment.IsLargeArc,
                            arcSegment.SweepDirection == XSweepDirection.Clockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise);

                        previous = arcSegment.Point;
                    }
                    else if (segment is XBezierSegment)
                    {
                        var bezierSegment = segment as XBezierSegment;
                        sgc.BezierTo(
                            new Point(bezierSegment.Point1.X, bezierSegment.Point1.Y),
                            new Point(bezierSegment.Point2.X, bezierSegment.Point2.Y),
                            new Point(bezierSegment.Point3.X, bezierSegment.Point3.Y));

                        previous = bezierSegment.Point3;
                    }
                    else if (segment is XLineSegment)
                    {
                        var lineSegment = segment as XLineSegment;
                        sgc.LineTo(
                            new Point(lineSegment.Point.X, lineSegment.Point.Y));

                        previous = lineSegment.Point;
                    }
                    else if (segment is XPolyBezierSegment)
                    {
                        var polyBezierSegment = segment as XPolyBezierSegment;
                        if (polyBezierSegment.Points.Count >= 3)
                        {
                            sgc.BezierTo(
                                new Point(
                                    polyBezierSegment.Points[0].X,
                                    polyBezierSegment.Points[0].Y),
                                new Point(
                                    polyBezierSegment.Points[1].X,
                                    polyBezierSegment.Points[1].Y),
                                new Point(
                                    polyBezierSegment.Points[2].X,
                                    polyBezierSegment.Points[2].Y));

                            previous = polyBezierSegment.Points[2];
                        }

                        if (polyBezierSegment.Points.Count > 3
                            && polyBezierSegment.Points.Count % 3 == 0)
                        {
                            for (int i = 3; i < polyBezierSegment.Points.Count; i += 3)
                            {
                                sgc.BezierTo(
                                    new Point(
                                        polyBezierSegment.Points[i].X,
                                        polyBezierSegment.Points[i].Y),
                                    new Point(
                                        polyBezierSegment.Points[i + 1].X,
                                        polyBezierSegment.Points[i + 1].Y),
                                    new Point(
                                        polyBezierSegment.Points[i + 2].X,
                                        polyBezierSegment.Points[i + 2].Y));

                                previous = polyBezierSegment.Points[i + 2];
                            }
                        }
                    }
                    else if (segment is XPolyLineSegment)
                    {
                        var polyLineSegment = segment as XPolyLineSegment;
                        if (polyLineSegment.Points.Count >= 1)
                        {
                            sgc.LineTo(
                                new Point(
                                    polyLineSegment.Points[0].X,
                                    polyLineSegment.Points[0].Y));

                            previous = polyLineSegment.Points[0];
                        }

                        if (polyLineSegment.Points.Count > 1)
                        {
                            for (int i = 1; i < polyLineSegment.Points.Count; i++)
                            {
                                sgc.LineTo(
                                    new Point(
                                        polyLineSegment.Points[i].X,
                                        polyLineSegment.Points[i].Y));

                                previous = polyLineSegment.Points[i];
                            }
                        }
                    }
                    else if (segment is XPolyQuadraticBezierSegment)
                    {
                        var polyQuadraticSegment = segment as XPolyQuadraticBezierSegment;
                        if (polyQuadraticSegment.Points.Count >= 2)
                        {
                            var p1 = previous;
                            var p2 = polyQuadraticSegment.Points[0];
                            var p3 = polyQuadraticSegment.Points[1];
                            double x1 = p1.X;
                            double y1 = p1.Y;
                            double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                            double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                            double x3 = x2 + (p3.X - p1.X) / 3.0;
                            double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                            double x4 = p3.X;
                            double y4 = p3.Y;
                            sgc.BezierTo(
                                new Point(x2, y2),
                                new Point(x3, y3),
                                new Point(x4, y4));

                            previous = polyQuadraticSegment.Points[1];
                        }

                        if (polyQuadraticSegment.Points.Count > 2
                            && polyQuadraticSegment.Points.Count % 2 == 0)
                        {
                            for (int i = 3; i < polyQuadraticSegment.Points.Count; i += 3)
                            {
                                var p1 = polyQuadraticSegment.Points[i - 1];
                                var p2 = polyQuadraticSegment.Points[i];
                                var p3 = polyQuadraticSegment.Points[i + 1];
                                double x1 = p1.X;
                                double y1 = p1.Y;
                                double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                                double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                                double x3 = x2 + (p3.X - p1.X) / 3.0;
                                double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                                double x4 = p3.X;
                                double y4 = p3.Y;
                                sgc.BezierTo(
                                    new Point(x2, y2),
                                    new Point(x3, y3),
                                    new Point(x4, y4));

                                previous = polyQuadraticSegment.Points[i + 1];
                            }
                        }
                    }
                    else if (segment is XQuadraticBezierSegment)
                    {
                        var qbezierSegment = segment as XQuadraticBezierSegment;
                        var p1 = previous;
                        var p2 = qbezierSegment.Point1;
                        var p3 = qbezierSegment.Point2;
                        double x1 = p1.X;
                        double y1 = p1.Y;
                        double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                        double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                        double x3 = x2 + (p3.X - p1.X) / 3.0;
                        double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                        double x4 = p3.X;
                        double y4 = p3.Y;
                        sgc.BezierTo(
                            new Point(x2, y2),
                            new Point(x3, y3),
                            new Point(x4, y4));

                        previous = qbezierSegment.Point2;
                    }
                    else
                    {
                        throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                    }
                }

                sgc.EndFigure(xpf.IsClosed);
            }

            // TODO: Perspex does not need to dispose StreamGeometryContext?
            //sgc.Close();
            sgc.Dispose();

            // TODO: Perspex has not yet implemented FillRule.
            //sg.FillRule = xpg.FillRule == XFillRule.Nonzero ? FillRule.Nonzero : FillRule.EvenOdd;

            return sg;
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PathMarkupParser"/> class.
 /// </summary>
 /// <param name="geometry">The geometry in which the path should be stored.</param>
 /// <param name="context">The context for <paramref name="geometry"/>.</param>
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     _geometry = geometry;
     _context = context;
 }
Esempio n. 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="qbezier"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XQBezier qbezier, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            if (!qbezier.IsFilled && !qbezier.IsStroked)
                return;

            var _dc = dc as IDrawingContext;

            Brush brush = ToSolidBrush(qbezier.Style.Fill);
            Pen pen = ToPen(qbezier.Style, _scaleToPage);

            var sg = new StreamGeometry();
            using (var sgc = sg.Open())
            {
                var p1 = qbezier.Point1;
                var p2 = qbezier.Point2;
                var p3 = qbezier.Point3;
                double x1 = p1.X;
                double y1 = p1.Y;
                double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                double x3 = x2 + (p3.X - p1.X) / 3.0;
                double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                double x4 = p3.X;
                double y4 = p3.Y;

                sgc.BeginFigure(
                    new Point(x1, y1),
                    qbezier.IsFilled);

                sgc.BezierTo(
                    new Point(x2, y2),
                    new Point(x3, y3),
                    new Point(x4, y4));

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                qbezier.IsFilled ? brush : null,
                qbezier.IsStroked ? pen : null,
                sg);

            // TODO: sg.Dispose();
            // TODO: brush.Dispose();
            // TODO: pen.Dispose();
        }
Esempio n. 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="bezier"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XBezier bezier, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            if (!bezier.IsFilled && !bezier.IsStroked)
                return;

            var _dc = dc as IDrawingContext;

            Brush brush = ToSolidBrush(bezier.Style.Fill);
            Pen pen = ToPen(bezier.Style, _scaleToPage);

            var sg = new StreamGeometry();
            using (var sgc = sg.Open())
            {
                sgc.BeginFigure(
                    new Point(bezier.Point1.X, bezier.Point1.Y),
                    bezier.IsFilled);

                sgc.BezierTo(
                    new Point(bezier.Point2.X, bezier.Point2.Y),
                    new Point(bezier.Point3.X, bezier.Point3.Y),
                    new Point(bezier.Point4.X, bezier.Point4.Y));

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                bezier.IsFilled ? brush : null,
                bezier.IsStroked ? pen : null,
                sg);

            // TODO: sg.Dispose();
            // TODO: brush.Dispose();
            // TODO: pen.Dispose();
        }
Esempio n. 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="arc"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            if (!arc.IsFilled && !arc.IsStroked)
                return;

            var _dc = dc as IDrawingContext;

            Brush brush = ToSolidBrush(arc.Style.Fill);
            Pen pen = ToPen(arc.Style, _scaleToPage);

            var sg = new StreamGeometry();
            using (var sgc = sg.Open())
            {
                var a = WpfArc.FromXArc(arc, dx, dy);

                sgc.BeginFigure(
                    new Point(a.Start.X, a.Start.Y),
                    arc.IsFilled);

                sgc.ArcTo(
                    new Point(a.End.X, a.End.Y),
                    new Size(a.Radius.Width, a.Radius.Height),
                    0.0,
                    a.IsLargeArc,
                    SweepDirection.Clockwise);

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                arc.IsFilled ? brush : null,
                arc.IsStroked ? pen : null,
                sg);

            // TODO: sg.Dispose();
            // TODO: brush.Dispose();
            // TODO: pen.Dispose();
        }
Esempio n. 11
0
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     this.geometry = geometry;
     this.context = context;
 }