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

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

            List <List <Vector2> > stroke = SVGSimplePath.CreateStroke(paths, svgElement.paintable, ClosePathRule.AUTO);

            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));
            }
        }
Exemplo n.º 2
0
        public static List <List <Vector2> > GetPaths(SVGMatrix matrix, SVGPathElement svgElement)
        {
            lastCommand = SVGPathSegTypes.Unknown;

            List <Vector2>         positionBuffer = new List <Vector2>();
            List <List <Vector2> > output         = new List <List <Vector2> >();
            SVGPathSegList         segList        = svgElement.segList;

            for (int i = 0; i < segList.Count; i++)
            {
                GetSegment(svgElement, segList.GetItem(i), output, positionBuffer, matrix);
            }

            if (lastCommand != SVGPathSegTypes.Close && positionBuffer.Count > 0)
            {
                output.Add(new List <Vector2>(positionBuffer.ToArray()));
            }

            //Vector2 startPoint, endPoint;
            for (int i = 0; i < output.Count; i++)
            {
                // Ramer Douglas Peucker Reduction
                if (output[i] == null || output[i].Count < 3)
                {
                    continue;
                }
                output[i] = SVGBezier.Optimise(output[i], SVGGraphics.vpm);
            }

            return(output);
        }
Exemplo n.º 3
0
        static void CreateStroke(SVGPathElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

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

            List <List <Vector2> > path = SVGSimplePath.CreateStroke(paths, svgElement.paintable, ClosePathRule.AUTO);

            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));
             * }
             */
        }
Exemplo n.º 4
0
        public static void Create(SVGPathElement svgElement)
        {
            if (svgElement.paintable.visibility != SVGVisibility.Visible || svgElement.paintable.display == SVGDisplay.None)
            {
                return;
            }

            paths = GetPaths(svgElement.transformMatrix, svgElement);

            if (svgElement.paintable.IsFill())
            {
                CreateFill(svgElement);
            }
            if (svgElement.paintable.IsStroke())
            {
                CreateStroke(svgElement);
            }

            paths = null;
        }
Exemplo n.º 5
0
        public static List <List <Vector2> > GetClipPath(SVGMatrix matrix, SVGPathElement svgElement)
        {
            List <List <Vector2> > path = GetPaths(matrix, svgElement);

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

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

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

            if (svgElement.paintable.IsStroke())
            {
                List <StrokeSegment[]> segments = new List <StrokeSegment[]>();
                for (int i = 0; i < path.Count; i++)
                {
                    if (path[i] == null || path[i].Count < 2)
                    {
                        continue;
                    }
                    segments.Add(SVGSimplePath.GetSegments(path[i]));
                }

                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.AUTO, SVGGraphics.roundQuality);
                if (strokePath != null && strokePath.Count > 0)
                {
                    clipPath.AddRange(strokePath);
                }
            }

            return(clipPath);
        }
Exemplo n.º 6
0
        static void CreateFill(SVGPathElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");

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

            List <List <Vector2> > path;

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

            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));
            }
        }
