コード例 #1
0
ファイル: SvgPointCollectionTests.cs プロジェクト: vvvv/SVG
 public void ToStringReturnsValidString()
 {
     var collection = new SvgPointCollection
     {
         new SvgUnit(1.6f), new SvgUnit(3.2f),
         new SvgUnit(1.2f), new SvgUnit(5f)
     };
     Assert.AreEqual("1.6,3.2 1.2,5", collection.ToString());
 }
コード例 #2
0
        public void ToStringReturnsValidString()
        {
            var collection = new SvgPointCollection
            {
                new SvgUnit(1.6f), new SvgUnit(3.2f),
                new SvgUnit(1.2f), new SvgUnit(5f)
            };

            Assert.Equal("1.6,3.2 1.2,5", collection.ToString());
        }
コード例 #3
0
        public override RenderedSvg RenderColumn()
        {
            var result = base.RenderColumn();


            SvgGroup group = new SvgGroup();

            VisualLayerPresentingVM[] layers = vm.Layers.ToArray();



            for (int i = 0; i < layers.Length; i++)
            {
                VisualLayerPresentingVM lvm = layers[i];
                if (lvm.Origin.CurrentClass != null)
                {
                    ISideCurveGenerator sideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(lvm.Origin.CurrentClass.RightSideForm);

                    SvgPatternServer sps = lvm.Origin.CurrentClass.BackgroundPattern;
                    sps.PatternContentUnits = SvgCoordinateUnits.ObjectBoundingBox;
                    sps.PatternUnits        = SvgCoordinateUnits.UserSpaceOnUse;
                    float ratio = sps.Width.Value / 64f;
                    sps.Width  /= ratio;
                    sps.Height /= ratio;

                    SvgPolygon poly = new SvgPolygon();
                    poly.Stroke      = new SvgColourServer(System.Drawing.Color.Black);
                    poly.StrokeWidth = 1f;
                    poly.Fill        = sps;

                    var points = Drawing.GetPolygon(lvm.Width, lvm.Height, sideCurveGenerator).ToArray();

                    SvgPointCollection svgPoints = new SvgPointCollection();
                    for (int j = 0; j < points.Length; j++)
                    {
                        var point = points[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgPoints, point);
                    }

                    poly.Points = svgPoints;

                    group.Children.Add(poly);
                }
            }

            result.SVG = group;

            return(result);
        }
コード例 #4
0
ファイル: Converter.cs プロジェクト: boonepeter/wpf-uwp-icons
        private static PointCollection GetPoints(SvgPointCollection collection)
        {
            PointCollection points = new PointCollection();

            for (int i = 0; i < collection.Count - 1; i += 2)
            {
                Point point = new Point()
                {
                    X = collection[i],
                    Y = collection[i + 1]
                };
                points.Add(point);
            }
            string lol = collection.ToString();

            return(points);
        }
コード例 #5
0
        public string AddPolygon(Color color, params Vector2[] points)
        {
            var polyPoints = new SvgPointCollection();

            polyPoints.AddRange(
                points.SelectMany(p => new[] { new SvgUnit(p.X), new SvgUnit(p.Y) }));

            var id = Guid.NewGuid().ToString();

            _svg.Children.Add(new SvgPolygon
            {
                Points = polyPoints,
                Fill   = new SvgColourServer(color),
                ID     = id
            });

            return(id);
        }
コード例 #6
0
        public void DrawPolygon(SvgDocument SvgDocument, PointF[] vertices, Color c)
        {
            SvgPointCollection points = new SvgPointCollection();

            foreach (PointF p in vertices)
            {
                points.Add(new SvgUnit(p.X));
                points.Add(new SvgUnit(p.Y));
            }

            SvgPolygon SvgPolygon = new SvgPolygon()
            {
                Points      = points,
                Fill        = new SvgColourServer(c),
                StrokeWidth = 0
            };

            SvgDocument.Children.Add(SvgPolygon);
        }
