Example #1
0
        /// <summary>
        /// Start drawing a Figure flow (continuous),must call <see cref="EndFigures"/> to end this Figure or combine Figures(generate by <see cref="BeginFigure(PenF, Color?, PointF, bool)"/>)
        /// </summary>
        public void BeginFigure(PenF pen, Color?fillColor, PointF begin, bool isClosed)
        {
            pen.Color = _transform.Transform(pen.Color);
            if (fillColor.HasValue)
            {
                fillColor = _transform.Transform(fillColor.Value);
            }

            if (_begin.HasValue)
            {
                if (_subGeo.IsClosed && _begin != _current)
                {
                    _LineTo(_begin.Value, true);
                }
                else
                {
                    _subGeo.UnClosedLine = _DrawLine(PenF.NULL, _current.Value, _begin.Value);
                }
            }

            begin    = _transform.Transform(begin);
            _begin   = begin;
            _current = begin;
            _subGeo  = new _SimpleGeometry(pen, fillColor, _begin.Value, isClosed);

            if (_geo == null)
            {
                _geo = new _ComplexGeometry()
                {
                    _bounds = RectF.Empty
                }
            }
            ;
            _geo.AddChild(_subGeo);
        }
Example #2
0
        private _Line _DrawLine(PenF pen, PointF start, PointF end)
        {
            if (start == end)
            {
                return(null);
            }

            return(new _Line(start, end, pen));
        }
Example #3
0
        public void DrawGlyphRun(PenF pen, Color?fillColor, GlyphRun glyphRun, float?tolerance = null)
        {
            pen.Color = _transform.Transform(pen.Color);
            if (fillColor.HasValue)
            {
                fillColor = _transform.Transform(fillColor.Value);
            }

            _DrawGeometry(pen, fillColor, glyphRun.BuildGeometry(), tolerance);
        }
Example #4
0
 public _SimpleGeometry(PenF pen, Color?fillColor, PointF begin, bool isClosed)
 {
     _bounds      = RectF.Empty;
     _pen         = pen;
     _fillColor   = fillColor;
     Begin        = begin;
     _isClosed    = isClosed;
     UnClosedLine = null;
     _stream      = new List <IPrimitive>();
 }
Example #5
0
        public void DrawText(PenF pen, Color?fillColor, FormattedText textToDraw, PointF origin, float?tolerance = null)
        {
            pen.Color = _transform.Transform(pen.Color);
            if (fillColor.HasValue)
            {
                fillColor = _transform.Transform(fillColor.Value);
            }

            _DrawGeometry(pen, fillColor, textToDraw.BuildGeometry(new Point(origin.X, -origin.Y - textToDraw.Height)), tolerance);
        }
Example #6
0
        private void _AttachModel(IPrimitive primitive, PenF pen)
        {
            if (primitive.Type == PrimitiveType.ComplexGeometry)
            {
                foreach (var child in ((_ComplexGeometry)primitive).Children.Where(c => !c.Pen.IsNULL))
                {
                    _AttachModel(child, child.Pen);
                }
                return;
            }

            if (primitive.Type == PrimitiveType.SimpleGeometry)
            {
                foreach (var child in ((_SimpleGeometry)primitive).Stream.Where(c => !c.Pen.IsNULL))
                {
                    _AttachModel(child, pen);
                }
                return;
            }

            var model  = default(MeshModel);
            var models = default(SortedDictionary <PenF, List <MeshModel> >);

            if (primitive.Type == PrimitiveType.Arc)
            {
                models = _arcModels;
            }
            else
            {
                models = _lineModels;
            }

            if (models.ContainsKey(pen))
            {
                model = models[pen].Last();
            }
            else
            {
                model = _GreateModel(primitive);
                models.Add(pen, new List <MeshModel>()
                {
                    model
                });
            }
            if (!model.TryAttachPrimitive(primitive))
            {
                model = _GreateModel(primitive);
                models[pen].Add(model);
                model.TryAttachPrimitive(primitive);
            }
            primitive.Model = model;
        }
