public void EndFigure(bool isClosed)
        {
            this.impl.Operations.Enqueue(new EndOp { IsClosed = isClosed });

            double maxX = 0;
            double maxY = 0;

            foreach (var p in this.points)
            {
                maxX = System.Math.Max(p.X, maxX);
                maxY = System.Math.Max(p.Y, maxY);
            }

            var context = new Cairo.Context(new Cairo.ImageSurface(Cairo.Format.Argb32, (int)maxX, (int)maxY));
            var clone = new Queue<GeometryOp>(this.impl.Operations);

            context.LineWidth = 2;

            while (clone.Count > 0)
            {
                var current = clone.Dequeue();

                if (current is BeginOp)
                {
                    var bo = current as BeginOp;
                    context.MoveTo(bo.Point.ToCairo());
                }
                else if (current is LineToOp)
                {
                    var lto = current as LineToOp;
                    context.LineTo(lto.Point.ToCairo());
                }
                else if (current is EndOp)
                {
                    if (((EndOp)current).IsClosed)
                        context.ClosePath();
                }
                else if (current is CurveToOp)
                {
                    var cto = current as CurveToOp;
                    context.CurveTo(cto.Point.ToCairo(), cto.Point2.ToCairo(), cto.Point3.ToCairo());
                }

                context.StrokePreserve();
                context.FillPreserve();
            }

            var test = context.StrokeExtents();
            this.impl.Bounds = new Rect(test.X, test.Y, test.Width, test.Height);

            context.Dispose();
        }
 public StreamGeometryContextImpl(StreamGeometryImpl imp)
 {
     this.impl = imp;
     this.surf = new Cairo.ImageSurface(Cairo.Format.Argb32, 0, 0);
     this.context = new Cairo.Context(this.surf);
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawingContext"/> class.
 /// </summary>
 /// <param name="surface">The GDK drawable.</param>
 public DrawingContext(Gdk.Drawable drawable)
 {
     this.Drawable         = drawable;
     this.context          = Gdk.CairoHelper.Create(drawable);
     this.CurrentTransform = Matrix.Identity;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawingContext"/> class.
 /// </summary>
 /// <param name="surface">The target surface.</param>
 public DrawingContext(Cairo.Surface surface)
 {
     this.surface          = surface;
     this.context          = new Cairo.Context(surface);
     this.CurrentTransform = Matrix.Identity;
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawingContext"/> class.
 /// </summary>
 /// <param name="surface">The GDK drawable.</param>
 public DrawingContext(Gdk.Drawable drawable)
 {
     this.Drawable = drawable;
     this.context = Gdk.CairoHelper.Create(drawable);
     this.CurrentTransform = Matrix.Identity;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawingContext"/> class.
 /// </summary>
 /// <param name="surface">The target surface.</param>
 public DrawingContext(Cairo.Surface surface)
 {
     this.surface = surface;
     this.context = new Cairo.Context(surface);
     this.CurrentTransform = Matrix.Identity;
 }