コード例 #7
0
        public void DrawPolygon(IEnumerable <Point> points, GraphicsContext context, DeviceDescription description)
        {
            var svgContext = _mapper.MapGraphicsContextToSvg(context);
            var collection = new SvgPointCollection();

            collection.AddRange(points.Select(p => _mapper.MapPoint(p))
                                .Select(p => new[] { p.X, p.Y })
                                .SelectMany(p => p));
            AddChild(new SvgPolygon
            {
                Fill            = svgContext.Fill,
                FillOpacity     = svgContext.Opacity,
                Points          = collection,
                Stroke          = svgContext.Pen.Stroke,
                StrokeDashArray = svgContext.Pen.StrokeDashArray,
                StrokeLineCap   = svgContext.Pen.StrokeLineCap,
                StrokeLineJoin  = svgContext.Pen.StrokeLineJoin,
                StrokeWidth     = svgContext.Pen.StrokeWidth
            });
        }
コード例 #8
0
        public void DrawPolyline(IEnumerable<Point> points, GraphicsContext context, DeviceDescription description)
        {
            var svgContext = _mapper.MapGraphicsContextToSvg(context);
            var collection = new SvgPointCollection();

            collection.AddRange(points.Select(p => _mapper.MapPoint(p, SvgUnitType.User))
                                      .Select(p => new[] { p.X, p.Y })
                                      .SelectMany(p => p));

            AddChild(new SvgPolyline
            {
                Fill = svgContext.Fill,
                FillOpacity = svgContext.Opacity,
                Points = collection,
                Stroke = svgContext.Pen.Stroke,
                StrokeDashArray = svgContext.Pen.StrokeDashArray,
                StrokeLineCap = svgContext.Pen.StrokeLineCap,
                StrokeLineJoin = svgContext.Pen.StrokeLineJoin,
                StrokeWidth = svgContext.Pen.StrokeWidth
            });
        }
コード例 #9
0
        public override RenderedSvg RenderColumn()
        {
            var result = base.RenderColumn();


            SvgGroup group = new SvgGroup();

            VisualLayerPresentingVM[] layers = vm.Layers.ToArray();



            for (int i = 0; i < layers.Length; i++)
            {
                VisualLayerPresentingVM lvm = layers[i];
                SvgGroup levelGroup         = new SvgGroup();
                if (lvm.BackgroundClass.CurrentClass != null)
                {
                    ISideCurveGenerator rightSideCurveGenerator = null;
                    if ((lvm.RightSideClass != null) && (lvm.RightSideClass.CurrentClass != null))
                    {
                        rightSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(lvm.RightSideClass.CurrentClass.RightSideForm);
                    }
                    else
                    {
                        rightSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(AnnotationPlane.Template.RightSideFormEnum.NotDefined);
                    }

                    SvgPolyline rightEdge = new SvgPolyline
                    {
                        Stroke      = new SvgColourServer(System.Drawing.Color.Black),
                        StrokeWidth = 1f
                    };

                    var rightPoints = Drawing.GetRightPolyline(lvm.Width, lvm.Height, rightSideCurveGenerator).ToArray();

                    SvgPointCollection svgPoints = new SvgPointCollection();
                    for (int j = 0; j < rightPoints.Length; j++)
                    {
                        var point = rightPoints[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgPoints, point);
                    }

                    rightEdge.Points = svgPoints;

                    levelGroup.Children.Add(rightEdge);


                    ISideCurveGenerator bottomSideCurveGenerator = null;
                    if ((lvm.BottomSideClass != null) && (lvm.BottomSideClass.CurrentClass != null))
                    {
                        bottomSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(lvm.BottomSideClass.CurrentClass.BottomSideForm);
                    }
                    else
                    {
                        bottomSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(AnnotationPlane.Template.BottomSideFormEnum.NotDefined);
                    }

                    SvgPolyline bottomEdge = new SvgPolyline
                    {
                        Stroke        = new SvgColourServer(System.Drawing.Color.Black),
                        StrokeLineCap = SvgStrokeLineCap.Round,
                        StrokeWidth   = 1f
                    };
                    if (lvm.BottomSideClass.CurrentClass != null)
                    {
                        if (lvm.BottomSideClass.CurrentClass.BottomSideForm == AnnotationPlane.Template.BottomSideFormEnum.Dotted)
                        {
                            bottomEdge.StrokeDashArray = new List <float>()
                            {
                                3, 3
                            }.
                            Select(p => new SvgUnit(p)) as SvgUnitCollection;
                        }
                    }

                    var bottomPoints = Drawing.GetBottomPolyline(lvm.Width, lvm.Height, bottomSideCurveGenerator).ToArray();

                    SvgPointCollection svgBottomPoints = new SvgPointCollection();
                    for (int j = 0; j < bottomPoints.Length; j++)
                    {
                        var point = bottomPoints[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgBottomPoints, point);
                    }

                    bottomEdge.Points = svgBottomPoints;

                    levelGroup.Children.Add(bottomEdge);


                    SvgPolygon bckgrPolygon = new SvgPolygon
                    {
                        StrokeWidth = 0f
                    };

                    SvgPatternServer sps = lvm.BackgroundClass.CurrentClass.BackgroundPattern;
                    sps.PatternContentUnits = SvgCoordinateUnits.ObjectBoundingBox;
                    sps.PatternUnits        = SvgCoordinateUnits.UserSpaceOnUse;
                    float ratio = sps.Width.Value / 64f;
                    sps.Width  /= ratio;
                    sps.Height /= ratio;

                    bckgrPolygon.Fill = sps;

                    var bckgrPoints = Drawing.GetBackgroundPolyline(lvm.Width, lvm.Height, rightSideCurveGenerator).ToArray();

                    SvgPointCollection svgBckgrPoints = new SvgPointCollection();
                    for (int j = 0; j < bckgrPoints.Length; j++)
                    {
                        var point = bckgrPoints[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgBckgrPoints, point);
                    }

                    bckgrPolygon.Points = svgBckgrPoints;

                    levelGroup.Children.Add(bckgrPolygon);


                    group.Children.Add(levelGroup);
                }
            }

            result.SVG = group;

            return(result);
        }