Example #7
0
        private void _DrawRectangle(PenF pen, Color?fillColor, params PointF[] points)
        {
            var geo    = new _ComplexGeometry();
            var subgeo = new _SimpleGeometry(pen, fillColor, points[0], false);

            subgeo.StreamTo(new _Line(points[0], points[1], pen));
            subgeo.StreamTo(new _Line(points[1], points[2], pen));
            subgeo.StreamTo(new _Line(points[2], points[3], pen));
            subgeo.StreamTo(new _Line(points[3], points[0], pen));
            geo.AddChild(subgeo);
            geo.Close();
            _primitives.Add(geo);
        }
Example #8
0
        public void DrawCicle(PenF pen, Color?fillColor, PointF center, float radius)
        {
            center  = _transform.Transform(center);
            radius *= _transform.ScaleX;

            pen.Color = _transform.Transform(pen.Color);
            if (fillColor.HasValue)
            {
                fillColor = _transform.Transform(fillColor.Value);
            }

            _primitives.Add(new _Arc(center, radius, float.PositiveInfinity, float.PositiveInfinity, pen, fillColor));
        }
Example #9
0
        public void DrawLine(PenF pen, PointF start, PointF end)
        {
            start     = _transform.Transform(start);
            end       = _transform.Transform(end);
            pen.Color = _transform.Transform(pen.Color);

            var line = _DrawLine(pen, start, end);

            if (line != null)
            {
                _primitives.Add(line);
            }
        }
Example #10
0
 private void _DrawGeometry(PenF pen, Color?fillColor, Geometry geometry, float?tolerance = null)
 {
     if (geometry.IsEmpty())
     {
         return;
     }
     foreach (var figure in geometry.GetOutlinedPathGeometry().Figures)
     {
         BeginFigure(pen, fillColor, _Transform(figure.StartPoint), figure.IsClosed);
         foreach (var segment in figure.Segments)
         {
             if (segment is LineSegment)
             {
                 var line = (LineSegment)segment;
                 LineTo(_Transform(line.Point), true);
             }
             if (segment is PolyLineSegment)
             {
                 var line = (PolyLineSegment)segment;
                 PolyLineTo(_Transform(line.Points.ToArray()), true);
             }
             if (segment is BezierSegment)
             {
                 var bezier = (BezierSegment)segment;
                 BezierTo(3, new List <PointF>()
                 {
                     _Transform(bezier.Point1), _Transform(bezier.Point2), _Transform(bezier.Point3)
                 }, true, tolerance);
             }
             if (segment is QuadraticBezierSegment)
             {
                 var bezier = (QuadraticBezierSegment)segment;
                 BezierTo(2, new List <PointF>()
                 {
                     _Transform(bezier.Point1), _Transform(bezier.Point2)
                 }, true, tolerance);
             }
             if (segment is PolyBezierSegment)
             {
                 var bezier = (PolyBezierSegment)segment;
                 PolyBezierTo(3, _Transform(bezier.Points.ToArray()), true, tolerance);
             }
             if (segment is PolyQuadraticBezierSegment)
             {
                 var bezier = (PolyQuadraticBezierSegment)segment;
                 PolyBezierTo(2, _Transform(bezier.Points.ToArray()), true, tolerance);
             }
         }
     }
     _EndFigures(true);
 }
Example #11
0
        public _Bezier(PointF[] points, PenF pen, float tolerance)
        {
            _points = points;
            _pen    = pen;

            _bounds = RectF.Empty;

            _innerLines = default(List <_Line>);
            _innerLines = GeometryHelper.CalcSampleLines(tolerance, _points);

            foreach (var line in _innerLines)
            {
                _bounds.Union(line.GetBounds(1f));
            }
        }
Example #12
0
        public void DrawRectangle(PenF pen, Color?fillColor, RectF rectangle)
        {
            var p1 = rectangle.TopLeft;
            var p2 = rectangle.TopRight;
            var p3 = rectangle.BottomRight;
            var p4 = rectangle.BottomLeft;

            p1 = _transform.Transform(p1);
            p2 = _transform.Transform(p2);
            p3 = _transform.Transform(p3);
            p4 = _transform.Transform(p4);

            pen.Color = _transform.Transform(pen.Color);
            if (fillColor.HasValue)
            {
                fillColor = _transform.Transform(fillColor.Value);
            }

            _DrawRectangle(pen, fillColor, p1, p2, p3, p4);
        }
