示例#1
0
        private IBezier ReadBezier()
        {
            var bezier = new XBezier()
            {
                Id              = _reader.ReadInt32(),
                Start           = ReadPoint(),
                Point1          = ReadPoint(),
                Point2          = ReadPoint(),
                Point3          = ReadPoint(),
                Stroke          = ReadColor(),
                StrokeThickness = _reader.ReadDouble(),
                Fill            = ReadColor(),
                IsFilled        = _reader.ReadBoolean(),
                IsClosed        = _reader.ReadBoolean()
            };

            _natives.Add(bezier.Id, bezier);
            return(bezier);
        }
示例#2
0
        public void Draw(object ds, XBezier bezier, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            var _ds = ds as CanvasDrawingSession;

            double thickness = bezier.Style.Thickness / _state.Zoom;
            var    brush     = ToColor(bezier.Style.Fill);
            var    pen       = ToColor(bezier.Style.Stroke);
            var    ss        = CreateStrokeStyle(bezier.Style);

            CanvasGeometry g;

            using (var builder = new CanvasPathBuilder(_ds))
            {
                builder.BeginFigure((float)bezier.Point1.X, (float)bezier.Point1.Y);
                builder.AddCubicBezier(
                    new N.Vector2(
                        (float)bezier.Point2.X,
                        (float)bezier.Point2.Y),
                    new N.Vector2(
                        (float)bezier.Point3.X,
                        (float)bezier.Point3.Y),
                    new N.Vector2(
                        (float)bezier.Point4.X,
                        (float)bezier.Point4.Y));
                builder.EndFigure(CanvasFigureLoop.Open);
                g = CanvasGeometry.CreatePath(builder);
            }

            if (bezier.IsFilled)
            {
                _ds.FillGeometry(g, brush);
            }

            if (bezier.IsStroked)
            {
                _ds.DrawGeometry(g, pen, (float)thickness, ss);
            }

            g.Dispose();
            ss.Dispose();
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></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 gfx, XBezier bezier, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            var _gfx = gfx as Graphics;

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

            var path = new GraphicsPath();

            path.AddBezier(
                new PointF(
                    _scaleToPage(bezier.Point1.X),
                    _scaleToPage(bezier.Point1.Y)),
                new PointF(
                    _scaleToPage(bezier.Point2.X),
                    _scaleToPage(bezier.Point2.Y)),
                new PointF(
                    _scaleToPage(bezier.Point3.X),
                    _scaleToPage(bezier.Point3.Y)),
                new PointF(
                    _scaleToPage(bezier.Point4.X),
                    _scaleToPage(bezier.Point4.Y)));

            if (bezier.IsFilled)
            {
                _gfx.FillPath(brush, path);
            }

            if (bezier.IsStroked)
            {
                _gfx.DrawPath(pen, path);
            }

            path.Dispose();
            brush.Dispose();
            pen.Dispose();
        }
示例#4
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 DrawingContext;

            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();
        }
示例#5
0
 private IBezier ReadBezier()
 {
     var bezier = new XBezier()
     {
         Id = _reader.ReadInt32(),
         Start = ReadPoint(),
         Point1 = ReadPoint(),
         Point2 = ReadPoint(),
         Point3 = ReadPoint(),
         Stroke = ReadColor(),
         StrokeThickness = _reader.ReadDouble(),
         Fill = ReadColor(),
         IsFilled = _reader.ReadBoolean(),
         IsClosed = _reader.ReadBoolean()
     };
     _natives.Add(bezier.Id, bezier);
     return bezier;
 }
示例#6
0
 public IBezier CreateBezier()
 {
     var bezier = new XBezier()
     {
         Start = new XPoint(0.0, 0.0),
         Point1 = new XPoint(0.0, 0.0),
         Point2 = new XPoint(0.0, 0.0),
         Point3 = new XPoint(0.0, 0.0),
         Stroke = new XColor(0xFF, 0x00, 0x00, 0x00),
         StrokeThickness = 2.0,
         Fill = new XColor(0x00, 0xFF, 0xFF, 0xFF),
         IsFilled = false,
         IsClosed = false
     };
     bezier.Start.Connected.Add(bezier);
     bezier.Point1.Connected.Add(bezier);
     bezier.Point2.Connected.Add(bezier);
     bezier.Point3.Connected.Add(bezier);
     return bezier;
 }
示例#7
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)
        {
            var _dc = dc as DrawingContext;

            var style = bezier.Style;

            if (style == null)
            {
                return;
            }

            double thickness = style.Thickness / _state.Zoom;
            double half      = thickness / 2.0;

            Tuple <Brush, Pen> cache = null;
            Brush fill;
            Pen   stroke;

            if (_enableStyleCache &&
                _styleCache.TryGetValue(style, out cache))
            {
                fill   = cache.Item1;
                stroke = cache.Item2;
            }
            else
            {
                fill   = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                if (_enableStyleCache)
                {
                    _styleCache.Add(style, Tuple.Create(fill, stroke));
                }
            }

            PathGeometry pg = null;

            if (_enableBezierCache &&
                _bezierCache.TryGetValue(bezier, out pg))
            {
                var pf = pg.Figures[0];
                pf.StartPoint = new Point(bezier.Point1.X + dx, bezier.Point1.Y + dy);
                pf.IsFilled   = bezier.IsFilled;
                var bs = pf.Segments[0] as BezierSegment;
                bs.Point1    = new Point(bezier.Point2.X + dx, bezier.Point2.Y + dy);
                bs.Point2    = new Point(bezier.Point3.X + dx, bezier.Point3.Y + dy);
                bs.Point3    = new Point(bezier.Point4.X + dx, bezier.Point4.Y + dy);
                bs.IsStroked = bezier.IsStroked;
            }
            else
            {
                var pf = new PathFigure()
                {
                    StartPoint = new Point(bezier.Point1.X + dx, bezier.Point1.Y + dy),
                    IsFilled   = bezier.IsFilled
                };
                var bs = new BezierSegment(
                    new Point(bezier.Point2.X + dx, bezier.Point2.Y + dy),
                    new Point(bezier.Point3.X + dx, bezier.Point3.Y + dy),
                    new Point(bezier.Point4.X + dx, bezier.Point4.Y + dy),
                    bezier.IsStroked);
                //bs.Freeze();
                pf.Segments.Add(bs);
                //pf.Freeze();
                pg = new PathGeometry();
                pg.Figures.Add(pf);
                //pg.Freeze();

                if (_enableBezierCache)
                {
                    _bezierCache.Add(bezier, pg);
                }
            }

            DrawPathGeometryInternal(_dc, half, fill, stroke, bezier.IsStroked, bezier.IsFilled, pg);
        }