Exemplo n.º 7
0
        bool GetSegment(SVGPathElement svgElement, SVGPathSeg segment, List <List <Vector2> > output, List <Vector2> positionBuffer, SVGMatrix matrix)
        {
            if (segment == null)
            {
                return(false);
            }

//            Debug.Log("command: "+segment.type+", lastCommand: "+lastCommand);

            switch (segment.type)
            {
            case SVGPathSegTypes.Arc_Abs:
                SVGPathSegArcAbs arcAbs = segment as SVGPathSegArcAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("arcAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcAbs.previousPoint, matrix), arcAbs.r1, arcAbs.r2, arcAbs.angle, arcAbs.largeArcFlag, arcAbs.sweepFlag, SVGGeomUtils.TransformPoint(arcAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.Arc_Rel:
                SVGPathSegArcRel arcRel = segment as SVGPathSegArcRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("arcRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcRel.previousPoint, matrix), arcRel.r1, arcRel.r2, arcRel.angle, arcRel.largeArcFlag, arcRel.sweepFlag, SVGGeomUtils.TransformPoint(arcRel.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.Close:
                    #if PATH_COMMAND_DEBUG
                Debug.Log("Close");
                    #endif
                //Debug.Log("Close");
                if (positionBuffer.Count > 0)
                {
                    output.Add(new List <Vector2>(positionBuffer.ToArray()));
                }
                positionBuffer.Clear();
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Abs:
                SVGPathSegCurvetoCubicAbs curvetoCubicAbs = segment as SVGPathSegCurvetoCubicAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Rel:
                SVGPathSegCurvetoCubicRel curvetoCubicRel = segment as SVGPathSegCurvetoCubicRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Smooth_Abs:
                SVGPathSegCurvetoCubicSmoothAbs curvetoCubicSmoothAbs = segment as SVGPathSegCurvetoCubicSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicSmoothAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Smooth_Rel:
                SVGPathSegCurvetoCubicSmoothRel curvetoCubicSmoothRel = segment as SVGPathSegCurvetoCubicSmoothRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicSmoothRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Abs:
                SVGPathSegCurvetoQuadraticAbs curvetoQuadraticAbs = segment as SVGPathSegCurvetoQuadraticAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Rel:
                SVGPathSegCurvetoQuadraticRel curvetoQuadraticRel = segment as SVGPathSegCurvetoQuadraticRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Abs:
                SVGPathSegCurvetoQuadraticSmoothAbs curvetoQuadraticSmoothAbs = segment as SVGPathSegCurvetoQuadraticSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticSmoothAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Rel:
                SVGPathSegCurvetoQuadraticSmoothRel curvetoQuadraticSmoothRel = segment as SVGPathSegCurvetoQuadraticSmoothRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticSmoothRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.LineTo_Abs:
                SVGPathSegLinetoAbs linetoAbs = segment as SVGPathSegLinetoAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoAbs");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Horizontal_Abs:
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoHorizontalAbs");
                    #endif
                SVGPathSegLinetoHorizontalAbs linetoHorizontalAbs = segment as SVGPathSegLinetoHorizontalAbs;
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Horizontal_Rel:
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoHorizontalRel");
                    #endif
                SVGPathSegLinetoHorizontalRel linetoHorizontalRel = segment as SVGPathSegLinetoHorizontalRel;
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalRel.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Rel:
                SVGPathSegLinetoRel linetoRel = segment as SVGPathSegLinetoRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoRel");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoRel.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Vertical_Abs:
                SVGPathSegLinetoVerticalAbs linetoVerticalAbs = segment as SVGPathSegLinetoVerticalAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoVerticalAbs");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Vertical_Rel:
                SVGPathSegLinetoVerticalRel linetoVerticalRel = segment as SVGPathSegLinetoVerticalRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoVerticalRel");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalRel.currentPoint, matrix));
                break;

            case SVGPathSegTypes.MoveTo_Abs:
                if (lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                {
                    if (positionBuffer.Count > 0)
                    {
                        output.Add(new List <Vector2>(positionBuffer.ToArray()));
                        positionBuffer.Clear();
                    }
                }
                SVGPathSegMovetoAbs movetoAbs = segment as SVGPathSegMovetoAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("movetoAbs");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.MoveTo_Rel:
                if (lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                {
                    if (positionBuffer.Count > 0)
                    {
                        output.Add(new List <Vector2>(positionBuffer.ToArray()));
                        positionBuffer.Clear();
                    }
                }
                SVGPathSegMovetoRel movetoRel = segment as SVGPathSegMovetoRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("movetoRel");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoRel.currentPoint, matrix));
                break;
            }

            lastCommand = segment.type;
            return(true);
        }
Exemplo n.º 8
0
        static bool GetSegment(SVGPathElement svgElement, SVGPathSeg segment, List<List<Vector2>> output, List<Vector2> positionBuffer, SVGMatrix matrix)
        {
            if (segment == null)
                return false;

//            Debug.Log("command: "+segment.type+", lastCommand: "+lastCommand);

            switch (segment.type)
            {
                case SVGPathSegTypes.Arc_Abs:
                    SVGPathSegArcAbs arcAbs = segment as SVGPathSegArcAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("arcAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcAbs.previousPoint, matrix), arcAbs.r1, arcAbs.r2, arcAbs.angle, arcAbs.largeArcFlag, arcAbs.sweepFlag, SVGGeomUtils.TransformPoint(arcAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.Arc_Rel:
                    SVGPathSegArcRel arcRel = segment as SVGPathSegArcRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("arcRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcRel.previousPoint, matrix), arcRel.r1, arcRel.r2, arcRel.angle, arcRel.largeArcFlag, arcRel.sweepFlag, SVGGeomUtils.TransformPoint(arcRel.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.Close:
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("Close");
                    #endif
                    //Debug.Log("Close");
                    if(positionBuffer.Count > 0)
                    {
                        output.Add(new List<Vector2>(positionBuffer.ToArray()));
                    }
                    positionBuffer.Clear();
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Abs:
                    SVGPathSegCurvetoCubicAbs curvetoCubicAbs = segment as SVGPathSegCurvetoCubicAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Rel:
                    SVGPathSegCurvetoCubicRel curvetoCubicRel = segment as SVGPathSegCurvetoCubicRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicRel");
                    #endif          
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Smooth_Abs:
                    SVGPathSegCurvetoCubicSmoothAbs curvetoCubicSmoothAbs = segment as SVGPathSegCurvetoCubicSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicSmoothAbs");
                    #endif               
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Smooth_Rel:
                    SVGPathSegCurvetoCubicSmoothRel curvetoCubicSmoothRel = segment as SVGPathSegCurvetoCubicSmoothRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicSmoothRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Abs:
                    SVGPathSegCurvetoQuadraticAbs curvetoQuadraticAbs = segment as SVGPathSegCurvetoQuadraticAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Rel:
                    SVGPathSegCurvetoQuadraticRel curvetoQuadraticRel = segment as SVGPathSegCurvetoQuadraticRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Abs:
                    SVGPathSegCurvetoQuadraticSmoothAbs curvetoQuadraticSmoothAbs = segment as SVGPathSegCurvetoQuadraticSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticSmoothAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Rel:
                    SVGPathSegCurvetoQuadraticSmoothRel curvetoQuadraticSmoothRel = segment as SVGPathSegCurvetoQuadraticSmoothRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticSmoothRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.LineTo_Abs:
                    SVGPathSegLinetoAbs linetoAbs = segment as SVGPathSegLinetoAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoAbs");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Horizontal_Abs:
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoHorizontalAbs");
                    #endif
                    SVGPathSegLinetoHorizontalAbs linetoHorizontalAbs = segment as SVGPathSegLinetoHorizontalAbs;
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Horizontal_Rel:
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoHorizontalRel");
                    #endif
                    SVGPathSegLinetoHorizontalRel linetoHorizontalRel = segment as SVGPathSegLinetoHorizontalRel;
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalRel.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Rel:
                    SVGPathSegLinetoRel linetoRel = segment as SVGPathSegLinetoRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoRel");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoRel.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Vertical_Abs:
                    SVGPathSegLinetoVerticalAbs linetoVerticalAbs = segment as SVGPathSegLinetoVerticalAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoVerticalAbs");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Vertical_Rel:
                    SVGPathSegLinetoVerticalRel linetoVerticalRel = segment as SVGPathSegLinetoVerticalRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoVerticalRel");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalRel.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.MoveTo_Abs:
                    if(lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                    {
                        if(positionBuffer.Count > 0)
                        {
                            output.Add(new List<Vector2>(positionBuffer.ToArray()));
                            positionBuffer.Clear();
                        }
                    }
                    SVGPathSegMovetoAbs movetoAbs = segment as SVGPathSegMovetoAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("movetoAbs");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.MoveTo_Rel:
                    if(lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                    {
                        if(positionBuffer.Count > 0)
                        {
                            output.Add(new List<Vector2>(positionBuffer.ToArray()));
                            positionBuffer.Clear();
                        }
                    }
                    SVGPathSegMovetoRel movetoRel = segment as SVGPathSegMovetoRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("movetoRel");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoRel.currentPoint, matrix));
                    break;
            }
            
            lastCommand = segment.type;
            return true;
        }
Exemplo n.º 9
0
        static void CreateStroke(SVGPathElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");
            if (string.IsNullOrEmpty(name))
                name = "Path Stroke ";

            List<List<Vector2>> stroke = SVGSimplePath.CreateStroke(paths, svgElement.paintable, ClosePathRule.AUTO);
            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));
            }
        }
Exemplo n.º 10
0
        static void CreateFill(SVGPathElement svgElement)
        {
            string name = svgElement.attrList.GetValue("id");
            if (string.IsNullOrEmpty(name))
                name = "Path Fill";

            List<List<Vector2>> path;
            if(svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
            {
                path = SVGGeom.ClipPolygon(paths, svgElement.paintable.clipPathList);
            } else {
                path = paths;
            }
            
            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));
            }
        }
