public static List <List <Vector2> > GetClipPath(SVGMatrix matrix, SVGPolylineElement svgElement)
        {
            List <Vector2> path = GetPath(matrix, svgElement);

            if (path == null || path.Count == 0)
            {
                return(null);
            }

            List <List <Vector2> > clipPath = new List <List <Vector2> >();

            if (svgElement.paintable.IsFill())
            {
                clipPath.Add(path);
            }

            if (svgElement.paintable.IsStroke())
            {
                List <StrokeSegment[]> segments = new List <StrokeSegment[]>()
                {
                    SVGSimplePath.GetSegments(path)
                };
                List <List <Vector2> > strokePath = SVGLineUtils.StrokeShape(segments, svgElement.paintable.strokeWidth, Color.black, SVGSimplePath.GetStrokeLineJoin(svgElement.paintable.strokeLineJoin), SVGSimplePath.GetStrokeLineCap(svgElement.paintable.strokeLineCap), svgElement.paintable.miterLimit, svgElement.paintable.dashArray, svgElement.paintable.dashOffset, ClosePathRule.NEVER, SVGGraphics.roundQuality);
                if (strokePath != null && strokePath.Count > 0)
                {
                    clipPath.AddRange(strokePath);
                }
            }

            return(clipPath);
        }
Beispiel #2
0
        static void CreateStroke(SVGPolylineElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

            if (string.IsNullOrEmpty(name))
            {
                name = "Polyline Stroke ";
            }

            List <List <Vector2> > stroke = SVGSimplePath.CreateStroke(SVGGraphics.position_buffer, svgElement.paintable, ClosePathRule.NEVER);

            if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
            {
                stroke = SVGGeom.ClipPolygon(stroke, svgElement.paintable.clipPathList);
            }

            Mesh antialiasingMesh;
            Mesh mesh = SVGLineUtils.TessellateStroke(stroke, SVGSimplePath.GetStrokeColor(svgElement.paintable), out antialiasingMesh);

            if (mesh == null)
            {
                return;
            }
            mesh.name = name;
            SVGGraphics.AddMesh(new SVGMesh(mesh, svgElement.paintable.svgFill, svgElement.paintable.opacity));
            if (antialiasingMesh != null)
            {
                SVGFill svgFill = svgElement.paintable.svgFill.Clone();
                svgFill.blend = FILL_BLEND.ALPHA_BLENDED;
                SVGGraphics.AddMesh(new SVGMesh(antialiasingMesh, svgFill, svgElement.paintable.opacity));
            }
        }
        static void CreateStroke(SVGPolylineElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

            if (string.IsNullOrEmpty(name))
            {
                name = "Polyline Stroke ";
            }

            List <List <Vector2> > path = SVGSimplePath.CreateStroke(SVGGraphics.position_buffer, svgElement.paintable, ClosePathRule.NEVER);

            if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
            {
                path = SVGGeom.ClipPolygon(path, svgElement.paintable.clipPathList);
            }

            SVGGraphics.AddLayer(name, path, svgElement.paintable, svgElement.transformMatrix, true);

            /*
             * Mesh antialiasingMesh;
             * Mesh mesh = SVGLineUtils.TessellateStroke(path, SVGSimplePath.GetStrokeColor(svgElement.paintable), out antialiasingMesh);
             * if(mesh == null) return;
             * mesh.name = name;
             * SVGGraphics.AddLayer(new SVGMesh(mesh, svgElement.paintable.svgFill, svgElement.paintable.opacity));
             * if(antialiasingMesh != null)
             * {
             *  SVGFill svgFill = svgElement.paintable.svgFill.Clone();
             *  svgFill.blend = FILL_BLEND.ALPHA_BLENDED;
             *  SVGGraphics.AddLayer(new SVGMesh(antialiasingMesh, svgFill, svgElement.paintable.opacity));
             * }
             */
        }
        public static List<Vector2> GetPath(SVGMatrix matrix, SVGPolylineElement svgElement)
        {
            List<Vector2> output = new List<Vector2>(svgElement.listPoints.Count + 1);
            List<Vector2> listPoints = svgElement.listPoints;
            for (int i = 0; i < listPoints.Count; i++)
            {
                output.Add(matrix.Transform(listPoints[i]));
            }

            // Douglas Peucker Reduction
            return SVGBezier.Optimise(output, SVGGraphics.vpm);
        }
        public static List <Vector2> GetPath(SVGMatrix matrix, SVGPolylineElement svgElement)
        {
            List <Vector2> output     = new List <Vector2>(svgElement.listPoints.Count + 1);
            List <Vector2> listPoints = svgElement.listPoints;

            for (int i = 0; i < listPoints.Count; i++)
            {
                output.Add(matrix.Transform(listPoints[i]));
            }

            // Douglas Peucker Reduction
            return(SVGBezier.Optimise(output, SVGGraphics.vpm));
        }
        public static void Create(SVGPolylineElement svgElement)
        {
            if (svgElement.paintable.visibility != SVGVisibility.Visible || svgElement.paintable.display == SVGDisplay.None)
            {
                return;
            }

            SVGGraphics.position_buffer = GetPath(svgElement.transformMatrix, svgElement);

            if (svgElement.paintable.IsFill())
            {
                CreateFill(svgElement);
            }
            if (svgElement.paintable.IsStroke())
            {
                CreateStroke(svgElement);
            }
        }
        static void CreateFill(SVGPolylineElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

            if (string.IsNullOrEmpty(name))
            {
                name = "Polyline Fill";
            }

            List <List <Vector2> > path;

            if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
            {
                path = SVGGeom.ClipPolygon(new List <List <Vector2> >()
                {
                    SVGGraphics.position_buffer
                }, svgElement.paintable.clipPathList);
            }
            else
            {
                path = new List <List <Vector2> >()
                {
                    SVGGraphics.position_buffer
                };
            }

            SVGGraphics.AddLayer(name, path, svgElement.paintable, svgElement.transformMatrix);

            /*
             * Mesh antialiasingMesh;
             * Mesh mesh = SVGSimplePath.CreatePolygon(path, svgElement.paintable, svgElement.transformMatrix, out antialiasingMesh);
             * if(mesh == null) return;
             * mesh.name = name;
             * SVGGraphics.AddLayer(new SVGMesh(mesh, svgElement.paintable.svgFill, svgElement.paintable.opacity));
             * if(antialiasingMesh != null)
             * {
             *  SVGFill svgFill = svgElement.paintable.svgFill.Clone();
             *  svgFill.blend = FILL_BLEND.ALPHA_BLENDED;
             *  SVGGraphics.AddLayer(new SVGMesh(antialiasingMesh, svgFill, svgElement.paintable.opacity));
             * }
             */
        }
 public static List <Vector2> GetPath(SVGPolylineElement svgElement)
 {
     return(GetPath(SVGMatrix.Identity(), svgElement));
 }
