예제 #1
0
        public ISvgMarker GetMarker(int index)
        {
            var         segmentList = this.SegmentList();
            ISvgPathSeg segment     = segmentList[index];

            return(new SvgMarker(index, segment));
        }
예제 #2
0
 public SvgMarker(int index, ISvgPathSeg segment)
 {
     _index   = index;
     _segment = segment;
     if (segment != null)
     {
         _position = segment.AbsXY;
     }
 }
예제 #3
0
        public ISvgPathSeg AppendItem(ISvgPathSeg newItem)
        {
            if (_readOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }
            _segments.Add(newItem);
            setListAndIndex(newItem as SvgPathSeg, _segments.Count - 1);

            return(newItem);
        }
예제 #4
0
        public ISvgPathSeg InsertItemBefore(ISvgPathSeg newItem, int index)
        {
            if (_readOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }
            _segments.Insert(index, newItem);
            setListAndIndex(newItem as SvgPathSeg, index);
            changeIndexes(index + 1, 1);

            return(newItem);
        }
예제 #5
0
        public ISvgPathSeg ReplaceItem(ISvgPathSeg newItem, int index)
        {
            if (_readOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }
            ISvgPathSeg replacedItem = GetItem(index);

            _segments[index] = newItem;
            setListAndIndex(newItem as SvgPathSeg, index);

            return(replacedItem);
        }
예제 #6
0
        public ISvgPathSeg RemoveItem(int index)
        {
            if (_readOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }
            ISvgPathSeg result = GetItem(index);

            _segments.RemoveAt(index);
            changeIndexes(index, -1);

            return(result);
        }
 public void Add(ISvgPathSeg item)
 {
     this.AppendItem(item);
 }
예제 #8
0
 ISvgPathSeg ISvgPathSegList.ReplaceItem(ISvgPathSeg newItem, int index)
 {
     return(this.ReplaceItem((SvgPathSeg)newItem, index));
 }
예제 #9
0
        public ISvgPathSeg Initialize(ISvgPathSeg newItem)
        {
            Clear();

            return(AppendItem(newItem));
        }
예제 #10
0
        public static GraphicsPath CreatePath(SvgPathElement element)
        {
            GraphicsPath gp = new GraphicsPath();

            SvgPointF initPoint = new SvgPointF(0, 0);
            SvgPointF lastPoint = new SvgPointF(0, 0);

            ISvgPathSeg       segment     = null;
            SvgPathSegMoveto  pathMoveTo  = null;
            SvgPathSegLineto  pathLineTo  = null;
            SvgPathSegCurveto pathCurveTo = null;
            SvgPathSegArc     pathArc     = null;

            ISvgPathSegList segments = element.PathSegList;
            int             nElems   = segments.NumberOfItems;

            for (int i = 0; i < nElems; i++)
            {
                segment = segments.GetItem(i);

                if (DynamicCast.Cast(segment, out pathMoveTo))
                {
                    //SvgPathSegMoveto seg = (SvgPathSegMoveto)segment;
                    gp.StartFigure();
                    lastPoint = initPoint = pathMoveTo.AbsXY;
                }
                else if (DynamicCast.Cast(segment, out pathLineTo))
                {
                    //SvgPathSegLineto seg = (SvgPathSegLineto)segment;
                    SvgPointF p = pathLineTo.AbsXY;
                    gp.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y);

                    lastPoint = p;
                }
                else if (DynamicCast.Cast(segment, out pathCurveTo))
                {
                    // SvgPathSegCurveto seg = (SvgPathSegCurveto)segment;
                    SvgPointF xy   = pathCurveTo.AbsXY;
                    SvgPointF x1y1 = pathCurveTo.CubicX1Y1;
                    SvgPointF x2y2 = pathCurveTo.CubicX2Y2;
                    gp.AddBezier(lastPoint.X, lastPoint.Y, x1y1.X, x1y1.Y, x2y2.X, x2y2.Y, xy.X, xy.Y);

                    lastPoint = xy;
                }
                else if (DynamicCast.Cast(segment, out pathArc))
                {
                    //SvgPathSegArc seg = (SvgPathSegArc)segment;
                    SvgPointF p = pathArc.AbsXY;
                    if (lastPoint.Equals(p))
                    {
                        // If the endpoints (x, y) and (x0, y0) are identical, then this
                        // is equivalent to omitting the elliptical arc segment entirely.
                    }
                    else if (pathArc.R1 == 0 || pathArc.R2 == 0)
                    {
                        // Ensure radii are valid
                        gp.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y);
                    }
                    else
                    {
                        CalculatedArcValues calcValues = pathArc.GetCalculatedArcValues();

                        GraphicsPath gp2 = new GraphicsPath();
                        gp2.StartFigure();
                        gp2.AddArc((float)(calcValues.Cx - calcValues.CorrRx),
                                   (float)(calcValues.Cy - calcValues.CorrRy),
                                   (float)calcValues.CorrRx * 2, (float)calcValues.CorrRy * 2,
                                   (float)calcValues.AngleStart, (float)calcValues.AngleExtent);

                        Matrix matrix = new Matrix();
                        matrix.Translate(-(float)calcValues.Cx, -(float)calcValues.Cy);
                        gp2.Transform(matrix);

                        matrix = new Matrix();
                        matrix.Rotate((float)pathArc.Angle);
                        gp2.Transform(matrix);

                        matrix = new Matrix();
                        matrix.Translate((float)calcValues.Cx, (float)calcValues.Cy);
                        gp2.Transform(matrix);

                        gp.AddPath(gp2, true);
                    }

                    lastPoint = p;
                }
                else if (segment is SvgPathSegClosePath)
                {
                    gp.CloseFigure();
                    lastPoint = initPoint;
                }
            }

            string fillRule = element.GetPropertyValue("fill-rule");

            if (fillRule == "evenodd")
            {
                gp.FillMode = FillMode.Alternate;
            }
            else
            {
                gp.FillMode = FillMode.Winding;
            }

            return(gp);
        }