Exemplo n.º 11
0
        public static void Create(SVGPathElement svgElement)
        {
            if(svgElement.paintable.visibility != SVGVisibility.Visible || svgElement.paintable.display == SVGDisplay.None)
                return;

            paths = GetPaths(svgElement.transformMatrix, svgElement);

            if(svgElement.paintable.IsFill())
                CreateFill(svgElement);
            if(svgElement.paintable.IsStroke())
                CreateStroke(svgElement); 

            paths = null;
        }
Exemplo n.º 12
0
        public static List<List<Vector2>> GetClipPath(SVGMatrix matrix, SVGPathElement svgElement)
        {
            List<List<Vector2>> path = GetPaths(matrix, svgElement);
            if(path == null || path.Count == 0) return null;

            List<List<Vector2>> clipPath = new List<List<Vector2>>();
            if(svgElement.paintable.IsFill())
            {
                clipPath.AddRange(path);
            }

            if(svgElement.paintable.IsStroke())
            {
                List<StrokeSegment[]> segments = new List<StrokeSegment[]>();
                for(int i = 0; i < path.Count; i++)
                {
                    if(path[i] == null || path[i].Count < 2) continue;
                    segments.Add(SVGSimplePath.GetSegments(path[i]));
                }

                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.AUTO, SVGGraphics.roundQuality);
                if(strokePath != null && strokePath.Count > 0) clipPath.AddRange(strokePath);
            }

            return clipPath;
        }
