예제 #1
0
        public static List <List <Vector2> > GetClipPath(SVGMatrix matrix, SVGRectElement 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);
        }
예제 #2
0
        static void CreateStroke(SVGRectElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

            if (string.IsNullOrEmpty(name))
            {
                name = "Rectangle 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));
             * }
             */
        }
예제 #3
0
        public static List <Vector2> GetPath(SVGMatrix matrix, SVGRectElement svgElement)
        {
            List <Vector2> output = new List <Vector2>();

            float width = svgElement.width.value, height = svgElement.height.value;
            float x = svgElement.x.value, y = svgElement.y.value, rx = svgElement.rx.value, ry = svgElement.ry.value;

            Vector2 p1 = new Vector2(x, y),
                    p2 = new Vector2(x + width, y),
                    p3 = new Vector2(x + width, y + height),
                    p4 = new Vector2(x, y + height);

            if (rx == 0.0f && ry == 0.0f)
            {
                output = new List <Vector2>(new Vector2[] {
                    matrix.Transform(p1),
                    matrix.Transform(p2),
                    matrix.Transform(p3),
                    matrix.Transform(p4)
                });
            }
            else
            {
                float t_rx = (rx == 0.0f) ? ry : rx;
                float t_ry = (ry == 0.0f) ? rx : ry;

                t_rx = (t_rx > (width * 0.5f - 2f)) ? (width * 0.5f - 2f) : t_rx;
                t_ry = (t_ry > (height * 0.5f - 2f)) ? (height * 0.5f - 2f) : t_ry;

                float angle = svgElement.transformAngle;

                Vector2 t_p1 = matrix.Transform(new Vector2(p1.x + t_rx, p1.y));
                Vector2 t_p2 = matrix.Transform(new Vector2(p2.x - t_rx, p2.y));
                Vector2 t_p3 = matrix.Transform(new Vector2(p2.x, p2.y + t_ry));
                Vector2 t_p4 = matrix.Transform(new Vector2(p3.x, p3.y - t_ry));

                Vector2 t_p5 = matrix.Transform(new Vector2(p3.x - t_rx, p3.y));
                Vector2 t_p6 = matrix.Transform(new Vector2(p4.x + t_rx, p4.y));
                Vector2 t_p7 = matrix.Transform(new Vector2(p4.x, p4.y - t_ry));
                Vector2 t_p8 = matrix.Transform(new Vector2(p1.x, p1.y + t_ry));

                output = SVGGeomUtils.RoundedRect(t_p1, t_p2, t_p3, t_p4, t_p5, t_p6, t_p7, t_p8, t_rx, t_ry, angle);
            }

            output.Add(output[0]);

            return(output);
        }
예제 #4
0
        public static void Create(SVGRectElement 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);
            }
        }
예제 #5
0
        static void CreateFill(SVGRectElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

            if (string.IsNullOrEmpty(name))
            {
                name = "Rectangle 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));
             * }
             */
        }
예제 #6
0
 public static List <Vector2> GetPath(SVGRectElement svgElement)
 {
     return(GetPath(SVGMatrix.Identity(), svgElement));
 }
예제 #7
0
 static void CreateStroke(SVGRectElement svgElement)
 {
     string name = svgElement.attrList.GetValue("id");
     if (string.IsNullOrEmpty(name)) name = "Rectangle 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));
     }
 }
예제 #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);
        }
예제 #9
0
 static void CreateFill(SVGRectElement svgElement)
 {
     string name = svgElement.attrList.GetValue("id");
     if (string.IsNullOrEmpty(name)) name = "Rectangle 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));
     }
 }
예제 #10
0
        public static void Create(SVGRectElement 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);
        }
예제 #11
0
 public static List<List<Vector2>> GetClipPath(SVGMatrix matrix, SVGRectElement 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;
 }
예제 #12
0
        public static List<Vector2> GetPath(SVGMatrix matrix, SVGRectElement svgElement)
        {
            List<Vector2> output = new List<Vector2>();

            float width = svgElement.width.value, height = svgElement.height.value;
            float x = svgElement.x.value, y = svgElement.y.value, rx = svgElement.rx.value, ry = svgElement.ry.value;
            
            Vector2 p1 = new Vector2(x, y),
            p2 = new Vector2(x + width, y),
            p3 = new Vector2(x + width, y + height),
            p4 = new Vector2(x, y + height);
            
            if(rx == 0.0f && ry == 0.0f) {
                output = new List<Vector2>(new Vector2[]{
                    matrix.Transform(p1),
                    matrix.Transform(p2),
                    matrix.Transform(p3),
                    matrix.Transform(p4)
                });
            } else {
                float t_rx = (rx == 0.0f) ? ry : rx;
                float t_ry = (ry == 0.0f) ? rx : ry;
                
                t_rx = (t_rx > (width * 0.5f - 2f)) ? (width * 0.5f - 2f) : t_rx;
                t_ry = (t_ry > (height * 0.5f - 2f)) ? (height * 0.5f - 2f) : t_ry;
                
                float angle = svgElement.transformAngle;
                
                Vector2 t_p1 = matrix.Transform(new Vector2(p1.x + t_rx, p1.y));
                Vector2 t_p2 = matrix.Transform(new Vector2(p2.x - t_rx, p2.y));
                Vector2 t_p3 = matrix.Transform(new Vector2(p2.x, p2.y + t_ry));
                Vector2 t_p4 = matrix.Transform(new Vector2(p3.x, p3.y - t_ry));
                
                Vector2 t_p5 = matrix.Transform(new Vector2(p3.x - t_rx, p3.y));
                Vector2 t_p6 = matrix.Transform(new Vector2(p4.x + t_rx, p4.y));
                Vector2 t_p7 = matrix.Transform(new Vector2(p4.x, p4.y - t_ry));
                Vector2 t_p8 = matrix.Transform(new Vector2(p1.x, p1.y + t_ry));
                
                output = SVGGeomUtils.RoundedRect(t_p1, t_p2, t_p3, t_p4, t_p5, t_p6, t_p7, t_p8, t_rx, t_ry, angle);
            }
            
            output.Add(output[0]);

            return output;
        }
예제 #13
0
 public static List<Vector2> GetPath(SVGRectElement svgElement)
 {
     return GetPath(SVGMatrix.Identity(), svgElement);
 }