예제 #11
0
 ISvgPathSeg ISvgPathSegList.InsertItemBefore(ISvgPathSeg newItem, int index)
 {
     return(this.InsertItemBefore((SvgPathSeg)newItem, index));
 }
예제 #12
0
        public ISvgPathSeg AppendItem( ISvgPathSeg newItem )
        {
            if(readOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }
            else
            {
                segments.Add(newItem);
                setListAndIndex(newItem as SvgPathSeg, segments.Count - 1);

                return newItem;
            }
        }
예제 #13
0
        public ISvgPathSeg InsertItemBefore( ISvgPathSeg newItem, int index )
        {
            if(readOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }
            else
            {
                segments.Insert(index, newItem);
                setListAndIndex(newItem as SvgPathSeg, index);
                changeIndexes(index+1, 1);

                return newItem;
            }
        }
        public Geometry CreateGeometry(SvgPathElement element)
        {
            PathGeometry geometry = new PathGeometry();

            string fillRule = element.GetPropertyValue("fill-rule");
            string clipRule = element.GetAttribute("clip-rule");

            if (!string.IsNullOrWhiteSpace(clipRule) &&
                string.Equals(clipRule, "evenodd") || string.Equals(clipRule, "nonzero"))
            {
                fillRule = clipRule;
            }
            if (fillRule == "evenodd")
            {
                geometry.FillRule = FillRule.EvenOdd;
            }
            else if (fillRule == "nonzero")
            {
                geometry.FillRule = FillRule.Nonzero;
            }

            SvgPointF initPoint = new SvgPointF(0, 0);
            SvgPointF lastPoint = new SvgPointF(0, 0);

            ISvgPathSeg       segment     = null;
            SvgPathSegMoveto  pathMoveTo  = null;
            SvgPathSegLineto  pathLineTo  = null;
            SvgPathSegCurveto pathCurveTo = null;
            SvgPathSegArc     pathArc     = null;

            ISvgPathSegList segments = element.PathSegList;
            int             nElems   = segments.NumberOfItems;

            PathFigure pathFigure = null;

            for (int i = 0; i < nElems; i++)
            {
                segment = segments.GetItem(i);

                if (DynamicCast.Cast(segment, out pathMoveTo))
                {
                    if (pathFigure != null)
                    {
                        pathFigure.IsClosed = false;
                        pathFigure.IsFilled = true;
                        geometry.Figures.Add(pathFigure);
                        pathFigure = null;
                    }

                    lastPoint = initPoint = pathMoveTo.AbsXY;

                    pathFigure            = new PathFigure();
                    pathFigure.StartPoint = new Point(initPoint.ValueX, initPoint.ValueY);
                }
                else if (DynamicCast.Cast(segment, out pathLineTo))
                {
                    SvgPointF p = pathLineTo.AbsXY;
                    pathFigure.Segments.Add(new LineSegment(new Point(p.ValueX, p.ValueY), true));

                    lastPoint = p;
                }
                else if (DynamicCast.Cast(segment, out pathCurveTo))
                {
                    SvgPointF xy   = pathCurveTo.AbsXY;
                    SvgPointF x1y1 = pathCurveTo.CubicX1Y1;
                    SvgPointF x2y2 = pathCurveTo.CubicX2Y2;
                    pathFigure.Segments.Add(new BezierSegment(new Point(x1y1.ValueX, x1y1.ValueY),
                                                              new Point(x2y2.ValueX, x2y2.ValueY), new Point(xy.ValueX, xy.ValueY), true));

                    lastPoint = xy;
                }
                else if (DynamicCast.Cast(segment, out pathArc))
                {
                    SvgPointF p = pathArc.AbsXY;
                    if (lastPoint.Equals(p))
                    {
                        // If the endpoints (x, y) and (x0, y0) are identical, then this
                        // is equivalent to omitting the elliptical arc segment entirely.
                    }
                    else if (pathArc.R1.Equals(0) || pathArc.R2.Equals(0))
                    {
                        // Ensure radii are valid
                        pathFigure.Segments.Add(new LineSegment(new Point(p.ValueX, p.ValueY), true));
                    }
                    else
                    {
                        CalculatedArcValues calcValues = pathArc.GetCalculatedArcValues();

                        pathFigure.Segments.Add(new ArcSegment(new Point(p.ValueX, p.ValueY),
                                                               new Size(pathArc.R1, pathArc.R2), pathArc.Angle, pathArc.LargeArcFlag,
                                                               pathArc.SweepFlag ? SweepDirection.Clockwise : SweepDirection.Counterclockwise,
                                                               true));
                    }

                    lastPoint = p;
                }
                else if (segment is SvgPathSegClosePath)
                {
                    if (pathFigure != null)
                    {
                        pathFigure.IsClosed = true;
                        pathFigure.IsFilled = true;
                        geometry.Figures.Add(pathFigure);
                        pathFigure = null;
                    }

                    lastPoint = initPoint;
                }
            }

            if (pathFigure != null)
            {
                pathFigure.IsClosed = false;
                pathFigure.IsFilled = true;
                geometry.Figures.Add(pathFigure);
            }

            return(geometry);
        }