Exemplo n.º 13
0
        public static List<List<Vector2>> GetPaths(SVGMatrix matrix, SVGPathElement svgElement)
        {            
            lastCommand = SVGPathSegTypes.Unknown;

            List<Vector2> positionBuffer = new List<Vector2>();
            List<List<Vector2>> output = new List<List<Vector2>>();
            SVGPathSegList segList = svgElement.segList;

            for (int i = 0; i < segList.Count; i++)
            {
                GetSegment(svgElement, segList.GetItem(i), output, positionBuffer, matrix);
            }
            
            if(lastCommand != SVGPathSegTypes.Close && positionBuffer.Count > 0)
            {
                output.Add(new List<Vector2>(positionBuffer.ToArray()));
            }

            //Vector2 startPoint, endPoint;
            for(int i = 0; i < output.Count; i++)
            {
                // Ramer Douglas Peucker Reduction
                if(output[i] == null || output[i].Count < 3) continue;
                output[i] = SVGBezier.Optimise(output[i], SVGGraphics.vpm);
            }

            return output;
        }
Exemplo n.º 14
0
 public static List<List<Vector2>> GetPaths(SVGPathElement svgElement)
 {
     return GetPaths(SVGMatrix.Identity(), svgElement);
 }
Exemplo n.º 15
0
 public static List <List <Vector2> > GetPaths(SVGPathElement svgElement)
 {
     return(GetPaths(SVGMatrix.Identity(), svgElement));
 }
Exemplo n.º 16
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);
        }