コード例 #1
0
        VgVisualElement CreatePolyline(VgVisualElement parentNode, SvgPolylineSpec polylineSpec)
        {
            VgVisualElement vgPolyline = new VgVisualElement(WellknownSvgElementName.Polyline, polylineSpec, _vgVisualDoc);

            PointF[] points = polylineSpec.Points;
            int      j      = points.Length;

            if (j > 1)
            {
                using (Tools.BorrowVxs(out var v1))
                {
                    PointF p = points[0];
                    v1.AddMoveTo(p.X, p.Y);
                    for (int i = 1; i < j; ++i)
                    {
                        p = points[i];
                        v1.AddLineTo(p.X, p.Y);
                    }
                    vgPolyline.VxsPath = v1.CreateTrim();
                }
                AssignAttributes(polylineSpec);

                //--------------------------------------------------------------------
                ResolveMarkers(vgPolyline, polylineSpec);
                if (vgPolyline._pathMarkers != null)
                {
                    //create primary instance plan for this polyline
                    VgPathVisualMarkers pathMarkers = vgPolyline._pathMarkers;
                    pathMarkers.AllPoints = points;

                    //start, mid, end
                    if (pathMarkers.StartMarker != null)
                    {
                        //turn marker to the start direction
                        PointF p0 = points[0];
                        PointF p1 = points[1];
                        //find rotation angle
                        double        rotateRad  = Math.Atan2(p0.Y - p1.Y, p0.X - p1.X);
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.StartMarker._visualSpec;

                        //create local-transformation matrix
                        pathMarkers.StartMarkerPos = new PointF(p0.X, p0.Y);

                        AffineMat mat = AffineMat.Iden();
                        mat.Translate(-markerSpec.RefX.Number, -markerSpec.RefY.Number); //move to the ref point
                        mat.Rotate(rotateRad);

                        pathMarkers.StartMarkerAffine = new Affine(mat);
                    }
                    //-------------------------------
                    if (pathMarkers.MidMarker != null)
                    {
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.StartMarker._visualSpec;
                        pathMarkers.MidMarkerAffine = Affine.NewTranslation(-markerSpec.RefX.Number, -markerSpec.RefY.Number);
                    }
                    //-------------------------------
                    if (pathMarkers.EndMarker != null)
                    {
                        //turn marker to the start direction
                        PointF p0 = points[j - 2]; //before the last one
                        PointF p1 = points[j - 1]; //the last one
                                                   //find rotation angle
                        double        rotateRad  = Math.Atan2(p1.Y - p0.Y, p1.X - p0.X);
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.EndMarker._visualSpec;


                        //create local-transformation matrix
                        pathMarkers.EndMarkerPos = new PointF(p1.X, p1.Y);

                        AffineMat mat = AffineMat.Iden();
                        mat.Translate(-markerSpec.RefX.Number, -markerSpec.RefY.Number); //move to the ref point
                        mat.Rotate(rotateRad);
                        pathMarkers.EndMarkerAffine = new Affine(mat);
                    }
                }
            }
            return(vgPolyline);
        }