Beispiel #9
0
        private List <List <Vector2> > GetClipPath(Node node, SVGMatrix svgMatrix)
        {
            SVGTransformList transformList = new SVGTransformList();

            switch (node.name)
            {
            case SVGNodeName.Rect:
            {
                return(SVGRectElement.GetClipPath(svgMatrix, new SVGRectElement(node, transformList)));
            }

            case SVGNodeName.Line:
            {
                return(SVGLineElement.GetClipPath(svgMatrix, new SVGLineElement(node, transformList)));
            }

            case SVGNodeName.Circle:
            {
                return(SVGCircleElement.GetClipPath(svgMatrix, new SVGCircleElement(node, transformList)));
            }

            case SVGNodeName.Ellipse:
            {
                return(SVGEllipseElement.GetClipPath(svgMatrix, new SVGEllipseElement(node, transformList)));
            }

            case SVGNodeName.PolyLine:
            {
                return(SVGPolylineElement.GetClipPath(svgMatrix, new SVGPolylineElement(node, transformList)));
            }

            case SVGNodeName.Polygon:
            {
                return(SVGPolygonElement.GetClipPath(svgMatrix, new SVGPolygonElement(node, transformList)));
            }

            case SVGNodeName.Path:
            {
                return(SVGPathElement.GetClipPath(svgMatrix, new SVGPathElement(node, transformList)));
            }

            case SVGNodeName.Use:
            {
                string xlink = node.attributes.GetValue("xlink:href");
                if (!string.IsNullOrEmpty(xlink))
                {
                    if (xlink [0] == '#')
                    {
                        xlink = xlink.Remove(0, 1);
                    }

                    if (SVGParser._defs.ContainsKey(xlink))
                    {
                        Node definitionNode = SVGParser._defs [xlink];
                        if (definitionNode != null && definitionNode != node)
                        {
                            return(GetClipPath(definitionNode, svgMatrix));
                        }
                    }
                }
                break;
            }
            }

            return(null);
        }
 public static List<List<Vector2>> GetClipPath(SVGMatrix matrix, SVGPolylineElement svgElement)
 {
     List<Vector2> path = GetPath(matrix, svgElement);
     if(path == null || path.Count == 0) return null;
     
     List<List<Vector2>> clipPath = new List<List<Vector2>>();
     if(svgElement.paintable.IsFill())
     {
         clipPath.Add(path);
     }
     
     if(svgElement.paintable.IsStroke())
     {
         List<StrokeSegment[]> segments = new List<StrokeSegment[]>(){SVGSimplePath.GetSegments(path)};
         List<List<Vector2>> strokePath = SVGLineUtils.StrokeShape(segments, svgElement.paintable.strokeWidth, Color.black, SVGSimplePath.GetStrokeLineJoin(svgElement.paintable.strokeLineJoin), SVGSimplePath.GetStrokeLineCap(svgElement.paintable.strokeLineCap), svgElement.paintable.miterLimit, svgElement.paintable.dashArray, svgElement.paintable.dashOffset, ClosePathRule.NEVER, SVGGraphics.roundQuality);
         if(strokePath != null && strokePath.Count > 0) clipPath.AddRange(strokePath);
     }
     
     return clipPath;
 }
 public static List<Vector2> GetPath(SVGPolylineElement svgElement)
 {
     return GetPath(SVGMatrix.Identity(), svgElement);
 }
        static void CreateStroke(SVGPolylineElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");
            if (string.IsNullOrEmpty(name))
                name = "Polyline Stroke ";

            List<List<Vector2>> stroke = SVGSimplePath.CreateStroke(SVGGraphics.position_buffer, svgElement.paintable, ClosePathRule.NEVER);
            if(svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
            {
                stroke = SVGGeom.ClipPolygon(stroke, svgElement.paintable.clipPathList);
            }
            
            Mesh antialiasingMesh;
            Mesh mesh = SVGLineUtils.TessellateStroke(stroke, SVGSimplePath.GetStrokeColor(svgElement.paintable), out antialiasingMesh);
            if(mesh == null) return;            
            mesh.name = name;
            SVGGraphics.AddMesh(new SVGMesh(mesh, svgElement.paintable.svgFill, svgElement.paintable.opacity));
            if(antialiasingMesh != null)
            {
                SVGFill svgFill = svgElement.paintable.svgFill.Clone();
                svgFill.blend = FILL_BLEND.ALPHA_BLENDED;
                SVGGraphics.AddMesh(new SVGMesh(antialiasingMesh, svgFill, svgElement.paintable.opacity));
            }
        }
 static void CreateFill(SVGPolylineElement svgElement)
 {
     string name = svgElement.attrList.GetValue("id");
     if (string.IsNullOrEmpty(name))
         name = "Polyline Fill";
     
     List<List<Vector2>> path;
     if(svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
     {
         path = SVGGeom.ClipPolygon(new List<List<Vector2>>(){SVGGraphics.position_buffer}, svgElement.paintable.clipPathList);
     } else {
         path = new List<List<Vector2>>(){SVGGraphics.position_buffer};
     }
     
     Mesh antialiasingMesh;
     Mesh mesh = SVGSimplePath.CreatePolygon(path, svgElement.paintable, svgElement.transformMatrix, out antialiasingMesh);
     if(mesh == null) return;
     mesh.name = name;
     SVGGraphics.AddMesh(new SVGMesh(mesh, svgElement.paintable.svgFill, svgElement.paintable.opacity));
     if(antialiasingMesh != null)
     {
         SVGFill svgFill = svgElement.paintable.svgFill.Clone();
         svgFill.blend = FILL_BLEND.ALPHA_BLENDED;
         SVGGraphics.AddMesh(new SVGMesh(antialiasingMesh, svgFill, svgElement.paintable.opacity));
     }
 }
        public static void Create(SVGPolylineElement svgElement)
        {
            if(svgElement.paintable.visibility != SVGVisibility.Visible || svgElement.paintable.display == SVGDisplay.None)
                return;

            SVGGraphics.position_buffer = GetPath(svgElement.transformMatrix, svgElement);
            
            if(svgElement.paintable.IsFill())
                CreateFill(svgElement);
            if(svgElement.paintable.IsStroke())
                CreateStroke(svgElement);
        }