Example #13
0
        public _Spline(int degree, float[] knots, PointF[] controlPoints, float[] weights, PointF[] fitPoints, PenF pen, float tolerance)
        {
            //degree = degree;
            knots         = knots ?? new float[0];
            controlPoints = controlPoints ?? new PointF[0];
            weights       = weights ?? new float[0];
            fitPoints     = fitPoints ?? new PointF[0];
            _pen          = pen;

            _bounds     = RectF.Empty;
            _innerLines = default(List <_Line>);

            Regular(knots, degree);

            _innerLines = GeometryHelper.CalcSampleLines(degree, knots, controlPoints, weights, fitPoints, tolerance);

            foreach (var innerLine in _innerLines)
            {
                _bounds.Union(innerLine.GetBounds(1f));
            }
        }
Example #14
0
        public _Arc(PointF center, float radius, float startRadian, float endRadian, PenF pen, Color?fillColor = null, bool isReverse = false)
        {
            _pen       = pen;
            _fillColor = fillColor;
            _bounds    = RectF.Empty;

            Center      = center;
            Radius      = radius;
            StartRadian = startRadian;
            EndRadian   = endRadian;

            _isReverse = isReverse;

            if (IsCicle)
            {
                _bounds = new RectF(new PointF(center.X - radius, center.Y - radius), new PointF(center.X + radius, center.Y + radius));
            }
            else
            {
                _bounds = GeometryHelper.CalcBounds(this);
            }
        }
Example #15
0
        public void DrawArc(PenF pen, PointF center, float radius, float startAngle, float endAngle, bool isClockwise)
        {
            if (startAngle == endAngle)
            {
                return;
            }

            if (!isClockwise)
            {
                MathUtil.Switch(ref startAngle, ref endAngle);
            }

            pen.Color = _transform.Transform(pen.Color);

            GeometryHelper.FormatAngle(ref startAngle);
            GeometryHelper.FormatAngle(ref endAngle);

            var startRadian = GeometryHelper.GetRadian(startAngle);
            var endRadian   = GeometryHelper.GetRadian(endAngle);

            if (!_transform.IsIdentity)
            {
                var start = new PointF(center.X + radius * (float)Math.Cos(startRadian), center.Y + radius * (float)Math.Sin(startRadian));
                var end   = new PointF(center.X + radius * (float)Math.Cos(endRadian), center.Y + radius * (float)Math.Sin(endRadian));

                start  = _transform.Transform(start);
                end    = _transform.Transform(end);
                center = _transform.Transform(center);
                radius = (start - center).Length;

                startRadian = (float)Math.Atan2(start.Y - center.Y, start.X - center.X);
                endRadian   = (float)Math.Atan2(end.Y - center.Y, end.X - center.X);

                GeometryHelper.FormatRadian(ref startRadian);
                GeometryHelper.FormatRadian(ref endRadian);
            }
            _primitives.Add(new _Arc(center, radius, startRadian, endRadian, pen, null, !isClockwise));
        }
Example #16
0
        public _Line(PointF start, PointF end, PenF pen)
        {
            _pen = pen;

            Line = new Line(start, end);
        }
Example #17
0
 /// <summary>
 /// The points.Count() == degree + 1;
 /// </summary>
 public void DrawBezier(PenF pen, int degree, IEnumerable <PointF> points, float?tolerance = null)
 {
     _primitives.Add(_DrawBezier(pen, points.Select(p => _transform.Transform(p)), tolerance));
 }
Example #18
0
        /// <summary>
        /// Non-uniform rational B-spline (NURBS)
        /// </summary>
        public void DrawSpline(PenF pen, int degree, IEnumerable <float> knots, IEnumerable <PointF> controlPoints, IEnumerable <float> weights, IEnumerable <PointF> fitPoints, float?tolerance = null)
        {
            pen.Color = _transform.Transform(pen.Color);

            _primitives.Add(new _Spline(degree, knots?.ToArray(), controlPoints?.Select(c => _transform.Transform(c)).ToArray(), weights?.ToArray(), fitPoints?.Select(f => _transform.Transform(f)).ToArray(), pen, tolerance ?? _visual.Panel.Preference.Tolerance));
        }
Example #19
0
        private _Bezier _DrawBezier(PenF pen, IEnumerable <PointF> points, float?tolerance = null)
        {
            pen.Color = _transform.Transform(pen.Color);

            return(new _Bezier(points.ToArray(), pen, tolerance ?? _visual.Panel.Preference.Tolerance));
        }