示例#1
0
        public override Primitives.VisualItem Create( Primitives.Path source )
        {
            Primitives.Container container = new Primitives.Container( _offset );
            PathCommandVisitor visitor = new PathCommandVisitor( this );

            source = _renderer.FlattenPath( source );

            foreach( Primitives.Path.Command command in source.Commands )
            {
                command.Visit( visitor );
            }

            foreach( Primitives.Path path in visitor.Paths )
            {
                container.AddFront( path );
            }

            return container;
        }
示例#2
0
        private GraphicsPath CreateGraphicsPath( Primitives.Path path )
        {
            GraphicsPath gp;

            if( _mapPathToGraphicsPath.TryGetValue( path, out gp ) )
            {
                return gp;
            }

            PathCommandVisitor visitor = new PathCommandVisitor();

            foreach( Primitives.Path.Command pathCommand in path.Commands )
            {
                pathCommand.Visit( visitor );
            }

            gp = visitor.GetGraphicsPath();

            _mapPathToGraphicsPath.Add( path, gp );

            return gp;
        }
示例#3
0
        public override Primitives.Path FlattenPath( Primitives.Path source )
        {
            PathCommandVisitor visitor = new PathCommandVisitor();

            foreach( Primitives.Path.Command pathCommand in source.Commands )
            {
                pathCommand.Visit( visitor );
            }

            using( GraphicsPath gp = visitor.GetGraphicsPath() )
            {
                gp.Flatten();

                PointF lastPoint = PointF.Empty;

                Primitives.Path path = new Primitives.Path();

                path.Pen = source.Pen;
                path.Brush = source.Brush;

                for( int i = 0; i < gp.PointCount; ++i )
                {
                    PointF point = gp.PathPoints[i];
                    byte type = gp.PathTypes[i];
                    PointF nextPoint = point;

                    if( i < gp.PointCount - 1 && gp.PathTypes[i + 1] == 1 )
                    {
                        nextPoint = gp.PathPoints[i + 1];
                    }

                    switch( type )
                    {
                        case 0:
                            {
                                path.Add( new Primitives.Path.Move( new Types.Point( point.X, point.Y ) ) );
                                break;
                            }
                        case 1:
                            {
                                bool first = (i == 0) || gp.PathTypes[i - 1] != 1;
                                bool last = (i == gp.PointCount - 1) || gp.PathTypes[i + 1] != 1;

                                if( first || last
                                    || Math.Sqrt( Math.Pow( point.X - lastPoint.X, 2 ) + Math.Pow( point.Y - lastPoint.Y, 2 ) ) > _accuracy
                                    || Math.Sqrt( Math.Pow( point.X - nextPoint.X, 2 ) + Math.Pow( point.Y - nextPoint.Y, 2 ) ) > _accuracy )
                                {
                                    path.Add( new Primitives.Path.Line( new Types.Point( point.X, point.Y ) ) );
                                    lastPoint = point;
                                }

                                break;
                            }
                        case 129:
                            {
                                path.Add( new Primitives.Path.Line( new Types.Point( point.X, point.Y ) ) );
                                path.Add( new Primitives.Path.Close() );
                                break;
                            }
                        default:
                            throw new InvalidOperationException();
                    }
                }

                return path;
            }
        }