コード例 #10
0
 /// <summary>
 /// Addts a point to points
 /// </summary>
 /// <param name="points"></param>
 /// <param name="point"></param>
 private static void AddPointToCollection(SvgPointCollection points, Point point)
 {
     points.Add(Helpers.dtos(point.X));
     points.Add(Helpers.dtos(point.Y));
 }
コード例 #11
0
        public static void DrawOrDiscardEntity(BlockTableRecord btr, Transaction tx,
                                               Matrix3d transform, Svg.SvgGroup group)//, int upscale)
        {
            foreach (oid oid in btr)
            {
                switch (oid.ObjectClass.Name)
                {
                case "AcDbLine":
                    //prdDbg(oid.ObjectClass.Name);
                    Line line = oid.Go <Line>(tx);
                    using (Line newLine = new Line(line.StartPoint, line.EndPoint))
                    {
                        newLine.TransformBy(transform);
                        SvgLine sline = new Svg.SvgLine
                        {
                            StartX      = ts(newLine.StartPoint.X),
                            StartY      = ts(-newLine.StartPoint.Y),
                            EndX        = ts(newLine.EndPoint.X),
                            EndY        = ts(-newLine.EndPoint.Y),
                            StrokeWidth = ts(0.1),
                            Stroke      = new Svg.SvgColourServer(System.Drawing.Color.Black)
                        };
                        //if (flip != Flip.PP)
                        //{
                        //    sline.Transforms = AddTransforms(flip,
                        //        sline.StartX + sline.EndX,
                        //        sline.StartY + sline.EndY);
                        //}
                        group.Children.Add(sline);
                        //mSpc.AppendEntity(newLine);
                        //tx.AddNewlyCreatedDBObject(newLine, true);
                    }
                    break;

                case "AcDbPolyline":
                    //prdDbg(oid.ObjectClass.Name);
                    Polyline pline = oid.Go <Polyline>(tx);
                    using (Polyline newPline = new Polyline(pline.NumberOfVertices))
                    {
                        for (int i = 0; i < pline.NumberOfVertices; i++)
                        {
                            newPline.AddVertexAt(i, pline.GetPoint2dAt(i), 0, 0, 0);
                        }
                        newPline.TransformBy(transform);
                        Extents3d          bbox = newPline.GeometricExtents; //Prepare for Svg.Transforms
                        SvgPointCollection pcol = new SvgPointCollection();
                        for (int i = 0; i < newPline.NumberOfVertices; i++)
                        {
                            Point2d p2d = newPline.GetPoint2dAt(i);
                            pcol.Add(ts(p2d.X));
                            pcol.Add(ts(-p2d.Y));
                        }
                        SvgPolyline sPline = new SvgPolyline();
                        sPline.Points = pcol;
                        if (pline.NumberOfVertices == 2)
                        {
                            sPline.StrokeWidth = ts(0.1);
                            sPline.Stroke      = new SvgColourServer(System.Drawing.Color.Black);
                        }
                        else
                        {
                            sPline.Fill = new SvgColourServer(System.Drawing.Color.Black);
                        }
                        //if (flip != Flip.PP)
                        //{
                        //    sPline.Transforms = AddTransforms(flip,
                        //    ts(bbox.MinPoint.X + bbox.MaxPoint.X),
                        //    ts(bbox.MinPoint.Y + bbox.MaxPoint.Y));
                        //}
                        group.Children.Add(sPline);
                    }
                    break;

                case "AcDbCircle":
                    //prdDbg(oid.ObjectClass.Name);
                    Circle circle = oid.Go <Circle>(tx);
                    using (Circle newCircle = new Circle())
                    {
                        newCircle.SetDatabaseDefaults();
                        newCircle.Center = circle.Center;
                        newCircle.Radius = circle.Radius;
                        newCircle.TransformBy(transform);
                        SvgCircle sCircle = new Svg.SvgCircle
                        {
                            CenterX = ts(newCircle.Center.X),
                            CenterY = ts(-newCircle.Center.Y),
                            Radius  = ts(newCircle.Radius),
                            Fill    = new Svg.SvgColourServer(System.Drawing.Color.Black),
                        };
                        //if (flip != Flip.PP)
                        //{
                        //    sCircle.Transforms = AddTransforms(flip,
                        //    2 * sCircle.CenterX,
                        //    2 * sCircle.CenterY);
                        //}
                        group.Children.Add(sCircle);
                        //mSpc.AppendEntity(newCircle);
                        //tx.AddNewlyCreatedDBObject(newCircle, true);
                    }
                    break;

                case "AcDbMText":
                    prdDbg(oid.ObjectClass.Name);
                    MText  mText = oid.Go <MText>(tx);
                    string text  = mText.Contents;
                    using (DBText newText = new DBText())
                    {
                        newText.SetDatabaseDefaults();
                        newText.TextString = text;
                        newText.Position   = mText.Location;
                        newText.Rotation   = mText.Rotation;
                        //newText.TransformBy(transform);
                        SvgText sText = new SvgText(newText.TextString);
                        prdDbg(ts(newText.Position.X).ToString());
                        prdDbg(ts(newText.Position.Y).ToString());
                        sText.X.Add(ts(newText.Position.X));
                        sText.Y.Add(ts(newText.Position.Y + 0.1));
                        sText.FontFamily = "Arial";
                        sText.FontSize   = ts(0.50);
                        prdDbg(ts(newText.Rotation * (180 / Math.PI)).ToString());
                        sText.Rotate = ts(newText.Rotation * (180 / Math.PI)).ToString();
                        sText.Fill   = new SvgColourServer(System.Drawing.Color.Black);
                        group.Children.Add(sText);
                    }
                    break;

                case "AcDbBlockReference":
                    DrawOrDiscardEntity(tx.GetObject(oid, OpenMode.ForRead) as BlockReference, tx, group);    //, upscale);
                    break;

                default:
                    //prdDbg("Not implemented: " + oid.ObjectClass.Name);
                    break;
                }
            }
        }
コード例 #12
0
        public void CloneReturnsValidObjectType()
        {
            var collection = new SvgPointCollection();

            Assert.IsInstanceOf(typeof(SvgPointCollection), collection.Clone());
        }