예제 #15
0
 bool ICollection <ISvgPathSeg> .Remove(ISvgPathSeg item)
 {
     return(this.Remove((SvgPathSeg)item));
 }
예제 #16
0
 bool ICollection <ISvgPathSeg> .Contains(ISvgPathSeg item)
 {
     return(this.Contains((SvgPathSeg)item));
 }
예제 #17
0
 void ICollection <ISvgPathSeg> .Add(ISvgPathSeg item)
 {
     this.Add((SvgPathSeg)item);
 }
예제 #18
0
 void IList <ISvgPathSeg> .Insert(int index, ISvgPathSeg item)
 {
     this.Insert(index, (SvgPathSeg)item);
 }
예제 #19
0
 int IList <ISvgPathSeg> .IndexOf(ISvgPathSeg item)
 {
     return(this.IndexOf((SvgPathSeg)item));
 }
예제 #20
0
 ISvgPathSeg ISvgPathSegList.AppendItem(ISvgPathSeg newItem)
 {
     return(this.AppendItem((SvgPathSeg)newItem));
 }
예제 #21
0
 public bool Contains(ISvgPathSeg item)
 {
     return(this._segments.Contains(item));
 }
예제 #22
0
 public int IndexOf(ISvgPathSeg item)
 {
     return(this._segments.IndexOf(item));
 }
예제 #23
0
 public ISvgPathSeg Initialize(ISvgPathSeg newItem )
 {
     Clear();
     return AppendItem(newItem);
 }
예제 #24
0
 public SvgMarker(int index, SvgPointF position, ISvgPathSeg segment)
 {
     _index    = index;
     _position = position;
     _segment  = segment;
 }
예제 #25
0
        public ISvgPathSeg ReplaceItem(ISvgPathSeg newItem, int index )
        {
            if(readOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }
            else
            {
                ISvgPathSeg replacedItem = GetItem(index);
                segments[index] = newItem;
                setListAndIndex(newItem as SvgPathSeg, index);

                return replacedItem;
            }
        }
예제 #26
0
 public bool Remove(ISvgPathSeg item)
 {
     return(this._segments.Remove(item));
 }
예제 #27
0
 public void Insert(int index, ISvgPathSeg item)
 {
     this.ReplaceItem(item, index);
 }
예제 #28
0
 ISvgPathSeg ISvgPathSegList.Initialize(ISvgPathSeg newItem)
 {
     return(this.Initialize((SvgPathSeg)newItem));
 }