Exemplo n.º 1
0
        static void CreateStroke(SVGPolygonElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

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

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

            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(stroke, 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));
             * }
             */
        }
Exemplo n.º 2
0
        public static List <List <Vector2> > GetClipPath(SVGMatrix matrix, SVGPolygonElement 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.ALWAYS, SVGGraphics.roundQuality);
                if (strokePath != null && strokePath.Count > 0)
                {
                    clipPath.AddRange(strokePath);
                }
            }

            return(clipPath);
        }
        public static List<Vector2> GetPath(SVGMatrix matrix, SVGPolygonElement 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]));
            }
            output.Add(output[0]);

            // Douglas Peucker Reduction
            return SVGBezier.Optimise(output, SVGGraphics.vpm);
        }
Exemplo n.º 4
0
        public static List <Vector2> GetPath(SVGMatrix matrix, SVGPolygonElement 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]));
            }
            output.Add(output[0]);

            // Douglas Peucker Reduction
            return(SVGBezier.Optimise(output, SVGGraphics.vpm));
        }
Exemplo n.º 5
0
        public static void Create(SVGPolygonElement 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);
            }
        }
Exemplo n.º 6
0
        static void CreateFill(SVGPolygonElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

            if (string.IsNullOrEmpty(name))
            {
                name = "Polygon 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));
             * }
             */
        }
Exemplo n.º 7
0
 public static List <Vector2> GetPath(SVGPolygonElement svgElement)
 {
     return(GetPath(SVGMatrix.Identity(), svgElement));
 }
Exemplo n.º 8
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, SVGPolygonElement 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.ALWAYS, SVGGraphics.roundQuality);
         if(strokePath != null && strokePath.Count > 0) clipPath.AddRange(strokePath);
     }
     
     return clipPath;
 }
 public static List<Vector2> GetPath(SVGPolygonElement svgElement)
 {
     return GetPath(SVGMatrix.Identity(), svgElement);
 }
 static void CreateStroke(SVGPolygonElement svgElement)
 {
     string name = svgElement.attrList.GetValue("id");
     if (string.IsNullOrEmpty(name))
         name = "Polygon Stroke ";
     
     List<List<Vector2>> stroke = SVGSimplePath.CreateStroke(SVGGraphics.position_buffer, svgElement.paintable, ClosePathRule.ALWAYS);
     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(SVGPolygonElement svgElement)
 {
     string name = svgElement.attrList.GetValue("id");
     if (string.IsNullOrEmpty(name))
         name = "Polygon 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(SVGPolygonElement 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);
        }